mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-08 16:18:59 +08:00
fix: do not mutate the rule condition (#5141)
* fix: do not mutate the rule condition * chore: add unit * chore: add test
This commit is contained in:
parent
694f2562bf
commit
e5f96ac896
@ -437,7 +437,14 @@ func (r *ThresholdRule) prepareQueryRange(ts time.Time) *v3.QueryRangeParamsV3 {
|
|||||||
Start: start,
|
Start: start,
|
||||||
End: end,
|
End: end,
|
||||||
Step: int64(math.Max(float64(common.MinAllowedStepInterval(start, end)), 60)),
|
Step: int64(math.Max(float64(common.MinAllowedStepInterval(start, end)), 60)),
|
||||||
CompositeQuery: r.ruleCondition.CompositeQuery,
|
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),
|
Variables: make(map[string]interface{}, 0),
|
||||||
NoCache: true,
|
NoCache: true,
|
||||||
}
|
}
|
||||||
@ -460,9 +467,14 @@ func (r *ThresholdRule) prepareQueryRange(ts time.Time) *v3.QueryRangeParamsV3 {
|
|||||||
r.SetHealth(HealthBad)
|
r.SetHealth(HealthBad)
|
||||||
return params
|
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 {
|
if r.ruleCondition.CompositeQuery != nil && r.ruleCondition.CompositeQuery.BuilderQueries != nil {
|
||||||
for _, q := range r.ruleCondition.CompositeQuery.BuilderQueries {
|
for _, q := range r.ruleCondition.CompositeQuery.BuilderQueries {
|
||||||
|
@ -876,5 +876,9 @@ func TestThresholdRuleClickHouseTmpl(t *testing.T) {
|
|||||||
params := rule.prepareQueryRange(ts)
|
params := rule.prepareQueryRange(ts)
|
||||||
|
|
||||||
assert.Equal(t, c.expectedQuery, params.CompositeQuery.ClickHouseQueries["A"].Query, "Test case %d", idx)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user