@@ -16,7 +16,6 @@ package metricsstore
16
16
17
17
import (
18
18
"context"
19
- "fmt"
20
19
"io"
21
20
"net"
22
21
"net/http"
@@ -183,7 +182,7 @@ func TestGetLatencies(t *testing.T) {
183
182
wantName : "service_operation_latencies" ,
184
183
wantDescription : "0.95th quantile latency, grouped by service & operation" ,
185
184
wantLabels : map [string ]string {
186
- "span_name " : "/OrderResult" ,
185
+ "operation " : "/OrderResult" ,
187
186
"service_name" : "emailservice" ,
188
187
},
189
188
wantPromQlQuery : `histogram_quantile(0.95, sum(rate(duration_bucket{service_name =~ "emailservice", ` +
@@ -215,7 +214,7 @@ func TestGetLatencies(t *testing.T) {
215
214
wantName : "service_operation_latencies" ,
216
215
wantDescription : "0.95th quantile latency, grouped by service & operation" ,
217
216
wantLabels : map [string ]string {
218
- "span_name " : "/OrderResult" ,
217
+ "operation " : "/OrderResult" ,
219
218
"service_name" : "emailservice" ,
220
219
},
221
220
wantPromQlQuery : `histogram_quantile(0.95, sum(rate(span_metrics_duration_bucket{service_name =~ "emailservice", ` +
@@ -234,7 +233,7 @@ func TestGetLatencies(t *testing.T) {
234
233
wantName : "service_operation_latencies" ,
235
234
wantDescription : "0.95th quantile latency, grouped by service & operation" ,
236
235
wantLabels : map [string ]string {
237
- "span_name " : "/OrderResult" ,
236
+ "operation " : "/OrderResult" ,
238
237
"service_name" : "emailservice" ,
239
238
},
240
239
wantPromQlQuery : `histogram_quantile(0.95, sum(rate(duration_seconds_bucket{service_name =~ "emailservice", ` +
@@ -257,7 +256,7 @@ func TestGetLatencies(t *testing.T) {
257
256
258
257
m , err := reader .GetLatencies (context .Background (), & params )
259
258
require .NoError (t , err )
260
- assertMetrics (t , tc . name , m , tc .wantLabels , tc .wantName , tc .wantDescription )
259
+ assertMetrics (t , m , tc .wantLabels , tc .wantName , tc .wantDescription )
261
260
assert .Len (t , exp .GetSpans (), 1 , "HTTP request was traced and span reported" )
262
261
})
263
262
}
@@ -286,7 +285,7 @@ func TestGetCallRates(t *testing.T) {
286
285
wantName : "service_operation_call_rate" ,
287
286
wantDescription : "calls/sec, grouped by service & operation" ,
288
287
wantLabels : map [string ]string {
289
- "span_name " : "/OrderResult" ,
288
+ "operation " : "/OrderResult" ,
290
289
"service_name" : "emailservice" ,
291
290
},
292
291
wantPromQlQuery : `sum(rate(calls{service_name =~ "emailservice", ` +
@@ -317,7 +316,7 @@ func TestGetCallRates(t *testing.T) {
317
316
wantName : "service_operation_call_rate" ,
318
317
wantDescription : "calls/sec, grouped by service & operation" ,
319
318
wantLabels : map [string ]string {
320
- "span_name " : "/OrderResult" ,
319
+ "operation " : "/OrderResult" ,
321
320
"service_name" : "emailservice" ,
322
321
},
323
322
wantPromQlQuery : `sum(rate(span_metrics_calls{service_name =~ "emailservice", ` +
@@ -335,7 +334,7 @@ func TestGetCallRates(t *testing.T) {
335
334
wantName : "service_operation_call_rate" ,
336
335
wantDescription : "calls/sec, grouped by service & operation" ,
337
336
wantLabels : map [string ]string {
338
- "span_name " : "/OrderResult" ,
337
+ "operation " : "/OrderResult" ,
339
338
"service_name" : "emailservice" ,
340
339
},
341
340
wantPromQlQuery : `sum(rate(calls_total{service_name =~ "emailservice", ` +
@@ -357,7 +356,7 @@ func TestGetCallRates(t *testing.T) {
357
356
358
357
m , err := reader .GetCallRates (context .Background (), & params )
359
358
require .NoError (t , err )
360
- assertMetrics (t , tc . name , m , tc .wantLabels , tc .wantName , tc .wantDescription )
359
+ assertMetrics (t , m , tc .wantLabels , tc .wantName , tc .wantDescription )
361
360
assert .Len (t , exp .GetSpans (), 1 , "HTTP request was traced and span reported" )
362
361
})
363
362
}
@@ -387,7 +386,7 @@ func TestGetErrorRates(t *testing.T) {
387
386
wantName : "service_operation_error_rate" ,
388
387
wantDescription : "error rate, computed as a fraction of errors/sec over calls/sec, grouped by service & operation" ,
389
388
wantLabels : map [string ]string {
390
- "span_name " : "/OrderResult" ,
389
+ "operation " : "/OrderResult" ,
391
390
"service_name" : "emailservice" ,
392
391
},
393
392
wantPromQlQuery : `sum(rate(calls{service_name =~ "emailservice", status_code = "STATUS_CODE_ERROR", ` +
@@ -439,7 +438,7 @@ func TestGetErrorRates(t *testing.T) {
439
438
wantName : "service_operation_error_rate" ,
440
439
wantDescription : "error rate, computed as a fraction of errors/sec over calls/sec, grouped by service & operation" ,
441
440
wantLabels : map [string ]string {
442
- "span_name " : "/OrderResult" ,
441
+ "operation " : "/OrderResult" ,
443
442
"service_name" : "emailservice" ,
444
443
},
445
444
wantPromQlQuery : `sum(rate(span_metrics_calls{service_name =~ "emailservice", status_code = "STATUS_CODE_ERROR", ` +
@@ -458,7 +457,7 @@ func TestGetErrorRates(t *testing.T) {
458
457
wantName : "service_operation_error_rate" ,
459
458
wantDescription : "error rate, computed as a fraction of errors/sec over calls/sec, grouped by service & operation" ,
460
459
wantLabels : map [string ]string {
461
- "span_name " : "/OrderResult" ,
460
+ "operation " : "/OrderResult" ,
462
461
"service_name" : "emailservice" ,
463
462
},
464
463
wantPromQlQuery : `sum(rate(calls_total{service_name =~ "emailservice", status_code = "STATUS_CODE_ERROR", ` +
@@ -481,7 +480,7 @@ func TestGetErrorRates(t *testing.T) {
481
480
482
481
m , err := reader .GetErrorRates (context .Background (), & params )
483
482
require .NoError (t , err )
484
- assertMetrics (t , tc . name , m , tc .wantLabels , tc .wantName , tc .wantDescription )
483
+ assertMetrics (t , m , tc .wantLabels , tc .wantName , tc .wantDescription )
485
484
assert .Len (t , exp .GetSpans (), 1 , "HTTP request was traced and span reported" )
486
485
})
487
486
}
@@ -945,17 +944,16 @@ func prepareMetricsReaderAndServer(t *testing.T, config config.Configuration, wa
945
944
return reader , mockPrometheus
946
945
}
947
946
948
- func assertMetrics (t * testing.T , testName string , gotMetrics * metrics.MetricFamily , wantLabels map [string ]string , wantName , wantDescription string ) {
947
+ func assertMetrics (t * testing.T , gotMetrics * metrics.MetricFamily , wantLabels map [string ]string , wantName , wantDescription string ) {
949
948
assert .Len (t , gotMetrics .Metrics , 1 )
950
949
assert .Equal (t , wantName , gotMetrics .Name )
951
950
assert .Equal (t , wantDescription , gotMetrics .Help )
952
951
mps := gotMetrics .Metrics [0 ].MetricPoints
953
952
assert .Len (t , mps , 1 )
954
953
955
954
// logging for expected and actual labels
956
- fmt .Printf ("Test Name: %s\n " , testName )
957
- fmt .Printf ("Expected labels: %v\n " , wantLabels )
958
- fmt .Printf ("Actual labels: %v\n " , gotMetrics .Metrics [0 ].Labels )
955
+ t .Logf ("Expected labels: %v\n " , wantLabels )
956
+ t .Logf ("Actual labels: %v\n " , gotMetrics .Metrics [0 ].Labels )
959
957
960
958
// There is no guaranteed order of labels, so we need to take the approach of using a map of expected values.
961
959
labels := gotMetrics .Metrics [0 ].Labels
@@ -968,8 +966,8 @@ func assertMetrics(t *testing.T, testName string, gotMetrics *metrics.MetricFami
968
966
assert .Empty (t , wantLabels )
969
967
970
968
// Additional logging to show that all expected labels were found and matched
971
- fmt . Printf ("Remaining expected labels after matching: %v\n " , wantLabels )
972
- fmt . Printf ("\n " )
969
+ t . Logf ("Remaining expected labels after matching: %v\n " , wantLabels )
970
+ t . Logf ("\n " )
973
971
974
972
assert .Equal (t , int64 (1620351786 ), mps [0 ].Timestamp .GetSeconds ())
975
973
0 commit comments