mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
f6a46744a6
Backend: * Update the Grafana Alerting engine to provide feedback to HysteresisCommand. The feedback information is stored in state.Manager as a fingerprint of each state. The fingerprint is persisted to the database. Only fingerprints that belong to Pending and Alerting states are considered as "loaded" and provided back to the command. - add ResultFingerprint to state.State. It's different from other fingerprints we store in the state because it is calculated from the result labels. - add rule_fingerprint column to alert_instance - update alerting evaluator to accept AlertingResultsReader via context, and update scheduler to provide it. - add AlertingResultsFromRuleState that implements the new interface in eval package - update getExprRequest to patch the hysteresis command. * Only one "Recovery Threshold" query is allowed to be used in the alert rule and it must be the Condition. Frontend: * Add hysteresis option to Threshold in UI. It's called "Recovery Threshold" * Add test for getUnloadEvaluatorTypeFromCondition * Hide hysteresis in panel expressions * Refactor isInvalid and add test for it * Remove unnecesary React.memo * Add tests for updateEvaluatorConditions --------- Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>
38 lines
998 B
Go
38 lines
998 B
Go
package eval
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
|
|
|
"github.com/grafana/grafana/pkg/services/auth/identity"
|
|
)
|
|
|
|
// AlertingResultsReader provides fingerprints of results that are in alerting state.
|
|
// It is used during the evaluation of queries.
|
|
type AlertingResultsReader interface {
|
|
Read() map[data.Fingerprint]struct{}
|
|
}
|
|
|
|
// EvaluationContext represents the context in which a condition is evaluated.
|
|
type EvaluationContext struct {
|
|
Ctx context.Context
|
|
User identity.Requester
|
|
AlertingResultsReader AlertingResultsReader
|
|
}
|
|
|
|
func NewContext(ctx context.Context, user identity.Requester) EvaluationContext {
|
|
return EvaluationContext{
|
|
Ctx: ctx,
|
|
User: user,
|
|
}
|
|
}
|
|
|
|
func NewContextWithPreviousResults(ctx context.Context, user identity.Requester, reader AlertingResultsReader) EvaluationContext {
|
|
return EvaluationContext{
|
|
Ctx: ctx,
|
|
User: user,
|
|
AlertingResultsReader: reader,
|
|
}
|
|
}
|