|
44 | 44 | wantDescription string
|
45 | 45 | wantLabels map[string]string
|
46 | 46 | wantPromQlQuery string
|
| 47 | + tags map[string]string |
47 | 48 | }
|
48 | 49 | )
|
49 | 50 |
|
@@ -162,6 +163,21 @@ func TestGetLatencies(t *testing.T) {
|
162 | 163 | wantPromQlQuery: `histogram_quantile(0.95, sum(rate(duration_bucket{service_name =~ "emailservice", ` +
|
163 | 164 | `span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name,le))`,
|
164 | 165 | },
|
| 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 | + }, |
165 | 181 | {
|
166 | 182 | name: "group by service and operation should be reflected in name/description and query group-by",
|
167 | 183 | serviceNames: []string{"emailservice"},
|
@@ -265,6 +281,23 @@ func TestGetCallRates(t *testing.T) {
|
265 | 281 | wantPromQlQuery: `sum(rate(calls{service_name =~ "emailservice", ` +
|
266 | 282 | `span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name)`,
|
267 | 283 | },
|
| 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 | + }, |
268 | 301 | {
|
269 | 302 | name: "group by service and operation should be reflected in name/description and query group-by",
|
270 | 303 | serviceNames: []string{"emailservice"},
|
@@ -366,6 +399,24 @@ func TestGetErrorRates(t *testing.T) {
|
366 | 399 | `span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name) / ` +
|
367 | 400 | `sum(rate(calls{service_name =~ "emailservice", span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name)`,
|
368 | 401 | },
|
| 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 | + }, |
369 | 420 | {
|
370 | 421 | name: "group by service and operation should be reflected in name/description and query group-by",
|
371 | 422 | serviceNames: []string{"emailservice"},
|
@@ -937,6 +988,8 @@ func startMockPrometheusServer(t *testing.T, wantPromQlQuery string, wantWarning
|
937 | 988 | mockResponsePayloadFile := "testdata/service_datapoint_response.json"
|
938 | 989 | if strings.Contains(promQuery, "by (service_name,span_name") {
|
939 | 990 | mockResponsePayloadFile = "testdata/service_span_name_datapoint_response.json"
|
| 991 | + } else if strings.Contains(promQuery, "http_method=") { |
| 992 | + mockResponsePayloadFile = "testdata/service_with_tags_response.json" |
940 | 993 | }
|
941 | 994 | sendResponse(t, w, mockResponsePayloadFile)
|
942 | 995 | }))
|
@@ -964,6 +1017,7 @@ func buildTestBaseQueryParametersFrom(tc metricsTestCase) metricstore.BaseQueryP
|
964 | 1017 | Step: &step,
|
965 | 1018 | RatePer: &ratePer,
|
966 | 1019 | SpanKinds: tc.spanKinds,
|
| 1020 | + Tags: tc.tags, |
967 | 1021 | }
|
968 | 1022 | }
|
969 | 1023 |
|
|
0 commit comments