Skip to content

Commit

Permalink
feat(loki): Add tenant for loki
Browse files Browse the repository at this point in the history
What :
This change allows to add a "tenant header" in the configuration file at the
loki.tenant key.

Why :
Loki is able to differentiate logs comming from a specific tenant , but
it is needed to add a header in the configuration :

https://grafana.com/docs/loki/latest/operations/multi-tenancy/

This change does not bring any breaking changes.

Signed-off-by: Julien Godin <julien.godin@camptocamp.com>
  • Loading branch information
JGodin-C2C committed Feb 7, 2022
1 parent 51ce72a commit a5b8ef0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func getConfig() *types.Configuration {
v.SetDefault("Loki.MinimumPriority", "")
v.SetDefault("Loki.MutualTLS", false)
v.SetDefault("Loki.CheckCert", true)
v.SetDefault("Loki.Tenant", "")

v.SetDefault("AWS.AccessKeyID", "")
v.SetDefault("AWS.SecretAccessKey", "")
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ func init() {
config.Loki.HostPort = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Loki")
if config.Loki.Tenant != "" {
lokiClient.AddHeader("X-Scope-OrgID", config.Loki.Tenant)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ type lokiOutputConfig struct {
MinimumPriority string
CheckCert bool
MutualTLS bool
Tenant string
}

type natsOutputConfig struct {
Expand Down

0 comments on commit a5b8ef0

Please sign in to comment.