Alerting: Use only token for images in notifications (#70196)
* Alerting: Use only tokens for images in notifications * update tests * make linter and modfile validator happy
This commit is contained in:
@@ -48,11 +48,8 @@ func StateToPostableAlert(alertState *State, appURL *url.URL) *models.PostableAl
|
||||
nA[alertingModels.ValueStringAnnotation] = alertState.LastEvaluationString
|
||||
}
|
||||
|
||||
if alertState.Image != nil {
|
||||
imageURI := generateImageURI(alertState.Image)
|
||||
if imageURI != "" {
|
||||
nA[alertingModels.ImageTokenAnnotation] = imageURI
|
||||
}
|
||||
if alertState.Image != nil && alertState.Image.Token != "" {
|
||||
nA[alertingModels.ImageTokenAnnotation] = alertState.Image.Token
|
||||
}
|
||||
|
||||
if alertState.StateReason != "" {
|
||||
@@ -169,17 +166,3 @@ func FromAlertsStateToStoppedAlert(firingStates []StateTransition, appURL *url.U
|
||||
}
|
||||
return alerts
|
||||
}
|
||||
|
||||
// generateImageURI returns a string that serves as an identifier for the image.
|
||||
// It first checks if there is an image URL available, and if not,
|
||||
// it prefixes the image token with `token://` and uses it as the URI.
|
||||
func generateImageURI(image *ngModels.Image) string {
|
||||
if image.URL != "" {
|
||||
return image.URL
|
||||
}
|
||||
if image.Token != "" {
|
||||
return "token://" + image.Token
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func Test_StateToPostableAlert(t *testing.T) {
|
||||
for k, v := range alertState.Annotations {
|
||||
expected[k] = v
|
||||
}
|
||||
expected["__alertImageToken__"] = "token://" + alertState.Image.Token
|
||||
expected["__alertImageToken__"] = alertState.Image.Token
|
||||
|
||||
require.Equal(t, expected, result.Annotations)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user