Skip to content

Commit f35f45c

Browse files
committed
tests
Signed-off-by: Harshil Gupta <[email protected]>
1 parent 426a3f5 commit f35f45c

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

internal/storage/metricstore/prometheus/metricstore/reader.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ func (m MetricsReader) buildPromQuery(metricsParams metricsQueryParams) string {
365365
}
366366
}
367367

368-
fmt.Println(">>>>>>>>> tagfilters", tagFilters)
369368
promParams := promQueryParams{
370369
serviceFilter: strings.Join(metricsParams.ServiceNames, "|"),
371370
spanKindFilter: spanKindFilter,

internal/storage/metricstore/prometheus/metricstore/reader_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type (
4444
wantDescription string
4545
wantLabels map[string]string
4646
wantPromQlQuery string
47+
tags map[string]string
4748
}
4849
)
4950

@@ -162,6 +163,21 @@ func TestGetLatencies(t *testing.T) {
162163
wantPromQlQuery: `histogram_quantile(0.95, sum(rate(duration_bucket{service_name =~ "emailservice", ` +
163164
`span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name,le))`,
164165
},
166+
{
167+
name: "tag filtering should be included in the query",
168+
serviceNames: []string{"emailservice"},
169+
spanKinds: []string{"SPAN_KIND_SERVER"},
170+
tags: map[string]string{"http.method": "GET"},
171+
groupByOperation: false,
172+
wantName: "service_latencies",
173+
wantDescription: "0.95th quantile latency, grouped by service",
174+
wantLabels: map[string]string{
175+
"service_name": "emailservice",
176+
"http.method": "GET",
177+
},
178+
wantPromQlQuery: `histogram_quantile(0.95, sum(rate(duration_bucket{service_name =~ "emailservice", ` +
179+
`span_kind =~ "SPAN_KIND_SERVER", http_method="GET"}[10m])) by (service_name,le))`,
180+
},
165181
{
166182
name: "group by service and operation should be reflected in name/description and query group-by",
167183
serviceNames: []string{"emailservice"},
@@ -265,6 +281,23 @@ func TestGetCallRates(t *testing.T) {
265281
wantPromQlQuery: `sum(rate(calls{service_name =~ "emailservice", ` +
266282
`span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name)`,
267283
},
284+
{
285+
name: "tag filtering should be included in the query",
286+
serviceNames: []string{"emailservice"},
287+
spanKinds: []string{"SPAN_KIND_SERVER"},
288+
groupByOperation: false,
289+
tags: map[string]string{
290+
"http.method": "GET",
291+
},
292+
wantName: "service_call_rate",
293+
wantDescription: "calls/sec, grouped by service",
294+
wantLabels: map[string]string{
295+
"http.method": "GET",
296+
"service_name": "emailservice",
297+
},
298+
wantPromQlQuery: `sum(rate(calls{service_name =~ "emailservice", span_kind =~ "SPAN_KIND_SERVER",` +
299+
` http_method="GET"}[10m])) by (service_name)`,
300+
},
268301
{
269302
name: "group by service and operation should be reflected in name/description and query group-by",
270303
serviceNames: []string{"emailservice"},
@@ -366,6 +399,24 @@ func TestGetErrorRates(t *testing.T) {
366399
`span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name) / ` +
367400
`sum(rate(calls{service_name =~ "emailservice", span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name)`,
368401
},
402+
{
403+
name: "tag filtering should be included in the query",
404+
serviceNames: []string{"emailservice"},
405+
spanKinds: []string{"SPAN_KIND_SERVER"},
406+
groupByOperation: false,
407+
tags: map[string]string{
408+
"http.method": "GET",
409+
},
410+
wantName: "service_error_rate",
411+
wantDescription: "error rate, computed as a fraction of errors/sec over calls/sec, grouped by service",
412+
wantLabels: map[string]string{
413+
"service_name": "emailservice",
414+
"http.method": "GET",
415+
},
416+
wantPromQlQuery: `sum(rate(calls{service_name =~ "emailservice", status_code = "STATUS_CODE_ERROR", ` +
417+
`span_kind =~ "SPAN_KIND_SERVER", http_method="GET"}[10m])) by (service_name) / ` +
418+
`sum(rate(calls{service_name =~ "emailservice", span_kind =~ "SPAN_KIND_SERVER", http_method="GET"}[10m])) by (service_name)`,
419+
},
369420
{
370421
name: "group by service and operation should be reflected in name/description and query group-by",
371422
serviceNames: []string{"emailservice"},
@@ -937,6 +988,8 @@ func startMockPrometheusServer(t *testing.T, wantPromQlQuery string, wantWarning
937988
mockResponsePayloadFile := "testdata/service_datapoint_response.json"
938989
if strings.Contains(promQuery, "by (service_name,span_name") {
939990
mockResponsePayloadFile = "testdata/service_span_name_datapoint_response.json"
991+
} else if strings.Contains(promQuery, "http_method=") {
992+
mockResponsePayloadFile = "testdata/service_with_tags_response.json"
940993
}
941994
sendResponse(t, w, mockResponsePayloadFile)
942995
}))
@@ -964,6 +1017,7 @@ func buildTestBaseQueryParametersFrom(tc metricsTestCase) metricstore.BaseQueryP
9641017
Step: &step,
9651018
RatePer: &ratePer,
9661019
SpanKinds: tc.spanKinds,
1020+
Tags: tc.tags,
9671021
}
9681022
}
9691023

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"status": "success",
3+
"data": {
4+
"resultType": "matrix",
5+
"result": [
6+
{
7+
"metric": {
8+
"service_name": "emailservice",
9+
"http.method": "GET"
10+
},
11+
"values": [
12+
[
13+
1620351786,
14+
"9223372036854"
15+
]
16+
]
17+
}
18+
]
19+
}
20+
}

0 commit comments

Comments
 (0)