@@ -10,7 +10,6 @@ import (
10
10
"crypto/x509/pkix"
11
11
"encoding/json"
12
12
"fmt"
13
- "math"
14
13
"math/rand"
15
14
"net/http"
16
15
"os"
@@ -24,7 +23,6 @@ import (
24
23
"github.com/prometheus/common/model"
25
24
"github.com/prometheus/prometheus/model/labels"
26
25
"github.com/prometheus/prometheus/model/rulefmt"
27
- "github.com/prometheus/prometheus/model/value"
28
26
"github.com/prometheus/prometheus/prompb"
29
27
"github.com/stretchr/testify/assert"
30
28
"github.com/stretchr/testify/require"
@@ -200,119 +198,6 @@ func TestRulerAPISingleBinary(t *testing.T) {
200
198
require .NoError (t , cortexRestarted .WaitSumMetrics (e2e .Equals (1 ), "cortex_ruler_managers_total" ))
201
199
}
202
200
203
- func TestRulerEvaluationDelay (t * testing.T ) {
204
- s , err := e2e .NewScenario (networkName )
205
- require .NoError (t , err )
206
- defer s .Close ()
207
-
208
- namespace := "ns"
209
- user := "fake"
210
-
211
- evaluationDelay := time .Minute * 5
212
-
213
- configOverrides := map [string ]string {
214
- "-ruler-storage.local.directory" : filepath .Join (e2e .ContainerSharedDir , "ruler_configs" ),
215
- "-ruler.poll-interval" : "2s" ,
216
- "-ruler.rule-path" : filepath .Join (e2e .ContainerSharedDir , "rule_tmp/" ),
217
- "-ruler.evaluation-delay-duration" : evaluationDelay .String (),
218
- }
219
-
220
- // Start Cortex components.
221
- require .NoError (t , copyFileToSharedDir (s , "docs/configuration/single-process-config-blocks-local.yaml" , cortexConfigFile ))
222
- require .NoError (t , writeFileToSharedDir (s , filepath .Join ("ruler_configs" , user , namespace ), []byte (cortexRulerEvalStaleNanConfigYaml )))
223
- cortex := e2ecortex .NewSingleBinaryWithConfigFile ("cortex" , cortexConfigFile , configOverrides , "" , 9009 , 9095 )
224
- require .NoError (t , s .StartAndWaitReady (cortex ))
225
-
226
- // Create a client with the ruler address configured
227
- c , err := e2ecortex .NewClient (cortex .HTTPEndpoint (), cortex .HTTPEndpoint (), "" , cortex .HTTPEndpoint (), "" )
228
- require .NoError (t , err )
229
-
230
- now := time .Now ()
231
-
232
- // Generate series that includes stale nans
233
- samplesToSend := 10
234
- series := prompb.TimeSeries {
235
- Labels : []prompb.Label {
236
- {Name : "__name__" , Value : "a_sometimes_stale_nan_series" },
237
- {Name : "instance" , Value : "sometimes-stale" },
238
- },
239
- }
240
- series .Samples = make ([]prompb.Sample , samplesToSend )
241
- posStale := 2
242
-
243
- // Create samples, that are delayed by the evaluation delay with increasing values.
244
- for pos := range series .Samples {
245
- series .Samples [pos ].Timestamp = e2e .TimeToMilliseconds (now .Add (- evaluationDelay ).Add (time .Duration (pos ) * time .Second ))
246
- series .Samples [pos ].Value = float64 (pos + 1 )
247
-
248
- // insert staleness marker at the positions marked by posStale
249
- if pos == posStale {
250
- series .Samples [pos ].Value = math .Float64frombits (value .StaleNaN )
251
- }
252
- }
253
-
254
- // Insert metrics
255
- res , err := c .Push ([]prompb.TimeSeries {series })
256
- require .NoError (t , err )
257
- require .Equal (t , 200 , res .StatusCode )
258
-
259
- // Get number of rule evaluations just after push
260
- ruleEvaluationsAfterPush , err := cortex .SumMetrics ([]string {"cortex_prometheus_rule_evaluations_total" })
261
- require .NoError (t , err )
262
-
263
- // Wait until the rule is evaluated for the first time
264
- require .NoError (t , cortex .WaitSumMetrics (e2e .Greater (ruleEvaluationsAfterPush [0 ]), "cortex_prometheus_rule_evaluations_total" ))
265
-
266
- // Query the timestamp of the latest result to ensure the evaluation is delayed
267
- result , err := c .Query ("timestamp(stale_nan_eval)" , now )
268
- require .NoError (t , err )
269
- require .Equal (t , model .ValVector , result .Type ())
270
-
271
- vector := result .(model.Vector )
272
- require .Equal (t , 1 , vector .Len (), "expect one sample returned" )
273
-
274
- // 290 seconds gives 10 seconds of slack between the rule evaluation and the query
275
- // to account for CI latency, but ensures the latest evaluation was in the past.
276
- var maxDiff int64 = 290_000
277
- require .GreaterOrEqual (t , e2e .TimeToMilliseconds (time .Now ())- int64 (vector [0 ].Value )* 1000 , maxDiff )
278
-
279
- // Wait until all the pushed samples have been evaluated by the rule. This
280
- // ensures that rule results are successfully written even after a
281
- // staleness period.
282
- require .NoError (t , cortex .WaitSumMetrics (e2e .GreaterOrEqual (ruleEvaluationsAfterPush [0 ]+ float64 (samplesToSend )), "cortex_prometheus_rule_evaluations_total" ))
283
-
284
- // query all results to verify rules have been evaluated correctly
285
- result , err = c .QueryRange ("stale_nan_eval" , now .Add (- evaluationDelay ), now , time .Second )
286
- require .NoError (t , err )
287
- require .Equal (t , model .ValMatrix , result .Type ())
288
-
289
- matrix := result .(model.Matrix )
290
- require .GreaterOrEqual (t , 1 , matrix .Len (), "expect at least a series returned" )
291
-
292
- // Iterate through the values recorded and ensure they exist as expected.
293
- inputPos := 0
294
- for _ , m := range matrix {
295
- for _ , v := range m .Values {
296
- // Skip values for stale positions
297
- if inputPos == posStale {
298
- inputPos ++
299
- }
300
-
301
- expectedValue := model .SampleValue (2 * (inputPos + 1 ))
302
- require .Equal (t , expectedValue , v .Value )
303
-
304
- // Look for next value
305
- inputPos ++
306
-
307
- // We have found all input values
308
- if inputPos >= len (series .Samples ) {
309
- break
310
- }
311
- }
312
- }
313
- require .Equal (t , len (series .Samples ), inputPos , "expect to have returned all evaluations" )
314
- }
315
-
316
201
func TestRulerSharding (t * testing.T ) {
317
202
const numRulesGroups = 100
318
203
0 commit comments