Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unittest does not work with complex expressions #4749

Closed
mbeltre opened this Issue Oct 16, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@mbeltre
Copy link

mbeltre commented Oct 16, 2018

Bug Report

What did you do?
I have the following rules file:

groups:
  - name: test
    rules:
      - alert: TestAlertComplex
        annotations:
          description: Complex alert test
          summary: Really complex expression
        expr: ceil(sum(rate(my_metric_count[5m]))) > 1
        for: 1m
        labels:
          namespace: dev

And the following unit test file

rule_files:
  - rules.yml

tests:
  - interval: 5m
    input_series:
      - series: my_metric_count
        values: 600
  
    alert_rule_test:
      - eval_time: 5m
        alertname: TestAlertComplex
        exp_alerts: 
          - exp_labels:
              namespace: dev

What did you expect to see?
I was expecting the TestAlertComplex to be triggered in this case.

What did you see instead? Under which circumstances?

Unit Testing:  alert_tests.yml
    alertname:TestAlertComplex, time:5m0s,
        exp:"[Labels:{alertname=\"TestAlertComplex\", namespace=\"dev\"} Annotations:{}]",
        got:"[]"

Environment

  • System information:

    • Darwin 17.7.0 x86_64
  • Prometheus version:

prometheus, version  (branch: master, revision: c4a6acf )
  build user:
  build date:
  go version:       go1.11.1```



@mbeltre mbeltre changed the title test unittest does not work with complex expressions Oct 16, 2018

@simonpasquier

This comment has been minimized.

Copy link
Member

simonpasquier commented Oct 17, 2018

I'm not super familiar with this new feature but I suspect that the problem is because the metric doesn't increase. If I change the input series to this, the alert fires:

  - interval: 1m
    input_series:
      - series: my_metric_count
        values: 600 1000 12300 12312312 12313132132

cc @codesome

@mbeltre

This comment has been minimized.

Copy link
Author

mbeltre commented Oct 18, 2018

thanks, that did actually work. I suppose it's using the first value as a baseline, i din't think about that.

@mbeltre mbeltre closed this Oct 18, 2018

@codesome

This comment has been minimized.

Copy link
Member

codesome commented Oct 18, 2018

@mbeltre The first value from input is at timestamp 0. So did you miss this point?

@lock lock bot locked and limited conversation to collaborators Apr 16, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.