2023-01-06 12:06:01 -06:00
|
|
|
package historian
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-01-19 03:45:31 -06:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
2023-01-06 12:06:01 -06:00
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/state"
|
|
|
|
)
|
|
|
|
|
2023-01-17 13:58:52 -06:00
|
|
|
type remoteLokiClient interface {
|
|
|
|
ping() error
|
|
|
|
}
|
|
|
|
|
2023-01-06 12:06:01 -06:00
|
|
|
type RemoteLokiBackend struct {
|
2023-01-17 13:58:52 -06:00
|
|
|
client remoteLokiClient
|
|
|
|
log log.Logger
|
2023-01-06 12:06:01 -06:00
|
|
|
}
|
|
|
|
|
2023-01-18 13:24:40 -06:00
|
|
|
func NewRemoteLokiBackend(cfg LokiConfig) *RemoteLokiBackend {
|
2023-01-17 13:58:52 -06:00
|
|
|
logger := log.New("ngalert.state.historian", "backend", "loki")
|
2023-01-06 12:06:01 -06:00
|
|
|
return &RemoteLokiBackend{
|
2023-01-18 13:24:40 -06:00
|
|
|
client: newLokiClient(cfg, logger),
|
2023-01-17 13:58:52 -06:00
|
|
|
log: logger,
|
2023-01-06 12:06:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 13:58:52 -06:00
|
|
|
func (h *RemoteLokiBackend) TestConnection() error {
|
|
|
|
return h.client.ping()
|
|
|
|
}
|
|
|
|
|
2023-01-06 12:06:01 -06:00
|
|
|
func (h *RemoteLokiBackend) RecordStatesAsync(ctx context.Context, _ *models.AlertRule, _ []state.StateTransition) {
|
2023-01-17 13:58:52 -06:00
|
|
|
logger := h.log.FromContext(ctx)
|
|
|
|
logger.Debug("Remote Loki state history backend was called with states")
|
2023-01-06 12:06:01 -06:00
|
|
|
}
|
2023-01-19 03:45:31 -06:00
|
|
|
|
|
|
|
func (h *RemoteLokiBackend) QueryStates(ctx context.Context, query models.HistoryQuery) (*data.Frame, error) {
|
|
|
|
return data.NewFrame("states"), nil
|
|
|
|
}
|