Skip to content

Commit f30dc87

Browse files
committed
Deprecate -ruler.evaluation-delay-duration
Signed-off-by: Daniel Deluiggi <ddeluigg@amazon.com>
1 parent a0704d3 commit f30dc87

File tree

6 files changed

+22
-242
lines changed

6 files changed

+22
-242
lines changed

docs/configuration/config-file-reference.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,11 +3340,6 @@ query_rejection:
33403340
# them.
33413341
[query_attributes: <list of QueryAttribute> | default = []]
33423342

3343-
# Duration to delay the evaluation of rules to ensure the underlying metrics
3344-
# have been pushed to Cortex.
3345-
# CLI flag: -ruler.evaluation-delay-duration
3346-
[ruler_evaluation_delay_duration: <duration> | default = 0s]
3347-
33483343
# The default tenant's shard size when the shuffle-sharding strategy is used by
33493344
# ruler. When this setting is specified in the per-tenant overrides, a value of
33503345
# 0 disables shuffle sharding for the tenant.

pkg/ruler/compat.go

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/prometheus/prometheus/model/histogram"
1414
"github.com/prometheus/prometheus/model/labels"
1515
"github.com/prometheus/prometheus/model/metadata"
16-
"github.com/prometheus/prometheus/model/value"
1716
"github.com/prometheus/prometheus/notifier"
1817
"github.com/prometheus/prometheus/promql"
1918
"github.com/prometheus/prometheus/promql/parser"
@@ -46,27 +45,15 @@ type PusherAppender struct {
4645
histogramLabels []labels.Labels
4746
histograms []cortexpb.Histogram
4847
userID string
49-
evaluationDelay time.Duration
5048
}
5149

5250
func (a *PusherAppender) AppendHistogram(_ storage.SeriesRef, l labels.Labels, t int64, h *histogram.Histogram, fh *histogram.FloatHistogram) (storage.SeriesRef, error) {
5351
if h == nil && fh == nil {
5452
return 0, errors.New("no histogram")
5553
}
56-
5754
if h != nil {
58-
// A histogram sample is considered stale if its sum is set to NaN.
59-
// https://github.com/prometheus/prometheus/blob/b6ef745016fa9472fdd0ae20f75a9682e01d1e5c/tsdb/head_append.go#L339-L346
60-
if a.evaluationDelay > 0 && (value.IsStaleNaN(h.Sum)) {
61-
t -= a.evaluationDelay.Milliseconds()
62-
}
6355
a.histograms = append(a.histograms, cortexpb.HistogramToHistogramProto(t, h))
6456
} else {
65-
// A histogram sample is considered stale if its sum is set to NaN.
66-
// https://github.com/prometheus/prometheus/blob/b6ef745016fa9472fdd0ae20f75a9682e01d1e5c/tsdb/head_append.go#L339-L346
67-
if a.evaluationDelay > 0 && (value.IsStaleNaN(fh.Sum)) {
68-
t -= a.evaluationDelay.Milliseconds()
69-
}
7057
a.histograms = append(a.histograms, cortexpb.FloatHistogramToHistogramProto(t, fh))
7158
}
7259
a.histogramLabels = append(a.histogramLabels, l)
@@ -75,19 +62,6 @@ func (a *PusherAppender) AppendHistogram(_ storage.SeriesRef, l labels.Labels, t
7562

7663
func (a *PusherAppender) Append(_ storage.SeriesRef, l labels.Labels, t int64, v float64) (storage.SeriesRef, error) {
7764
a.labels = append(a.labels, l)
78-
79-
// Adapt staleness markers for ruler evaluation delay. As the upstream code
80-
// is using the actual time, when there is a no longer available series.
81-
// This then causes 'out of order' append failures once the series is
82-
// becoming available again.
83-
// see https://github.com/prometheus/prometheus/blob/6c56a1faaaad07317ff585bda75b99bdba0517ad/rules/manager.go#L647-L660
84-
// Similar to staleness markers, the rule manager also appends actual time to the ALERTS and ALERTS_FOR_STATE series.
85-
// See: https://github.com/prometheus/prometheus/blob/ae086c73cb4d6db9e8b67d5038d3704fea6aec4a/rules/alerting.go#L414-L417
86-
metricName := l.Get(labels.MetricName)
87-
if a.evaluationDelay > 0 && (value.IsStaleNaN(v) || metricName == "ALERTS" || metricName == "ALERTS_FOR_STATE") {
88-
t -= a.evaluationDelay.Milliseconds()
89-
}
90-
9165
a.samples = append(a.samples, cortexpb.Sample{
9266
TimestampMs: t,
9367
Value: v,
@@ -164,16 +138,14 @@ func (t *PusherAppendable) Appender(ctx context.Context) storage.Appender {
164138
failedWrites: t.failedWrites,
165139
totalWrites: t.totalWrites,
166140

167-
ctx: ctx,
168-
pusher: t.pusher,
169-
userID: t.userID,
170-
evaluationDelay: t.rulesLimits.EvaluationDelay(t.userID),
141+
ctx: ctx,
142+
pusher: t.pusher,
143+
userID: t.userID,
171144
}
172145
}
173146

174147
// RulesLimits defines limits used by Ruler.
175148
type RulesLimits interface {
176-
EvaluationDelay(userID string) time.Duration
177149
MaxQueryLength(userID string) time.Duration
178150
RulerTenantShardSize(userID string) int
179151
RulerMaxRuleGroupsPerTenant(userID string) int
@@ -182,7 +154,7 @@ type RulesLimits interface {
182154
DisabledRuleGroups(userID string) validation.DisabledRuleGroups
183155
}
184156

185-
// EngineQueryFunc returns a new engine query function by passing an altered timestamp.
157+
// EngineQueryFunc returns a new engine query function validating max queryLength.
186158
// Modified from Prometheus rules.EngineQueryFunc
187159
// https://github.com/prometheus/prometheus/blob/v2.39.1/rules/manager.go#L189.
188160
func EngineQueryFunc(engine promql.QueryEngine, q storage.Queryable, overrides RulesLimits, userID string, lookbackDelta time.Duration) rules.QueryFunc {
@@ -202,8 +174,7 @@ func EngineQueryFunc(engine promql.QueryEngine, q storage.Queryable, overrides R
202174
}
203175
}
204176

205-
evaluationDelay := overrides.EvaluationDelay(userID)
206-
q, err := engine.NewInstantQuery(ctx, q, nil, qs, t.Add(-evaluationDelay))
177+
q, err := engine.NewInstantQuery(ctx, q, nil, qs, t)
207178
if err != nil {
208179
return nil, err
209180
}

pkg/ruler/compat_test.go

Lines changed: 9 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func TestPusherAppendable(t *testing.T) {
4343

4444
lbls1 := cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{labels.MetricName: "foo_bar"}))
4545
lbls2 := cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{labels.MetricName: "ALERTS", labels.AlertName: "boop"}))
46-
lbls3 := cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{labels.MetricName: "ALERTS_FOR_STATE", labels.AlertName: "boop"}))
4746

