diff --git a/pkg/loki/config_handler.go b/pkg/loki/config_handler.go index 48de706ff1b69..23b3341834273 100644 --- a/pkg/loki/config_handler.go +++ b/pkg/loki/config_handler.go @@ -5,6 +5,7 @@ import ( "net/http" "reflect" + "github.com/grafana/dskit/tenant" "gopkg.in/yaml.v2" ) @@ -113,6 +114,29 @@ func configHandler(actualCfg interface{}, defaultCfg interface{}) http.HandlerFu } } +func (t *Loki) tenantLimitsHandler() func(http.ResponseWriter, *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + if t.TenantLimits == nil { + http.Error(w, "Tenant configs not enabled", http.StatusNotFound) + return + } + + user, _, err := tenant.ExtractTenantIDFromHTTPRequest(r) + if err != nil { + http.Error(w, err.Error(), http.StatusUnauthorized) + return + } + + limit := t.TenantLimits.TenantLimits(user) + if limit == nil { + http.Error(w, "Tenant limits not found", http.StatusNotFound) + return + } + + writeYAMLResponse(w, limit) + } +} + // writeYAMLResponse writes some YAML as a HTTP response. func writeYAMLResponse(w http.ResponseWriter, v interface{}) { // There is not standardised content-type for YAML, text/plain ensures the diff --git a/pkg/loki/loki.go b/pkg/loki/loki.go index 3e10e8aed47d7..9f6683112d362 100644 --- a/pkg/loki/loki.go +++ b/pkg/loki/loki.go @@ -11,10 +11,6 @@ import ( rt "runtime" "time" - "go.uber.org/atomic" - - "google.golang.org/grpc/health/grpc_health_v1" - "github.com/fatih/color" "github.com/felixge/fgprof" "github.com/go-kit/log/level" @@ -30,6 +26,8 @@ import ( "github.com/grafana/dskit/signals" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" + "go.uber.org/atomic" + "google.golang.org/grpc/health/grpc_health_v1" "github.com/grafana/loki/v3/pkg/analytics" blockbuilder "github.com/grafana/loki/v3/pkg/blockbuilder/builder" @@ -505,6 +503,7 @@ func (t *Loki) bindConfigEndpoint(opts RunOpts) { configEndpointHandlerFn = opts.CustomConfigEndpointHandlerFn } t.Server.HTTP.Path("/config").Methods("GET").HandlerFunc(configEndpointHandlerFn) + t.Server.HTTP.Path("/config/tenant/v1/limits").Methods("GET").HandlerFunc(t.tenantLimitsHandler()) } // ListTargets prints a list of available user visible targets and their