{"record":{"id":"85fea78978a07d5f","repo":"thanos-io/thanos","slug":"unable-to-create-request","errorCode":null,"errorMessage":"unable to create request","messagePattern":"unable to create request","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/prometheus.go","lineNumber":472,"sourceCode":"\n\treturn chks, nil\n}\n\nfunc (p *PrometheusStore) startPromRemoteRead(ctx context.Context, q *prompb.Query) (presp *http.Response, err error) {\n\treqb, err := proto.Marshal(&prompb.ReadRequest{\n\t\tQueries:               []*prompb.Query{q},\n\t\tAcceptedResponseTypes: p.remoteReadAcceptableResponses,\n\t})\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"marshal read request\")\n\t}\n\n\tu := *p.base\n\tu.Path = path.Join(u.Path, \"api/v1/read\")\n\n\tpreq, err := http.NewRequest(\"POST\", u.String(), bytes.NewReader(snappy.Encode(nil, reqb)))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"unable to create request\")\n\t}\n\tpreq.Header.Add(\"Content-Encoding\", \"snappy\")\n\tpreq.Header.Set(\"Content-Type\", \"application/x-stream-protobuf\")\n\tpreq.Header.Set(\"X-Prometheus-Remote-Read-Version\", \"0.1.0\")\n\n\tpreq.Header.Set(\"User-Agent\", clientconfig.ThanosUserAgent)\n\tpresp, err = p.client.Do(preq.WithContext(ctx))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"send request\")\n\t}\n\tif presp.StatusCode/100 != 2 {\n\t\t// Best effort read.\n\t\tb, err := io.ReadAll(presp.Body)\n\t\tif err != nil {\n\t\t\tlevel.Error(p.logger).Log(\"msg\", \"failed to read response from non 2XX remote read request\", \"err\", err)\n\t\t}\n\t\t_ = presp.Body.Close()\n\t\treturn nil, errors.Errorf(\"request failed with code %s; msg %s\", presp.Status, string(b))","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/prometheus.go#L454-L490","documentation":"After building the URL (base + /api/v1/read), startPromRemoteRead creates the POST http.Request via http.NewRequest. If the URL is invalid or malformed, the wrapped error \"unable to create request\" is returned. This almost always means the store's configured base address is not a valid absolute HTTP URL.","triggerScenarios":"Constructing a PrometheusStore with --store-address / base URL that is empty, missing scheme (e.g. \"prometheus:9090\" instead of \"http://prometheus:9090\"), or contains characters http.NewRequest rejects (spaces, control chars).","commonSituations":"Typo in store address flag; missing http:// scheme prefix in static config or file_sd targets; environment interpolation producing an empty address; invalid characters from templated addresses.","solutions":["Fix the store's base address to be a full absolute URL including scheme (http://host:9090)","Validate the address at store-creation time with url.Parse before issuing queries","Check config files/env vars feeding the address for empty or malformed values","Verify path joining does not produce an invalid URL when the base path is unusual"],"exampleFix":"// before\naddress: \"prometheus:9090\"\n// after\naddress: \"http://prometheus:9090\"","handlingStrategy":"validation","validationCode":"u, err := url.Parse(addr)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid store address %q: need absolute URL with scheme\", addr)\n}","typeGuard":null,"tryCatchPattern":"resp, err := store.Series(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"unable to create request\") {\n    // address malformed: fix --store-address / config and re-create the store\n}","preventionTips":["Always include the scheme (http:// or https://) in store addresses","Validate addresses at startup, not on first query","Escape/trim whitespace from templated or env-provided addresses"],"tags":["prometheus","http","url","configuration"],"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"}