Skip to content

Commit

Permalink
Merge branch 'develop' into some-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv authored Sep 13, 2024
2 parents 607bbd3 + 5b22490 commit 37899ac
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 17 deletions.
19 changes: 17 additions & 2 deletions pkg/query-service/app/clickhouseReader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,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
Expand All @@ -3272,12 +3273,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
}

Expand All @@ -3289,6 +3294,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
Expand Down Expand Up @@ -4866,7 +4881,7 @@ func (r *ClickHouseReader) GetTimeSeriesResultV3(ctx context.Context, query stri

if err != nil {
zap.L().Error("error while reading time series result", zap.Error(err))
return nil, err
return nil, errors.New(err.Error())
}
defer rows.Close()

Expand Down Expand Up @@ -4913,7 +4928,7 @@ func (r *ClickHouseReader) GetListResultV3(ctx context.Context, query string) ([

if err != nil {
zap.L().Error("error while reading time series result", zap.Error(err))
return nil, err
return nil, errors.New(err.Error())
}
defer rows.Close()

Expand Down
16 changes: 12 additions & 4 deletions pkg/query-service/app/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3674,8 +3674,12 @@ func (aH *APIHandler) queryRangeV3(ctx context.Context, queryRangeParams *v3.Que
result, errQuriesByName, err = aH.querier.QueryRange(ctx, queryRangeParams)

if err != nil {
apiErrObj := &model.ApiError{Typ: model.ErrorBadData, Err: err}
RespondError(w, apiErrObj, errQuriesByName)
queryErrors := map[string]string{}
for name, err := range errQuriesByName {
queryErrors[fmt.Sprintf("Query-%s", name)] = err.Error()
}
apiErrObj := &model.ApiError{Typ: model.ErrorInternal, Err: err}
RespondError(w, apiErrObj, queryErrors)
return
}

Expand Down Expand Up @@ -4118,8 +4122,12 @@ func (aH *APIHandler) queryRangeV4(ctx context.Context, queryRangeParams *v3.Que
result, errQuriesByName, err = aH.querierV2.QueryRange(ctx, queryRangeParams)

if err != nil {
apiErrObj := &model.ApiError{Typ: model.ErrorBadData, Err: err}
RespondError(w, apiErrObj, errQuriesByName)
queryErrors := map[string]string{}
for name, err := range errQuriesByName {
queryErrors[fmt.Sprintf("Query-%s", name)] = err.Error()
}
apiErrObj := &model.ApiError{Typ: model.ErrorInternal, Err: err}
RespondError(w, apiErrObj, queryErrors)
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/query-service/app/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (q *querier) runBuilderListQueries(ctx context.Context, params *v3.QueryRan
rowList, err := q.reader.GetListResultV3(ctx, query)

if err != nil {
ch <- channelResult{Err: fmt.Errorf("error in query-%s: %v", name, err), Name: name, Query: query}
ch <- channelResult{Err: err, Name: name, Query: query}
return
}
ch <- channelResult{List: rowList, Name: name, Query: query}
Expand Down
2 changes: 1 addition & 1 deletion pkg/query-service/app/querier/v2/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (q *querier) runBuilderListQueries(ctx context.Context, params *v3.QueryRan
rowList, err := q.reader.GetListResultV3(ctx, query)

if err != nil {
ch <- channelResult{Err: fmt.Errorf("error in query-%s: %v", name, err), Name: name, Query: query}
ch <- channelResult{Err: err, Name: name, Query: query}
return
}
ch <- channelResult{List: rowList, Name: name, Query: query}
Expand Down
2 changes: 2 additions & 0 deletions pkg/query-service/model/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ type AlertsInfo struct {
SpanMetricsPrometheusQueries int `json:"spanMetricsPrometheusQueries"`
AlertNames []string `json:"alertNames"`
AlertsWithTSV2 int `json:"alertsWithTSv2"`
AlertsWithLogsChQuery int `json:"alertsWithLogsChQuery"`
}

type SavedViewsInfo struct {
Expand All @@ -646,6 +647,7 @@ type DashboardsInfo struct {
TracesBasedPanels int `json:"tracesBasedPanels"`
DashboardNames []string `json:"dashboardNames"`
QueriesWithTSV2 int `json:"queriesWithTSV2"`
DashboardsWithLogsChQuery int `json:"dashboardsWithLogsChQuery"`
}

type TagTelemetryData struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/query-service/rules/base_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func NewBaseRule(id string, p *PostableRule, reader interfaces.Reader, opts ...R
id: id,
name: p.AlertName,
source: p.Source,
typ: p.AlertType,
ruleCondition: p.RuleCondition,
evalWindow: time.Duration(p.EvalWindow),
labels: qslabels.FromMap(p.Labels),
Expand Down
4 changes: 4 additions & 0 deletions pkg/query-service/rules/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion pkg/query-service/rules/promrule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestPromRuleShouldAlert(t *testing.T) {
postableRule := PostableRule{
AlertName: "Test Rule",
AlertType: "METRIC_BASED_ALERT",
AlertType: AlertTypeMetric,
RuleType: RuleTypeProm,
EvalWindow: Duration(5 * time.Minute),
Frequency: Duration(1 * time.Minute),
Expand Down
Loading

0 comments on commit 37899ac

Please sign in to comment.