Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: do not mutate the rule condition (#5141)

Srikanth Chekurie5f96ac89647
diff --git a/pkg/query-service/rules/thresholdRule.go b/pkg/query-service/rules/thresholdRule.go
index c8aad7803c..0b8d080bd9 100644
--- a/pkg/query-service/rules/thresholdRule.go
+++ b/pkg/query-service/rules/thresholdRule.go
@@ -434,12 +434,19 @@ func (r *ThresholdRule) prepareQueryRange(ts time.Time) *v3.QueryRangeParamsV3 {
if r.ruleCondition.QueryType() == v3.QueryTypeClickHouseSQL {
params := &v3.QueryRangeParamsV3{
- Start: start,
- End: end,
- Step: int64(math.Max(float64(common.MinAllowedStepInterval(start, end)), 60)),
- CompositeQuery: r.ruleCondition.CompositeQuery,
- Variables: make(map[string]interface{}, 0),
- NoCache: true,
+ Start: start,
+ End: end,
+ Step: int64(math.Max(float64(common.MinAllowedStepInterval(start, end)), 60)),
+ CompositeQuery: &v3.CompositeQuery{
+ QueryType: r.ruleCondition.CompositeQuery.QueryType,
+ PanelType: r.ruleCondition.CompositeQuery.PanelType,
+ BuilderQueries: make(map[string]*v3.BuilderQuery),
+ ClickHouseQueries: make(map[string]*v3.ClickHouseQuery),
+ PromQueries: make(map[string]*v3.PromQuery),
+ Unit: r.ruleCondition.CompositeQuery.Unit,
+ },
+ Variables: make(map[string]interface{}, 0),
+ NoCache: true,
}
querytemplate.AssignReservedVarsV3(params)
for name, chQuery := range r.ruleCondition.CompositeQuery.ClickHouseQueries {
@@ -460,8 +467,13 @@ func (r *ThresholdRule) prepareQueryRange(ts time.Time) *v3.QueryRangeParamsV3 {
r.SetHealth(HealthBad)
return params
}
- r.ruleCondition.CompositeQuery.ClickHouseQueries[name].Query = query.String()
+ params.CompositeQuery.ClickHouseQueries[name] = &v3.ClickHouseQuery{
+ Query: query.String(),
+ Disabled: chQuery.Disabled,
+ Legend: chQuery.Legend,
+ }
}
+ return params
}
if r.ruleCondition.CompositeQuery != nil && r.ruleCondition.CompositeQuery.BuilderQueries != nil {
diff --git a/pkg/query-service/rules/thresholdRule_test.go b/pkg/query-service/rules/thresholdRule_test.go
index 3f1af04a11..762666cbf3 100644
--- a/pkg/query-service/rules/thresholdRule_test.go
+++ b/pkg/query-service/rules/thresholdRule_test.go
@@ -876,5 +876,9 @@ func TestThresholdRuleClickHouseTmpl(t *testing.T) {
params := rule.prepareQueryRange(ts)
assert.Equal(t, c.expectedQuery, params.CompositeQuery.ClickHouseQueries["A"].Query, "Test case %d", idx)
+
+ secondTimeParams := rule.prepareQueryRange(ts)
+
+ assert.Equal(t, c.expectedQuery, secondTimeParams.CompositeQuery.ClickHouseQueries["A"].Query, "Test case %d", idx)
}
}