mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 05:55:59 +08:00
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
This commit is contained in:
parent
011b2167ba
commit
f854cdd9d3
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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))
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user