Skip to content

Commit 6818c90

Browse files
authored
feat: Add endpoint returning tenant configured limits (#17101)
1 parent f691cdf commit 6818c90

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Diff for: pkg/loki/config_handler.go

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"reflect"
77

8+
"github.com/grafana/dskit/tenant"
89
"gopkg.in/yaml.v2"
910
)
1011

@@ -113,6 +114,29 @@ func configHandler(actualCfg interface{}, defaultCfg interface{}) http.HandlerFu
113114
}
114115
}
115116

117+
func (t *Loki) tenantLimitsHandler() func(http.ResponseWriter, *http.Request) {
118+
return func(w http.ResponseWriter, r *http.Request) {
119+
if t.TenantLimits == nil {
120+
http.Error(w, "Tenant configs not enabled", http.StatusNotFound)
121+
return
122+
}
123+
124+
user, _, err := tenant.ExtractTenantIDFromHTTPRequest(r)
125+
if err != nil {
126+
http.Error(w, err.Error(), http.StatusUnauthorized)
127+
return
128+
}
129+
130+
limit := t.TenantLimits.TenantLimits(user)
131+
if limit == nil {
132+
http.Error(w, "Tenant limits not found", http.StatusNotFound)
133+
return
134+
}
135+
136+
writeYAMLResponse(w, limit)
137+
}
138+
}
139+
116140
// writeYAMLResponse writes some YAML as a HTTP response.
117141
func writeYAMLResponse(w http.ResponseWriter, v interface{}) {
118142
// There is not standardised content-type for YAML, text/plain ensures the

Diff for: pkg/loki/loki.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import (
1111
rt "runtime"
1212
"time"
1313

14-
"go.uber.org/atomic"
15-
16-
"google.golang.org/grpc/health/grpc_health_v1"
17-
1814
"github.com/fatih/color"
1915
"github.com/felixge/fgprof"
2016
"github.com/go-kit/log/level"
@@ -30,6 +26,8 @@ import (
3026
"github.com/grafana/dskit/signals"
3127
"github.com/pkg/errors"
3228
"github.com/prometheus/client_golang/prometheus"
29+
"go.uber.org/atomic"
30+
"google.golang.org/grpc/health/grpc_health_v1"
3331

3432
"github.com/grafana/loki/v3/pkg/analytics"
3533
blockbuilder "github.com/grafana/loki/v3/pkg/blockbuilder/builder"
@@ -505,6 +503,7 @@ func (t *Loki) bindConfigEndpoint(opts RunOpts) {
505503
configEndpointHandlerFn = opts.CustomConfigEndpointHandlerFn
506504
}
507505
t.Server.HTTP.Path("/config").Methods("GET").HandlerFunc(configEndpointHandlerFn)
506+
t.Server.HTTP.Path("/config/tenant/v1/limits").Methods("GET").HandlerFunc(t.tenantLimitsHandler())
508507
}
509508

510509
// ListTargets prints a list of available user visible targets and their

0 commit comments

Comments
 (0)