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

@@ -21,9 +21,9 @@ type CountingImageService struct {
Called int
}
func (c *CountingImageService) NewImage(_ context.Context, _ *ngmodels.AlertRule) (*store.Image, error) {
func (c *CountingImageService) NewImage(_ context.Context, _ *ngmodels.AlertRule) (*ngmodels.Image, error) {
c.Called += 1
return &store.Image{
return &ngmodels.Image{
Token: fmt.Sprint(rand.Int()),
}, nil
}
@@ -40,7 +40,7 @@ func Test_maybeNewImage(t *testing.T) {
true,
&State{
State: eval.Alerting,
Image: &store.Image{
Image: &ngmodels.Image{
Token: "erase me",
},
},
@@ -60,7 +60,7 @@ func Test_maybeNewImage(t *testing.T) {
&State{
Resolved: true,
State: eval.Normal,
Image: &store.Image{
Image: &ngmodels.Image{
Token: "abcd",
},
},
@@ -71,7 +71,7 @@ func Test_maybeNewImage(t *testing.T) {
false,
&State{
State: eval.Alerting,
Image: &store.Image{
Image: &ngmodels.Image{
Token: "already set",
},
},