mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Loki: Add multitenancy support for the HTTP client * Loki: Support to push with multitenancy mode * Apply feedback suggestions
31 lines
600 B
Go
31 lines
600 B
Go
package lokigrpc
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
const (
|
|
lowerOrgIDHeaderName = "x-scope-orgid"
|
|
)
|
|
|
|
var (
|
|
ErrDifferentOrgIDPresent = errors.New("different org ID already present")
|
|
ErrTooManyOrgIDs = errors.New("multiple org IDs present")
|
|
)
|
|
|
|
func injectOrgID(ctx context.Context, tenantID string) context.Context {
|
|
md, ok := metadata.FromOutgoingContext(ctx)
|
|
if ok {
|
|
md = md.Copy()
|
|
} else {
|
|
md = metadata.New(map[string]string{})
|
|
}
|
|
|
|
md[lowerOrgIDHeaderName] = []string{tenantID}
|
|
newCtx := metadata.NewOutgoingContext(ctx, md)
|
|
return newCtx
|
|
}
|