Alertmanager uses Go templates to template notifications. In Go templates, 
it is possible to re-define existing templates across multiple calls to 
Parse(text string), but not in the same call to Parse(text string).

For example, the following template returns the error "template: tmpl:1: 
template: multiple definition of template "tmpl"":

{{ define "tmpl" }}{{ .Var1 }}{{ end }}{{ define "tmpl" }}{{ .Var2 }}{{ end 
}}

However, if we call parse twice, first with:

{{ define "tmpl" }}{{ .Var1 }}{{ end }}

and then with:

{{ define "tmpl" }}{{ .Var2 }}{{ end }}

The second template "tmpl" will replace the first template "tmpl".

When using FromGlobs, as done in Alertmanager, duplicate templates replace 
each other like in the second example rather than conflict like in the 
first example.

In the case where Alertmanager is used for large, multi-team installations, 
great care is required to ensure that no two templates write templates with 
conflicting names. In most cases, the error would not be noticed until a 
notification was sent, and even then might be hard to debug.

Despite this behaviour being intentional in Go, I wonder if it is 
undesirable in Alertmanager for the reasons aforementioned. Changing this 
behaviour, however, would require additional parsing code outside of 
text/template and html/template as from the perspective of the template 
there is just one parsed template per name.

George

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to prometheus-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-developers/d7ddb4c0-7da5-4684-8440-2d239152a145n%40googlegroups.com.

Reply via email to