Alerting: Export pure function to convert query results to alert results (#85393)

Exported pure function to convert query results to alert results
This commit is contained in:
Alexander Weaver 2024-04-05 08:57:31 -05:00 committed by GitHub
parent 362c95c606
commit 734d0111cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -83,8 +83,7 @@ func (r *conditionEvaluator) Evaluate(ctx context.Context, now time.Time) (Resul
if err != nil {
return nil, err
}
execResults := queryDataResponseToExecutionResults(r.condition, response)
return evaluateExecutionResult(execResults, now), nil
return EvaluateAlert(response, r.condition, now), nil
}
type evaluatorImpl struct {
@ -108,6 +107,12 @@ func NewEvaluatorFactory(
}
}
// EvaluateAlert takes the results of an executed query and evaluates it as an alert rule, returning alert states that the query produces.
func EvaluateAlert(queryResponse *backend.QueryDataResponse, condition models.Condition, now time.Time) Results {
execResults := queryDataResponseToExecutionResults(condition, queryResponse)
return evaluateExecutionResult(execResults, now)
}
// invalidEvalResultFormatError is an error for invalid format of the alert definition evaluation results.
type invalidEvalResultFormatError struct {
refID string