Skip to content

Commit

Permalink
Disable sourcemap upload endpoint when data streams enabled (#4735) (#…
Browse files Browse the repository at this point in the history
…4848)

Co-authored-by: Juan Álvarez <juan.alvarez@elastic.co>
  • Loading branch information
axw and jalvz authored Feb 20, 2021
1 parent daa0d5f commit 6bd4c31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"error": "forbidden request: When APM Server is managed by Fleet, Sourcemaps must be uploaded directly to Elasticsearch."
}
5 changes: 4 additions & 1 deletion beater/api/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ func sourcemapMiddleware(cfg *config.Config, auth *authorization.Handler) []midd
msg := "Sourcemap upload endpoint is disabled. " +
"Configure the `apm-server.rum` section in apm-server.yml to enable sourcemap uploads. " +
"If you are not using the RUM agent, you can safely ignore this error."
enabled := cfg.RumConfig.IsEnabled() && cfg.RumConfig.SourceMapping.IsEnabled()
if cfg.DataStreams.Enabled {
msg = "When APM Server is managed by Fleet, Sourcemaps must be uploaded directly to Elasticsearch."
}
enabled := cfg.RumConfig.IsEnabled() && cfg.RumConfig.SourceMapping.IsEnabled() && !cfg.DataStreams.Enabled
return append(backendMiddleware(cfg, auth, sourcemap.MonitoringMap),
middleware.KillSwitchMiddleware(enabled, msg))
}
Expand Down
9 changes: 9 additions & 0 deletions beater/api/mux_sourcemap_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ func TestSourcemapHandler_KillSwitchMiddleware(t *testing.T) {
approvaltest.ApproveJSON(t, approvalPathAsset(t.Name()), rec.Body.Bytes())
})

t.Run("DataStreams", func(t *testing.T) {
cfg := cfgEnabledRUM()
cfg.DataStreams.Enabled = true
rec, err := requestToMuxerWithPattern(cfg, AssetSourcemapPath)
require.NoError(t, err)
require.Equal(t, http.StatusForbidden, rec.Code)
approvaltest.ApproveJSON(t, approvalPathAsset(t.Name()), rec.Body.Bytes())
})

t.Run("On", func(t *testing.T) {
rec, err := requestToMuxerWithPattern(cfgEnabledRUM(), AssetSourcemapPath)
require.NoError(t, err)
Expand Down

0 comments on commit 6bd4c31

Please sign in to comment.