Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uppromtool rules migration produces unreadable rule files #3115
Comments
This comment has been minimized.
This comment has been minimized.
|
First one seems hard to fix given how the Go maps and probably the YAML lib work. How are we feeling about our decision overall? So far it seems there's some migration pain and YAML isn't free of issues either but generally I've heard several people welcome the decision as it's easier to work with in general. |
This comment has been minimized.
This comment has been minimized.
|
The indentation issue was unexpected, but doesn't seem to have caused problems overall so I think YAML is still the way to go. |
This comment has been minimized.
This comment has been minimized.
|
FYI, I migrated my (handful of) rules manually and reached some conclusions regarding how to combine YAML, go templates and Prometheus' rule language to get something that's (1) easy to migrate and (2) easy to understand and thus maintain. I still find the combination of the 3 different formats/languages with wildly different newline, quoting and whitespace requirements a huge and unnecessary PITA, but that's not the point. This approach may be useful for writing an automated tool (way too much for my own needs) or for aiding in a manual migration. I'll start off with a rather complex sample migrated rule so you can appreciate whether it's worth the effort or not: - alert: TasksMissing
expr: |
(
# Compare with a matching job-specific threshold, keeping all labels on the left
job_env:up:ratio
<= on(job) group_left()
job:up:ratio_critical_threshold
) or (
# Or select all jobs without a matching job-specific threshold
(
job_env:up:ratio
unless on(job)
job:up:ratio_critical_threshold
)
# And compare with the default threshold, keeping all labels on the left
<= on() group_left()
job:up:ratio_critical_threshold{job=""}
)
for: 1m
labels:
severity: critical
annotations:
summary: Tasks missing for {{ $labels.job }} in {{ $labels.env }}
description:
'{{ with printf `job_env:up:count{job="%s",env="%s"} - job_env:up:sum{job="%s",env="%s"}` $labels.job $labels.env $labels.job $labels.env | query }}
{{- . | first | value -}}
{{ end }}
of
{{ with printf `job_env:up:count{job="%s",env="%s"}` $labels.job $labels.env | query }}
{{- . | first | value -}}
{{ end }}
{{ $labels.job }} instances are missing in {{ $labels.env }}:
{{ range printf `up{job="%s",env="%s"}==0` $labels.job $labels.env | query }}
{{- .Labels.instance }}
{{ end }}'
debug: '{{ externalURL }}{{ printf `up{job="%s",env="%s"}==0` $labels.job $labels.env | graphLink }}'Note how it allows you to keep indentation, newlines and comments even though YAML tries really hard to prevent it. It basically uses literal block notation and single quoted flow notation in different places and limits specific quotation characters to specific uses. The basic ideas are
All in all very simple and natural.</sarcasm> But if anyone was willing (and had gobs of time) it would be possible to automate at least parts of it. |
gouthamve
added
the
hacktoberfest
label
Sep 28, 2017
This comment has been minimized.
This comment has been minimized.
|
This is obsolete as the rule migration tool is deprecated by now and taken out of current releases. However, pretty formatting of rules is still a thing, see #5370 . Still, closing this one to avoid confusion. |
grobie commentedAug 25, 2017
The current rules files migration tool produces output files which are unusable for us.
Smaller issues:
"^(?:ext.|xfs)$"instead of"ext.|xfs"Bigger issue:
promtool fmtformatting should be used here.