-
Notifications
You must be signed in to change notification settings - Fork 467
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat alertmanager: add new template function grafanaExploreURL #3849
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one :) left one suggestion, otherwise LGTM
}, | ||
}) | ||
if err != nil { | ||
panic(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit reluctant of including this especially for something that runs on a regular basis in the alertmanager. WDYT about returning a string which contains the error? It will result in ugly templates, but won't crash the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not sure about that one. But the panic is wrong either way, the function should return error probably as described in https://pkg.go.dev/text/template#FuncMap
I do see your point on not failing, on the other way Alertmanager does expose metrics about failed template renders and if it does not fail, it might stay unnoticed otherwise you should have an alert on failed template renders anyway 馃し
Alertmanager itself panics or returns errors but does not render the error as a result, but I do not have a strong opinion, so if you prefer rendering it, I'll be happy to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, refactored to return the error properly in 57d203b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I have a question about the actual generated URL and a couple of nits 馃檱
docs/sources/mimir/operators-guide/architecture/components/alertmanager.md
Outdated
Show resolved
Hide resolved
{ | ||
name: "generate grafana explore URL", | ||
template: `{{ grafanaExploreURL "https://foo.bar" "test_datasoruce" "now-12h" "now" "up{foo!=\"bar\"}" }}`, | ||
result: `https://foo.bar/explore?left=` + url.QueryEscape(`{"datasource":"test_datasoruce","range":{"from":"now-12h","to":"now"},"queries":[{"datasource":"test_datasoruce","expr":"up{foo!=\"bar\"}","instant":false,"range":true,"refId":"A"}]}`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to compare it with the URL generated by Grafana 9.4 and I got it slightly different (look at the datasource
inside queries
):
{
"datasource":"P1809F7CD0C75ACF3",
"queries":[{"refId":"A","datasource":{"type":"prometheus","uid":"P1809F7CD0C75ACF3"},"editorMode":"code","expr":"count(up)","legendFormat":"__auto","range":true,"instant":false}],
"range":{"from":"now-1h","to":"now"}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yes, there are more somehow backward compatible ways to refer to datasource (even in the dashboard JSON IIRC).
But yes, you're right. I updated it and seems to be working even with our 9.2 Grafana instance, so hopefully will be compatible enough.
PTAL e7abe5c
Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
e7abe5c
to
db42bbd
Compare
Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
Rebased and added changelog note |
Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
As discussed in #2997 (comment)
Not sure about the naming 馃し
Moved the custom template functions to a separate file for more clarity, tests are passing and generated URL seems to be working.