Skip to content

Commit

Permalink
improve explain telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Feb 9, 2024
1 parent 848a5bc commit 971515f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
16 changes: 8 additions & 8 deletions connector/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (s *Server[RawConfiguration, Configuration, State]) QueryExplain(w http.Res
attribute.String("reason", "json_decode"),
}
span.SetAttributes(attributes...)
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(attributes...))
s.telemetry.queryExplainCounter.Add(r.Context(), 1, metric.WithAttributes(attributes...))
return
}
decodeSpan.End()
Expand All @@ -280,7 +280,7 @@ func (s *Server[RawConfiguration, Configuration, State]) QueryExplain(w http.Res
attribute.String("reason", fmt.Sprintf("%d", status)),
}
span.SetAttributes(attributes...)
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttributes...)...))
s.telemetry.queryExplainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttributes...)...))
return
}
execSpan.End()
Expand All @@ -290,10 +290,10 @@ func (s *Server[RawConfiguration, Configuration, State]) QueryExplain(w http.Res
_, responseSpan := s.telemetry.Tracer.Start(ctx, "Response")
writeJson(w, logger, http.StatusOK, response)
responseSpan.End()
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttribute)...))
s.telemetry.queryExplainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttribute)...))

// record latency for success requests only
s.telemetry.explainLatencyHistogram.Record(r.Context(), time.Since(startTime).Seconds(), metric.WithAttributes(collectionAttr))
s.telemetry.queryExplainLatencyHistogram.Record(r.Context(), time.Since(startTime).Seconds(), metric.WithAttributes(collectionAttr))
}

// MutationExplain implements a handler for the /mutation/explain endpoint, POST method that explains a mutation by creating an execution plan.
Expand All @@ -320,7 +320,7 @@ func (s *Server[RawConfiguration, Configuration, State]) MutationExplain(w http.
attribute.String("reason", "json_decode"),
}
span.SetAttributes(attributes...)
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(attributes...))
s.telemetry.mutationExplainCounter.Add(r.Context(), 1, metric.WithAttributes(attributes...))
return
}
decodeSpan.End()
Expand All @@ -343,7 +343,7 @@ func (s *Server[RawConfiguration, Configuration, State]) MutationExplain(w http.
attribute.String("reason", fmt.Sprintf("%d", status)),
}
span.SetAttributes(attributes...)
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttributes...)...))
s.telemetry.mutationExplainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttributes...)...))
return
}
execSpan.End()
Expand All @@ -353,10 +353,10 @@ func (s *Server[RawConfiguration, Configuration, State]) MutationExplain(w http.
_, responseSpan := s.telemetry.Tracer.Start(ctx, "Response")
writeJson(w, logger, http.StatusOK, response)
responseSpan.End()
s.telemetry.explainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttribute)...))
s.telemetry.mutationExplainCounter.Add(r.Context(), 1, metric.WithAttributes(append(attributes, statusAttribute)...))

// record latency for success requests only
s.telemetry.explainLatencyHistogram.Record(r.Context(), time.Since(startTime).Seconds(), metric.WithAttributes(collectionAttr))
s.telemetry.mutationExplainLatencyHistogram.Record(r.Context(), time.Since(startTime).Seconds(), metric.WithAttributes(collectionAttr))
}

// Mutation implements a handler for the /mutation endpoint, POST method that executes a mutation.
Expand Down
45 changes: 30 additions & 15 deletions connector/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ import (
)

type TelemetryState struct {
Tracer traceapi.Tracer
Meter metricapi.Meter
Shutdown func(context.Context) error
queryCounter metricapi.Int64Counter
mutationCounter metricapi.Int64Counter
explainCounter metricapi.Int64Counter
queryLatencyHistogram metricapi.Float64Histogram
explainLatencyHistogram metricapi.Float64Histogram
mutationLatencyHistogram metricapi.Float64Histogram
Tracer traceapi.Tracer
Meter metricapi.Meter
Shutdown func(context.Context) error
queryCounter metricapi.Int64Counter
mutationCounter metricapi.Int64Counter
queryExplainCounter metricapi.Int64Counter
mutationExplainCounter metricapi.Int64Counter
queryLatencyHistogram metricapi.Float64Histogram
queryExplainLatencyHistogram metricapi.Float64Histogram
mutationExplainLatencyHistogram metricapi.Float64Histogram
mutationLatencyHistogram metricapi.Float64Histogram
}

// setupOTelSDK bootstraps the OpenTelemetry pipeline.
Expand Down Expand Up @@ -226,9 +228,17 @@ func setupMetrics(telemetry *TelemetryState, metricsPrefix string) error {
return err
}

telemetry.explainCounter, err = meter.Int64Counter(
fmt.Sprintf("%sexplain.total", metricsPrefix),
metricapi.WithDescription("The total number of explain requests"),
telemetry.queryExplainCounter, err = meter.Int64Counter(
fmt.Sprintf("%squery.explain_total", metricsPrefix),
metricapi.WithDescription("The total number of explain query requests"),
)
if err != nil {
return err
}

telemetry.mutationExplainCounter, err = meter.Int64Counter(
fmt.Sprintf("%smutation.explain_total", metricsPrefix),
metricapi.WithDescription("The total number of explain mutation requests"),
)
if err != nil {
return err
Expand All @@ -250,9 +260,14 @@ func setupMetrics(telemetry *TelemetryState, metricsPrefix string) error {
return err
}

telemetry.explainLatencyHistogram, err = meter.Float64Histogram(
fmt.Sprintf("%sexplain.total_time", metricsPrefix),
metricapi.WithDescription("Total time taken to plan and execute an explain request, in seconds"),
telemetry.queryExplainLatencyHistogram, err = meter.Float64Histogram(

Check failure on line 263 in connector/telemetry.go

View workflow job for this annotation

GitHub Actions / Run Go lint and unit tests

ineffectual assignment to err (ineffassign)

Check failure on line 263 in connector/telemetry.go

View workflow job for this annotation

GitHub Actions / Run Go lint and unit tests

ineffectual assignment to err (ineffassign)
fmt.Sprintf("%squery.explain_total_time", metricsPrefix),
metricapi.WithDescription("Total time taken to plan and execute an explain query request, in seconds"),
)

telemetry.mutationExplainLatencyHistogram, err = meter.Float64Histogram(
fmt.Sprintf("%smutation.explain_total_time", metricsPrefix),
metricapi.WithDescription("Total time taken to plan and execute an explain mutation request, in seconds"),
)

return err
Expand Down

0 comments on commit 971515f

Please sign in to comment.