VictoriaMetrics/VictoriaMetrics · error
cannot parse server url=%q: %w
Error message
cannot parse server url=%q: %w
What it means
getAPIServerPath parses the (scheme-prefixed) server URL with net/url.Parse. If parsing fails, the error is wrapped with this message including the full server string. It means the Kuma control-plane URL is syntactically invalid even after the automatic http:// prefixing.
Source
Thrown at lib/promscrape/discovery/kuma/api.go:113
return nil, fmt.Errorf("cannot discover Kuma targets: %w", err)
}
cfg.wg.Go(func() {
cfg.runTargetsWatcher(ctx)
})
return cfg, nil
}
func getAPIServerPath(serverURL string) (string, string, error) {
if serverURL == "" {
return "", "", fmt.Errorf("missing server url")
}
if !strings.Contains(serverURL, "://") {
serverURL = "http://" + serverURL
}
psu, err := url.Parse(serverURL)
if err != nil {
return "", "", fmt.Errorf("cannot parse server url=%q: %w", serverURL, err)
}
apiServer := fmt.Sprintf("%s://%s", psu.Scheme, psu.Host)
apiPath := psu.Path
if !strings.HasSuffix(apiPath, "/") {
apiPath += "/"
}
apiPath += "v3/discovery:monitoringassignments"
if psu.RawQuery != "" {
apiPath += "?" + psu.RawQuery
}
return apiServer, apiPath, nil
}
func (cfg *apiConfig) runTargetsWatcher(ctx context.Context) {
ticker := time.NewTicker(*SDCheckInterval)
defer ticker.Stop()
doneCh := ctx.Done()View on GitHub (pinned to 5079fb58f1)
Solutions
- Fix the `server` value so it parses as a URL (quote it in YAML, remove spaces/control chars)
- Wrap IPv6 hosts in brackets: `http://[::1]:5676`
- Pre-validate with Go url.Parse or any URL validator before deploying the config
- Read the wrapped error to see url.Parse's exact complaint (e.g. invalid port, invalid character)
Example fix
# before server: http://kuma cp:5676 # unquoted, contains space # after server: "http://kuma-cp:5676"
Defensive patterns
Strategy: validation
Validate before calling
func validKumaURL(server string) error {
if server == "" {
return errors.New("missing server url")
}
u := server
if !strings.Contains(u, "://") {
u = "http://" + u
}
psu, err := url.Parse(u)
if err != nil {
return fmt.Errorf("invalid server url %q: %w", server, err)
}
if psu.Host == "" {
return fmt.Errorf("server url %q has no host", server)
}
return nil
} Try / catch
ac, err := kuma.NewSDConfig(sdc)
if err != nil {
if strings.Contains(err.Error(), "cannot parse server url") {
log.Errorf("malformed kuma server URL: %v", err)
}
return err
} Prevention
- Quote server URLs in YAML files
- Remove whitespace/control characters pasted into URLs
- Bracket IPv6 literals: http://[::1]:5676
- Run url.Parse-based validation in CI on scrape configs
When it happens
Trigger: Server string containing spaces, control characters, stray brackets/quotes, or otherwise failing url.Parse (e.g. `server: "http://kuma cp:5676"`), when getAPIServerPath runs.
Common situations: Unquoted YAML values with special characters; copy-pasted URLs with trailing whitespace; IPv6 literal addresses missing brackets; templating artifacts left in the URL.
Related errors
- cannot parse server %q: %w
- cannot create HTTP client for %q: %w
- missing server url
- cannot parse auth config: %w
- cannot parse proxy auth config: %w
AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03).
Data as JSON: /api/errors/983525d1ca107975.
Report an issue: GitHub.