Skip to content

Commit 4965c0b

Browse files
committed
chore: integration: add tests for browser metric source allowlisting
1 parent 748c3ec commit 4965c0b

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

integration/integration_test.go

+71
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,77 @@ func TestSMK6Browser(t *testing.T) {
419419
}
420420
}
421421
})
422+
423+
t.Run("only includes document browser metrics", func(t *testing.T) {
424+
t.Parallel()
425+
426+
for _, mf := range mfs {
427+
for _, m := range mf.Metric {
428+
for _, lp := range m.Label {
429+
if *lp.Name == "resource_type" && *lp.Value != "Document" {
430+
t.Fatalf("metric %q should not have %s=%q", *mf.Name, *lp.Name, *lp.Value)
431+
}
432+
}
433+
}
434+
}
435+
})
436+
437+
t.Run("number of timeseries is sane", func(t *testing.T) {
438+
t.Parallel()
439+
440+
for _, mf := range mfs {
441+
sane := 3
442+
if found := len(mf.Metric); found > sane {
443+
t.Fatalf("Found suspicioulsy large number of timeseries (%d>%d) for metric %q", found, sane, *mf.Name)
444+
}
445+
}
446+
})
447+
})
448+
449+
t.Run("non-default allowlist", func(t *testing.T) {
450+
// Do not run this one in parallel, as crocochrome only supports one concurrent script run.
451+
452+
// Custom allowlist, mixed case.
453+
mfs := runBrowserScript(t, "browser-script.js", []string{"SM_K6_BROWSER_RESOURCE_TYPES=image,script"})
454+
455+
t.Run("only includes expected browser metrics", func(t *testing.T) {
456+
t.Parallel()
457+
458+
expected := []string{"Image", "Script"}
459+
for _, mf := range mfs {
460+
for _, m := range mf.Metric {
461+
for _, lp := range m.Label {
462+
if *lp.Name == "resource_type" && !slices.Contains(expected, *lp.Value) {
463+
t.Fatalf("metric %q should not have %s=%q", *mf.Name, *lp.Name, *lp.Value)
464+
}
465+
}
466+
}
467+
}
468+
})
469+
})
470+
471+
t.Run("allow all the things", func(t *testing.T) {
472+
// Do not run this one in parallel, as crocochrome only supports one concurrent script run.
473+
474+
mfs := runBrowserScript(t, "browser-script.js", []string{"SM_K6_BROWSER_RESOURCE_TYPES=*"}) // All The Things!
475+
476+
t.Run("only includes expected browser metrics", func(t *testing.T) {
477+
t.Parallel()
478+
479+
for _, mf := range mfs {
480+
for _, m := range mf.Metric {
481+
for _, lp := range m.Label {
482+
if *lp.Name == "resource_type" && *lp.Value == "Script" {
483+
// We found a metric with resource_type=Script, which is not in the default allowlist.
484+
// Approximating this as the wildcard working, and calling the test good.
485+
return
486+
}
487+
}
488+
}
489+
}
490+
491+
t.Fatalf("Did not found any metric with resource_type=Script")
492+
})
422493
})
423494
}
424495

0 commit comments

Comments
 (0)