Skip to content

Commit

Permalink
Add scrape target path and scheme relabelling
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinBisson authored and jacksontj committed Jan 19, 2021
1 parent f6fdd39 commit 3a16c3e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/promxy/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/servergroup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 10 additions & 4 deletions pkg/servergroup/servergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
Expand All @@ -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)
Expand All @@ -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})
Expand Down

0 comments on commit 3a16c3e

Please sign in to comment.