{"record":{"id":"2fd5f1b75530a77d","repo":"thanos-io/thanos","slug":"parse-alert-query-url","errorCode":null,"errorMessage":"parse alert query url","messagePattern":"parse alert query url","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/rule.go","lineNumber":196,"sourceCode":"\t\t\"(Deprecated) Enables the ingestion of native histograms. This flag is a no-op now and will be removed in the future. Native histogram ingestion is always enabled.\").\n\t\tDefault(\"true\").BoolVar(&conf.tsdbEnableNativeHistograms)\n\n\tconf.rwConfig = extflag.RegisterPathOrContent(cmd, \"remote-write.config\", \"YAML config for the remote-write configurations, that specify servers where samples should be sent to (see https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write). This automatically enables stateless mode for ruler and no series will be stored in the ruler's TSDB. If an empty config (or file) is provided, the flag is ignored and ruler is run with its own TSDB.\", extflag.WithEnvSubstitution())\n\n\tconf.objStoreConfig = extkingpin.RegisterCommonObjStoreFlags(cmd, \"\", false)\n\n\treqLogConfig := extkingpin.RegisterRequestLoggingFlags(cmd)\n\n\tvar err error\n\tcmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, reload <-chan struct{}, _ bool) error {\n\t\tconf.lset, err = parseFlagLabels(*labelStrs)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"parse labels\")\n\t\t}\n\n\t\tconf.alertQueryURL, err = url.Parse(*conf.alertmgr.alertQueryURL)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"parse alert query url\")\n\t\t}\n\n\t\ttsdbOpts := &tsdb.Options{\n\t\t\tMinBlockDuration:  int64(time.Duration(*tsdbBlockDuration) / time.Millisecond),\n\t\t\tMaxBlockDuration:  int64(time.Duration(*tsdbBlockDuration) / time.Millisecond),\n\t\t\tRetentionDuration: int64(time.Duration(*tsdbRetention) / time.Millisecond),\n\t\t\tNoLockfile:        *noLockFile,\n\t\t\tWALCompression:    compressutil.ParseCompressionType(*walCompression, compression.Snappy),\n\t\t}\n\n\t\tagentOpts := &agent.Options{\n\t\t\tWALCompression: compressutil.ParseCompressionType(*walCompression, compression.Snappy),\n\t\t\tNoLockfile:     *noLockFile,\n\t\t}\n\n\t\t// Parse and check query configuration.\n\t\tlookupQueries := map[string]struct{}{}\n\t\tfor _, q := range conf.query.addrs {","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/rule.go#L178-L214","documentation":"After parsing labels, the rule command parses --alertmanagers.url (alertQueryURL) with net/url.Parse. This wraps the parse error when the URL string is malformed and aborts startup, since the alert manager client cannot be built from an invalid URL.","triggerScenarios":"url.Parse(*conf.alertmgr.alertQueryURL) returns an error for strings with invalid characters (spaces, unescaped control chars) or grossly malformed schemes that url.Parse rejects (e.g. 'http://al ert:9093' or '://host').","commonSituations":"Space in the URL from a YAML list split across lines; unencoded special characters like % or | in the host; forgetting the scheme combined with odd syntax; shell quoting mangling the value.","solutions":["URL-encode the value and remove whitespace: --alertmanagers.url=http://alertmanager:9093.","Quote the flag in the shell/Helm values so spaces or pipes are not interpreted.","Verify each URL parses with a quick script (python -c \"import urllib.parse;urllib.parse.urlparse('...')\").","If using multiple URLs, ensure each entry in --alertmanagers.url is individually valid."],"exampleFix":"// before\nthanos rule --alertmanagers.url=http://alert manager:9093\n// after\nthanos rule --alertmanagers.url=http://alertmanager:9093","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\ndef check_alertmanager_url(u):\n    p = urlparse(u)\n    if p.scheme not in (\"http\", \"https\") or not p.netloc or any(c.isspace() for c in u):\n        raise SystemExit(f\"invalid --alertmanagers.url: {u!r}\")\n    return u","typeGuard":"def is_valid_url(u):\n    from urllib.parse import urlparse\n    try:\n        p = urlparse(u)\n        return bool(p.scheme in (\"http\", \"https\") and p.netloc)\n    except (ValueError, AttributeError):\n        return False","tryCatchPattern":null,"preventionTips":["Validate URLs in Helm values with schema checks before deploy.","Never leave raw spaces or unencoded '%' in URLs.","Quote all URL flags in shell/systemd units.","One URL per flag occurrence when passing multiple alertmanagers."],"tags":["cli","url","config","startup"],"backgroundTag":"invalid-url-format","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}