Files
grafana/pkg/services/ngalert/metrics/notification_historian.go
Vadim Stepanov bccc980b90 Alerting: Notifiication history (#107644)
* Add unified_alerting.notification_history to ini files

* Parse notification history settings

* Move Loki client to a separate package

* Loki client: add params for metrics and traces

* add NotificationHistorian

* rm writeDuration

* remove RangeQuery stuff

* wip

* wip

* wip

* wip

* pass notification historian in tests

* unify loki settings

* unify loki settings

* add test

* update grafana/alerting

* make update-workspace

* add feature toggle

* fix configureNotificationHistorian

* Revert "add feature toggle"

This reverts commit de7af8f7

* add feature toggle

* more tests

* RuleUID

* fix metrics test

* met.Info.Set(0)
2025-07-17 14:26:26 +01:00

52 lines
1.9 KiB
Go

package metrics
import (
"github.com/grafana/dskit/instrument"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type NotificationHistorian struct {
Info prometheus.Gauge
WritesTotal prometheus.Counter
WritesFailed prometheus.Counter
WriteDuration *instrument.HistogramCollector
BytesWritten prometheus.Counter
}
func NewNotificationHistorianMetrics(r prometheus.Registerer) *NotificationHistorian {
return &NotificationHistorian{
Info: promauto.With(r).NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: Subsystem,
Name: "notification_history_info",
Help: "Information about the notification history store.",
}),
WritesTotal: promauto.With(r).NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: Subsystem,
Name: "notification_history_writes_total",
Help: "The total number of notification history batches that were attempted to be written.",
}),
WritesFailed: promauto.With(r).NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: Subsystem,
Name: "notification_history_writes_failed_total",
Help: "The total number of failed writes of notification history batches.",
}),
WriteDuration: instrument.NewHistogramCollector(promauto.With(r).NewHistogramVec(prometheus.HistogramOpts{
Namespace: Namespace,
Subsystem: Subsystem,
Name: "notification_history_request_duration_seconds",
Help: "Histogram of request durations to the notification history store.",
Buckets: instrument.DefBuckets,
}, instrument.HistogramCollectorBuckets)),
BytesWritten: promauto.With(r).NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: Subsystem,
Name: "notification_history_writes_bytes_total",
Help: "The total number of bytes sent within a batch to the notification history store.",
}),
}
}