Skip to content

Give a more explicit error in promtool when number of alerts does not match#7883

Closed
lebaptiste wants to merge 1 commit intoprometheus:masterfrom
lebaptiste:explicit-exp-alerts-error
Closed

Give a more explicit error in promtool when number of alerts does not match#7883
lebaptiste wants to merge 1 commit intoprometheus:masterfrom
lebaptiste:explicit-exp-alerts-error

Conversation

@lebaptiste
Copy link
Copy Markdown

@lebaptiste lebaptiste commented Sep 2, 2020

When testing a new alert with promtool I made a silly mistake in the yaml:

      - alertname: my_alert
        eval_time: 1m
        exp_alerts:
          - exp_labels:
              team: myteam
              severity: critical
              environment: prod
          -  exp_annotations:       # <= wrong '-' added by mistake! It is rightly understood as 2 distinct alerts
              summary: "My summary..."
              description: "My description..."

Since the alertname is appended by the tool to the expected labels, I did not get exactly what went wrong when reading the error dump. I only realised my mistake after debugging the tool.
This PR is to give a bit more context and explicitly reporting that the length of alerts is not what expected.

Error dump before:

  FAILED:
    alertname:myalert, time:1m, 
        exp:"[Labels:{alertname=\"myalert\", environment=\"prod\", severity=\"critical\", team=\"myteam\"} Annotations:{}, Labels:{alertname=\"myalert\"} Annotations:{description=\"My description...\", summary=\"My summary...\"}]", 
        got:"[Labels:{alertname=\"myalert\", environment=\"prod\", severity=\"critical\", team=\"myteam\"} Annotations:{description=\"My description...\", summary=\"My summary...\"}]"

Error dump after:

  FAILED:
    alertname:myalert, time:1m, 
        exp:2 alerts "[Labels:{alertname=\"myalert\"} Annotations:{description=\"My description...\", summary=\"My summary...\"}, Labels:{alertname=\"myalert\", environment=\"prod\", severity=\"critical\", team=\"myteam\"} Annotations:{}]", 
        got:1 alerts "[Labels:{alertname=\"myalert\", environment=\"prod\", severity=\"critical\", team=\"myteam\"} Annotations:{description=\"My description...\", summary=\"My summary...\"}]"

I have also sorted the alerts before outputting the dump for better read.

Signed-off-by: Baptiste Lefrancois <lebaptiste.dev@gmail.com>
@roidelapluie
Copy link
Copy Markdown
Member

cc @simonpasquier

@codesome
Copy link
Copy Markdown
Member

Closing in favor of #8064, thanks for the PR @lebaptiste!

@codesome codesome closed this Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants