2022-10-19 14:19:43 -05:00
|
|
|
package eval
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-01-04 10:47:13 -06:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
|
|
|
|
2024-06-12 23:11:35 -05:00
|
|
|
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
2022-10-19 14:19:43 -05:00
|
|
|
)
|
|
|
|
|
2024-01-04 10:47:13 -06:00
|
|
|
// 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{}
|
|
|
|
}
|
|
|
|
|
2022-10-19 14:19:43 -05:00
|
|
|
// EvaluationContext represents the context in which a condition is evaluated.
|
|
|
|
type EvaluationContext struct {
|
2024-01-04 10:47:13 -06:00
|
|
|
Ctx context.Context
|
|
|
|
User identity.Requester
|
|
|
|
AlertingResultsReader AlertingResultsReader
|
2022-10-19 14:19:43 -05:00
|
|
|
}
|
|
|
|
|
2023-11-14 08:47:34 -06:00
|
|
|
func NewContext(ctx context.Context, user identity.Requester) EvaluationContext {
|
2022-10-19 14:19:43 -05:00
|
|
|
return EvaluationContext{
|
|
|
|
Ctx: ctx,
|
|
|
|
User: user,
|
|
|
|
}
|
|
|
|
}
|
2024-01-04 10:47:13 -06:00
|
|
|
|
|
|
|
func NewContextWithPreviousResults(ctx context.Context, user identity.Requester, reader AlertingResultsReader) EvaluationContext {
|
|
|
|
return EvaluationContext{
|
|
|
|
Ctx: ctx,
|
|
|
|
User: user,
|
|
|
|
AlertingResultsReader: reader,
|
|
|
|
}
|
|
|
|
}
|