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:
Santiago
2023-06-21 20:53:45 -03:00
committed by GitHub
parent ff9eff49bd
commit d3bb9fbbaf
3 changed files with 3 additions and 22 deletions
+2 -19
View File
@@ -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 ""
}
+1 -1
View File
@@ -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)
})