Skip to content

Commit

Permalink
proxy metadata requests to the default tenant if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
blind-oracle committed Mar 10, 2022
1 parent 9c42710 commit bcaeed2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -56,6 +56,10 @@ timeout: 10s
timeout_shutdown: 10s
# Max number of parallel incoming HTTP requests to handle
concurrency: 10
# Whether to forward metrics metadata from Prometheus to Cortex
# Since metadata requests have no timeseries in them - we cannot divide them into tenants
# So the metadata requests will be sent to the default tenant only, if one is not defined - they will be dropped
metadata: false

tenant:
# Which label to look for the tenant information
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
1.5.0
1.6.0
1 change: 1 addition & 0 deletions config.go
Expand Up @@ -19,6 +19,7 @@ type config struct {
Timeout time.Duration
TimeoutShutdown time.Duration `yaml:"timeout_shutdown"`
Concurrency int
Metadata bool

Tenant struct {
Label string
Expand Down
1 change: 1 addition & 0 deletions config.yml
Expand Up @@ -6,6 +6,7 @@ log_level: debug
timeout: 10s
timeout_shutdown: 0s
concurrency: 10
metadata: false

tenant:
label: tenant
Expand Down
18 changes: 15 additions & 3 deletions processor.go
Expand Up @@ -113,19 +113,31 @@ func (p *processor) handle(ctx *fh.RequestCtx) {
return
}

clientIP := ctx.RemoteAddr()
reqID, _ := uuid.NewRandom()

if len(wrReqIn.Timeseries) == 0 {
// If there's metadata - just accept the request and drop it
if len(wrReqIn.Metadata) > 0 {
if p.cfg.Metadata && p.cfg.Tenant.Default != "" {
code, body, err := p.send(clientIP, reqID, p.cfg.Tenant.Default, wrReqIn)
if err != nil {
ctx.Error(err.Error(), fh.StatusInternalServerError)
p.Errorf("src=%s req_id=%s: unable to proxy metadata: %s", clientIP, reqID, err)
return
}

ctx.SetStatusCode(code)
ctx.SetBody(body)
}

return
}

ctx.Error("No timeseries found in the request", fh.StatusBadRequest)
return
}

clientIP := ctx.RemoteAddr()
reqID, _ := uuid.NewRandom()

m, err := p.createWriteRequests(wrReqIn)
if err != nil {
ctx.Error(err.Error(), fh.StatusBadRequest)
Expand Down

0 comments on commit bcaeed2

Please sign in to comment.