|
4 | 4 | package allocrunner |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "strings" |
7 | 8 | "testing" |
8 | 9 | "time" |
9 | 10 |
|
@@ -287,24 +288,28 @@ func TestMaxRunDurationHook_EmitMetrics(t *testing.T) { |
287 | 288 | err = hook.Prerun((*taskenv.TaskEnv)(nil)) |
288 | 289 | must.NoError(t, err) |
289 | 290 |
|
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 | | - |
299 | 291 | data := inMemorySink.Data() |
300 | 292 | must.Len(t, 1, data) |
301 | | - must.MapContainsKey(t, data[0].Gauges, configuredName) |
302 | | - must.MapContainsKey(t, data[0].Gauges, remainingName) |
303 | 293 |
|
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 | + } |
306 | 312 |
|
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) |
310 | 315 | } |
0 commit comments