[v10.0.x] Alerting: Add image URI annotation only when there's an image (#69858)
* 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)
(cherry picked from commit ff3e028a85)
* Update compat_test.go
---------
Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>
This commit is contained in:
co-authored by
Santiago
parent
bbe52eea97
commit
4184cd09f4
@@ -50,7 +50,10 @@ func stateToPostableAlert(alertState *state.State, appURL *url.URL) *models.Post
|
||||
}
|
||||
|
||||
if alertState.Image != nil {
|
||||
nA[alertingModels.ImageTokenAnnotation] = generateImageURI(alertState.Image)
|
||||
imageURI := generateImageURI(alertState.Image)
|
||||
if imageURI != "" {
|
||||
nA[alertingModels.ImageTokenAnnotation] = imageURI
|
||||
}
|
||||
}
|
||||
|
||||
if alertState.StateReason != "" {
|
||||
@@ -175,5 +178,9 @@ func generateImageURI(image *ngModels.Image) string {
|
||||
if image.URL != "" {
|
||||
return image.URL
|
||||
}
|
||||
return "token://" + image.Token
|
||||
if image.Token != "" {
|
||||
return "token://" + image.Token
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -134,6 +134,21 @@ func Test_stateToPostableAlert(t *testing.T) {
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user