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

promtool convert alert rules don't respect the go template #5121

Open
DreamRivulet opened this Issue Jan 21, 2019 · 8 comments

Comments

Projects
None yet
4 participants
@DreamRivulet
Copy link

DreamRivulet commented Jan 21, 2019

What did you do?
I use the promtool to convert old 1.8 version alert rules to new yaml format.

What did you expect to see?
template like {{ var }} should not be split into multi-line.

What did you see instead? Under which circumstances?
template {{ var }} are split like:

..., This is a alert template {{ var 
  }}

when string is long.

Environment

  • System information:

    Linux 4.4.0-130-generic x86_64

  • Prometheus version:

  promtool, version 2.5.0 (branch: HEAD, revision: 67dc912ac8b24f94a1fc478f352d25179c94ab9b)
  build user:       root@578ab108d0b9
  build date:       20181106-11:40:44
  go version:       go1.11.1

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Jan 21, 2019

Does this change the resulting output label?

@DreamRivulet

This comment has been minimized.

Copy link
Author

DreamRivulet commented Jan 21, 2019

yes, the alert template will not work when span newlines, see: go template.

@DreamRivulet

This comment has been minimized.

Copy link
Author

DreamRivulet commented Jan 21, 2019

It's better that promtool can respect the go template when converting alert rules into yaml format, i see promtool uses https://github.com/go-yaml/yaml to do the marshal, but i didn't find any place which will split the string into multi-lines.

@simonpasquier

This comment has been minimized.

Copy link
Member

simonpasquier commented Jan 21, 2019

Can you share the original alert rule file?

@DreamRivulet

This comment has been minimized.

Copy link
Author

DreamRivulet commented Jan 21, 2019

## alert.rules ##
  ALERT WorkerFailedAlert
    IF changes(worker_fail_count [300m]) > 3
    LABELS {
      severity = "warning",
      workerID = "{{ $labels.workerID }}",
      alert_key = "This is a test to prove that promtool fails , {{ $labels.workerID }}"
    }

Above is a simple old format alert rule, you can use the promtool to convert it, then you will get the following output:

groups:
- name: test.rules
  rules:
  - alert: WorkerFailedAlert
    expr: changes(worker_fail_count[5h]) > 3
    labels:
      alert_key: This is a test to prove that promtool fails , {{ $labels.workerID
        }}
      severity: warning
      workerID: '{{ $labels.workerID }}'
@codesome

This comment has been minimized.

Copy link
Member

codesome commented Jan 21, 2019

Related go-yaml/yaml#166

@DreamRivulet

This comment has been minimized.

Copy link
Author

DreamRivulet commented Jan 22, 2019

It looks like the fix will merged into go-yaml v3 version, will promtool upgrade the go-yaml to v3 when it's available ?

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Jan 22, 2019

This code no longer exists in current master. If the yaml library is producing output that it itself can't parse, we should probably add that information to that bug.

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