-
Notifications
You must be signed in to change notification settings - Fork 673
Do not export per user and integration Alertmanager metrics when value is 0 #1783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,10 +296,10 @@ func (m *alertmanagerMetrics) Collect(out chan<- prometheus.Metric) { | |
| data.SendSumOfCountersPerUser(out, m.alertsReceived, "alertmanager_alerts_received_total") | ||
| data.SendSumOfCountersPerUser(out, m.alertsInvalid, "alertmanager_alerts_invalid_total") | ||
|
|
||
| data.SendSumOfCountersPerUserWithLabels(out, m.numNotifications, "alertmanager_notifications_total", "integration") | ||
| data.SendSumOfCountersPerUserWithLabels(out, m.numFailedNotifications, "alertmanager_notifications_failed_total", "integration") | ||
| data.SendSumOfCountersPerUserWithLabels(out, m.numNotificationRequestsTotal, "alertmanager_notification_requests_total", "integration") | ||
| data.SendSumOfCountersPerUserWithLabels(out, m.numNotificationRequestsFailedTotal, "alertmanager_notification_requests_failed_total", "integration") | ||
| data.SendSumOfCountersPerUserWithLabelsAndOptions(out, m.numNotifications, "alertmanager_notifications_total", []string{"integration"}, util.SkipZeroValueMetrics) | ||
|
||
| data.SendSumOfCountersPerUserWithLabelsAndOptions(out, m.numFailedNotifications, "alertmanager_notifications_failed_total", []string{"integration"}, util.SkipZeroValueMetrics) | ||
| data.SendSumOfCountersPerUserWithLabelsAndOptions(out, m.numNotificationRequestsTotal, "alertmanager_notification_requests_total", []string{"integration"}, util.SkipZeroValueMetrics) | ||
| data.SendSumOfCountersPerUserWithLabelsAndOptions(out, m.numNotificationRequestsFailedTotal, "alertmanager_notification_requests_failed_total", []string{"integration"}, util.SkipZeroValueMetrics) | ||
| data.SendSumOfHistograms(out, m.notificationLatencySeconds, "alertmanager_notification_latency_seconds") | ||
| data.SendSumOfGaugesPerUserWithLabels(out, m.markerAlerts, "alertmanager_alerts", "state") | ||
|
|
||
|
|
@@ -334,7 +334,7 @@ func (m *alertmanagerMetrics) Collect(out chan<- prometheus.Metric) { | |
| data.SendSumOfCounters(out, m.persistTotal, "alertmanager_state_persist_total") | ||
| data.SendSumOfCounters(out, m.persistFailed, "alertmanager_state_persist_failed_total") | ||
|
|
||
| data.SendSumOfCountersPerUserWithLabels(out, m.notificationRateLimited, "alertmanager_notification_rate_limited_total", "integration") | ||
| data.SendSumOfCountersPerUserWithLabelsAndOptions(out, m.notificationRateLimited, "alertmanager_notification_rate_limited_total", []string{"integration"}, util.SkipZeroValueMetrics) | ||
| data.SendSumOfCountersPerUser(out, m.dispatcherAggregationGroupsLimitReached, "alertmanager_dispatcher_aggregation_group_limit_reached_total") | ||
| data.SendSumOfCountersPerUser(out, m.insertAlertFailures, "alertmanager_alerts_insert_limited_total") | ||
| data.SendSumOfGaugesPerUser(out, m.alertsLimiterAlertsCount, "alertmanager_alerts_limiter_current_alerts") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,12 +124,16 @@ func (mfm MetricFamilyMap) SumSummariesTo(name string, output *SummaryData) { | |
| } | ||
| } | ||
|
|
||
| func (mfm MetricFamilyMap) sumOfSingleValuesWithLabels(metric string, labelNames []string, extractFn func(*dto.Metric) float64, aggregateFn func(labelsKey string, labelValues []string, value float64)) { | ||
| func (mfm MetricFamilyMap) sumOfSingleValuesWithLabels(metric string, labelNames []string, extractFn func(*dto.Metric) float64, aggregateFn func(labelsKey string, labelValues []string, value float64), skipZeroValue bool) { | ||
| metricsPerLabelValue := getMetricsWithLabelNames(mfm[metric], labelNames) | ||
|
|
||
| for key, mlv := range metricsPerLabelValue { | ||
| for _, m := range mlv.metrics { | ||
| val := extractFn(m) | ||
| if skipZeroValue && val == 0 { | ||
| continue | ||
| } | ||
|
|
||
| aggregateFn(key, mlv.labelValues, val) | ||
| } | ||
| } | ||
|
|
@@ -155,7 +159,7 @@ func (d MetricFamiliesPerUser) SendSumOfCounters(out chan<- prometheus.Metric, d | |
| } | ||
|
|
||
| func (d MetricFamiliesPerUser) SendSumOfCountersWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, counter string, labelNames ...string) { | ||
| d.sumOfSingleValuesWithLabels(counter, counterValue, labelNames).WriteToMetricChannel(out, desc, prometheus.CounterValue) | ||
| d.sumOfSingleValuesWithLabels(counter, counterValue, labelNames, false).WriteToMetricChannel(out, desc, prometheus.CounterValue) | ||
| } | ||
|
|
||
| func (d MetricFamiliesPerUser) SendSumOfCountersPerUser(out chan<- prometheus.Metric, desc *prometheus.Desc, counter string) { | ||
|
|
@@ -165,13 +169,20 @@ func (d MetricFamiliesPerUser) SendSumOfCountersPerUser(out chan<- prometheus.Me | |
| // SendSumOfCountersPerUserWithLabels provides metrics with the provided label names on a per-user basis. This function assumes that `user` is the | ||
| // first label on the provided metric Desc | ||
| func (d MetricFamiliesPerUser) SendSumOfCountersPerUserWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, metric string, labelNames ...string) { | ||
| d.SendSumOfCountersPerUserWithLabelsAndOptions(out, desc, metric, labelNames) | ||
|
||
| } | ||
|
|
||
| // SendSumOfCountersPerUserWithLabelsAndOptions provides metrics with the provided label names on a per-user basis. This function assumes that `user` is the | ||
| // first label on the provided metric Desc | ||
| func (d MetricFamiliesPerUser) SendSumOfCountersPerUserWithLabelsAndOptions(out chan<- prometheus.Metric, desc *prometheus.Desc, metric string, labelNames []string, options ...MetricOption) { | ||
| for _, userEntry := range d { | ||
| if userEntry.user == "" { | ||
| continue | ||
| } | ||
|
|
||
| result := singleValueWithLabelsMap{} | ||
| userEntry.metrics.sumOfSingleValuesWithLabels(metric, labelNames, counterValue, result.aggregateFn) | ||
| opts := applyMetricOptions(options...) | ||
| userEntry.metrics.sumOfSingleValuesWithLabels(metric, labelNames, counterValue, result.aggregateFn, opts.skipZeroValueMetrics) | ||
| result.prependUserLabelValue(userEntry.user) | ||
| result.WriteToMetricChannel(out, desc, prometheus.CounterValue) | ||
| } | ||
|
|
@@ -190,7 +201,7 @@ func (d MetricFamiliesPerUser) SendSumOfGauges(out chan<- prometheus.Metric, des | |
| } | ||
|
|
||
| func (d MetricFamiliesPerUser) SendSumOfGaugesWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string, labelNames ...string) { | ||
| d.sumOfSingleValuesWithLabels(gauge, gaugeValue, labelNames).WriteToMetricChannel(out, desc, prometheus.GaugeValue) | ||
| d.sumOfSingleValuesWithLabels(gauge, gaugeValue, labelNames, false).WriteToMetricChannel(out, desc, prometheus.GaugeValue) | ||
| } | ||
|
|
||
| func (d MetricFamiliesPerUser) SendSumOfGaugesPerUser(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string) { | ||
|
|
@@ -206,16 +217,16 @@ func (d MetricFamiliesPerUser) SendSumOfGaugesPerUserWithLabels(out chan<- prome | |
| } | ||
|
|
||
| result := singleValueWithLabelsMap{} | ||
| userEntry.metrics.sumOfSingleValuesWithLabels(metric, labelNames, gaugeValue, result.aggregateFn) | ||
| userEntry.metrics.sumOfSingleValuesWithLabels(metric, labelNames, gaugeValue, result.aggregateFn, false) | ||
| result.prependUserLabelValue(userEntry.user) | ||
| result.WriteToMetricChannel(out, desc, prometheus.GaugeValue) | ||
| } | ||
| } | ||
|
|
||
| func (d MetricFamiliesPerUser) sumOfSingleValuesWithLabels(metric string, fn func(*dto.Metric) float64, labelNames []string) singleValueWithLabelsMap { | ||
| func (d MetricFamiliesPerUser) sumOfSingleValuesWithLabels(metric string, fn func(*dto.Metric) float64, labelNames []string, skipZeroValue bool) singleValueWithLabelsMap { | ||
| result := singleValueWithLabelsMap{} | ||
| for _, userEntry := range d { | ||
| userEntry.metrics.sumOfSingleValuesWithLabels(metric, labelNames, fn, result.aggregateFn) | ||
| userEntry.metrics.sumOfSingleValuesWithLabels(metric, labelNames, fn, result.aggregateFn, skipZeroValue) | ||
| } | ||
| return result | ||
| } | ||
|
|
@@ -810,3 +821,25 @@ type CollectorVec interface { | |
| prometheus.Collector | ||
| Delete(labels prometheus.Labels) bool | ||
| } | ||
|
|
||
| // MetricOption defines a functional-style option for metrics aggregation. | ||
| type MetricOption func(options *metricOptions) | ||
|
|
||
| // SkipZeroValueMetrics controls whether metrics aggregation should skip zero value metrics. | ||
| func SkipZeroValueMetrics(options *metricOptions) { | ||
| options.skipZeroValueMetrics = true | ||
| } | ||
|
|
||
| // applyMetricOptions returns a metricOptions with all the input options applied. | ||
| func applyMetricOptions(options ...MetricOption) *metricOptions { | ||
| actual := &metricOptions{} | ||
| for _, option := range options { | ||
| option(actual) | ||
| } | ||
|
|
||
| return actual | ||
| } | ||
|
|
||
| type metricOptions struct { | ||
| skipZeroValueMetrics bool | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tangential question: What's our policy on the
cortex_prefix? I take it we don't want to break existing dashboards but is there a plan to eventually deprecate them?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed it and we won't rename it until we can't provide a smooth upgrade path to users.