Skip to content

Commit

Permalink
rename metrics and service
Browse files Browse the repository at this point in the history
Signed-off-by: Kavindu Dodanduwa <[email protected]>
  • Loading branch information
Kavindu-Dodan committed Jul 4, 2023
1 parent f3fbe6d commit 9d2aba1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion core/pkg/runtime/from_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
syncProviderGrpc = "grpc"
syncProviderKubernetes = "kubernetes"
syncProviderHTTP = "http"
svcName = "openfeature/flagd"
svcName = "flagd"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion core/pkg/service/sync/sync_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
serviceName = "openfeature/flagd-proxy"
serviceName = "flagd-proxy"
)

func (s *Server) captureMetrics() error {
Expand Down
37 changes: 22 additions & 15 deletions core/pkg/telemetry/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ import (
)

const (
requestDurationName = "http_request_duration_seconds"
responseSizeName = "http_response_size_bytes"
FlagdProviderName = "flagd"
FeatureFlagReasonKeyName = "feature_flag.reason"
ExceptionTypeKeyName = "exception.type"
FeatureFlagReasonKey = attribute.Key(FeatureFlagReasonKeyName)
ExceptionTypeKey = attribute.Key(ExceptionTypeKeyName)
ProviderName = "flagd"

FeatureFlagReasonKey = attribute.Key("feature_flag.reason")
ExceptionTypeKey = attribute.Key("ExceptionTypeKeyName")

httpRequestDurationMetric = "http.server.duration"
httpResponseSizeMetric = "http.server.response.size"
httpActiveRequestsMetric = "http.server.active_requests"
impressionMetric = "feature_flag." + ProviderName + ".impression"
reasonMetric = "feature_flag." + ProviderName + ".evaluation.reason"
)

type MetricsRecorder struct {
Expand Down Expand Up @@ -72,7 +75,7 @@ func (r MetricsRecorder) Impressions(ctx context.Context, reason, variant, key s

func (r MetricsRecorder) Reasons(ctx context.Context, key string, reason string, err error) {
attrs := []attribute.KeyValue{
semconv.FeatureFlagProviderName(FlagdProviderName),
semconv.FeatureFlagProviderName(ProviderName),
FeatureFlagReason(reason),
}
if err == nil {
Expand Down Expand Up @@ -116,9 +119,9 @@ func NewOTelRecorder(exporter msdk.Reader, resource *resource.Resource, serviceN
provider := msdk.NewMeterProvider(
msdk.WithReader(exporter),
// for the request duration metric we use the default bucket size which are tailored for response time in seconds
msdk.WithView(getDurationView(requestDurationName, serviceName, prometheus.DefBuckets)),
msdk.WithView(getDurationView(httpRequestDurationMetric, serviceName, prometheus.DefBuckets)),
// for response size we want 8 exponential bucket starting from 100 Bytes
msdk.WithView(getDurationView(responseSizeName, serviceName, prometheus.ExponentialBuckets(100, 10, 8))),
msdk.WithView(getDurationView(httpResponseSizeMetric, serviceName, prometheus.ExponentialBuckets(100, 10, 8))),
// set entity producing telemetry
msdk.WithResource(resource),
)
Expand All @@ -127,25 +130,29 @@ func NewOTelRecorder(exporter msdk.Reader, resource *resource.Resource, serviceN

// we can ignore errors from OpenTelemetry since they could occur if we select the wrong aggregator
hduration, _ := meter.Float64Histogram(
requestDurationName,
httpRequestDurationMetric,
metric.WithDescription("The latency of the HTTP requests"),
metric.WithUnit("s"),
)
hsize, _ := meter.Float64Histogram(
responseSizeName,
httpResponseSizeMetric,
metric.WithDescription("The size of the HTTP responses"),
metric.WithUnit("By"),
)
reqCounter, _ := meter.Int64UpDownCounter(
"http_requests_inflight",
httpActiveRequestsMetric,
metric.WithDescription("The number of inflight requests being handled at the same time"),
metric.WithUnit("{request}"),
)
impressions, _ := meter.Int64Counter(
"impressions",
impressionMetric,
metric.WithDescription("The number of evaluations for a given flag"),
metric.WithUnit("{impression}"),
)
reasons, _ := meter.Int64Counter(
"reasons",
reasonMetric,
metric.WithDescription("The number of evaluations for a given reason"),
metric.WithUnit("{reason}"),
)
return &MetricsRecorder{
httpRequestDurHistogram: hduration,
Expand Down

0 comments on commit 9d2aba1

Please sign in to comment.