chore: dashboard and alert names (#5705)

* chore: dashboard names

* chore: fix panel count
This commit is contained in:
Vishal Sharma 2024-08-16 18:08:59 +05:30 committed by GitHub
parent 0401c27dbc
commit 871e5ada9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 52 additions and 23 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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
}

View File

@ -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,