Alerting Unification: Use the State interface from the alerting package (#61333)

This commit is contained in:
gotjosh
2023-01-11 19:50:45 -04:00
committed by GitHub
parent 7eaa95729c
commit f85a948214

View File

@@ -7,18 +7,14 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/grafana/alerting/alerting"
"github.com/grafana/grafana/pkg/infra/kvstore" "github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
) )
const KVNamespace = "alertmanager" const KVNamespace = "alertmanager"
// State represents any of the two 'states' of the alertmanager. Notification log or Silences.
// MarshalBinary returns the binary representation of this internal state based on the protobuf.
type State interface {
MarshalBinary() ([]byte, error)
}
// FileStore is in charge of persisting the alertmanager files to the database. // FileStore is in charge of persisting the alertmanager files to the database.
// It uses the KVstore table and encodes the files as a base64 string. // It uses the KVstore table and encodes the files as a base64 string.
type FileStore struct { type FileStore struct {
@@ -67,7 +63,7 @@ func (fileStore *FileStore) FilepathFor(ctx context.Context, filename string) (s
} }
// Persist takes care of persisting the binary representation of internal state to the database as a base64 encoded string. // Persist takes care of persisting the binary representation of internal state to the database as a base64 encoded string.
func (fileStore *FileStore) Persist(ctx context.Context, filename string, st State) (int64, error) { func (fileStore *FileStore) Persist(ctx context.Context, filename string, st alerting.State) (int64, error) {
var size int64 var size int64
bytes, err := st.MarshalBinary() bytes, err := st.MarshalBinary()