mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* frontend, distributor: Add tenant ID validation
Use the same validation than in Mimir for consistency.
In addition, reject empty IDs ("").
* Validate tenantID everywhere except in frontend handlers
We can't do it in frontend handlers because we need to wait for the multitenant middleware,
but we rely on the validation middleware.
Validating everywhere follows the same pattern as Mimir and ensures we don't miss any edge case.
* Check status codes
* Add test for user overrides API
* add comment
28 lines
1015 B
Go
28 lines
1015 B
Go
package pipeline
|
|
|
|
import (
|
|
"github.com/grafana/tempo/modules/frontend/combiner"
|
|
"github.com/grafana/tempo/pkg/validation"
|
|
)
|
|
|
|
type tenantValidatorRoundTripper struct {
|
|
next AsyncRoundTripper[combiner.PipelineResponse]
|
|
}
|
|
|
|
// NewTenantValidatorMiddleware returns a middleware that validates the tenant ID in requests.
|
|
// It assumes there's only one tenant ID per request, otherwise it returns an error.
|
|
// For this reason it must run after the multiTenantMiddleware.
|
|
func NewTenantValidatorMiddleware() AsyncMiddleware[combiner.PipelineResponse] {
|
|
return AsyncMiddlewareFunc[combiner.PipelineResponse](func(next AsyncRoundTripper[combiner.PipelineResponse]) AsyncRoundTripper[combiner.PipelineResponse] {
|
|
return &tenantValidatorRoundTripper{next: next}
|
|
})
|
|
}
|
|
|
|
func (t *tenantValidatorRoundTripper) RoundTrip(req Request) (Responses[combiner.PipelineResponse], error) {
|
|
_, err := validation.ExtractValidTenantID(req.Context())
|
|
if err != nil {
|
|
return NewBadRequest(err), nil
|
|
}
|
|
return t.next.RoundTrip(req)
|
|
}
|