Skip to content

Commit

Permalink
fix: add telemetry for trace migration (#6537)
Browse files Browse the repository at this point in the history
  • Loading branch information
nityanandagohain authored Nov 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 24ab18d commit a3e57a1
Showing 4 changed files with 38 additions and 6 deletions.
27 changes: 21 additions & 6 deletions pkg/query-service/app/dashboards/model.go
Original file line number Diff line number Diff line change
@@ -468,6 +468,7 @@ func GetDashboardsInfo(ctx context.Context) (*model.DashboardsInfo, error) {
dashboardsInfo.MetricBasedPanels += dashboardsInfo.MetricBasedPanels
dashboardsInfo.LogsPanelsWithAttrContainsOp += dashboardInfo.LogsPanelsWithAttrContainsOp
dashboardsInfo.DashboardsWithLogsChQuery += dashboardInfo.DashboardsWithLogsChQuery
dashboardsInfo.DashboardsWithTraceChQuery += dashboardInfo.DashboardsWithTraceChQuery
if isDashboardWithTSV2(dashboard.Data) {
count = count + 1
}
@@ -499,6 +500,18 @@ func isDashboardWithLogsClickhouseQuery(data map[string]interface{}) bool {
return result
}

func isDashboardWithTracesClickhouseQuery(data map[string]interface{}) bool {
jsonData, err := json.Marshal(data)
if err != nil {
return false
}
str := string(jsonData)
result := strings.Contains(str, "signoz_traces.distributed_signoz_index_v2") ||
strings.Contains(str, "signoz_traces.distributed_signoz_spans") ||
strings.Contains(str, "signoz_traces.distributed_signoz_error_index_v2")
return result
}

func isDashboardWithPanelAndName(data map[string]interface{}) bool {
isDashboardName := false
isDashboardWithPanelAndName := false
@@ -559,7 +572,9 @@ func checkLogPanelAttrContains(data map[string]interface{}) int {

func countPanelsInDashboard(inputData map[string]interface{}) model.DashboardsInfo {
var logsPanelCount, tracesPanelCount, metricsPanelCount, logsPanelsWithAttrContains int
var logChQuery bool
traceChQueryCount := 0
logChQueryCount := 0

// totalPanels := 0
if inputData != nil && inputData["widgets"] != nil {
widgets, ok := inputData["widgets"]
@@ -593,7 +608,10 @@ func countPanelsInDashboard(inputData map[string]interface{}) model.DashboardsIn
}
} else if ok && query["queryType"] == "clickhouse_sql" && query["clickhouse_sql"] != nil {
if isDashboardWithLogsClickhouseQuery(inputData) {
logChQuery = true
logChQueryCount = 1
}
if isDashboardWithTracesClickhouseQuery(inputData) {
traceChQueryCount = 1
}
}
}
@@ -602,16 +620,13 @@ func countPanelsInDashboard(inputData map[string]interface{}) model.DashboardsIn
}
}

logChQueryCount := 0
if logChQuery {
logChQueryCount = 1
}
return model.DashboardsInfo{
LogsBasedPanels: logsPanelCount,
TracesBasedPanels: tracesPanelCount,
MetricBasedPanels: metricsPanelCount,

DashboardsWithLogsChQuery: logChQueryCount,
DashboardsWithTraceChQuery: traceChQueryCount,
LogsPanelsWithAttrContainsOp: logsPanelsWithAttrContains,
}
}
2 changes: 2 additions & 0 deletions pkg/query-service/model/response.go
Original file line number Diff line number Diff line change
@@ -636,6 +636,7 @@ type AlertsInfo struct {
AlertNames []string `json:"alertNames"`
AlertsWithTSV2 int `json:"alertsWithTSv2"`
AlertsWithLogsChQuery int `json:"alertsWithLogsChQuery"`
AlertsWithTraceChQuery int `json:"alertsWithTraceChQuery"`
AlertsWithLogsContainsOp int `json:"alertsWithLogsContainsOp"`
}

