From f854cdd9d303e397d16634ef044aa87953f17603 Mon Sep 17 00:00:00 2001 From: Nityananda Gohain Date: Fri, 13 Sep 2024 17:15:03 +0530 Subject: [PATCH] feat: collect telemetry for ch log queries in alerts and dashboards (#5967) * feat: collect telemtry for ch log queries in alerts and dashboards * feat: consider local table as well * fix: address pr comments --- pkg/query-service/app/clickhouseReader/reader.go | 15 +++++++++++++++ pkg/query-service/model/response.go | 2 ++ pkg/query-service/rules/db.go | 4 ++++ pkg/query-service/telemetry/telemetry.go | 2 ++ 4 files changed, 23 insertions(+) diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go index a3d2536aa8..84ddf3ac32 100644 --- a/pkg/query-service/app/clickhouseReader/reader.go +++ b/pkg/query-service/app/clickhouseReader/reader.go @@ -3373,6 +3373,7 @@ func (r *ClickHouseReader) GetDashboardsInfo(ctx context.Context) (*model.Dashbo totalDashboardsWithPanelAndName := 0 var dashboardNames []string count := 0 + logChQueriesCount := 0 for _, dashboard := range dashboardsData { if isDashboardWithPanelAndName(dashboard.Data) { totalDashboardsWithPanelAndName = totalDashboardsWithPanelAndName + 1 @@ -3388,12 +3389,16 @@ func (r *ClickHouseReader) GetDashboardsInfo(ctx context.Context) (*model.Dashbo if isDashboardWithTSV2(dashboard.Data) { count = count + 1 } + if isDashboardWithLogsClickhouseQuery(dashboard.Data) { + logChQueriesCount = logChQueriesCount + 1 + } } dashboardsInfo.DashboardNames = dashboardNames dashboardsInfo.TotalDashboards = len(dashboardsData) dashboardsInfo.TotalDashboardsWithPanelAndName = totalDashboardsWithPanelAndName dashboardsInfo.QueriesWithTSV2 = count + dashboardsInfo.DashboardsWithLogsChQuery = logChQueriesCount return &dashboardsInfo, nil } @@ -3405,6 +3410,16 @@ func isDashboardWithTSV2(data map[string]interface{}) bool { return strings.Contains(string(jsonData), "time_series_v2") } +func isDashboardWithLogsClickhouseQuery(data map[string]interface{}) bool { + jsonData, err := json.Marshal(data) + if err != nil { + return false + } + result := strings.Contains(string(jsonData), "signoz_logs.distributed_logs") || + strings.Contains(string(jsonData), "signoz_logs.logs") + return result +} + func isDashboardWithPanelAndName(data map[string]interface{}) bool { isDashboardName := false isDashboardWithPanelAndName := false diff --git a/pkg/query-service/model/response.go b/pkg/query-service/model/response.go index 5144dade47..4add34071e 100644 --- a/pkg/query-service/model/response.go +++ b/pkg/query-service/model/response.go @@ -665,6 +665,7 @@ type AlertsInfo struct { SpanMetricsPrometheusQueries int `json:"spanMetricsPrometheusQueries"` AlertNames []string `json:"alertNames"` AlertsWithTSV2 int `json:"alertsWithTSv2"` + AlertsWithLogsChQuery int `json:"alertsWithLogsChQuery"` } type SavedViewsInfo struct { @@ -681,6 +682,7 @@ type DashboardsInfo struct { TracesBasedPanels int `json:"tracesBasedPanels"` DashboardNames []string `json:"dashboardNames"` QueriesWithTSV2 int `json:"queriesWithTSV2"` + DashboardsWithLogsChQuery int `json:"dashboardsWithLogsChQuery"` } type TagTelemetryData struct { diff --git a/pkg/query-service/rules/db.go b/pkg/query-service/rules/db.go index d9a9be195c..f3a9de1c62 100644 --- a/pkg/query-service/rules/db.go +++ b/pkg/query-service/rules/db.go @@ -319,6 +319,10 @@ func (r *ruleDB) GetAlertsInfo(ctx context.Context) (*model.AlertsInfo, error) { if strings.Contains(alert, "time_series_v2") { alertsInfo.AlertsWithTSV2 = alertsInfo.AlertsWithTSV2 + 1 } + if strings.Contains(alert, "signoz_logs.distributed_logs") || + strings.Contains(alert, "signoz_logs.logs") { + alertsInfo.AlertsWithLogsChQuery = alertsInfo.AlertsWithLogsChQuery + 1 + } err = json.Unmarshal([]byte(alert), &rule) if err != nil { zap.L().Error("invalid rule data", zap.Error(err)) diff --git a/pkg/query-service/telemetry/telemetry.go b/pkg/query-service/telemetry/telemetry.go index 7f282ea3f9..048d23498f 100644 --- a/pkg/query-service/telemetry/telemetry.go +++ b/pkg/query-service/telemetry/telemetry.go @@ -339,6 +339,7 @@ func createTelemetry() { "metricBasedPanels": dashboardsInfo.MetricBasedPanels, "tracesBasedPanels": dashboardsInfo.TracesBasedPanels, "dashboardsWithTSV2": dashboardsInfo.QueriesWithTSV2, + "dashboardWithLogsChQuery": dashboardsInfo.DashboardsWithLogsChQuery, "totalAlerts": alertsInfo.TotalAlerts, "alertsWithTSV2": alertsInfo.AlertsWithTSV2, "logsBasedAlerts": alertsInfo.LogsBasedAlerts, @@ -358,6 +359,7 @@ func createTelemetry() { "metricsClickHouseQueries": alertsInfo.MetricsClickHouseQueries, "metricsPrometheusQueries": alertsInfo.MetricsPrometheusQueries, "spanMetricsPrometheusQueries": alertsInfo.SpanMetricsPrometheusQueries, + "alertsWithLogsChQuery": alertsInfo.AlertsWithLogsChQuery, } // send event only if there are dashboards or alerts or channels if (dashboardsInfo.TotalDashboards > 0 || alertsInfo.TotalAlerts > 0 || len(*channels) > 0 || savedViewsInfo.TotalSavedViews > 0) && apiErr == nil {