MCPcopy Index your code
hub / github.com/cortexproject/cortex / amConfigFromURL

Function amConfigFromURL

pkg/ruler/notifier.go:139–198  ·  view source on GitHub ↗
(rulerConfig *Config, url *url.URL, apiVersion config.AlertmanagerAPIVersion)

Source from the content-addressed store, hash-verified

137}
138
139func amConfigFromURL(rulerConfig *Config, url *url.URL, apiVersion config.AlertmanagerAPIVersion) *config.AlertmanagerConfig {
140 var sdConfig discovery.Configs
141 if rulerConfig.AlertmanagerDiscovery {
142 sdConfig = discovery.Configs{
143 &dns.SDConfig{
144 Names: []string{url.Host},
145 RefreshInterval: model.Duration(rulerConfig.AlertmanagerRefreshInterval),
146 Type: "SRV",
147 Port: 0, // Ignored, because of SRV.
148 },
149 }
150
151 } else {
152 sdConfig = discovery.Configs{
153 discovery.StaticConfig{
154 {
155 Targets: []model.LabelSet{{model.AddressLabel: model.LabelValue(url.Host)}},
156 },
157 },
158 }
159 }
160
161 amConfig := &config.AlertmanagerConfig{
162 APIVersion: apiVersion,
163 Scheme: url.Scheme,
164 PathPrefix: url.Path,
165 Timeout: model.Duration(rulerConfig.NotificationTimeout),
166 ServiceDiscoveryConfigs: sdConfig,
167 HTTPClientConfig: config_util.HTTPClientConfig{
168 TLSConfig: config_util.TLSConfig{
169 CAFile: rulerConfig.Notifier.TLS.CAPath,
170 CertFile: rulerConfig.Notifier.TLS.CertPath,
171 KeyFile: rulerConfig.Notifier.TLS.KeyPath,
172 InsecureSkipVerify: rulerConfig.Notifier.TLS.InsecureSkipVerify,
173 ServerName: rulerConfig.Notifier.TLS.ServerName,
174 },
175 },
176 }
177
178 // Check the URL for basic authentication information first
179 if url.User != nil {
180 amConfig.HTTPClientConfig.BasicAuth = &config_util.BasicAuth{
181 Username: url.User.Username(),
182 }
183
184 if password, isSet := url.User.Password(); isSet {
185 amConfig.HTTPClientConfig.BasicAuth.Password = config_util.Secret(password)
186 }
187 }
188
189 // Override URL basic authentication configs with hard coded config values if present
190 if rulerConfig.Notifier.BasicAuth.IsEnabled() {
191 amConfig.HTTPClientConfig.BasicAuth = &config_util.BasicAuth{
192 Username: rulerConfig.Notifier.BasicAuth.Username,
193 Password: config_util.Secret(rulerConfig.Notifier.BasicAuth.Password.Value),
194 }
195 }
196

Callers 1

buildNotifierConfigFunction · 0.85

Calls 1

IsEnabledMethod · 0.80

Tested by

no test coverage detected