mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 05:15:57 +08:00
fix: use the correct formatter for the description (#5388)
This commit is contained in:
parent
b0b69c83db
commit
326dec21fd
@ -401,8 +401,11 @@ type CompositeQuery struct {
|
|||||||
PromQueries map[string]*PromQuery `json:"promQueries,omitempty"`
|
PromQueries map[string]*PromQuery `json:"promQueries,omitempty"`
|
||||||
PanelType PanelType `json:"panelType"`
|
PanelType PanelType `json:"panelType"`
|
||||||
QueryType QueryType `json:"queryType"`
|
QueryType QueryType `json:"queryType"`
|
||||||
Unit string `json:"unit,omitempty"`
|
// Unit for the time series data shown in the graph
|
||||||
FillGaps bool `json:"fillGaps,omitempty"`
|
// This is used in alerts to format the value and threshold
|
||||||
|
Unit string `json:"unit,omitempty"`
|
||||||
|
// FillGaps is used to fill the gaps in the time series data
|
||||||
|
FillGaps bool `json:"fillGaps,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CompositeQuery) EnabledQueries() int {
|
func (c *CompositeQuery) EnabledQueries() int {
|
||||||
|
@ -111,13 +111,22 @@ func (r *PromRule) Condition() *RuleCondition {
|
|||||||
return r.ruleCondition
|
return r.ruleCondition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// targetVal returns the target value for the rule condition
|
||||||
|
// when the y-axis and target units are non-empty, it
|
||||||
|
// converts the target value to the y-axis unit
|
||||||
func (r *PromRule) targetVal() float64 {
|
func (r *PromRule) targetVal() float64 {
|
||||||
if r.ruleCondition == nil || r.ruleCondition.Target == nil {
|
if r.ruleCondition == nil || r.ruleCondition.Target == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the converter for the target unit
|
||||||
unitConverter := converter.FromUnit(converter.Unit(r.ruleCondition.TargetUnit))
|
unitConverter := converter.FromUnit(converter.Unit(r.ruleCondition.TargetUnit))
|
||||||
value := unitConverter.Convert(converter.Value{F: *r.ruleCondition.Target, U: converter.Unit(r.ruleCondition.TargetUnit)}, converter.Unit(r.Unit()))
|
// convert the target value to the y-axis unit
|
||||||
|
value := unitConverter.Convert(converter.Value{
|
||||||
|
F: *r.ruleCondition.Target,
|
||||||
|
U: converter.Unit(r.ruleCondition.TargetUnit),
|
||||||
|
}, converter.Unit(r.Unit()))
|
||||||
|
|
||||||
return value.F
|
return value.F
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,8 +379,7 @@ func (r *PromRule) Eval(ctx context.Context, ts time.Time, queriers *Queriers) (
|
|||||||
}
|
}
|
||||||
zap.L().Debug("alerting for series", zap.String("name", r.Name()), zap.Any("series", series))
|
zap.L().Debug("alerting for series", zap.String("name", r.Name()), zap.Any("series", series))
|
||||||
|
|
||||||
thresholdFormatter := formatter.FromUnit(r.ruleCondition.TargetUnit)
|
threshold := valueFormatter.Format(r.targetVal(), r.Unit())
|
||||||
threshold := thresholdFormatter.Format(r.targetVal(), r.ruleCondition.TargetUnit)
|
|
||||||
|
|
||||||
tmplData := AlertTemplateData(l, valueFormatter.Format(alertSmpl.F, r.Unit()), threshold)
|
tmplData := AlertTemplateData(l, valueFormatter.Format(alertSmpl.F, r.Unit()), threshold)
|
||||||
// Inject some convenience variables that are easier to remember for users
|
// Inject some convenience variables that are easier to remember for users
|
||||||
|
@ -165,13 +165,22 @@ func (r *ThresholdRule) PreferredChannels() []string {
|
|||||||
return r.preferredChannels
|
return r.preferredChannels
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// targetVal returns the target value for the rule condition
|
||||||
|
// when the y-axis and target units are non-empty, it
|
||||||
|
// converts the target value to the y-axis unit
|
||||||
func (r *ThresholdRule) targetVal() float64 {
|
func (r *ThresholdRule) targetVal() float64 {
|
||||||
if r.ruleCondition == nil || r.ruleCondition.Target == nil {
|
if r.ruleCondition == nil || r.ruleCondition.Target == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the converter for the target unit
|
||||||
unitConverter := converter.FromUnit(converter.Unit(r.ruleCondition.TargetUnit))
|
unitConverter := converter.FromUnit(converter.Unit(r.ruleCondition.TargetUnit))
|
||||||
value := unitConverter.Convert(converter.Value{F: *r.ruleCondition.Target, U: converter.Unit(r.ruleCondition.TargetUnit)}, converter.Unit(r.Unit()))
|
// convert the target value to the y-axis unit
|
||||||
|
value := unitConverter.Convert(converter.Value{
|
||||||
|
F: *r.ruleCondition.Target,
|
||||||
|
U: converter.Unit(r.ruleCondition.TargetUnit),
|
||||||
|
}, converter.Unit(r.Unit()))
|
||||||
|
|
||||||
return value.F
|
return value.F
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -874,8 +883,7 @@ func (r *ThresholdRule) Eval(ctx context.Context, ts time.Time, queriers *Querie
|
|||||||
}
|
}
|
||||||
|
|
||||||
value := valueFormatter.Format(smpl.V, r.Unit())
|
value := valueFormatter.Format(smpl.V, r.Unit())
|
||||||
thresholdFormatter := formatter.FromUnit(r.ruleCondition.TargetUnit)
|
threshold := valueFormatter.Format(r.targetVal(), r.Unit())
|
||||||
threshold := thresholdFormatter.Format(r.targetVal(), r.ruleCondition.TargetUnit)
|
|
||||||
zap.L().Debug("Alert template data for rule", zap.String("name", r.Name()), zap.String("formatter", valueFormatter.Name()), zap.String("value", value), zap.String("threshold", threshold))
|
zap.L().Debug("Alert template data for rule", zap.String("name", r.Name()), zap.String("formatter", valueFormatter.Name()), zap.String("value", value), zap.String("threshold", threshold))
|
||||||
|
|
||||||
tmplData := AlertTemplateData(l, value, threshold)
|
tmplData := AlertTemplateData(l, value, threshold)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user