From 54fca869011b9efada32bedf900fe464db28d726 Mon Sep 17 00:00:00 2001 From: Burhan Del Rey Date: Wed, 28 Jan 2026 17:10:06 +0300 Subject: [PATCH] Enhance the option metrics.influxdb2.token --- .../observability/metrics/influxdb2.md | 2 +- .../configuration-options.md | 2 +- pkg/observability/metrics/influxdb2.go | 8 +++++++- pkg/observability/types/metrics.go | 19 ++++++++++--------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/content/observability/metrics/influxdb2.md b/docs/content/observability/metrics/influxdb2.md index a5ab61877..22a139746 100644 --- a/docs/content/observability/metrics/influxdb2.md +++ b/docs/content/observability/metrics/influxdb2.md @@ -42,7 +42,7 @@ metrics: _Required, Default=""_ -Token with which to connect to InfluxDB v2. +Token with which to connect to InfluxDB v2. It accepts either a token value or a file path to the token. ```yaml tab="File (YAML)" metrics: diff --git a/docs/content/reference/install-configuration/configuration-options.md b/docs/content/reference/install-configuration/configuration-options.md index 8b08b6bac..f79962938 100644 --- a/docs/content/reference/install-configuration/configuration-options.md +++ b/docs/content/reference/install-configuration/configuration-options.md @@ -202,7 +202,7 @@ THIS FILE MUST NOT BE EDITED BY HAND | metrics.influxdb2.bucket | InfluxDB v2 bucket ID. | | | metrics.influxdb2.org | InfluxDB v2 org ID. | | | metrics.influxdb2.pushinterval | InfluxDB v2 push interval. | 10 | -| metrics.influxdb2.token | InfluxDB v2 access token. | | +| metrics.influxdb2.token | InfluxDB v2 access token. It accepts either a token value or a file path to the token. | | | metrics.otlp | OpenTelemetry metrics exporter type. | false | | metrics.otlp.addentrypointslabels | Enable metrics on entry points. | true | | metrics.otlp.addrouterslabels | Enable metrics on routers. | false | diff --git a/pkg/observability/metrics/influxdb2.go b/pkg/observability/metrics/influxdb2.go index aaa159391..1428c586c 100644 --- a/pkg/observability/metrics/influxdb2.go +++ b/pkg/observability/metrics/influxdb2.go @@ -3,6 +3,7 @@ package metrics import ( "context" "errors" + "strings" "time" "github.com/go-kit/kit/metrics/influx" @@ -138,11 +139,16 @@ func newInfluxDB2Client(config *otypes.InfluxDB2) (influxdb2.Client, error) { return nil, errors.New("token, org or bucket property is missing") } + token, err := config.Token.Read() + if err != nil { + return nil, err + } + // Disable InfluxDB2 logs. // See https://github.com/influxdata/influxdb-client-go/blob/v2.7.0/options.go#L128 influxdb2log.Log = nil - return influxdb2.NewClient(config.Address, config.Token), nil + return influxdb2.NewClient(config.Address, strings.TrimSpace(string(token))), nil } type influxDB2Writer struct { diff --git a/pkg/observability/types/metrics.go b/pkg/observability/types/metrics.go index 331544513..fa788ccf9 100644 --- a/pkg/observability/types/metrics.go +++ b/pkg/observability/types/metrics.go @@ -6,6 +6,7 @@ import ( "time" "github.com/traefik/paerser/types" + tTypes "github.com/traefik/traefik/v3/pkg/types" ) // Metrics provides options to expose and send Traefik metrics to different third party monitoring systems. @@ -87,15 +88,15 @@ func (s *Statsd) SetDefaults() { // InfluxDB2 contains address, token and metrics pushing interval configuration. type InfluxDB2 struct { - Address string `description:"InfluxDB v2 address." json:"address,omitempty" toml:"address,omitempty" yaml:"address,omitempty"` - Token string `description:"InfluxDB v2 access token." json:"token,omitempty" toml:"token,omitempty" yaml:"token,omitempty" loggable:"false"` - PushInterval types.Duration `description:"InfluxDB v2 push interval." json:"pushInterval,omitempty" toml:"pushInterval,omitempty" yaml:"pushInterval,omitempty" export:"true"` - Org string `description:"InfluxDB v2 org ID." json:"org,omitempty" toml:"org,omitempty" yaml:"org,omitempty" export:"true"` - Bucket string `description:"InfluxDB v2 bucket ID." json:"bucket,omitempty" toml:"bucket,omitempty" yaml:"bucket,omitempty" export:"true"` - AddEntryPointsLabels bool `description:"Enable metrics on entry points." json:"addEntryPointsLabels,omitempty" toml:"addEntryPointsLabels,omitempty" yaml:"addEntryPointsLabels,omitempty" export:"true"` - AddRoutersLabels bool `description:"Enable metrics on routers." json:"addRoutersLabels,omitempty" toml:"addRoutersLabels,omitempty" yaml:"addRoutersLabels,omitempty" export:"true"` - AddServicesLabels bool `description:"Enable metrics on services." json:"addServicesLabels,omitempty" toml:"addServicesLabels,omitempty" yaml:"addServicesLabels,omitempty" export:"true"` - AdditionalLabels map[string]string `description:"Additional labels (influxdb tags) on all metrics" json:"additionalLabels,omitempty" toml:"additionalLabels,omitempty" yaml:"additionalLabels,omitempty" export:"true"` + Address string `description:"InfluxDB v2 address." json:"address,omitempty" toml:"address,omitempty" yaml:"address,omitempty"` + Token tTypes.FileOrContent `description:"InfluxDB v2 access token. It accepts either a token value or a file path to the token." json:"token,omitempty" toml:"token,omitempty" yaml:"token,omitempty" loggable:"false"` + PushInterval types.Duration `description:"InfluxDB v2 push interval." json:"pushInterval,omitempty" toml:"pushInterval,omitempty" yaml:"pushInterval,omitempty" export:"true"` + Org string `description:"InfluxDB v2 org ID." json:"org,omitempty" toml:"org,omitempty" yaml:"org,omitempty" export:"true"` + Bucket string `description:"InfluxDB v2 bucket ID." json:"bucket,omitempty" toml:"bucket,omitempty" yaml:"bucket,omitempty" export:"true"` + AddEntryPointsLabels bool `description:"Enable metrics on entry points." json:"addEntryPointsLabels,omitempty" toml:"addEntryPointsLabels,omitempty" yaml:"addEntryPointsLabels,omitempty" export:"true"` + AddRoutersLabels bool `description:"Enable metrics on routers." json:"addRoutersLabels,omitempty" toml:"addRoutersLabels,omitempty" yaml:"addRoutersLabels,omitempty" export:"true"` + AddServicesLabels bool `description:"Enable metrics on services." json:"addServicesLabels,omitempty" toml:"addServicesLabels,omitempty" yaml:"addServicesLabels,omitempty" export:"true"` + AdditionalLabels map[string]string `description:"Additional labels (influxdb tags) on all metrics" json:"additionalLabels,omitempty" toml:"additionalLabels,omitempty" yaml:"additionalLabels,omitempty" export:"true"` } // SetDefaults sets the default values.