mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* tech(routines): move the async logic from notification to alerting notifier
* tech(notification): reduce code dupe
* fix(notification): dont touch the response unless its an error
* feat(alerting): make alerting exeuction async but flow sync
* tech(alerting): remove commented code
* tech(alerting): remove unused code
* tech(alerting): fix typo
* tech(alerting): implement Context on EvalContext
* tech(alerting): wait for all alerts to return
* feat(alerting): dont allow alert responses to cancel
* Revert "feat(alerting): dont allow alert responses to cancel"
This reverts commit 324b006c96
.
* feat(alerting): give alerts some time to finish before closing down
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package tsdb
|
|
|
|
import "context"
|
|
|
|
type FakeExecutor struct {
|
|
results map[string]*QueryResult
|
|
resultsFn map[string]ResultsFn
|
|
}
|
|
|
|
type ResultsFn func(context *QueryContext) *QueryResult
|
|
|
|
func NewFakeExecutor(dsInfo *DataSourceInfo) *FakeExecutor {
|
|
return &FakeExecutor{
|
|
results: make(map[string]*QueryResult),
|
|
resultsFn: make(map[string]ResultsFn),
|
|
}
|
|
}
|
|
|
|
func (e *FakeExecutor) Execute(ctx context.Context, queries QuerySlice, context *QueryContext) *BatchResult {
|
|
result := &BatchResult{QueryResults: make(map[string]*QueryResult)}
|
|
for _, query := range queries {
|
|
if results, has := e.results[query.RefId]; has {
|
|
result.QueryResults[query.RefId] = results
|
|
}
|
|
if testFunc, has := e.resultsFn[query.RefId]; has {
|
|
result.QueryResults[query.RefId] = testFunc(context)
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func (e *FakeExecutor) Return(refId string, series TimeSeriesSlice) {
|
|
e.results[refId] = &QueryResult{
|
|
RefId: refId, Series: series,
|
|
}
|
|
}
|
|
|
|
func (e *FakeExecutor) HandleQuery(refId string, fn ResultsFn) {
|
|
e.resultsFn[refId] = fn
|
|
}
|