Skip to content

Commit c395736

Browse files
test: add TestEvaluate_ZeroErrors_Absent5xxSeries to verify error rate evaluation when 5xx metrics are missing
1 parent c525a2e commit c395736

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎internal/rollout/promql_test.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,33 @@ func TestEvaluate_ZeroSample_AbsentSeries(t *testing.T) {
323323
}
324324
}
325325

326+
// TestEvaluate_ZeroErrors_Absent5xxSeries verifies that when request count is sufficient
327+
// (>= minRequestSample) and 5xx series are absent (evaluating to 0.0 via `or vector(0)`),
328+
// Evaluate completes with ErrorRate=0.0, SampleTooSmall=false, and ThresholdBreached=false.
329+
func TestEvaluate_ZeroErrors_Absent5xxSeries(t *testing.T) {
330+
// Sequence: count=200 (sufficient), errorRate=0.0 (0% errors / absent 5xx series), p99=80ms.
331+
srv := prometheusServer(t, []float64{200.0, 0.0, 80.0})
332+
defer srv.Close()
333+
334+
ad := makeAD("agent", "ns", "1%", 200)
335+
result, err := Evaluate(context.Background(), metrics.NewClient(srv.URL), ad, 2*time.Minute)
336+
if err != nil {
337+
t.Fatalf("unexpected error when 5xx series is absent: %v", err)
338+
}
339+
if result.SampleTooSmall {
340+
t.Errorf("expected SampleTooSmall=false when count is 200, got %v", result.SampleTooSmall)
341+
}
342+
if result.ThresholdBreached {
343+
t.Errorf("expected ThresholdBreached=false when errorRate is 0.0, got %v (reason: %s)", result.ThresholdBreached, result.BreachReason)
344+
}
345+
if result.ErrorRate != 0.0 {
346+
t.Errorf("expected ErrorRate=0.0, got %f", result.ErrorRate)
347+
}
348+
if result.SampleCount != 200.0 {
349+
t.Errorf("expected SampleCount=200.0, got %f", result.SampleCount)
350+
}
351+
}
352+
326353
// ── promDuration helper ───────────────────────────────────────────────────────
327354

328355
// TestPromDuration_Format verifies that promDuration formats durations correctly.

0 commit comments

Comments
 (0)