From 4969df8a8306de6073a9edc584f91e77931eb569 Mon Sep 17 00:00:00 2001 From: Steve Simpson Date: Thu, 4 Dec 2025 22:56:07 +0100 Subject: [PATCH] Alerting: Add basic auth options to historian args (#114880) --- .../historian/pkg/app/config/config.go | 3 +++ .../historian/pkg/app/config/config_test.go | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/alerting/historian/pkg/app/config/config.go b/apps/alerting/historian/pkg/app/config/config.go index d294395643e..5d8027d933b 100644 --- a/apps/alerting/historian/pkg/app/config/config.go +++ b/apps/alerting/historian/pkg/app/config/config.go @@ -67,6 +67,9 @@ func (v urlVar) Type() string { func addLokiFlags(l *lokiclient.LokiConfig, prefix string, flags *pflag.FlagSet) { flags.Var(urlVar{&l.ReadPathURL}, prefix+".read-url", "URL to Loki instance for performing queries") + flags.StringVar(&l.BasicAuthUser, prefix+".user", "", "Basic auth Username to authenticate to the Loki instance") + flags.StringVar(&l.BasicAuthPassword, prefix+".password", "", "Basic auth password to authenticate to the Loki instance") + flags.StringVar(&l.TenantID, prefix+".tenant-id", "", "Value to use for X-Scope-OrgID") flags.DurationVar(&l.MaxQueryLength, prefix+".max-query-length", lokiDefaultMaxQueryLength, "Maximum allowed time range for queries") flags.IntVar(&l.MaxQuerySize, prefix+".max-query-size", lokiDefaultMaxQuerySize, "Maximum allowed size of a query string passed to Loki") } diff --git a/apps/alerting/historian/pkg/app/config/config_test.go b/apps/alerting/historian/pkg/app/config/config_test.go index 870ed8e9785..8234f4c945f 100644 --- a/apps/alerting/historian/pkg/app/config/config_test.go +++ b/apps/alerting/historian/pkg/app/config/config_test.go @@ -47,15 +47,23 @@ func TestRuntimeConfig(t *testing.T) { }, }, { - name: "with loki read url", - args: []string{"--alerting.historian.notification.loki.read-url=http://localhost:3100"}, + name: "with loki options", + args: []string{ + "--alerting.historian.notification.loki.read-url=http://localhost:3100", + "--alerting.historian.notification.loki.user=foo", + "--alerting.historian.notification.loki.password=bar", + "--alerting.historian.notification.loki.tenant-id=baz", + }, expected: RuntimeConfig{ Notification: NotificationConfig{ Enabled: false, Loki: lokiclient.LokiConfig{ - ReadPathURL: lokiURL, - MaxQueryLength: 721 * time.Hour, - MaxQuerySize: 65536, + ReadPathURL: lokiURL, + BasicAuthUser: "foo", + BasicAuthPassword: "bar", + TenantID: "baz", + MaxQueryLength: 721 * time.Hour, + MaxQuerySize: 65536, }, }, },