Alerting: do not expand template for labels\annotations if value is not a template (#71492)

This commit is contained in:
Yuri Tseretyan 2023-07-12 14:53:40 -04:00 committed by GitHub
parent 5099e88227
commit 64aa5465ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,6 +96,10 @@ func (e ExpandError) Error() string {
}
func Expand(ctx context.Context, name, tmpl string, data Data, externalURL *url.URL, evaluatedAt time.Time) (string, error) {
if !strings.Contains(tmpl, "{{") { // If it is not a template, skip expanding it.
return tmpl, nil
}
// add __alert_ to avoid possible conflicts with other templates
name = "__alert_" + name
// add variables for the labels and values to the beginning of the template