thanos-io/thanos · error

invalid alert source template

Error message

invalid alert source template

What it means

This error is returned when validateTemplate rejects the alert source template configured for the Rule component's Alertmanager. runRule validates the template after building the query config. It means the alertsource template text is not a valid template (parse/compile failure).

Solutions

  1. Check the template braces are balanced and all actions are closed: {{ ... }}.
  2. Simplify the template to a known-good minimal value and re-add parts until it fails to find the culprit.
  3. Escape braces correctly for your shell/manifest (single-quote flag values in scripts).
  4. Consult the validateTemplate implementation for the exact parse error wrapped under this message.

Example fix

// before
--alert.source-template='{{ if .Labels }}{{ .Labels
// after
--alert.source-template='{{ .GeneratorURL }}'
Defensive patterns

Strategy: validation

Validate before calling

func validTemplate(t string) bool {
    _, err := template.New("probe").Funcs(funcMap).Parse(t)
    return err == nil
}

Prevention

When it happens

Trigger: conf.alertmgr.alertSourceTemplate contains a template string that fails validateTemplate — e.g. unbalanced {{ }} braces or invalid template functions/actions.

Common situations: Hand-editing the --alert.source-template flag and leaving an unclosed `{{` or using a function the template engine doesn't expose; quoting problems in the shell stripping braces.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/ad489ca6556f4b6f. Report an issue: GitHub.

Appendix: source

Thrown at cmd/thanos/rule.go:380

					HTTPConfig: clientconfig.HTTPConfig{
						EndpointsConfig: clientconfig.HTTPEndpointsConfig{
							Scheme:        "http",
							FileSDConfigs: fileSDConfigs,
						},
					},
				},
			)
		}

		grpcQueryCfg, err := clientconfig.BuildConfigFromGRPCAddresses(conf.grpcQueryEndpoints)
		if err != nil {
			return errors.Wrap(err, "query configuration")
		}
		queryCfg = append(queryCfg, grpcQueryCfg...)
	}

	if err := validateTemplate(*conf.alertmgr.alertSourceTemplate); err != nil {
		return errors.Wrap(err, "invalid alert source template")
	}

	queryProvider := dns.NewProvider(
		logger,
		extprom.WrapRegistererWithPrefix("thanos_rule_query_apis_", reg),
		dns.ResolverType(conf.query.dnsSDResolver),
	)
	var (
		queryClients    []*clientconfig.HTTPClient
		promClients     []*promclient.Client
		grpcEndpointSet *query.EndpointSet
		grpcEndpoints   []string
	)

	queryClientMetrics := extpromhttp.NewClientMetrics(extprom.WrapRegistererWith(prometheus.Labels{"client": "query"}, reg))

	for _, cfg := range queryCfg {
		if cfg.HTTPConfig.NotEmpty() {

View on GitHub (pinned to 35b8b99117)