thanos-io/thanos · error

alertmanagers.url contains empty host

Error message

alertmanagers.url contains empty host

What it means

BuildAlertmanagerConfig requires the alertmanagers.url to include a host; an empty host means a scheme was present but no hostname/IP followed (e.g. "http://"). The client cannot target any endpoint without it.

Solutions

  1. Set a complete URL including host: http://alertmanager:9093.
  2. Check that the env var/template producing the host is populated in the actual runtime environment.
  3. Validate the URL with net/url.Parse and require Host != "" before writing config.

Example fix

// before
url: ${ALERTMANAGER_HOST}   # ALERTMANAGER_HOST empty -> http://
// after
url: http://alertmanager.monitoring.svc:9093
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(cfg.URL)
if err != nil || u.Host == "" {
    return fmt.Errorf("alertmanagers.url %q must include a host", cfg.URL)
}

Prevention

When it happens

Trigger: url like "http://" or "https:///path" in alertmanagers config; template variable for the host part resolving to empty string.

Common situations: Environment variable like ALERTMANAGER_URL set to empty in the deployment, yielding http://; truncated URL after removing a hostname; YAML template with unfilled placeholder.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


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

Appendix: source

Thrown at pkg/alert/config.go:104

	}
	return cfg, nil
}

// BuildAlertmanagerConfig initializes and returns an Alertmanager client configuration from a static address.
func BuildAlertmanagerConfig(address string, timeout time.Duration) (AlertmanagerConfig, error) {
	parsed, err := url.Parse(address)
	if err != nil {
		return AlertmanagerConfig{}, err
	}

	scheme := parsed.Scheme
	if scheme == "" {
		return AlertmanagerConfig{}, errors.New("alertmanagers.url contains empty scheme")
	}

	host := parsed.Host
	if host == "" {
		return AlertmanagerConfig{}, errors.New("alertmanagers.url contains empty host")
	}

	for _, qType := range []dns.QType{dns.A, dns.SRV, dns.SRVNoA} {
		prefix := string(qType) + "+"
		if strings.HasPrefix(strings.ToLower(scheme), prefix) {
			// Scheme is of the form "<dns type>+<http scheme>".
			scheme = strings.TrimPrefix(scheme, prefix)
			host = prefix + parsed.Host
			if qType == dns.A {
				if _, _, err := net.SplitHostPort(parsed.Host); err != nil {
					// The host port could be missing. Append the defaultAlertmanagerPort.
					host = host + ":" + strconv.Itoa(defaultAlertmanagerPort)
				}
			}
			break
		}
	}
	var basicAuth clientconfig.BasicAuth

View on GitHub (pinned to 35b8b99117)