query: handle the x-rule-uid header (#95223)

This commit is contained in:
Gábor Farkas 2024-10-23 10:49:54 +02:00 committed by GitHub
parent 6f7528f896
commit 1dbbbd9ca7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 0 deletions

View File

@ -22,6 +22,7 @@ type UseAlertHeadersMiddleware struct {
var alertHeaders = []string{
"X-Rule-Name",
"X-Rule-Uid",
"X-Rule-Folder",
"X-Rule-Source",
"X-Rule-Type",

View File

@ -39,6 +39,7 @@ func TestUserAlertingHeadersMiddleware(t *testing.T) {
// the normal http headers
require.Equal(t, "", outReq.GetHTTPHeader("X-Rule-Name"))
require.Equal(t, "", outReq.GetHTTPHeader("X-Rule-Uid"))
require.Equal(t, "", outReq.GetHTTPHeader("X-Rule-Folder"))
require.Equal(t, "", outReq.GetHTTPHeader("X-Rule-Source"))
require.Equal(t, "", outReq.GetHTTPHeader("X-Rule-Type"))
@ -50,6 +51,7 @@ func TestUserAlertingHeadersMiddleware(t *testing.T) {
require.NoError(t, err)
req.Header.Set("Fromalert", "true")
req.Header.Set("X-Rule-Name", "n1")
req.Header.Set("X-Rule-Uid", "u1")
req.Header.Set("X-Rule-Folder", "f1")
req.Header.Set("X-Rule-Source", "s1")
req.Header.Set("X-Rule-Type", "t1")
@ -62,6 +64,7 @@ func TestUserAlertingHeadersMiddleware(t *testing.T) {
// normal http headers
require.Equal(t, "n1", outReq.GetHTTPHeader("X-Rule-Name"))
require.Equal(t, "u1", outReq.GetHTTPHeader("X-Rule-Uid"))
require.Equal(t, "f1", outReq.GetHTTPHeader("X-Rule-Folder"))
require.Equal(t, "s1", outReq.GetHTTPHeader("X-Rule-Source"))
require.Equal(t, "t1", outReq.GetHTTPHeader("X-Rule-Type"))

View File

@ -97,6 +97,7 @@ func TestIntegrationLoki(t *testing.T) {
req.Header.Set("X-Unspported-Header", "uh")
req.Header.Set("Fromalert", "true")
req.Header.Set("X-Rule-Name", "n1")
req.Header.Set("X-Rule-Uid", "u1")
req.Header.Set("X-Rule-Folder", "f1")
req.Header.Set("X-Rule-Source", "s1")
req.Header.Set("X-Rule-Type", "t1")
@ -120,6 +121,7 @@ func TestIntegrationLoki(t *testing.T) {
require.Equal(t, "", outgoingRequest.Header.Get("X-Unspported-Header"))
require.Equal(t, "true", outgoingRequest.Header.Get("Fromalert"))
require.Equal(t, "n1", outgoingRequest.Header.Get("X-Rule-Name"))
require.Equal(t, "u1", outgoingRequest.Header.Get("X-Rule-Uid"))
require.Equal(t, "f1", outgoingRequest.Header.Get("X-Rule-Folder"))
require.Equal(t, "s1", outgoingRequest.Header.Get("X-Rule-Source"))
require.Equal(t, "t1", outgoingRequest.Header.Get("X-Rule-Type"))