Alerting: Add stored screenshot utilities to the channels package. (#49470)

Adds three functions:
`withStoredImages` iterates over a list of models.Alerts, extracting a stored image's data from storage, if available, and executing a user-provided function.
`withStoredImage` does this for an image attached to a specific alert.
`openImage` finds and opens an image file on disk.

Moves `store.Image` to `models.Image`
Simplifies `channels.ImageStore` interface and updates notifiers that use it to use the simpler methods.
Updates all pkg/alert/notifier/channels to use withStoredImage routines.
This commit is contained in:
Joe Blubaugh
2022-05-26 13:29:56 +08:00
committed by GitHub
parent 33d4850c90
commit 9e8efaa459
20 changed files with 289 additions and 386 deletions

View File

@@ -12,12 +12,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/ngalert/models"
"github.com/grafana/grafana/pkg/services/ngalert/store"
"github.com/grafana/grafana/pkg/services/ngalert/tests"
)
func createTestImg(fakeUrl string, fakePath string) *store.Image {
return &store.Image{
func createTestImg(fakeUrl string, fakePath string) *models.Image {
return &models.Image{
ID: 0,
Token: "",
Path: fakeUrl + "local",
@@ -25,12 +26,12 @@ func createTestImg(fakeUrl string, fakePath string) *store.Image {
}
}
func addID(img *store.Image, id int64) *store.Image {
func addID(img *models.Image, id int64) *models.Image {
img.ID = id
return img
}
func addToken(img *store.Image) *store.Image {
func addToken(img *models.Image) *models.Image {
token, err := uuid.NewV4()
if err != nil {
panic("wat")
@@ -47,7 +48,7 @@ func TestIntegrationSaveAndGetImage(t *testing.T) {
// Here are some images to save.
imgs := []struct {
name string
img *store.Image
img *models.Image
errors bool
}{
{
@@ -99,7 +100,7 @@ func TestIntegrationDeleteExpiredImages(t *testing.T) {
_, dbstore := tests.SetupTestEnv(t, baseIntervalSeconds)
// Save two images.
imgs := []*store.Image{
imgs := []*models.Image{
createTestImg("", ""),
createTestImg("", ""),
}