Skip to content

Commit

Permalink
feat: Add proxy options to alertmanager client
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Sochacki <[email protected]>
  • Loading branch information
pascal-sochacki committed Sep 19, 2024
1 parent a26416d commit 3212a1d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
15 changes: 15 additions & 0 deletions docs/sources/shared/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4638,6 +4638,21 @@ alertmanager_client:
# CLI flag: -ruler.alertmanager-client.credentials-file
[credentials_file: <string> | default = ""]
# HTTP proxy server to use to connect to the targets.
[proxy_url: <string> | default = ""]
# NoProxy contains addresses that should not use a proxy.
[no_proxy: <string> | default = ""]
# ProxyFromEnvironment makes use of net/http ProxyFromEnvironment function to determine proxies.
[proxy_from_environment: <boolean>]
# ProxyConnectHeader optionally specifies headers to send to
# proxies during CONNECT requests. Assume that at least _some_ of
# these headers are going to contain secrets and use Secret as the
# value type instead of string.
[proxy_connect_header: <map of string to list of strings>]
# Max time to tolerate outage for restoring "for" state of alert.
# CLI flag: -ruler.for-outage-tolerance
[for_outage_tolerance: <duration> | default = 1h]
Expand Down
6 changes: 6 additions & 0 deletions pkg/ruler/base/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ func amConfigFromURL(cfg *ruler_config.AlertManagerConfig, url *url.URL, apiVers
Timeout: model.Duration(cfg.NotificationTimeout),
ServiceDiscoveryConfigs: sdConfig,
HTTPClientConfig: config_util.HTTPClientConfig{
ProxyConfig: config_util.ProxyConfig{
ProxyURL: cfg.Notifier.Proxy.ProxyURL,
NoProxy: cfg.Notifier.Proxy.NoProxy,
ProxyConnectHeader: cfg.Notifier.Proxy.ProxyConnectHeader,
ProxyFromEnvironment: cfg.Notifier.Proxy.ProxyFromEnvironment,
},
TLSConfig: config_util.TLSConfig{
CAFile: cfg.Notifier.TLS.CAPath,
CertFile: cfg.Notifier.TLS.CertPath,
Expand Down
47 changes: 47 additions & 0 deletions pkg/ruler/base/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package base

import (
"fmt"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -397,6 +398,52 @@ func TestBuildNotifierConfig(t *testing.T) {
},
},
},
{
name: "with proxy",
cfg: &Config{
AlertManagerConfig: ruler_config.AlertManagerConfig{
AlertmanagerURL: "http://alertmanager.default.svc.cluster.local/alertmanager",
Notifier: ruler_config.NotifierConfig{
Proxy: config_util.ProxyConfig{
ProxyURL: config_util.URL{
URL: &url.URL{},
},
NoProxy: "127.0.0.1/8",
ProxyFromEnvironment: false,
ProxyConnectHeader: config_util.ProxyHeader{},
},
},
},
},
ncfg: &config.Config{
AlertingConfig: config.AlertingConfig{
AlertmanagerConfigs: []*config.AlertmanagerConfig{
{
APIVersion: "v1",
Scheme: "http",
PathPrefix: "/alertmanager",
ServiceDiscoveryConfigs: discovery.Configs{
discovery.StaticConfig{
{
Targets: []model.LabelSet{{"__address__": "alertmanager.default.svc.cluster.local"}},
},
},
},
HTTPClientConfig: config_util.HTTPClientConfig{
ProxyConfig: config_util.ProxyConfig{
ProxyURL: config_util.URL{
URL: &url.URL{},
},
NoProxy: "127.0.0.1/8",
ProxyFromEnvironment: false,
ProxyConnectHeader: config_util.ProxyHeader{},
},
},
},
},
},
},
},
}

for _, tt := range tests {
Expand Down
8 changes: 5 additions & 3 deletions pkg/ruler/config/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/grafana/dskit/crypto/tls"
"github.com/prometheus/common/config"
"github.com/prometheus/prometheus/model/relabel"

"github.com/grafana/loki/v3/pkg/util"
Expand All @@ -30,9 +31,10 @@ type AlertManagerConfig struct {
}

type NotifierConfig struct {
TLS tls.ClientConfig `yaml:",inline"`
BasicAuth util.BasicAuth `yaml:",inline"`
HeaderAuth util.HeaderAuth `yaml:",inline"`
Proxy config.ProxyConfig `yaml:",inline"`
TLS tls.ClientConfig `yaml:",inline"`
BasicAuth util.BasicAuth `yaml:",inline"`
HeaderAuth util.HeaderAuth `yaml:",inline"`
}

func (cfg *NotifierConfig) RegisterFlags(f *flag.FlagSet) {
Expand Down

0 comments on commit 3212a1d

Please sign in to comment.