mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-13 20:05:58 +08:00
fix: add back the templating for query (#5079)
This commit is contained in:
parent
1369fe1912
commit
2f7495c6e4
@ -1,9 +1,11 @@
|
|||||||
package rules
|
package rules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"math"
|
"math"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -27,6 +29,7 @@ import (
|
|||||||
"go.signoz.io/signoz/pkg/query-service/interfaces"
|
"go.signoz.io/signoz/pkg/query-service/interfaces"
|
||||||
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
||||||
"go.signoz.io/signoz/pkg/query-service/utils/labels"
|
"go.signoz.io/signoz/pkg/query-service/utils/labels"
|
||||||
|
querytemplate "go.signoz.io/signoz/pkg/query-service/utils/queryTemplate"
|
||||||
"go.signoz.io/signoz/pkg/query-service/utils/times"
|
"go.signoz.io/signoz/pkg/query-service/utils/times"
|
||||||
"go.signoz.io/signoz/pkg/query-service/utils/timestamp"
|
"go.signoz.io/signoz/pkg/query-service/utils/timestamp"
|
||||||
|
|
||||||
@ -430,7 +433,7 @@ func (r *ThresholdRule) prepareQueryRange(ts time.Time) *v3.QueryRangeParamsV3 {
|
|||||||
end = end - (end % (60 * 1000))
|
end = end - (end % (60 * 1000))
|
||||||
|
|
||||||
if r.ruleCondition.QueryType() == v3.QueryTypeClickHouseSQL {
|
if r.ruleCondition.QueryType() == v3.QueryTypeClickHouseSQL {
|
||||||
return &v3.QueryRangeParamsV3{
|
params := &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)),
|
||||||
@ -438,6 +441,27 @@ func (r *ThresholdRule) prepareQueryRange(ts time.Time) *v3.QueryRangeParamsV3 {
|
|||||||
Variables: make(map[string]interface{}, 0),
|
Variables: make(map[string]interface{}, 0),
|
||||||
NoCache: true,
|
NoCache: true,
|
||||||
}
|
}
|
||||||
|
querytemplate.AssignReservedVarsV3(params)
|
||||||
|
for name, chQuery := range r.ruleCondition.CompositeQuery.ClickHouseQueries {
|
||||||
|
if chQuery.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tmpl := template.New("clickhouse-query")
|
||||||
|
tmpl, err := tmpl.Parse(chQuery.Query)
|
||||||
|
if err != nil {
|
||||||
|
zap.L().Error("failed to parse clickhouse query to populate vars", zap.String("ruleid", r.ID()), zap.Error(err))
|
||||||
|
r.SetHealth(HealthBad)
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
var query bytes.Buffer
|
||||||
|
err = tmpl.Execute(&query, params.Variables)
|
||||||
|
if err != nil {
|
||||||
|
zap.L().Error("failed to populate clickhouse query", zap.String("ruleid", r.ID()), zap.Error(err))
|
||||||
|
r.SetHealth(HealthBad)
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
r.ruleCondition.CompositeQuery.ClickHouseQueries[name].Query = query.String()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.ruleCondition.CompositeQuery != nil && r.ruleCondition.CompositeQuery.BuilderQueries != nil {
|
if r.ruleCondition.CompositeQuery != nil && r.ruleCondition.CompositeQuery.BuilderQueries != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user