Skip to content

Commit

Permalink
feat: optional id label for all metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
damiankaminski-form3 committed Feb 22, 2024
1 parent 937eb76 commit d381ed9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions internal/run/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
var fakePrometheus FakePrometheus

const fakePrometheusNamespace = "test-namespace"
const fakePrometheusID = "test-run-name"

func TestMain(m *testing.M) {

Expand All @@ -29,6 +30,10 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatal(err)
}
err = os.Setenv("PROMETHEUS_ID_LABEL", fakePrometheusID)
if err != nil {
log.Fatal(err)
}

fakePrometheus.StartServer()

Expand Down
5 changes: 3 additions & 2 deletions internal/run/run_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func TestSetupMetricsAreRecorded(t *testing.T) {
there_is_a_metric_called("form3_loadtest_setup")
}

func TestNamespaceLabel(t *testing.T) {
func TestGroupedLabels(t *testing.T) {
given, when, then := NewRunTestStage(t)

given.
Expand All @@ -596,7 +596,8 @@ func TestNamespaceLabel(t *testing.T) {

then.
metrics_are_pushed_to_prometheus().and().
all_exported_metrics_contain_label("namespace", fakePrometheusNamespace)
all_exported_metrics_contain_label("namespace", fakePrometheusNamespace).and().
all_exported_metrics_contain_label("id", fakePrometheusID)
}

func TestFailureCounts(t *testing.T) {
Expand Down
11 changes: 8 additions & 3 deletions internal/run/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ func NewRun(options options.RunOptions, t *api.Trigger) (*Run, error) {
if prometheusUrl != "" {
run.pusher = push.New(prometheusUrl, "f1-"+options.Scenario).Gatherer(prometheus.DefaultGatherer)

prometheusNamespace := os.Getenv("PROMETHEUS_NAMESPACE")
if prometheusNamespace != "" {
run.pusher = run.pusher.Grouping("namespace", prometheusNamespace)
namespaceLabel := os.Getenv("PROMETHEUS_NAMESPACE")
if namespaceLabel != "" {
run.pusher = run.pusher.Grouping("namespace", namespaceLabel)
}

idLabel := os.Getenv("PROMETHEUS_ID_LABEL")
if idLabel != "" {
run.pusher = run.pusher.Grouping("id", idLabel)
}
}
if run.Options.RegisterLogHookFunc == nil {
Expand Down

0 comments on commit d381ed9

Please sign in to comment.