mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 10:24:54 -06:00
Alerting: Refactor away a layer of indirection around the goroutine in Loki state history (#62644)
Inline recordStreamsAsync in loki backend
This commit is contained in:
parent
1225e8d6d8
commit
fcecf4d3cb
@ -50,7 +50,15 @@ func (h *RemoteLokiBackend) TestConnection(ctx context.Context) error {
|
||||
func (h *RemoteLokiBackend) RecordStatesAsync(ctx context.Context, rule history_model.RuleMeta, states []state.StateTransition) <-chan error {
|
||||
logger := h.log.FromContext(ctx)
|
||||
streams := h.statesToStreams(rule, states, logger)
|
||||
return h.recordStreamsAsync(ctx, streams, logger)
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
defer close(errCh)
|
||||
if err := h.recordStreams(ctx, streams, logger); err != nil {
|
||||
logger.Error("Failed to save alert state history batch", "error", err)
|
||||
errCh <- fmt.Errorf("failed to save alert state history batch: %w", err)
|
||||
}
|
||||
}()
|
||||
return errCh
|
||||
}
|
||||
|
||||
func (h *RemoteLokiBackend) QueryStates(ctx context.Context, query models.HistoryQuery) (*data.Frame, error) {
|
||||
@ -106,18 +114,6 @@ func (h *RemoteLokiBackend) statesToStreams(rule history_model.RuleMeta, states
|
||||
return result
|
||||
}
|
||||
|
||||
func (h *RemoteLokiBackend) recordStreamsAsync(ctx context.Context, streams []stream, logger log.Logger) <-chan error {
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
defer close(errCh)
|
||||
if err := h.recordStreams(ctx, streams, logger); err != nil {
|
||||
logger.Error("Failed to save alert state history batch", "error", err)
|
||||
errCh <- fmt.Errorf("failed to save alert state history batch: %w", err)
|
||||
}
|
||||
}()
|
||||
return errCh
|
||||
}
|
||||
|
||||
func (h *RemoteLokiBackend) recordStreams(ctx context.Context, streams []stream, logger log.Logger) error {
|
||||
if err := h.client.push(ctx, streams); err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user