grafana/pkg/services/ngalert/schedule/recording_rule.go
Alexander Weaver 89b54d06e9
Alerting: Schedule a shim implementation for recording rules (#87939)
* Add shim rule implementation for recording rules

* Give ruleFactory access to the original rule definition

* Schedule shim implementation if the rule is a recording rule

* Fix or suppress linter

* Fix nolint
2024-05-21 16:42:58 -05:00

55 lines
1.1 KiB
Go

package schedule
import (
context "context"
"github.com/grafana/grafana/pkg/infra/log"
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
"github.com/grafana/grafana/pkg/util"
)
type recordingRule struct {
ctx context.Context
stopFn util.CancelCauseFunc
logger log.Logger
}
func newRecordingRule(parent context.Context, logger log.Logger) *recordingRule {
ctx, stop := util.WithCancelCause(parent)
return &recordingRule{
ctx: ctx,
stopFn: stop,
logger: logger,
}
}
func (r *recordingRule) Eval(eval *Evaluation) (bool, *Evaluation) {
return true, nil
}
func (r *recordingRule) Update(lastVersion RuleVersionAndPauseStatus) bool {
return true
}
func (r *recordingRule) Stop(reason error) {
if r.stopFn != nil {
r.stopFn(reason)
}
}
func (r *recordingRule) Run(key ngmodels.AlertRuleKey) error {
ctx := ngmodels.WithRuleKey(r.ctx, key)
logger := r.logger.FromContext(ctx)
logger.Debug("Recording rule routine started")
// nolint:gosimple
for {
select {
case <-ctx.Done():
logger.Debug("Stopping recording rule routine")
return nil
}
}
}