@@ -2,7 +2,9 @@ package manifests
22
33import (
44 "fmt"
5+ "net/url"
56
7+ "golang.org/x/net/http/httpproxy"
68 v1 "k8s.io/api/core/v1"
79)
810
@@ -29,13 +31,14 @@ func (a PrometheusAdditionalAlertmanagerConfigs) MarshalYAML() (interface{}, err
2931
3032// amConfigPrometheus is our internal representation of the Prometheus alerting configuration.
3133type amConfigPrometheus struct {
32- Scheme string `yaml:"scheme,omitempty"`
33- PathPrefix string `yaml:"path_prefix,omitempty"`
34- Timeout * string `yaml:"timeout,omitempty"`
35- APIVersion string `yaml:"api_version,omitempty"`
36- Authorization amConfigAuthorization `yaml:"authorization,omitempty"`
37- TLSConfig amConfigTLS `yaml:"tls_config,omitempty"`
38- StaticConfigs []amConfigStaticConfigs `yaml:"static_configs,omitempty"`
34+ Scheme string `yaml:"scheme,omitempty"`
35+ PathPrefix string `yaml:"path_prefix,omitempty"`
36+ Timeout * string `yaml:"timeout,omitempty"`
37+ APIVersion string `yaml:"api_version,omitempty"`
38+ Authorization amConfigAuthorization `yaml:"authorization,omitempty"`
39+ TLSConfig amConfigTLS `yaml:"tls_config,omitempty"`
40+ StaticConfigs []amConfigStaticConfigs `yaml:"static_configs,omitempty"`
41+ ProxyFromEnvironment bool `yaml:"proxy_from_environment,omitempty"`
3942}
4043
4144type amConfigAuthorization struct {
@@ -64,10 +67,11 @@ type prometheusAdditionalAlertmanagerConfig AdditionalAlertmanagerConfig
6467// compatible with the Prometheus configuration.
6568func (a prometheusAdditionalAlertmanagerConfig ) MarshalYAML () (interface {}, error ) {
6669 cfg := amConfigPrometheus {
67- Scheme : a .Scheme ,
68- PathPrefix : a .PathPrefix ,
69- Timeout : a .Timeout ,
70- APIVersion : a .APIVersion ,
70+ Scheme : a .Scheme ,
71+ PathPrefix : a .PathPrefix ,
72+ Timeout : a .Timeout ,
73+ APIVersion : a .APIVersion ,
74+ ProxyFromEnvironment : true ,
7175 TLSConfig : amConfigTLS {
7276 CA : "" ,
7377 Cert : "" ,
@@ -126,14 +130,15 @@ type thanosAlertmanagerConfiguration struct {
126130 APIVersion string `yaml:"api_version,omitempty"`
127131 HTTPConfig amHTTPConfig `yaml:"http_config,omitempty"`
128132 StaticConfigs []string `yaml:"static_configs,omitempty"`
133+ ProxyURL string `yaml:"proxy_url,omitempty"`
129134}
130135
131136type amHTTPConfig struct {
132137 BearerTokenFile string `yaml:"bearer_token_file,omitempty"`
133138 TLSConfig amConfigTLS `yaml:"tls_config,omitempty"`
134139}
135140
136- func ConvertToThanosAlertmanagerConfiguration (ta []AdditionalAlertmanagerConfig ) ([]thanosAlertmanagerConfiguration , error ) {
141+ func ( f * Factory ) ConvertToThanosAlertmanagerConfiguration (ta []AdditionalAlertmanagerConfig ) ([]thanosAlertmanagerConfiguration , error ) {
137142 result := make ([]thanosAlertmanagerConfiguration , len (ta ))
138143
139144 for i , a := range ta {
@@ -180,6 +185,36 @@ func ConvertToThanosAlertmanagerConfiguration(ta []AdditionalAlertmanagerConfig)
180185
181186 cfg .StaticConfigs = a .StaticConfigs
182187
188+ httpConfig := httpproxy.Config {
189+ HTTPProxy : f .proxy .HTTPProxy (),
190+ HTTPSProxy : f .proxy .HTTPSProxy (),
191+ NoProxy : f .proxy .NoProxy (),
192+ }
193+
194+ proxyFunc := httpConfig .ProxyFunc ()
195+
196+ for _ , host := range cfg .StaticConfigs {
197+ if host == "" {
198+ continue
199+ }
200+
201+ u := & url.URL {
202+ Scheme : cfg .Scheme ,
203+ Host : host ,
204+ }
205+
206+ proxyURL , err := proxyFunc (u )
207+ if err != nil {
208+ return nil , err
209+ }
210+
211+ // Assumes that all hosts share the same proxy policy
212+ if proxyURL != nil {
213+ cfg .ProxyURL = proxyURL .String ()
214+ break
215+ }
216+ }
217+
183218 result [i ] = cfg
184219 }
185220
0 commit comments