From 871e5ada9e7d33677aaf3e06c966675aed806c40 Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Fri, 16 Aug 2024 18:08:59 +0530 Subject: [PATCH] chore: dashboard and alert names (#5705) * chore: dashboard names * chore: fix panel count --- .../app/clickhouseReader/reader.go | 25 ++++++++++- pkg/query-service/model/response.go | 44 ++++++++++--------- pkg/query-service/rules/db.go | 4 +- pkg/query-service/telemetry/telemetry.go | 2 + 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go index 5f33bfe2a9..8dce05250d 100644 --- a/pkg/query-service/app/clickhouseReader/reader.go +++ b/pkg/query-service/app/clickhouseReader/reader.go @@ -3346,16 +3346,26 @@ func (r *ClickHouseReader) GetDashboardsInfo(ctx context.Context) (*model.Dashbo return &dashboardsInfo, err } totalDashboardsWithPanelAndName := 0 + var dashboardNames []string count := 0 for _, dashboard := range dashboardsData { if isDashboardWithPanelAndName(dashboard.Data) { totalDashboardsWithPanelAndName = totalDashboardsWithPanelAndName + 1 } - dashboardsInfo = countPanelsInDashboard(dashboard.Data) + dashboardName := extractDashboardName(dashboard.Data) + if dashboardName != "" { + dashboardNames = append(dashboardNames, dashboardName) + } + dashboardInfo := countPanelsInDashboard(dashboard.Data) + dashboardsInfo.LogsBasedPanels += dashboardInfo.LogsBasedPanels + dashboardsInfo.TracesBasedPanels += dashboardInfo.TracesBasedPanels + dashboardsInfo.MetricBasedPanels += dashboardsInfo.MetricBasedPanels if isDashboardWithTSV2(dashboard.Data) { count = count + 1 } } + + dashboardsInfo.DashboardNames = dashboardNames dashboardsInfo.TotalDashboards = len(dashboardsData) dashboardsInfo.TotalDashboardsWithPanelAndName = totalDashboardsWithPanelAndName dashboardsInfo.QueriesWithTSV2 = count @@ -3389,6 +3399,19 @@ func isDashboardWithPanelAndName(data map[string]interface{}) bool { return isDashboardWithPanelAndName } + +func extractDashboardName(data map[string]interface{}) string { + + if data != nil && data["title"] != nil { + title, ok := data["title"].(string) + if ok { + return title + } + } + + return "" +} + func countPanelsInDashboard(data map[string]interface{}) model.DashboardsInfo { var logsPanelCount, tracesPanelCount, metricsPanelCount int // totalPanels := 0 diff --git a/pkg/query-service/model/response.go b/pkg/query-service/model/response.go index b8250bd1d3..83df872175 100644 --- a/pkg/query-service/model/response.go +++ b/pkg/query-service/model/response.go @@ -634,21 +634,22 @@ type TagsInfo struct { } type AlertsInfo struct { - TotalAlerts int `json:"totalAlerts"` - LogsBasedAlerts int `json:"logsBasedAlerts"` - MetricBasedAlerts int `json:"metricBasedAlerts"` - TracesBasedAlerts int `json:"tracesBasedAlerts"` - SlackChannels int `json:"slackChannels"` - WebHookChannels int `json:"webHookChannels"` - PagerDutyChannels int `json:"pagerDutyChannels"` - OpsGenieChannels int `json:"opsGenieChannels"` - EmailChannels int `json:"emailChannels"` - MSTeamsChannels int `json:"microsoftTeamsChannels"` - MetricsBuilderQueries int `json:"metricsBuilderQueries"` - MetricsClickHouseQueries int `json:"metricsClickHouseQueries"` - MetricsPrometheusQueries int `json:"metricsPrometheusQueries"` - SpanMetricsPrometheusQueries int `json:"spanMetricsPrometheusQueries"` - AlertsWithTSV2 int `json:"alertsWithTSv2"` + TotalAlerts int `json:"totalAlerts"` + LogsBasedAlerts int `json:"logsBasedAlerts"` + MetricBasedAlerts int `json:"metricBasedAlerts"` + TracesBasedAlerts int `json:"tracesBasedAlerts"` + SlackChannels int `json:"slackChannels"` + WebHookChannels int `json:"webHookChannels"` + PagerDutyChannels int `json:"pagerDutyChannels"` + OpsGenieChannels int `json:"opsGenieChannels"` + EmailChannels int `json:"emailChannels"` + MSTeamsChannels int `json:"microsoftTeamsChannels"` + MetricsBuilderQueries int `json:"metricsBuilderQueries"` + MetricsClickHouseQueries int `json:"metricsClickHouseQueries"` + MetricsPrometheusQueries int `json:"metricsPrometheusQueries"` + SpanMetricsPrometheusQueries int `json:"spanMetricsPrometheusQueries"` + AlertNames []string `json:"alertNames"` + AlertsWithTSV2 int `json:"alertsWithTSv2"` } type SavedViewsInfo struct { @@ -658,12 +659,13 @@ type SavedViewsInfo struct { } type DashboardsInfo struct { - TotalDashboards int `json:"totalDashboards"` - TotalDashboardsWithPanelAndName int `json:"totalDashboardsWithPanelAndName"` // dashboards with panel and name without sample title - LogsBasedPanels int `json:"logsBasedPanels"` - MetricBasedPanels int `json:"metricBasedPanels"` - QueriesWithTSV2 int `json:"queriesWithTSV2"` - TracesBasedPanels int `json:"tracesBasedPanels"` + TotalDashboards int `json:"totalDashboards"` + TotalDashboardsWithPanelAndName int `json:"totalDashboardsWithPanelAndName"` // dashboards with panel and name without sample title + LogsBasedPanels int `json:"logsBasedPanels"` + MetricBasedPanels int `json:"metricBasedPanels"` + TracesBasedPanels int `json:"tracesBasedPanels"` + DashboardNames []string `json:"dashboardNames"` + QueriesWithTSV2 int `json:"queriesWithTSV2"` } type TagTelemetryData struct { diff --git a/pkg/query-service/rules/db.go b/pkg/query-service/rules/db.go index c49a8dd391..37e45f2711 100644 --- a/pkg/query-service/rules/db.go +++ b/pkg/query-service/rules/db.go @@ -308,6 +308,7 @@ func (r *ruleDB) GetAlertsInfo(ctx context.Context) (*model.AlertsInfo, error) { // fetch alerts from rules db query := "SELECT data FROM rules" var alertsData []string + var alertNames []string err := r.Select(&alertsData, query) if err != nil { zap.L().Error("Error in processing sql query", zap.Error(err)) @@ -323,6 +324,7 @@ func (r *ruleDB) GetAlertsInfo(ctx context.Context) (*model.AlertsInfo, error) { zap.L().Error("invalid rule data", zap.Error(err)) continue } + alertNames = append(alertNames, rule.AlertName) if rule.AlertType == "LOGS_BASED_ALERT" { alertsInfo.LogsBasedAlerts = alertsInfo.LogsBasedAlerts + 1 } else if rule.AlertType == "METRIC_BASED_ALERT" { @@ -346,6 +348,6 @@ func (r *ruleDB) GetAlertsInfo(ctx context.Context) (*model.AlertsInfo, error) { } alertsInfo.TotalAlerts = alertsInfo.TotalAlerts + 1 } - + alertsInfo.AlertNames = alertNames return &alertsInfo, nil } diff --git a/pkg/query-service/telemetry/telemetry.go b/pkg/query-service/telemetry/telemetry.go index ecfa86298e..c916135f4e 100644 --- a/pkg/query-service/telemetry/telemetry.go +++ b/pkg/query-service/telemetry/telemetry.go @@ -314,6 +314,8 @@ func createTelemetry() { dashboardsAlertsData := map[string]interface{}{ "totalDashboards": dashboardsInfo.TotalDashboards, "totalDashboardsWithPanelAndName": dashboardsInfo.TotalDashboardsWithPanelAndName, + "dashboardNames": dashboardsInfo.DashboardNames, + "alertNames": alertsInfo.AlertNames, "logsBasedPanels": dashboardsInfo.LogsBasedPanels, "metricBasedPanels": dashboardsInfo.MetricBasedPanels, "tracesBasedPanels": dashboardsInfo.TracesBasedPanels,