Skip to content

Commit f5e101f

Browse files
committed
use more accurate matching in loki query
Signed-off-by: Guy Daich <guy.daich@sap.com>
1 parent 0277eb3 commit f5e101f

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

test/e2e/tests/backend_health_check.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ var BackendHealthCheckEventLogTest = suite.ConformanceTest{
293293
Namespace: ns,
294294
})
295295

296-
count, err := QueryLogCountFromLoki(t, suite.Client, lokiLabels, "health_checker_type")
296+
// Scope to HC events from this test's route only.
297+
count, err := QueryLogCountFromLoki(t, suite.Client, lokiLabels, `health_checker_type.*http-with-hc-event-log`)
297298
require.NoError(t, err, "loki query failed")
298299
require.Equal(t, 0, count, "expected no HC events before HC-enabled route is active")
299300
})
@@ -319,18 +320,24 @@ var BackendHealthCheckEventLogTest = suite.ConformanceTest{
319320
suite.ControllerName, ancestorRef,
320321
)
321322

323+
// The HC event JSON Envoy emits contains both "health_checker_type" and
324+
// "cluster_name" (which includes the route name) on the same line.
325+
// Matching both ensures we only count HC events from this test's cluster,
326+
// not access logs or other lines that might mention the route name.
327+
const hcLogMatch = `health_checker_type.*http-with-hc-event-log`
328+
322329
t.Run("health check events appear in logs", func(t *testing.T) {
323330
http.AwaitConvergence(
324331
t,
325332
suite.TimeoutConfig.RequiredConsecutiveSuccesses,
326333
suite.TimeoutConfig.MaxTimeToConsistency,
327334
func(_ time.Duration) bool {
328-
count, err := QueryLogCountFromLoki(t, suite.Client, lokiLabels, "health_checker_type")
335+
count, err := QueryLogCountFromLoki(t, suite.Client, lokiLabels, hcLogMatch)
329336
if err != nil {
330337
tlog.Logf(t, "loki query error: %v", err)
331338
return false
332339
}
333-
tlog.Logf(t, "loki match %q count=%d", "health_checker_type", count)
340+
tlog.Logf(t, "loki match %q count=%d", hcLogMatch, count)
334341
return count > 0
335342
},
336343
)

0 commit comments

Comments
 (0)