Skip to content

Commit bcaeed2

Browse files
committed
proxy metadata requests to the default tenant if specified
1 parent 9c42710 commit bcaeed2

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ timeout: 10s
5656
timeout_shutdown: 10s
5757
# Max number of parallel incoming HTTP requests to handle
5858
concurrency: 10
59+
# Whether to forward metrics metadata from Prometheus to Cortex
60+
# Since metadata requests have no timeseries in them - we cannot divide them into tenants
61+
# So the metadata requests will be sent to the default tenant only, if one is not defined - they will be dropped
62+
metadata: false
5963

6064
tenant:
6165
# Which label to look for the tenant information

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.0
1+
1.6.0

config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type config struct {
1919
Timeout time.Duration
2020
TimeoutShutdown time.Duration `yaml:"timeout_shutdown"`
2121
Concurrency int
22+
Metadata bool
2223

2324
Tenant struct {
2425
Label string

config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ log_level: debug
66
timeout: 10s
77
timeout_shutdown: 0s
88
concurrency: 10
9+
metadata: false
910

1011
tenant:
1112
label: tenant

processor.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,31 @@ func (p *processor) handle(ctx *fh.RequestCtx) {
113113
return
114114
}
115115

116+
clientIP := ctx.RemoteAddr()
117+
reqID, _ := uuid.NewRandom()
118+
116119
if len(wrReqIn.Timeseries) == 0 {
117120
// If there's metadata - just accept the request and drop it
118121
if len(wrReqIn.Metadata) > 0 {
122+
if p.cfg.Metadata && p.cfg.Tenant.Default != "" {
123+
code, body, err := p.send(clientIP, reqID, p.cfg.Tenant.Default, wrReqIn)
124+
if err != nil {
125+
ctx.Error(err.Error(), fh.StatusInternalServerError)
126+
p.Errorf("src=%s req_id=%s: unable to proxy metadata: %s", clientIP, reqID, err)
127+
return
128+
}
129+
130+
ctx.SetStatusCode(code)
131+
ctx.SetBody(body)
132+
}
133+
119134
return
120135
}
121136

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

126-
clientIP := ctx.RemoteAddr()
127-
reqID, _ := uuid.NewRandom()
128-
129141
m, err := p.createWriteRequests(wrReqIn)
130142
if err != nil {
131143
ctx.Error(err.Error(), fh.StatusBadRequest)

0 commit comments

Comments
 (0)