@@ -656,6 +657,7 @@ type DashboardsInfo struct {
DashboardNames []string `json:"dashboardNames"`
QueriesWithTSV2 int `json:"queriesWithTSV2"`
DashboardsWithLogsChQuery int `json:"dashboardsWithLogsChQuery"`
DashboardsWithTraceChQuery int `json:"dashboardsWithTraceChQuery"`
LogsPanelsWithAttrContainsOp int `json:"logsPanelsWithAttrContainsOp"`
}

10 changes: 10 additions & 0 deletions pkg/query-service/rules/db.go
Original file line number Diff line number Diff line change
@@ -604,6 +604,16 @@ func (r *ruleDB) GetAlertsInfo(ctx context.Context) (*model.AlertsInfo, error) {
}
} else if rule.AlertType == AlertTypeTraces {
alertsInfo.TracesBasedAlerts = alertsInfo.TracesBasedAlerts + 1

if rule.RuleCondition != nil && rule.RuleCondition.CompositeQuery != nil {
if rule.RuleCondition.CompositeQuery.QueryType == v3.QueryTypeClickHouseSQL {
if strings.Contains(alert, "signoz_traces.distributed_signoz_index_v2") ||
strings.Contains(alert, "signoz_traces.distributed_signoz_spans") ||
strings.Contains(alert, "signoz_traces.distributed_signoz_error_index_v2") {
alertsInfo.AlertsWithTraceChQuery = alertsInfo.AlertsWithTraceChQuery + 1
}
}
}
}
alertsInfo.TotalAlerts = alertsInfo.TotalAlerts + 1
}
5 changes: 5 additions & 0 deletions pkg/query-service/telemetry/telemetry.go
Original file line number Diff line number Diff line change
@@ -307,8 +307,11 @@ func createTelemetry() {
"getLogsInfoInLastHeartBeatInterval": getLogsInfoInLastHeartBeatInterval,
"countUsers": userCount,
"metricsTTLStatus": metricsTTL.Status,
"metricsTTLValue": metricsTTL.MetricsMoveTime,
"tracesTTLStatus": traceTTL.Status,
"traceTTLValue": traceTTL.TracesTime,
"logsTTLStatus": logsTTL.Status,
"logsTTLValue": logsTTL.LogsTime,
"patUser": telemetry.patTokenUser,
}
telemetry.patTokenUser = false
@@ -343,6 +346,7 @@ func createTelemetry() {
"tracesBasedPanels": dashboardsInfo.TracesBasedPanels,
"dashboardsWithTSV2": dashboardsInfo.QueriesWithTSV2,
"dashboardWithLogsChQuery": dashboardsInfo.DashboardsWithLogsChQuery,
"dashboardWithTraceChQuery": dashboardsInfo.DashboardsWithTraceChQuery,
"totalAlerts": alertsInfo.TotalAlerts,
"alertsWithTSV2": alertsInfo.AlertsWithTSV2,
"logsBasedAlerts": alertsInfo.LogsBasedAlerts,
@@ -366,6 +370,7 @@ func createTelemetry() {
"spanMetricsPrometheusQueries": alertsInfo.SpanMetricsPrometheusQueries,
"alertsWithLogsChQuery": alertsInfo.AlertsWithLogsChQuery,
"alertsWithLogsContainsOp": alertsInfo.AlertsWithLogsContainsOp,
"alertsWithTraceChQuery": alertsInfo.AlertsWithTraceChQuery,
}
// send event only if there are dashboards or alerts or channels
if (dashboardsInfo.TotalDashboards > 0 || alertsInfo.TotalAlerts > 0 || alertsInfo.TotalChannels > 0 || savedViewsInfo.TotalSavedViews > 0) && apiErr == nil {

0 comments on commit a3e57a1

Please sign in to comment.