Skip to content

Commit d69e5e4

Browse files
committed
implement request duration metric and ensure firewall tests are working
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>
1 parent 61bf463 commit d69e5e4

6 files changed

Lines changed: 450 additions & 18 deletions

File tree

pkg/alertmanager/alertmanager.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/prometheus/alertmanager/notify/email"
3131
"github.com/prometheus/alertmanager/notify/incidentio"
3232
"github.com/prometheus/alertmanager/notify/jira"
33+
"github.com/prometheus/alertmanager/notify/mattermost"
3334
"github.com/prometheus/alertmanager/notify/msteams"
3435
"github.com/prometheus/alertmanager/notify/msteamsv2"
3536
"github.com/prometheus/alertmanager/notify/opsgenie"
@@ -87,14 +88,13 @@ type Config struct {
8788
// Tenant-specific local directory where AM can store its state (notifications, silences, templates). When AM is stopped, entire dir is removed.
8889
TenantDataDir string
8990

90-
ShardingEnabled bool
91-
ReplicationFactor int
92-
Replicator Replicator
93-
Store alertstore.AlertStore
94-
PersisterConfig PersisterConfig
95-
APIConcurrency int
96-
GCInterval time.Duration
97-
DispatchStartDelay time.Duration
91+
ShardingEnabled bool
92+
ReplicationFactor int
93+
Replicator Replicator
94+
Store alertstore.AlertStore
95+
PersisterConfig PersisterConfig
96+
APIConcurrency int
97+
GCInterval time.Duration
9898
}
9999

100100
// An Alertmanager manages the alerts for one user.
@@ -130,6 +130,8 @@ type Alertmanager struct {
130130
configHashMetric prometheus.Gauge
131131

132132
rateLimitedNotifications *prometheus.CounterVec
133+
134+
requestDuration *prometheus.HistogramVec
133135
}
134136

135137
var (
@@ -184,6 +186,17 @@ func New(cfg *Config, reg *prometheus.Registry) (*Alertmanager, error) {
184186
Help: "Number of rate-limited notifications per integration.",
185187
}, []string{"integration"}), // "integration" is consistent with other alertmanager metrics.
186188

189+
requestDuration: promauto.With(reg).NewHistogramVec(
190+
prometheus.HistogramOpts{
191+
Name: "alertmanager_http_request_duration_seconds",
192+
Help: "Histogram of latencies for HTTP requests.",
193+
Buckets: prometheus.DefBuckets,
194+
NativeHistogramBucketFactor: 1.1,
195+
NativeHistogramMaxBucketNumber: 100,
196+
NativeHistogramMinResetDuration: 1 * time.Hour,
197+
},
198+
[]string{"handler", "method", "code"},
199+
),
187200
}
188201

189202
am.registry = reg
@@ -292,7 +305,8 @@ func New(cfg *Config, reg *prometheus.Registry) (*Alertmanager, error) {
292305
GroupFunc: func(ctx context.Context, f1 func(*dispatch.Route) bool, f2 func(*types.Alert, time.Time) bool) (dispatch.AlertGroups, map[model.Fingerprint][]string, error) {
293306
return am.dispatcher.Groups(ctx, f1, f2)
294307
},
295-
Concurrency: am.cfg.APIConcurrency,
308+
Concurrency: am.cfg.APIConcurrency,
309+
RequestDuration: am.requestDuration,
296310
})
297311
if err != nil {
298312
return nil, fmt.Errorf("failed to create api: %v", err)
@@ -612,6 +626,11 @@ func buildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, fire
612626
return incidentio.New(c, tmpl, util_log.GoKitLogToSlog(l), httpOps...)
613627
})
614628
}
629+
for i, c := range nc.MattermostConfigs {
630+
add("mattermost", i, c, func(l log.Logger) (notify.Notifier, error) {
631+
return mattermost.New(c, tmpl, util_log.GoKitLogToSlog(l), httpOps...)
632+
})
633+
}
615634

616635
// If we add support for more integrations, we need to add them to validation as well. See validation.allowedIntegrationNames field.
617636
if errs.Len() > 0 {

pkg/alertmanager/api.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,15 +619,6 @@ func validateDiscordConfig(cfg config.DiscordConfig) error {
619619
return nil
620620
}
621621

622-
// validateMatterMostConfig validates the Discord Config and returns an error if it contains
623-
// settings not allowed by Cortex.
624-
func validateMattermostConfig(cfg config.MattermostConfig) error {
625-
if cfg.WebhookURLFile != "" {
626-
return errMatterMostWebhookUrlFileNotAllowed
627-
}
628-
return nil
629-
}
630-
631622
// validateEmailConfig validates the Email Config and returns an error if it contains
632623
// settings not allowed by Cortex.
633624
func validateEmailConfig(cfg config.EmailConfig) error {
@@ -650,3 +641,12 @@ func validateIncidentIOConfig(cfg config.IncidentioConfig) error {
650641

651642
return nil
652643
}
644+
645+
// validateMatterMostConfig validates the Mattermost Config and returns an error if it contains
646+
// settings not allowed by Cortex.
647+
func validateMattermostConfig(cfg config.MattermostConfig) error {
648+
if cfg.WebhookURLFile != "" {
649+
return errMatterMostWebhookUrlFileNotAllowed
650+
}
651+
return nil
652+
}

pkg/alertmanager/multitenant_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,21 @@ receivers:
526526
- api_url: %s
527527
token: token
528528
token_id: token-id
529+
`, backendURL)
530+
},
531+
},
532+
"mattermost": {
533+
getAlertmanagerConfig: func(backendURL string) string {
534+
return fmt.Sprintf(`
535+
route:
536+
receiver: mattermost
537+
group_wait: 0s
538+
group_interval: 1s
539+
540+
receivers:
541+
- name: mattermost
542+
mattermost_configs: {}
543+
- webhook_url: %s
529544
`, backendURL)
530545
},
531546
},

vendor/github.com/prometheus/alertmanager/config/receiver/receiver.go

Lines changed: 125 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)