prometheus/rules
Dimitar Dimitrov 3fb881af26
Simplify rule group's EvalTimestamp formula
I found it hard to understand how EvalTimestamp works, so I wanted to simplify the math there. This PR should be a noop.

Current formula is:

```
offset        = g.hash % g.interval
adjNow        = startTime - offset
base          = adjNow - (adjNow % g.interval)
EvalTimestamp = base + offset
```

I simplify `EvalTimestamp`

```
EvalTimestamp = base + offset
                # expand base
              = adjNow - (adjNow % g.interval) + offset
                # expand adjNow
              = startTime - offset - ((startTime - offset) % g.interval) + offset
                # cancel out offset
              = startTime - ((startTime - offset) % g.interval)
                # expand A+B (mod M) = (A (mod M) + B (mod M)) (mod M)
              = startTime - (startTime % g.interval - offset % g.interval) % g.interval
                # expand offset
              = startTime - (startTime % g.interval - ((g.hash % g.interval) % g.interval)) % g.interval
                # remove redundant mod g.interval
              = startTime - (startTime % g.interval - g.hash % g.interval) % g.interval
                # simplify (A (mod M) + B (mod M)) (mod M) = A+B (mod M)
              = startTime - (startTime - g.hash) % g.interval

offset            = (startTime - g.hash) % g.interval
EvalTimestamp     = startTime - offset
```

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
2022-09-13 10:52:32 +02:00
..
fixtures fixes yamllint errors 2021-06-12 12:47:47 +02:00
alerting.go delete redundant alias (#11180) 2022-08-31 15:50:38 +02:00
alerting_test.go rules: in tests use labels.FromStrings 2022-09-09 13:34:49 +02:00
manager.go Simplify rule group's EvalTimestamp formula 2022-09-13 10:52:32 +02:00
manager_test.go rules: in tests use labels.FromStrings 2022-09-09 13:34:49 +02:00
recording.go delete redundant alias (#11180) 2022-08-31 15:50:38 +02:00
recording_test.go rules: remove classic UI code (#10730) 2022-05-23 16:21:50 +02:00