diff --git a/cmd/promxy/config.yaml b/cmd/promxy/config.yaml index 75250cf25..95f296b8f 100644 --- a/cmd/promxy/config.yaml +++ b/cmd/promxy/config.yaml @@ -45,6 +45,7 @@ promxy: # configures the path to send remote read requests to. The default is "api/v1/read" remote_read_path: api/v1/read # path_prefix defines a prefix to prepend to all queries to hosts in this servergroup + # This can be relabeled using __path_prefix__ path_prefix: /example/prefix # query_params adds the following map of query parameters to downstream requests. # The initial use-case for this is to add `nocache=1` to VictoriaMetrics downstreams diff --git a/pkg/servergroup/config.go b/pkg/servergroup/config.go index 0c59ba8f3..7abed26d9 100644 --- a/pkg/servergroup/config.go +++ b/pkg/servergroup/config.go @@ -23,6 +23,11 @@ var ( } ) +const ( + // PathPrefixLabel is the name of the label that holds the path prefix for a scrape target. + PathPrefixLabel = "__path_prefix__" +) + // Config is the configuration for a ServerGroup that promxy will talk to. // This is where the vast majority of options exist. type Config struct { diff --git a/pkg/servergroup/servergroup.go b/pkg/servergroup/servergroup.go index 0624ddcca..3d1f1658e 100644 --- a/pkg/servergroup/servergroup.go +++ b/pkg/servergroup/servergroup.go @@ -109,7 +109,8 @@ SYNC_LOOP: for _, targetGroupList := range targetGroupMap { for _, targetGroup := range targetGroupList { for _, target := range targetGroup.Targets { - lbls := make([]labels.Label, 0, len(target)+len(targetGroup.Labels)) + + lbls := make([]labels.Label, 0, len(target)+len(targetGroup.Labels)+2) for ln, lv := range target { lbls = append(lbls, labels.Label{Name: string(ln), Value: string(lv)}) @@ -121,7 +122,11 @@ SYNC_LOOP: } } + lbls = append(lbls, labels.Label{Name: model.SchemeLabel, Value: string(s.Cfg.Scheme)}) + lbls = append(lbls, labels.Label{Name: PathPrefixLabel, Value: string(s.Cfg.PathPrefix)}) + lset := labels.New(lbls...) + logrus.Tracef("Potential target pre-relabel: %v", lset) lset = relabel.Process(lset, s.Cfg.RelabelConfigs...) logrus.Tracef("Potential target post-relabel: %v", lset) @@ -137,10 +142,11 @@ SYNC_LOOP: } u := &url.URL{ - Scheme: string(s.Cfg.GetScheme()), - Host: string(lset.Get(model.AddressLabel)), - Path: s.Cfg.PathPrefix, + Scheme: lset.Get(model.SchemeLabel), + Host: lset.Get(model.AddressLabel), + Path: lset.Get(PathPrefixLabel), } + targets = append(targets, u.Host) client, err := api.NewClient(api.Config{Address: u.String(), RoundTripper: s.client.Transport})