diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 458a8dd31..d8ca91469 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -669,6 +669,9 @@ func appendScrapeWork(dst []ScrapeWork, swc *scrapeWorkConfig, target string, ex if metricsPathRelabeled == "" { metricsPathRelabeled = "/metrics" } + if !strings.HasPrefix(metricsPathRelabeled, "/") { + metricsPathRelabeled = "/" + metricsPathRelabeled + } paramsRelabeled := getParamsFromLabels(labels, swc.params) optionalQuestion := "?" if len(paramsRelabeled) == 0 || strings.Contains(metricsPathRelabeled, "?") { diff --git a/lib/promscrape/config_test.go b/lib/promscrape/config_test.go index f1dd2727b..380c481e7 100644 --- a/lib/promscrape/config_test.go +++ b/lib/promscrape/config_test.go @@ -1333,6 +1333,45 @@ scrape_configs: jobNameOriginal: "snmp", }, }) + f(` +scrape_configs: +- job_name: path wo slash + static_configs: + - targets: ["foo.bar:1234"] + relabel_configs: + - replacement: metricspath + target_label: __metrics_path__ +`, []ScrapeWork{ + { + ScrapeURL: "http://foo.bar:1234/metricspath", + ScrapeInterval: defaultScrapeInterval, + ScrapeTimeout: defaultScrapeTimeout, + Labels: []prompbmarshal.Label{ + { + Name: "__address__", + Value: "foo.bar:1234", + }, + { + Name: "__metrics_path__", + Value: "metricspath", + }, + { + Name: "__scheme__", + Value: "http", + }, + { + Name: "instance", + Value: "foo.bar:1234", + }, + { + Name: "job", + Value: "path wo slash", + }, + }, + jobNameOriginal: "path wo slash", + AuthConfig: &promauth.Config{}, + }, + }) } var defaultRegexForRelabelConfig = regexp.MustCompile("^(.*)$")