Loki: Push support for multi-tenancy mode (#60866)

* Loki: Add multitenancy support for the HTTP client

* Loki: Support to push with multitenancy mode

* Apply feedback suggestions
This commit is contained in:
Joan López de la Franca Beltran
2023-01-23 16:24:22 +01:00
committed by GitHub
parent 35c7bbef57
commit afef0c926c
5 changed files with 161 additions and 1 deletions
+18 -1
View File
@@ -15,6 +15,7 @@ import (
"github.com/grafana/dskit/backoff"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/setting"
@@ -231,7 +232,7 @@ func (c *client) run() {
if !ok {
return
}
tenantID := ""
tenantID := c.getTenantID(e.Labels)
batch, ok := batches[tenantID]
// If the batch doesn't exist yet, we create a new one with the entry
@@ -266,6 +267,22 @@ func (c *client) run() {
}
}
func (c *client) getTenantID(labels model.LabelSet) string {
// Check if it has been overridden while processing the pipeline stages
if value, ok := labels[ReservedLabelTenantID]; ok {
return string(value)
}
// Check if has been specified in the config
if c.cfg.TenantID != "" {
return c.cfg.TenantID
}
// Defaults to an empty string, which means the X-Scope-OrgID header
// will not be sent
return ""
}
func (c *client) Chan() chan<- Entry {
return c.entries
}
+2
View File
@@ -18,4 +18,6 @@ type Config struct {
BackoffConfig backoff.Config
Timeout time.Duration
TenantID string
}