Skip to content

Commit eaa5fc3

Browse files
nadiamoed0ugal
andauthored
feat: refactor metrics processing (#34)
* benchmark presence checking on both a map and a slice * refactor metric processing * remove `iterations` metric Not seen in practice with iterations=1, but part of the test suite * create `http_status_code` metric * keep `status` label only on `http_requests_total` metric * remove high-cardinality `error` label * create `http_version` metric * remove most of the output unit tests * generate http_duration_seconds{phase="resolve"} hardcoded to zero * use custom sm phase names for http_duration_seconds * make `script_duration_seconds` actually seconds * integration: test for custom value of `tls_version` label * strip `tls` prefix of `tls_version` label value * integration: run subtests in parallel * do not strip `status` tag from any metric * Fix typo in output test Co-authored-by: Dougal Matthews <[email protected]> * keep `tls_version` and `proto` labels on all metrics To be consistent with the `status` label, and to ensure that we do not cause data loss due to duplicates. This should not impact cardinality. * make `probe_http_requests_failed_total` a counter instead of a rate `probe_http_requests_failed` is emitted as a rate now, as the original metric is --------- Co-authored-by: Dougal Matthews <[email protected]>
1 parent bd43062 commit eaa5fc3

File tree

5 files changed

+643
-1185
lines changed

5 files changed

+643
-1185
lines changed

integration/integration_test.go

+34-7
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ func TestSMK6(t *testing.T) {
8383
"probe_http_error_code",
8484
"probe_http_got_expected_response",
8585
"probe_http_info",
86-
"probe_http_requests_failed_total",
86+
"probe_http_requests_failed", // Original rate.
87+
"probe_http_requests_failed_total", // Computed counter.
8788
"probe_http_requests_total",
8889
"probe_http_ssl",
8990
"probe_http_status_code",
@@ -107,7 +108,7 @@ func TestSMK6(t *testing.T) {
107108

108109
unwantedMetrics := []string{
109110
"probe_checks",
110-
"probe_http_reqs", "probe_http_req_failed",
111+
"probe_http_reqs", "probe_http_req_failed", // Renamed s/req/requests.
111112
"probe_data_sent", "probe_data_received",
112113
"probe_http_req_duration", "probe_iteration_duration",
113114
"probe_http_req_blocked", "probe_http_req_connecting", "probe_http_req_receiving", "probe_http_req_sending", "probe_http_req_tls_handshaking", "probe_http_req_waiting",
@@ -152,8 +153,6 @@ func TestSMK6(t *testing.T) {
152153
// If a metric contains a label (key), and that metric is not in the list (value), the test fails.
153154
type exceptForMetrics []string
154155
forbiddenLabels := map[string]exceptForMetrics{
155-
"tls_version": {"probe_http_info"},
156-
"proto": {"probe_http_info"},
157156
"error": {"probe_http_info"},
158157
"expected_response": {"probe_http_got_expected_response"},
159158
"group": {},
@@ -284,19 +283,47 @@ func TestSMK6(t *testing.T) {
284283
assertValue: equals(0),
285284
},
286285
{
287-
name: "Total requests for each url",
288-
metricName: "probe_http_requests_total",
289-
assertValue: equals(1),
286+
name: "Total requests for a URL accessed once",
287+
metricName: "probe_http_requests_total",
288+
metricLabels: map[string]string{"url": "https://test-api.k6.io/public/crocodiles/"},
289+
assertValue: equals(1),
290+
},
291+
{
292+
name: "Total requests for a URL accessed twice",
293+
metricName: "probe_http_requests_total",
294+
metricLabels: map[string]string{"url": "https://test-api.k6.io/public/crocodiles4/"},
295+
assertValue: equals(2),
296+
},
297+
{
298+
name: "HTTP requests failed rate",
299+
metricName: "probe_http_requests_failed",
300+
metricLabels: map[string]string{"url": "https://test-api.k6.io/public/crocodiles4/"},
301+
assertValue: equals(1),
302+
},
303+
{
304+
name: "HTTP requests failed ttoal",
305+
metricName: "probe_http_requests_failed_total",
306+
metricLabels: map[string]string{"url": "https://test-api.k6.io/public/crocodiles4/"},
307+
assertValue: equals(2),
290308
},
291309
{
292310
name: "HTTP version",
293311
metricName: "probe_http_version",
294312
metricLabels: map[string]string{"url": "https://test-api.k6.io/public/crocodiles/"},
295313
assertValue: func(f float64) bool { return f >= 1.1 },
296314
},
315+
{
316+
name: "TLS version label value",
317+
metricName: "probe_http_info",
318+
// Test for a paticular URL to avoid matching a failed request, which has no TLS version.
319+
metricLabels: map[string]string{"tls_version": "1.3", "url": "https://test-api.k6.io/public/crocodiles/"},
320+
assertValue: any, // Just fail if not present.
321+
},
297322
} {
298323
tc := tc
299324
t.Run(tc.name, func(t *testing.T) {
325+
t.Parallel()
326+
300327
matchedMetrics := 0
301328
for _, mf := range mfs {
302329
if *mf.Name != tc.metricName {

integration/test-script.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ export default function () {
4141
http.get(`https://${testHost}/public/crocodiles2/`); // 404
4242
http.get(`https://${testHost}/public/crocodiles3/`); // 404
4343
http.get(`https://${testHost}/public/crocodiles4/`); // 404
44+
http.get(`https://${testHost}/public/crocodiles4/`); // Second 404, to assert differences between failure rate and counter.
4445
http.get(`http://fail.internal/public/crocodiles4/`); // failed
4546
}

0 commit comments

Comments
 (0)