mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
ff9eff49bd
commit
d3bb9fbbaf
2
go.sum
2
go.sum
@ -1394,8 +1394,6 @@ github.com/grafana/saml v0.4.13-0.20230331080031-67cbfa09c7b6 h1:oHn/OOUkECNX06D
|
|||||||
github.com/grafana/saml v0.4.13-0.20230331080031-67cbfa09c7b6/go.mod h1:igEejV+fihTIlHXYP8zOec3V5A8y3lws5bQBFsTm4gA=
|
github.com/grafana/saml v0.4.13-0.20230331080031-67cbfa09c7b6/go.mod h1:igEejV+fihTIlHXYP8zOec3V5A8y3lws5bQBFsTm4gA=
|
||||||
github.com/grafana/sqlds/v2 v2.3.10 h1:HWKhE0vR6LoEiE+Is8CSZOgaB//D1yqb2ntkass9Fd4=
|
github.com/grafana/sqlds/v2 v2.3.10 h1:HWKhE0vR6LoEiE+Is8CSZOgaB//D1yqb2ntkass9Fd4=
|
||||||
github.com/grafana/sqlds/v2 v2.3.10/go.mod h1:c6ibxnxRVGxV/0YkEgvy7QpQH/lyifFyV7K/14xvdIs=
|
github.com/grafana/sqlds/v2 v2.3.10/go.mod h1:c6ibxnxRVGxV/0YkEgvy7QpQH/lyifFyV7K/14xvdIs=
|
||||||
github.com/grafana/thema v0.0.0-20230601172625-e3eaca4d36bd h1:gK5LMNi8AUp8xcrOSNfbvE5g3dT46Qgy+/pCon1Z9jc=
|
|
||||||
github.com/grafana/thema v0.0.0-20230601172625-e3eaca4d36bd/go.mod h1:KWAKeFXxQYiJ/kBVbijBLRVq9atxkfkeeFIvmj4clEA=
|
|
||||||
github.com/grafana/thema v0.0.0-20230615161902-b6e21996aef8 h1:ESVwKjvGWVucGY65rJq0Hny3a6p8UYqEbClqXhP2qJk=
|
github.com/grafana/thema v0.0.0-20230615161902-b6e21996aef8 h1:ESVwKjvGWVucGY65rJq0Hny3a6p8UYqEbClqXhP2qJk=
|
||||||
github.com/grafana/thema v0.0.0-20230615161902-b6e21996aef8/go.mod h1:KWAKeFXxQYiJ/kBVbijBLRVq9atxkfkeeFIvmj4clEA=
|
github.com/grafana/thema v0.0.0-20230615161902-b6e21996aef8/go.mod h1:KWAKeFXxQYiJ/kBVbijBLRVq9atxkfkeeFIvmj4clEA=
|
||||||
github.com/grafana/xorm v0.8.3-0.20220614223926-2fcda7565af6 h1:I9dh1MXGX0wGyxdV/Sl7+ugnki4Dfsy8lv2s5Yf887o=
|
github.com/grafana/xorm v0.8.3-0.20220614223926-2fcda7565af6 h1:I9dh1MXGX0wGyxdV/Sl7+ugnki4Dfsy8lv2s5Yf887o=
|
||||||
|
@ -48,11 +48,8 @@ func StateToPostableAlert(alertState *State, appURL *url.URL) *models.PostableAl
|
|||||||
nA[alertingModels.ValueStringAnnotation] = alertState.LastEvaluationString
|
nA[alertingModels.ValueStringAnnotation] = alertState.LastEvaluationString
|
||||||
}
|
}
|
||||||
|
|
||||||
if alertState.Image != nil {
|
if alertState.Image != nil && alertState.Image.Token != "" {
|
||||||
imageURI := generateImageURI(alertState.Image)
|
nA[alertingModels.ImageTokenAnnotation] = alertState.Image.Token
|
||||||
if imageURI != "" {
|
|
||||||
nA[alertingModels.ImageTokenAnnotation] = imageURI
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if alertState.StateReason != "" {
|
if alertState.StateReason != "" {
|
||||||
@ -169,17 +166,3 @@ func FromAlertsStateToStoppedAlert(firingStates []StateTransition, appURL *url.U
|
|||||||
}
|
}
|
||||||
return alerts
|
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 {
|
for k, v := range alertState.Annotations {
|
||||||
expected[k] = v
|
expected[k] = v
|
||||||
}
|
}
|
||||||
expected["__alertImageToken__"] = "token://" + alertState.Image.Token
|
expected["__alertImageToken__"] = alertState.Image.Token
|
||||||
|
|
||||||
require.Equal(t, expected, result.Annotations)
|
require.Equal(t, expected, result.Annotations)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user