mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Add image URI annotation only when there's an image (#69825)
* Alerting: Add image URI annotation only when there's an image * fix function name (changed on main branch)
This commit is contained in:
parent
840e8d9772
commit
ff3e028a85
@ -49,7 +49,10 @@ func StateToPostableAlert(alertState *State, appURL *url.URL) *models.PostableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if alertState.Image != nil {
|
if alertState.Image != nil {
|
||||||
nA[alertingModels.ImageTokenAnnotation] = generateImageURI(alertState.Image)
|
imageURI := generateImageURI(alertState.Image)
|
||||||
|
if imageURI != "" {
|
||||||
|
nA[alertingModels.ImageTokenAnnotation] = imageURI
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if alertState.StateReason != "" {
|
if alertState.StateReason != "" {
|
||||||
@ -174,5 +177,9 @@ func generateImageURI(image *ngModels.Image) string {
|
|||||||
if image.URL != "" {
|
if image.URL != "" {
|
||||||
return image.URL
|
return image.URL
|
||||||
}
|
}
|
||||||
return "token://" + image.Token
|
if image.Token != "" {
|
||||||
|
return "token://" + image.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,21 @@ func Test_StateToPostableAlert(t *testing.T) {
|
|||||||
|
|
||||||
require.Equal(t, expected, result.Annotations)
|
require.Equal(t, expected, result.Annotations)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("don't add __alertImageToken__ if there's no image token", func(t *testing.T) {
|
||||||
|
alertState := randomState(tc.state)
|
||||||
|
alertState.Annotations = randomMapOfStrings()
|
||||||
|
alertState.Image = &ngModels.Image{}
|
||||||
|
|
||||||
|
result := StateToPostableAlert(alertState, appURL)
|
||||||
|
|
||||||
|
expected := make(models.LabelSet, len(alertState.Annotations)+1)
|
||||||
|
for k, v := range alertState.Annotations {
|
||||||
|
expected[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Equal(t, expected, result.Annotations)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should add state reason annotation if not empty", func(t *testing.T) {
|
t.Run("should add state reason annotation if not empty", func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user