Skip to content

Commit

Permalink
Add matcher based tenancy to /api/v1/rules
Browse files Browse the repository at this point in the history
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
  • Loading branch information
saswatamcode committed Feb 1, 2022
1 parent 2a045c4 commit 59b971f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions api/metrics/v1/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const (
labelNamesRoute = "/api/v1/labels"
labelValuesRoute = "/api/v1/label/{label_name}/values"
receiveRoute = "/api/v1/receive"
rulesRoute = "/api/v1/rules/raw"
rulesRoute = "/api/v1/rules"
rulesRawRoute = "/api/v1/rules/raw"
)

type handlerConfiguration struct {
Expand Down Expand Up @@ -214,6 +215,12 @@ func NewHandler(read, write, rulesEndpoint *url.URL, upstreamCA []byte, opts ...
prometheus.Labels{"group": "metricsv1", "handler": "label_values"},
otelhttp.WithRouteTag(c.spanRoutePrefix+labelValuesRoute, proxyRead),
))
// Thanos Query Rules API supports matchers from v0.25 so the WithEnforceTenancyOnMatchers
// middleware will not work here if prior versions are used.
r.Handle(rulesRoute, c.instrument.NewHandler(
prometheus.Labels{"group": "metricsv1", "handler": "rules"},
otelhttp.WithRouteTag(c.spanRoutePrefix+rulesRoute, proxyRead),
))
})

var uiProxy http.Handler
Expand Down Expand Up @@ -296,12 +303,12 @@ func NewHandler(read, write, rulesEndpoint *url.URL, upstreamCA []byte, opts ...

r.Group(func(r chi.Router) {
r.Use(c.uiMiddlewares...)
r.Get(rulesRoute, rh.get)
r.Get(rulesRawRoute, rh.get)
})

r.Group(func(r chi.Router) {
r.Use(c.writeMiddlewares...)
r.Put(rulesRoute, rh.put)
r.Put(rulesRawRoute, rh.put)
})
}

Expand Down

0 comments on commit 59b971f

Please sign in to comment.