4847
testHistogram := tsdbutil.GenerateTestHistogram(1)
4948
testFloatHistogram := tsdbutil.GenerateTestFloatHistogram(2)
@@ -55,14 +54,13 @@ func TestPusherAppendable(t *testing.T) {
5554
for _, tc := range []struct {
5655
name string
5756
series string
58-
evalDelay time.Duration
5957
value float64
6058
histogram *histogram.Histogram
6159
floatHistogram *histogram.FloatHistogram
6260
expectedReq *cortexpb.WriteRequest
6361
}{
6462
{
65-
name: "tenant without delay, normal value",
63+
name: "tenant, normal value",
6664
series: "foo_bar",
6765
value: 1.234,
6866
expectedReq: &cortexpb.WriteRequest{
@@ -80,7 +78,7 @@ func TestPusherAppendable(t *testing.T) {
8078
},
8179
},
8280
{
83-
name: "tenant without delay, stale nan value",
81+
name: "tenant, stale nan value",
8482
series: "foo_bar",
8583
value: math.Float64frombits(value.StaleNaN),
8684
expectedReq: &cortexpb.WriteRequest{
@@ -98,45 +96,7 @@ func TestPusherAppendable(t *testing.T) {
9896
},
9997
},
10098
{
101-
name: "tenant with delay, normal value",
102-
series: "foo_bar",
103-
value: 1.234,
104-
evalDelay: time.Minute,
105-
expectedReq: &cortexpb.WriteRequest{
106-
Timeseries: []cortexpb.PreallocTimeseries{
107-
{
108-
TimeSeries: &cortexpb.TimeSeries{
109-
Labels: lbls1,
110-
Samples: []cortexpb.Sample{
111-
{Value: 1.234, TimestampMs: 120_000},
112-
},
113-
},
114-
},
115-
},
116-
Source: cortexpb.RULE,
117-
},
118-
},
119-
{
120-
name: "tenant with delay, stale nan value",
121-
series: "foo_bar",
122-
value: math.Float64frombits(value.StaleNaN),
123-
evalDelay: time.Minute,
124-
expectedReq: &cortexpb.WriteRequest{
125-
Timeseries: []cortexpb.PreallocTimeseries{
126-
{
127-
TimeSeries: &cortexpb.TimeSeries{
128-
Labels: lbls1,
129-
Samples: []cortexpb.Sample{
130-
{Value: math.Float64frombits(value.StaleNaN), TimestampMs: 60_000},
131-
},
132-
},
133-
},
134-
},
135-
Source: cortexpb.RULE,
136-
},
137-
},
138-
{
139-
name: "ALERTS without delay, normal value",
99+
name: "ALERTS, normal value",
140100
series: `ALERTS{alertname="boop"}`,
141101
value: 1.234,
142102
expectedReq: &cortexpb.WriteRequest{
@@ -154,7 +114,7 @@ func TestPusherAppendable(t *testing.T) {
154114
},
155115
},
156116
{
157-
name: "ALERTS without delay, stale nan value",
117+
name: "ALERTS, stale nan value",
158118
series: `ALERTS{alertname="boop"}`,
159119
value: math.Float64frombits(value.StaleNaN),
160120
expectedReq: &cortexpb.WriteRequest{
@@ -172,45 +132,7 @@ func TestPusherAppendable(t *testing.T) {
172132
},
173133
},
174134
{
175-
name: "ALERTS with delay, normal value",
176-
series: `ALERTS{alertname="boop"}`,
177-
value: 1.234,
178-
evalDelay: time.Minute,
179-
expectedReq: &cortexpb.WriteRequest{
180-
Timeseries: []cortexpb.PreallocTimeseries{
181-
{
182-
TimeSeries: &cortexpb.TimeSeries{
183-
Labels: lbls2,
184-
Samples: []cortexpb.Sample{
185-
{Value: 1.234, TimestampMs: 60_000},
186-
},
187-
},
188-
},
189-
},
190-
Source: cortexpb.RULE,
191-
},
192-
},
193-
{
194-
name: "ALERTS with delay, stale nan value",
195-
series: `ALERTS_FOR_STATE{alertname="boop"}`,
196-
value: math.Float64frombits(value.StaleNaN),
197-
evalDelay: time.Minute,
198-
expectedReq: &cortexpb.WriteRequest{
199-
Timeseries: []cortexpb.PreallocTimeseries{
200-
{
201-
TimeSeries: &cortexpb.TimeSeries{
202-
Labels: lbls3,
203-
Samples: []cortexpb.Sample{
204-
{Value: math.Float64frombits(value.StaleNaN), TimestampMs: 60_000},
205-
},
206-
},
207-
},
208-
},
209-
Source: cortexpb.RULE,
210-
},
211-
},
212-
{
213-
name: "tenant without delay, normal histogram",
135+
name: "tenant, normal histogram",
214136
series: "foo_bar",
215137
histogram: testHistogram,
216138
expectedReq: &cortexpb.WriteRequest{
@@ -228,7 +150,7 @@ func TestPusherAppendable(t *testing.T) {
228150
},
229151
},
230152
{
231-
name: "tenant without delay, float histogram",
153+
name: "tenant, float histogram",
232154
series: "foo_bar",
233155
floatHistogram: testFloatHistogram,
234156
expectedReq: &cortexpb.WriteRequest{
@@ -246,7 +168,7 @@ func TestPusherAppendable(t *testing.T) {
246168
},
247169
},
248170
{
249-
name: "tenant without delay, both sample and histogram",
171+
name: "tenant, both sample and histogram",
250172
series: "foo_bar",
251173
value: 1.234,
252174
histogram: testHistogram,
@@ -273,7 +195,7 @@ func TestPusherAppendable(t *testing.T) {
273195
},
274196
},
275197
{
276-
name: "tenant without delay, both sample and float histogram",
198+
name: "tenant, both sample and float histogram",
277199
series: "foo_bar",
278200
value: 1.234,
279201
floatHistogram: testFloatHistogram,
@@ -299,106 +221,9 @@ func TestPusherAppendable(t *testing.T) {
299221
Source: cortexpb.RULE,
300222
},
301223
},
302-
{
303-
name: "tenant with delay and NaN sample, normal histogram",
304-
series: "foo_bar",
305-
value: math.Float64frombits(value.StaleNaN),
306-
evalDelay: time.Minute,
307-
histogram: testHistogram,
308-
expectedReq: &cortexpb.WriteRequest{
309-
Timeseries: []cortexpb.PreallocTimeseries{
310-
{
311-
TimeSeries: &cortexpb.TimeSeries{
312-
Labels: lbls1,
313-
Samples: []cortexpb.Sample{
314-
{Value: math.Float64frombits(value.StaleNaN), TimestampMs: 60_000},
315-
},
316-
},
317-
},
318-
{
319-
TimeSeries: &cortexpb.TimeSeries{
320-
Labels: lbls1,
321-
Histograms: []cortexpb.Histogram{
322-
cortexpb.HistogramToHistogramProto(120_000, testHistogram),
323-
},
324-
},
325-
},
326-
},
327-
Source: cortexpb.RULE,
328-
},
329-
},
330-
{
331-
name: "tenant with delay and NaN sample, float histogram",
332-
series: "foo_bar",
333-
value: math.Float64frombits(value.StaleNaN),
334-
evalDelay: time.Minute,
335-
floatHistogram: testFloatHistogram,
336-
expectedReq: &cortexpb.WriteRequest{
337-
Timeseries: []cortexpb.PreallocTimeseries{
338-
{
339-
TimeSeries: &cortexpb.TimeSeries{
340-
Labels: lbls1,
341-
Samples: []cortexpb.Sample{
342-
{Value: math.Float64frombits(value.StaleNaN), TimestampMs: 60_000},
343-
},
344-
},
345-
},
346-
{
347-
TimeSeries: &cortexpb.TimeSeries{
348-
Labels: lbls1,
349-
Histograms: []cortexpb.Histogram{
350-
cortexpb.FloatHistogramToHistogramProto(120_000, testFloatHistogram),
351-
},
352-
},
353-
},
354-
},
355-
Source: cortexpb.RULE,
356-
},
357-
},
358-
{
359-
name: "tenant with delay, NaN histogram",
360-
series: "foo_bar",
361-
histogram: testHistogramWithNaN,
362-
evalDelay: time.Minute,
363-
expectedReq: &cortexpb.WriteRequest{
364-
Timeseries: []cortexpb.PreallocTimeseries{
365-
{
366-
TimeSeries: &cortexpb.TimeSeries{
367-
Labels: lbls1,
368-
Histograms: []cortexpb.Histogram{
369-
cortexpb.HistogramToHistogramProto(60_000, testHistogramWithNaN),
370-
},
371-
},
372-
},
373-
},
374-
Source: cortexpb.RULE,
375-
},
376-
},
377-
{
378-
name: "tenant with delay, NaN float histogram",
379-
series: "foo_bar",
380-
floatHistogram: testFloatHistogramWithNaN,
381-
evalDelay: time.Minute,
382-
expectedReq: &cortexpb.WriteRequest{
383-
Timeseries: []cortexpb.PreallocTimeseries{
384-
{
385-
TimeSeries: &cortexpb.TimeSeries{
386-
Labels: lbls1,
387-
Histograms: []cortexpb.Histogram{
388-
cortexpb.FloatHistogramToHistogramProto(60_000, testFloatHistogramWithNaN),
389-
},
390-
},
391-
},
392-
},
393-
Source: cortexpb.RULE,
394-
},
395-
},
396224
} {
397225
t.Run(tc.name, func(t *testing.T) {
398226
ctx := context.Background()
399-
pa.rulesLimits = &ruleLimits{
400-
evalDelay: tc.evalDelay,
401-
}
402227

403228
lbls, err := parser.ParseMetric(tc.series)
404229
require.NoError(t, err)
@@ -461,7 +286,7 @@ func TestPusherErrors(t *testing.T) {
461286
writes := prometheus.NewCounter(prometheus.CounterOpts{})
462287
failures := prometheus.NewCounter(prometheus.CounterOpts{})
463288

464-
pa := NewPusherAppendable(pusher, "user-1", ruleLimits{evalDelay: 10 * time.Second}, writes, failures)
289+
pa := NewPusherAppendable(pusher, "user-1", ruleLimits{}, writes, failures)
465290

466291
lbls, err := parser.ParseMetric("foo_bar")
467292
require.NoError(t, err)

pkg/ruler/ruler_ring_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func TestGetReplicationSetForListRule(t *testing.T) {
223223
}
224224

225225
r, _ := buildRuler(t, cfg, nil, store, nil)
226-
r.limits = ruleLimits{evalDelay: 0}
226+
r.limits = ruleLimits{}
227227

228228
rulerRing := r.ring
229229
// We start ruler's ring, but nothing else (not even lifecycler).

0 commit comments

Comments
 (0)