Skip to content

Commit

Permalink
Merge pull request #31 from nicolastakashi/refactory/code-consistency
Browse files Browse the repository at this point in the history
[REFACTORY] code consistency
  • Loading branch information
nicolastakashi authored Feb 21, 2025
2 parents 66d462e + 9be96f2 commit 9cb3290
Show file tree
Hide file tree
Showing 4 changed files with 449 additions and 384 deletions.
2 changes: 1 addition & 1 deletion examples/perses/datasource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ spec:
plugin:
kind: PrometheusDatasource
spec:
directUrl: https://prometheus.demo.do.prometheus.io
directUrl: https://demo.promlabs.com
53 changes: 40 additions & 13 deletions pkg/panels/alertmanager/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
// from Alertmanager using Prometheus as the data source. It generates a time series panel with
// specific configurations for the Y-axis format and legend position.
//
// The panel uses the following Prometheus metrics:
// - alertmanager_alerts: Current number of alerts stored in Alertmanager
//
// Parameters:
// - datasourceName: The name of the Prometheus data source.
// - labelMatchers: A variadic parameter for Prometheus label matchers to filter the query.
Expand All @@ -22,7 +25,7 @@ import (
// - panelgroup.Option: A panel option that can be added to a panel group.
func Alerts(datasourceName string, labelMatchers ...promql.LabelMatcher) panelgroup.Option {
return panelgroup.AddPanel("Alerts",
panel.Description("Current set of alerts stored in the Alertmanager"),
panel.Description("Shows current alerts in Alertmanager"),
timeSeriesPanel.Chart(
timeSeriesPanel.WithLegend(timeSeriesPanel.Legend{
Position: timeSeriesPanel.BottomPosition,
Expand All @@ -37,14 +40,20 @@ func Alerts(datasourceName string, labelMatchers ...promql.LabelMatcher) panelgr
labelMatchers,
),
dashboards.AddQueryDataSource(datasourceName),
query.SeriesNameFormat("{{instance}}"),
query.SeriesNameFormat("{{instance}} - Alertmanager - Alerts"),
),
),
)
}

// AlertsReceiveRate creates a panel option for displaying the rate of alerts received by the Alertmanager.
// It includes a description of the panel, a time series chart with a legend, and a PromQL query to fetch the data.
// The panel uses the following Prometheus metrics:
// - alertmanager_alerts_received_total: Total number of alerts received
// - alertmanager_alerts_invalid_total: Total number of invalid alerts received
//
// The panel shows:
// - Rate of received alerts per instance
// - Rate of invalid alerts per instance
//
// Parameters:
// - datasourceName: The name of the data source to be used for the query.
Expand All @@ -54,7 +63,7 @@ func Alerts(datasourceName string, labelMatchers ...promql.LabelMatcher) panelgr
// - panelgroup.Option: The configured panel option.
func AlertsReceiveRate(datasourceName string, labelMatchers ...promql.LabelMatcher) panelgroup.Option {
return panelgroup.AddPanel("Alerts receive rate",
panel.Description("Rate of successful and invalid alerts received by the Alertmanager"),
panel.Description("Shows alert receive rate in Alertmanager"),
timeSeriesPanel.Chart(
timeSeriesPanel.WithLegend(timeSeriesPanel.Legend{
Position: timeSeriesPanel.BottomPosition,
Expand All @@ -69,7 +78,7 @@ func AlertsReceiveRate(datasourceName string, labelMatchers ...promql.LabelMatch
labelMatchers,
),
dashboards.AddQueryDataSource(datasourceName),
query.SeriesNameFormat("{{instance}} Received"),
query.SeriesNameFormat("{{instance}} - Alertmanager - Received"),
),
),
panel.AddQuery(
Expand All @@ -79,7 +88,7 @@ func AlertsReceiveRate(datasourceName string, labelMatchers ...promql.LabelMatch
labelMatchers,
),
dashboards.AddQueryDataSource(datasourceName),
query.SeriesNameFormat("{{instance}} Invalid"),
query.SeriesNameFormat("{{instance}} - Alertmanager - Invalid"),
),
),
)
Expand All @@ -92,6 +101,14 @@ func AlertsReceiveRate(datasourceName string, labelMatchers ...promql.LabelMatch
// notifications sent and another for the failed notifications, both grouped by
// integration and instance.
//
// The panel uses the following Prometheus metrics:
// - alertmanager_notifications_total: Total count of notifications sent
// - alertmanager_notifications_failed_total: Total count of failed notification attempts
//
// The panel shows:
// - Rate of total notifications sent per integration
// - Rate of failed notifications per integration
//
// Parameters:
// - datasourceName: The name of the data source to be used for the queries.
// - labelMatchers: A variadic parameter for Prometheus label matchers to filter the queries.
Expand All @@ -100,7 +117,7 @@ func AlertsReceiveRate(datasourceName string, labelMatchers ...promql.LabelMatch
// - panelgroup.Option: The configured panel option.
func NotificationsSendRate(datasourceName string, labelMatchers ...promql.LabelMatcher) panelgroup.Option {
return panelgroup.AddPanel("Notifications Send Rate",
panel.Description("Rate of successful and invalid notifications sent by the Alertmanager"),
panel.Description("Shows notification send rate for the Alertmanager"),
timeSeriesPanel.Chart(
timeSeriesPanel.WithLegend(timeSeriesPanel.Legend{
Position: timeSeriesPanel.BottomPosition,
Expand All @@ -115,7 +132,7 @@ func NotificationsSendRate(datasourceName string, labelMatchers ...promql.LabelM
labelMatchers,
),
dashboards.AddQueryDataSource(datasourceName),
query.SeriesNameFormat("{{ integration }} - {{instance}} Total"),
query.SeriesNameFormat("{{instance}} - {{integration}} - Total"),
),
),
panel.AddQuery(
Expand All @@ -125,7 +142,7 @@ func NotificationsSendRate(datasourceName string, labelMatchers ...promql.LabelM
labelMatchers,
),
dashboards.AddQueryDataSource(datasourceName),
query.SeriesNameFormat("{{ integration }} - {{instance}} Total"),
query.SeriesNameFormat("{{instance}} - {{integration}} - Failed"),
),
),
)
Expand All @@ -135,6 +152,16 @@ func NotificationsSendRate(datasourceName string, labelMatchers ...promql.LabelM
// from Alertmanager. It generates a time series panel with queries for the 99th percentile,
// median, and average notification latency.
//
// The panel uses the following Prometheus metrics:
// - alertmanager_notification_latency_seconds_bucket: Histogram of notification latency
// - alertmanager_notification_latency_seconds_sum: Total sum of notification latency
// - alertmanager_notification_latency_seconds_count: Total count of notifications
//
// The panel shows:
// - 99th percentile of notification latency
// - Median notification latency
// - Average notification latency
//
// Parameters:
// - datasourceName: The name of the data source to be used for the queries.
// - labelMatchers: A variadic parameter for Prometheus label matchers to filter the metrics.
Expand All @@ -143,7 +170,7 @@ func NotificationsSendRate(datasourceName string, labelMatchers ...promql.LabelM
// - panelgroup.Option: An option that adds the configured panel to a panel group.
func NotificationDuration(datasourceName string, labelMatchers ...promql.LabelMatcher) panelgroup.Option {
return panelgroup.AddPanel("Notification Duration",
panel.Description("Latency of notifications sent by the Alertmanager"),
panel.Description("Shows notification latency for the Alertmanager"),
timeSeriesPanel.Chart(
timeSeriesPanel.WithYAxis(timeSeriesPanel.YAxis{
Format: &commonSdk.Format{
Expand All @@ -163,7 +190,7 @@ func NotificationDuration(datasourceName string, labelMatchers ...promql.LabelMa
labelMatchers,
),
dashboards.AddQueryDataSource(datasourceName),
query.SeriesNameFormat("{{ integration }} - {{instance}} 99th "),
query.SeriesNameFormat("{{instance}} - {{integration}} - 99th Percentile"),
),
),
panel.AddQuery(
Expand All @@ -173,7 +200,7 @@ func NotificationDuration(datasourceName string, labelMatchers ...promql.LabelMa
labelMatchers,
),
dashboards.AddQueryDataSource(datasourceName),
query.SeriesNameFormat("{{ integration }} - {{instance}} Median"),
query.SeriesNameFormat("{{instance}} - {{integration}} - Median"),
),
),
panel.AddQuery(
Expand All @@ -183,7 +210,7 @@ func NotificationDuration(datasourceName string, labelMatchers ...promql.LabelMa
labelMatchers,
),
dashboards.AddQueryDataSource(datasourceName),
query.SeriesNameFormat("{{ integration }} - {{instance}} Average"),
query.SeriesNameFormat("{{instance}} - {{integration}} - Average"),
),
),
)
Expand Down
Loading

0 comments on commit 9cb3290

Please sign in to comment.