From 74785eceebbd2202edd1516a02962b2dd36a23ae Mon Sep 17 00:00:00 2001 From: simitt Date: Tue, 19 Dec 2023 13:16:34 +0100 Subject: [PATCH] Update to apm-data version to handle empty rquest bodies gracefully --- go.mod | 2 +- go.sum | 6 ++---- internal/beater/api/intake/handler_test.go | 4 ++-- .../intake/test_approved/BodyReader.approved.json | 8 -------- .../api/intake/test_approved/EmptyBody.approved.json | 3 +++ .../On.approved.json | 8 -------- ...tRUMHandler_NoAuthorizationRequired.approved.json | 8 -------- internal/beater/api/mux_intake_rum_test.go | 12 ++---------- 8 files changed, 10 insertions(+), 41 deletions(-) delete mode 100644 internal/beater/api/intake/test_approved/BodyReader.approved.json create mode 100644 internal/beater/api/intake/test_approved/EmptyBody.approved.json delete mode 100644 internal/beater/api/intake/test_approved/integration/rum/TestRUMHandler_KillSwitchMiddleware/On.approved.json delete mode 100644 internal/beater/api/intake/test_approved/integration/rum/TestRUMHandler_NoAuthorizationRequired.approved.json diff --git a/go.mod b/go.mod index 5d034be47bd..0568891de59 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/dgraph-io/badger/v2 v2.2007.3-0.20201012072640-f5a7e0a1c83b github.com/dustin/go-humanize v1.0.1 github.com/elastic/apm-aggregation v0.0.0-20230815024520-e75a37d9ddd6 - github.com/elastic/apm-data v0.1.1-0.20231218185351-dca9298f9dda + github.com/elastic/apm-data v0.1.1-0.20231023025237-39e2a3ca9117 github.com/elastic/beats/v7 v7.0.0-alpha2.0.20231218141841-a633696068ed github.com/elastic/elastic-agent-client/v7 v7.5.0 github.com/elastic/elastic-agent-libs v0.7.2 diff --git a/go.sum b/go.sum index 5ded8f04e01..a1d5499bd60 100644 --- a/go.sum +++ b/go.sum @@ -132,10 +132,8 @@ github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFP github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/elastic/apm-aggregation v0.0.0-20230815024520-e75a37d9ddd6 h1:Js+C3HEE0a5BDFmhEmJV/Uo4uzj/paHjd7yl6+KYguw= github.com/elastic/apm-aggregation v0.0.0-20230815024520-e75a37d9ddd6/go.mod h1:ba3gaJCuhxXN/O5AuiI56xxd6DukQdVOK0NfpzBntNo= -github.com/elastic/apm-data v0.1.1-0.20231019120308-82201b991ae5 h1:URlDi0TZetSAo8KAIbaMZQhM5EG8+SDgs0jTen7WvMg= -github.com/elastic/apm-data v0.1.1-0.20231019120308-82201b991ae5/go.mod h1:z4iJVl8vyQa5v5o7UapWGHTsycBKsKfJfILuf2TZpYo= -github.com/elastic/apm-data v0.1.1-0.20231218185351-dca9298f9dda h1:ZV1/XIvB0UMU5Mq7HGAmBsNZKHM55mQFPS3b+hcqK4o= -github.com/elastic/apm-data v0.1.1-0.20231218185351-dca9298f9dda/go.mod h1:z4iJVl8vyQa5v5o7UapWGHTsycBKsKfJfILuf2TZpYo= +github.com/elastic/apm-data v0.1.1-0.20231023025237-39e2a3ca9117 h1:qglWR4P715EJJD1CnrmKtWm1PaizFSpjhSP+h9+I3xE= +github.com/elastic/apm-data v0.1.1-0.20231023025237-39e2a3ca9117/go.mod h1:z4iJVl8vyQa5v5o7UapWGHTsycBKsKfJfILuf2TZpYo= github.com/elastic/beats/v7 v7.0.0-alpha2.0.20231218141841-a633696068ed h1:2ABWyeeCuBbi4ReJFeEAvfPUctfYLc0x5x3ZaQCAuWs= github.com/elastic/beats/v7 v7.0.0-alpha2.0.20231218141841-a633696068ed/go.mod h1:IyDGwc1d+ERmSiMOZZ2mJIJfCnFnIl85zQP7ZvtkSfY= github.com/elastic/elastic-agent-autodiscover v0.6.5 h1:5DeMpuNc8c/tN6HN0A4A2uOFTNFHSg7xrKApzfhvF1U= diff --git a/internal/beater/api/intake/handler_test.go b/internal/beater/api/intake/handler_test.go index cf15c2e7928..8cfa0c5a79d 100644 --- a/internal/beater/api/intake/handler_test.go +++ b/internal/beater/api/intake/handler_test.go @@ -64,14 +64,14 @@ func TestIntakeHandler(t *testing.T) { }(), code: http.StatusBadRequest, id: request.IDResponseErrorsValidate, }, - "BodyReader": { + "EmptyBody": { path: "errors.ndjson", r: func() *http.Request { req := httptest.NewRequest(http.MethodPost, "/", nil) req.Header.Set(headers.ContentType, "application/x-ndjson") return req }(), - code: http.StatusBadRequest, id: request.IDResponseErrorsValidate, + code: http.StatusAccepted, id: request.IDResponseValidAccepted, }, "CompressedBodyReaderDeflateInvalid": { path: "errors.ndjson", diff --git a/internal/beater/api/intake/test_approved/BodyReader.approved.json b/internal/beater/api/intake/test_approved/BodyReader.approved.json deleted file mode 100644 index fc636bfdcb3..00000000000 --- a/internal/beater/api/intake/test_approved/BodyReader.approved.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "accepted": 0, - "errors": [ - { - "message": "EOF while reading metadata" - } - ] -} diff --git a/internal/beater/api/intake/test_approved/EmptyBody.approved.json b/internal/beater/api/intake/test_approved/EmptyBody.approved.json new file mode 100644 index 00000000000..6b51efae3bf --- /dev/null +++ b/internal/beater/api/intake/test_approved/EmptyBody.approved.json @@ -0,0 +1,3 @@ +{ + "accepted": 0 +} diff --git a/internal/beater/api/intake/test_approved/integration/rum/TestRUMHandler_KillSwitchMiddleware/On.approved.json b/internal/beater/api/intake/test_approved/integration/rum/TestRUMHandler_KillSwitchMiddleware/On.approved.json deleted file mode 100644 index fc636bfdcb3..00000000000 --- a/internal/beater/api/intake/test_approved/integration/rum/TestRUMHandler_KillSwitchMiddleware/On.approved.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "accepted": 0, - "errors": [ - { - "message": "EOF while reading metadata" - } - ] -} diff --git a/internal/beater/api/intake/test_approved/integration/rum/TestRUMHandler_NoAuthorizationRequired.approved.json b/internal/beater/api/intake/test_approved/integration/rum/TestRUMHandler_NoAuthorizationRequired.approved.json deleted file mode 100644 index fc636bfdcb3..00000000000 --- a/internal/beater/api/intake/test_approved/integration/rum/TestRUMHandler_NoAuthorizationRequired.approved.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "accepted": 0, - "errors": [ - { - "message": "EOF while reading metadata" - } - ] -} diff --git a/internal/beater/api/mux_intake_rum_test.go b/internal/beater/api/mux_intake_rum_test.go index 946a6dfc373..f50f82d915a 100644 --- a/internal/beater/api/mux_intake_rum_test.go +++ b/internal/beater/api/mux_intake_rum_test.go @@ -75,11 +75,7 @@ func TestRUMHandler_NoAuthorizationRequired(t *testing.T) { cfg.AgentAuth.SecretToken = "1234" rec, err := requestToMuxerWithPattern(cfg, IntakeRUMPath) require.NoError(t, err) - assert.NotEqual(t, http.StatusUnauthorized, rec.Code) - - expected, err := os.ReadFile(approvalPathIntakeRUM(t.Name()) + ".approved.json") - require.NoError(t, err) - assert.JSONEq(t, string(expected), rec.Body.String()) + assert.Equal(t, http.StatusAccepted, rec.Code) } func TestRUMHandler_KillSwitchMiddleware(t *testing.T) { @@ -96,11 +92,7 @@ func TestRUMHandler_KillSwitchMiddleware(t *testing.T) { t.Run("On", func(t *testing.T) { rec, err := requestToMuxerWithPattern(cfgEnabledRUM(), IntakeRUMPath) require.NoError(t, err) - assert.NotEqual(t, http.StatusForbidden, rec.Code) - - expected, err := os.ReadFile(approvalPathIntakeRUM(t.Name()) + ".approved.json") - require.NoError(t, err) - assert.JSONEq(t, string(expected), rec.Body.String()) + assert.Equal(t, http.StatusAccepted, rec.Code) }) }