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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,18 +7,14 @@ import (
"os"
"path/filepath"
"github.com/grafana/alerting/alerting"
"github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/grafana/grafana/pkg/infra/log"
)
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.
// It uses the KVstore table and encodes the files as a base64 string.
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.
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
bytes, err := st.MarshalBinary()