Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore "operation" name in the metrics response #5673

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugin/metrics/prometheus/metricsstore/dbmodel/to_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type Translator struct {
// New returns a new Translator.
func New(spanNameLabel string) Translator {
return Translator{
// "span_name" is the label name that Jaeger UI expects.
labelMap: map[string]string{spanNameLabel: "span_name"},
// "operation" is the label name that Jaeger UI expects.
labelMap: map[string]string{spanNameLabel: "operation"},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestToDomainMetricsFamily(t *testing.T) {

wantMetricLabels := map[string]string{
"label_key": "label_value",
"span_name": "span_name_value", // assert the name is translated to a Jaeger-friendly label.
"operation": "span_name_value", // assert the name is translated to a Jaeger-friendly label.
}
assert.Len(t, mf.Metrics, 1)
for _, ml := range mf.Metrics[0].Labels {
Expand Down
4 changes: 2 additions & 2 deletions plugin/metrics/prometheus/metricsstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type (
metricsTranslator dbmodel.Translator
latencyMetricName string
callsMetricName string
operationLabel string
operationLabel string // name of the attribute that contains span name / operation
}

promQueryParams struct {
Expand Down Expand Up @@ -90,7 +90,7 @@ func NewMetricsReader(cfg config.Configuration, logger *zap.Logger, tracer trace
return nil, fmt.Errorf("failed to initialize prometheus client: %w", err)
}

operationLabel := "span_name"
const operationLabel = "span_name"

mr := &MetricsReader{
client: promapi.NewAPI(client),
Expand Down
36 changes: 17 additions & 19 deletions plugin/metrics/prometheus/metricsstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package metricsstore

import (
"context"
"fmt"
"io"
"net"
"net/http"
Expand Down Expand Up @@ -183,7 +182,7 @@ func TestGetLatencies(t *testing.T) {
wantName: "service_operation_latencies",
wantDescription: "0.95th quantile latency, grouped by service & operation",
wantLabels: map[string]string{
"span_name": "/OrderResult",
"operation": "/OrderResult",
"service_name": "emailservice",
},
wantPromQlQuery: `histogram_quantile(0.95, sum(rate(duration_bucket{service_name =~ "emailservice", ` +
Expand Down Expand Up @@ -215,7 +214,7 @@ func TestGetLatencies(t *testing.T) {
wantName: "service_operation_latencies",
wantDescription: "0.95th quantile latency, grouped by service & operation",
wantLabels: map[string]string{
"span_name": "/OrderResult",
"operation": "/OrderResult",
"service_name": "emailservice",
},
wantPromQlQuery: `histogram_quantile(0.95, sum(rate(span_metrics_duration_bucket{service_name =~ "emailservice", ` +
Expand All @@ -234,7 +233,7 @@ func TestGetLatencies(t *testing.T) {
wantName: "service_operation_latencies",
wantDescription: "0.95th quantile latency, grouped by service & operation",
wantLabels: map[string]string{
"span_name": "/OrderResult",
"operation": "/OrderResult",
"service_name": "emailservice",
},
wantPromQlQuery: `histogram_quantile(0.95, sum(rate(duration_seconds_bucket{service_name =~ "emailservice", ` +
Expand All @@ -257,7 +256,7 @@ func TestGetLatencies(t *testing.T) {

m, err := reader.GetLatencies(context.Background(), &params)
require.NoError(t, err)
assertMetrics(t, tc.name, m, tc.wantLabels, tc.wantName, tc.wantDescription)
assertMetrics(t, m, tc.wantLabels, tc.wantName, tc.wantDescription)
assert.Len(t, exp.GetSpans(), 1, "HTTP request was traced and span reported")
})
}
Expand Down Expand Up @@ -286,7 +285,7 @@ func TestGetCallRates(t *testing.T) {
wantName: "service_operation_call_rate",
wantDescription: "calls/sec, grouped by service & operation",
wantLabels: map[string]string{
"span_name": "/OrderResult",
"operation": "/OrderResult",
"service_name": "emailservice",
},
wantPromQlQuery: `sum(rate(calls{service_name =~ "emailservice", ` +
Expand Down Expand Up @@ -317,7 +316,7 @@ func TestGetCallRates(t *testing.T) {
wantName: "service_operation_call_rate",
wantDescription: "calls/sec, grouped by service & operation",
wantLabels: map[string]string{
"span_name": "/OrderResult",
"operation": "/OrderResult",
"service_name": "emailservice",
},
wantPromQlQuery: `sum(rate(span_metrics_calls{service_name =~ "emailservice", ` +
Expand All @@ -335,7 +334,7 @@ func TestGetCallRates(t *testing.T) {
wantName: "service_operation_call_rate",
wantDescription: "calls/sec, grouped by service & operation",
wantLabels: map[string]string{
"span_name": "/OrderResult",
"operation": "/OrderResult",
"service_name": "emailservice",
},
wantPromQlQuery: `sum(rate(calls_total{service_name =~ "emailservice", ` +
Expand All @@ -357,7 +356,7 @@ func TestGetCallRates(t *testing.T) {

m, err := reader.GetCallRates(context.Background(), &params)
require.NoError(t, err)
assertMetrics(t, tc.name, m, tc.wantLabels, tc.wantName, tc.wantDescription)
assertMetrics(t, m, tc.wantLabels, tc.wantName, tc.wantDescription)
assert.Len(t, exp.GetSpans(), 1, "HTTP request was traced and span reported")
})
}
Expand Down Expand Up @@ -387,7 +386,7 @@ func TestGetErrorRates(t *testing.T) {
wantName: "service_operation_error_rate",
wantDescription: "error rate, computed as a fraction of errors/sec over calls/sec, grouped by service & operation",
wantLabels: map[string]string{
"span_name": "/OrderResult",
"operation": "/OrderResult",
"service_name": "emailservice",
},
wantPromQlQuery: `sum(rate(calls{service_name =~ "emailservice", status_code = "STATUS_CODE_ERROR", ` +
Expand Down Expand Up @@ -439,7 +438,7 @@ func TestGetErrorRates(t *testing.T) {
wantName: "service_operation_error_rate",
wantDescription: "error rate, computed as a fraction of errors/sec over calls/sec, grouped by service & operation",
wantLabels: map[string]string{
"span_name": "/OrderResult",
"operation": "/OrderResult",
"service_name": "emailservice",
},
wantPromQlQuery: `sum(rate(span_metrics_calls{service_name =~ "emailservice", status_code = "STATUS_CODE_ERROR", ` +
Expand All @@ -458,7 +457,7 @@ func TestGetErrorRates(t *testing.T) {
wantName: "service_operation_error_rate",
wantDescription: "error rate, computed as a fraction of errors/sec over calls/sec, grouped by service & operation",
wantLabels: map[string]string{
"span_name": "/OrderResult",
"operation": "/OrderResult",
"service_name": "emailservice",
},
wantPromQlQuery: `sum(rate(calls_total{service_name =~ "emailservice", status_code = "STATUS_CODE_ERROR", ` +
Expand All @@ -481,7 +480,7 @@ func TestGetErrorRates(t *testing.T) {

m, err := reader.GetErrorRates(context.Background(), &params)
require.NoError(t, err)
assertMetrics(t, tc.name, m, tc.wantLabels, tc.wantName, tc.wantDescription)
assertMetrics(t, m, tc.wantLabels, tc.wantName, tc.wantDescription)
assert.Len(t, exp.GetSpans(), 1, "HTTP request was traced and span reported")
})
}
Expand Down Expand Up @@ -945,17 +944,16 @@ func prepareMetricsReaderAndServer(t *testing.T, config config.Configuration, wa
return reader, mockPrometheus
}

func assertMetrics(t *testing.T, testName string, gotMetrics *metrics.MetricFamily, wantLabels map[string]string, wantName, wantDescription string) {
func assertMetrics(t *testing.T, gotMetrics *metrics.MetricFamily, wantLabels map[string]string, wantName, wantDescription string) {
assert.Len(t, gotMetrics.Metrics, 1)
assert.Equal(t, wantName, gotMetrics.Name)
assert.Equal(t, wantDescription, gotMetrics.Help)
mps := gotMetrics.Metrics[0].MetricPoints
assert.Len(t, mps, 1)

// logging for expected and actual labels
fmt.Printf("Test Name: %s\n", testName)
fmt.Printf("Expected labels: %v\n", wantLabels)
fmt.Printf("Actual labels: %v\n", gotMetrics.Metrics[0].Labels)
t.Logf("Expected labels: %v\n", wantLabels)
t.Logf("Actual labels: %v\n", gotMetrics.Metrics[0].Labels)

// There is no guaranteed order of labels, so we need to take the approach of using a map of expected values.
labels := gotMetrics.Metrics[0].Labels
Expand All @@ -968,8 +966,8 @@ func assertMetrics(t *testing.T, testName string, gotMetrics *metrics.MetricFami
assert.Empty(t, wantLabels)

// Additional logging to show that all expected labels were found and matched
fmt.Printf("Remaining expected labels after matching: %v\n", wantLabels)
fmt.Printf("\n")
t.Logf("Remaining expected labels after matching: %v\n", wantLabels)
t.Logf("\n")

assert.Equal(t, int64(1620351786), mps[0].Timestamp.GetSeconds())

Expand Down
Loading