2

Morning everyone,

I have a prometheus alert that looks like that :

whatever_expr > 0.10 AND ON() absent(hour() >= 2 <= 3)

That excludes alert during some maintenance schedule.

Now that I want to unit test it, I can't find any information to mock the result of the hour() function.

I would like to do something like that in the test.yaml

    - interval: 1m
      input_series:
        - series: 'hour'
          values: 2 2 2 2 2 2 2 2 2 2

I start to think it's not even possible ?

If any idea, I'd be glad to hear it :)

Boris Le Méec
  • 2,383
  • 1
  • 16
  • 31

1 Answers1

0

I have a similar issue since i was using time(). I found this issue on github https://github.com/prometheus/docs/issues/1464 and it appears that all time related functions start at the timestamp 0, which equals Thu Jan 01 1970 00:00:00, and increase based on the interval of the test.

Its not very intuitive but I managed to provide a series for time based on the following schema:

tests:
  - interval: 1h
    input_series:
      - series: 'series_xyz'
        values: '1+0x5'
    alert_rule_test:
      - eval_time: 0h # => hour would be 0
        alertname: alertXYZ
      - eval_time: 1h  # => hour would be 1
        alertname: alertXYZ
      - eval_time: 2h  # => hour would be 2
        alertname: alertXYZ
      - eval_time: 3h # => hour would be 3
        alertname: alertXYZ
      - eval_time: 4h # => hour would be 4
     .....
fabs
  • 77
  • 1
  • 1
  • 13