Skip to content

Commit e34dbc9

Browse files
committed
yet another fix to TestMaxRunDurationHook_EmitMetrics
1 parent 6a6e6a6 commit e34dbc9

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

client/allocrunner/max_run_duration_hook_test.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package allocrunner
55

66
import (
7+
"strings"
78
"testing"
89
"time"
910

@@ -287,24 +288,28 @@ func TestMaxRunDurationHook_EmitMetrics(t *testing.T) {
287288
err = hook.Prerun((*taskenv.TaskEnv)(nil))
288289
must.NoError(t, err)
289290

290-
var metricKeySuffix string
291-
for _, label := range baseLabels {
292-
metricKeySuffix += ";" + label.Name + "=" + label.Value
293-
}
294-
metricKeySuffix += ";task_group=" + alloc.TaskGroup
295-
296-
configuredName := "nomad_test.client.allocs.max_run_duration.configured_seconds" + metricKeySuffix
297-
remainingName := "nomad_test.client.allocs.max_run_duration.remaining_seconds" + metricKeySuffix
298-
299291
data := inMemorySink.Data()
300292
must.Len(t, 1, data)
301-
must.MapContainsKey(t, data[0].Gauges, configuredName)
302-
must.MapContainsKey(t, data[0].Gauges, remainingName)
303293

304-
configuredGauge := data[0].Gauges[configuredName]
305-
must.Eq(t, float32(maxRunDuration.Seconds()), configuredGauge.Value)
294+
configuredSuffix := "client.allocs.max_run_duration.configured_seconds;node_id=node-123;task_group=" + alloc.TaskGroup
295+
remainingSuffix := "client.allocs.max_run_duration.remaining_seconds;node_id=node-123;task_group=" + alloc.TaskGroup
296+
297+
var configuredFound bool
298+
var remainingFound bool
299+
300+
for key, gauge := range data[0].Gauges {
301+
if strings.HasSuffix(key, configuredSuffix) {
302+
must.Eq(t, float32(maxRunDuration.Seconds()), gauge.Value)
303+
configuredFound = true
304+
}
305+
306+
if strings.HasSuffix(key, remainingSuffix) {
307+
must.Positive(t, gauge.Value)
308+
must.True(t, gauge.Value <= float32(maxRunDuration.Seconds()))
309+
remainingFound = true
310+
}
311+
}
306312

307-
remainingGauge := data[0].Gauges[remainingName]
308-
must.Positive(t, remainingGauge.Value)
309-
must.LessEq(t, remainingGauge.Value, float32(maxRunDuration.Seconds()))
313+
must.True(t, configuredFound)
314+
must.True(t, remainingFound)
310315
}

0 commit comments

Comments
 (0)