mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-21 23:59:48 +08:00
fix: use same time window as the logs/traces query (#4682)
This commit is contained in:
parent
c6c2b9d809
commit
c9816cce18
@ -182,26 +182,6 @@ func (r *PromRule) Annotations() qslabels.BaseLabels {
|
||||
return r.annotations
|
||||
}
|
||||
|
||||
func (r *PromRule) sample(alert *Alert, ts time.Time) pql.Sample {
|
||||
lb := plabels.NewBuilder(r.labels)
|
||||
|
||||
alertLabels := alert.Labels.(plabels.Labels)
|
||||
for _, l := range alertLabels {
|
||||
lb.Set(l.Name, l.Value)
|
||||
}
|
||||
|
||||
lb.Set(qslabels.MetricNameLabel, alertMetricName)
|
||||
lb.Set(qslabels.AlertNameLabel, r.name)
|
||||
lb.Set(qslabels.AlertStateLabel, alert.State.String())
|
||||
|
||||
s := pql.Sample{
|
||||
Metric: lb.Labels(),
|
||||
T: timestamp.FromTime(ts),
|
||||
F: 1,
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// GetEvaluationDuration returns the time in seconds it took to evaluate the alerting rule.
|
||||
func (r *PromRule) GetEvaluationDuration() time.Duration {
|
||||
r.mtx.Lock()
|
||||
@ -388,6 +368,7 @@ func (r *PromRule) Eval(ctx context.Context, ts time.Time, queriers *Queriers) (
|
||||
if !shouldAlert {
|
||||
continue
|
||||
}
|
||||
zap.S().Debugf("rule: %s, alerting for series: %v", r.Name(), series)
|
||||
|
||||
thresholdFormatter := formatter.FromUnit(r.ruleCondition.TargetUnit)
|
||||
threshold := thresholdFormatter.Format(r.targetVal(), r.ruleCondition.TargetUnit)
|
||||
@ -454,6 +435,7 @@ func (r *PromRule) Eval(ctx context.Context, ts time.Time, queriers *Queriers) (
|
||||
}
|
||||
}
|
||||
|
||||
zap.S().Debugf("For rule: %s, found %d alerts", r.Name(), len(alerts))
|
||||
// alerts[h] is ready, add or update active list now
|
||||
for h, a := range alerts {
|
||||
// Check whether we already have alerting state for the identifying label set.
|
||||
|
@ -823,10 +823,11 @@ func (r *ThresholdRule) prepareLinksToLogs(ts time.Time, lbls labels.Labels) str
|
||||
return ""
|
||||
}
|
||||
|
||||
q := r.prepareQueryRange(ts)
|
||||
// Logs list view expects time in milliseconds
|
||||
tr := timeRange{
|
||||
Start: ts.Add(-time.Duration(r.evalWindow)).UnixMilli(),
|
||||
End: ts.UnixMilli(),
|
||||
Start: q.Start,
|
||||
End: q.End,
|
||||
PageSize: 100,
|
||||
}
|
||||
|
||||
@ -886,10 +887,11 @@ func (r *ThresholdRule) prepareLinksToTraces(ts time.Time, lbls labels.Labels) s
|
||||
return ""
|
||||
}
|
||||
|
||||
q := r.prepareQueryRange(ts)
|
||||
// Traces list view expects time in nanoseconds
|
||||
tr := timeRange{
|
||||
Start: ts.Add(-time.Duration(r.evalWindow)).UnixNano(),
|
||||
End: ts.UnixNano(),
|
||||
Start: q.Start * time.Second.Microseconds(),
|
||||
End: q.End * time.Second.Microseconds(),
|
||||
PageSize: 100,
|
||||
}
|
||||
|
||||
|
@ -376,7 +376,7 @@ func TestPrepareLinksToLogs(t *testing.T) {
|
||||
ts := time.UnixMilli(1705469040000)
|
||||
|
||||
link := rule.prepareLinksToLogs(ts, labels.Labels{})
|
||||
assert.Contains(t, link, "&timeRange=%7B%22start%22%3A1705468740000%2C%22end%22%3A1705469040000%2C%22pageSize%22%3A100%7D&startTime=1705468740000&endTime=1705469040000")
|
||||
assert.Contains(t, link, "&timeRange=%7B%22start%22%3A1705468620000%2C%22end%22%3A1705468920000%2C%22pageSize%22%3A100%7D&startTime=1705468620000&endTime=1705468920000")
|
||||
}
|
||||
|
||||
func TestPrepareLinksToTraces(t *testing.T) {
|
||||
@ -418,5 +418,5 @@ func TestPrepareLinksToTraces(t *testing.T) {
|
||||
ts := time.UnixMilli(1705469040000)
|
||||
|
||||
link := rule.prepareLinksToTraces(ts, labels.Labels{})
|
||||
assert.Contains(t, link, "&timeRange=%7B%22start%22%3A1705468740000000000%2C%22end%22%3A1705469040000000000%2C%22pageSize%22%3A100%7D&startTime=1705468740000000000&endTime=1705469040000000000")
|
||||
assert.Contains(t, link, "&timeRange=%7B%22start%22%3A1705468620000000000%2C%22end%22%3A1705468920000000000%2C%22pageSize%22%3A100%7D&startTime=1705468620000000000&endTime=1705468920000000000")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user