From fa191dc78671e8ad9193602b21b3d432770a4427 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Thu, 24 Apr 2025 19:57:01 +0200 Subject: [PATCH 01/10] feat: bump beats and replace global loggers bump beats fix compile errors propagare logger and remove global loggers use logptest in tests --- NOTICE-fips.txt | 32 ++++----- NOTICE.txt | 32 ++++----- go.mod | 18 ++--- go.sum | 69 ++++++++++--------- internal/agentcfg/elasticsearch.go | 3 +- internal/agentcfg/elasticsearch_test.go | 6 +- internal/agentcfg/kibana.go | 4 +- internal/agentcfg/kibana_test.go | 9 +-- internal/agentcfg/reporter.go | 5 +- internal/agentcfg/reporter_test.go | 3 +- internal/beatcmd/beat.go | 39 +++++------ internal/beatcmd/beat_test.go | 9 ++- internal/beatcmd/maxprocs_test.go | 4 +- internal/beatcmd/reloader.go | 2 +- internal/beatcmd/reloader_test.go | 11 ++- internal/beatcmd/testcmd.go | 5 +- .../beater/api/config/agent/handler_test.go | 3 +- internal/beater/api/mux.go | 40 ++++++----- internal/beater/api/mux_config_agent_test.go | 4 +- internal/beater/api/mux_expvar_test.go | 4 +- .../beater/api/mux_intake_backend_test.go | 4 +- internal/beater/api/mux_intake_rum_test.go | 9 +-- internal/beater/api/mux_root_test.go | 4 +- internal/beater/api/mux_test.go | 25 ++++--- internal/beater/beater.go | 39 ++++++----- internal/beater/beater_test.go | 11 +-- internal/beater/beatertest/server.go | 4 +- internal/beater/config/agentconfig_test.go | 7 +- internal/beater/config/aggregation_test.go | 3 +- internal/beater/config/auth_test.go | 7 +- internal/beater/config/config.go | 4 +- internal/beater/config/config_test.go | 9 +-- internal/beater/config/sampling_test.go | 7 +- internal/beater/interceptors/logging_test.go | 7 +- .../beater/java_attacher/java_attacher.go | 5 +- .../java_attacher_nonwindows_test.go | 9 +-- .../java_attacher/java_attacher_test.go | 7 +- internal/beater/middleware/log_middleware.go | 9 +-- .../beater/middleware/log_middleware_test.go | 33 ++++----- internal/beater/otlp/http_test.go | 2 + internal/beater/server.go | 6 +- internal/beater/server_test.go | 14 +--- internal/beater/tracing.go | 1 + internal/idxmgmt/supporter_factory.go | 7 +- internal/idxmgmt/supporter_factory_test.go | 6 +- internal/logs/ratelimit_test.go | 4 +- internal/publish/pub_test.go | 10 ++- internal/sourcemap/body_caching.go | 3 +- internal/sourcemap/body_caching_test.go | 9 +-- internal/sourcemap/chained.go | 5 +- internal/sourcemap/elasticsearch.go | 5 +- internal/sourcemap/kibana.go | 5 +- internal/sourcemap/kibana_test.go | 3 +- internal/sourcemap/metadata_fetcher.go | 3 +- internal/sourcemap/metadata_fetcher_test.go | 25 +------ internal/sourcemap/processor_test.go | 16 ++--- internal/sourcemap/sourcemap_fetcher.go | 4 +- internal/sourcemap/sourcemap_fetcher_test.go | 3 +- systemtest/logging_test.go | 2 +- x-pack/apm-server/main.go | 8 +-- x-pack/apm-server/sampling/config_test.go | 3 +- .../sampling/eventstorage/pebble.go | 8 +-- .../sampling/eventstorage/prefix_test.go | 5 +- .../sampling/eventstorage/storage_manager.go | 8 +-- .../eventstorage/storage_manager_test.go | 3 +- x-pack/apm-server/sampling/processor.go | 4 +- .../sampling/processor_bench_test.go | 3 +- x-pack/apm-server/sampling/processor_test.go | 27 ++++---- x-pack/apm-server/sampling/pubsub/pubsub.go | 4 +- .../pubsub/pubsub_integration_test.go | 3 + .../apm-server/sampling/pubsub/pubsub_test.go | 2 + 71 files changed, 371 insertions(+), 345 deletions(-) diff --git a/NOTICE-fips.txt b/NOTICE-fips.txt index e03ce4f7629..3a6cd9871f6 100644 --- a/NOTICE-fips.txt +++ b/NOTICE-fips.txt @@ -455,11 +455,11 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/apm-data@v1.18. -------------------------------------------------------------------------------- Dependency : github.com/elastic/beats/v7 -Version: v7.0.0-alpha2.0.20250325090137-0c4e2d0af92c +Version: v7.0.0-alpha2.0.20250424141521-26cce27fe81e Licence type (autodetected): Elastic -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/beats/v7@v7.0.0-alpha2.0.20250325090137-0c4e2d0af92c/LICENSE.txt: +Contents of probable licence file $GOMODCACHE/github.com/elastic/beats/v7@v7.0.0-alpha2.0.20250424141521-26cce27fe81e/LICENSE.txt: Source code in this repository is variously licensed under the Apache License Version 2.0, an Apache compatible license, or the Elastic License. Outside of @@ -7373,11 +7373,11 @@ SOFTWARE. -------------------------------------------------------------------------------- Dependency : github.com/ebitengine/purego -Version: v0.8.1 +Version: v0.8.2 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/ebitengine/purego@v0.8.1/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/ebitengine/purego@v0.8.2/LICENSE: Apache License Version 2.0, January 2004 @@ -11472,11 +11472,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : github.com/pierrec/lz4/v4 -Version: v4.1.21 +Version: v4.1.22 Licence type (autodetected): BSD-3-Clause -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/pierrec/lz4/v4@v4.1.21/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/pierrec/lz4/v4@v4.1.22/LICENSE: Copyright (c) 2015, Pierre Curto All rights reserved. @@ -11971,11 +11971,11 @@ Contents of probable licence file $GOMODCACHE/github.com/prometheus/client_model -------------------------------------------------------------------------------- Dependency : github.com/prometheus/common -Version: v0.60.1 +Version: v0.62.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/prometheus/common@v0.60.1/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/prometheus/common@v0.62.0/LICENSE: Apache License Version 2.0, January 2004 @@ -12469,11 +12469,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : github.com/shirou/gopsutil/v4 -Version: v4.24.10 +Version: v4.25.1 Licence type (autodetected): BSD-3-Clause -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/shirou/gopsutil/v4@v4.24.10/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/shirou/gopsutil/v4@v4.25.1/LICENSE: gopsutil is distributed under BSD license reproduced below. @@ -12578,11 +12578,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : github.com/tklauser/numcpus -Version: v0.6.1 +Version: v0.8.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/tklauser/numcpus@v0.6.1/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/tklauser/numcpus@v0.8.0/LICENSE: Apache License @@ -13453,11 +13453,11 @@ Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/auto/sdk@v1.1. -------------------------------------------------------------------------------- Dependency : go.opentelemetry.io/collector/consumer -Version: v1.22.0 +Version: v1.28.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/collector/consumer@v1.22.0/LICENSE: +Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/collector/consumer@v1.28.0/LICENSE: Apache License @@ -13665,11 +13665,11 @@ Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/collector/cons -------------------------------------------------------------------------------- Dependency : go.opentelemetry.io/collector/semconv -Version: v0.119.0 +Version: v0.121.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/collector/semconv@v0.119.0/LICENSE: +Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/collector/semconv@v0.121.0/LICENSE: Apache License diff --git a/NOTICE.txt b/NOTICE.txt index 8aa9336dccc..3c1e0fa6953 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -455,11 +455,11 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/apm-data@v1.18. -------------------------------------------------------------------------------- Dependency : github.com/elastic/beats/v7 -Version: v7.0.0-alpha2.0.20250325090137-0c4e2d0af92c +Version: v7.0.0-alpha2.0.20250424141521-26cce27fe81e Licence type (autodetected): Elastic -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/beats/v7@v7.0.0-alpha2.0.20250325090137-0c4e2d0af92c/LICENSE.txt: +Contents of probable licence file $GOMODCACHE/github.com/elastic/beats/v7@v7.0.0-alpha2.0.20250424141521-26cce27fe81e/LICENSE.txt: Source code in this repository is variously licensed under the Apache License Version 2.0, an Apache compatible license, or the Elastic License. Outside of @@ -7373,11 +7373,11 @@ SOFTWARE. -------------------------------------------------------------------------------- Dependency : github.com/ebitengine/purego -Version: v0.8.1 +Version: v0.8.2 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/ebitengine/purego@v0.8.1/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/ebitengine/purego@v0.8.2/LICENSE: Apache License Version 2.0, January 2004 @@ -12969,11 +12969,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : github.com/pierrec/lz4/v4 -Version: v4.1.21 +Version: v4.1.22 Licence type (autodetected): BSD-3-Clause -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/pierrec/lz4/v4@v4.1.21/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/pierrec/lz4/v4@v4.1.22/LICENSE: Copyright (c) 2015, Pierre Curto All rights reserved. @@ -13468,11 +13468,11 @@ Contents of probable licence file $GOMODCACHE/github.com/prometheus/client_model -------------------------------------------------------------------------------- Dependency : github.com/prometheus/common -Version: v0.60.1 +Version: v0.62.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/prometheus/common@v0.60.1/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/prometheus/common@v0.62.0/LICENSE: Apache License Version 2.0, January 2004 @@ -13966,11 +13966,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : github.com/shirou/gopsutil/v4 -Version: v4.24.10 +Version: v4.25.1 Licence type (autodetected): BSD-3-Clause -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/shirou/gopsutil/v4@v4.24.10/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/shirou/gopsutil/v4@v4.25.1/LICENSE: gopsutil is distributed under BSD license reproduced below. @@ -14075,11 +14075,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : github.com/tklauser/numcpus -Version: v0.6.1 +Version: v0.8.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/tklauser/numcpus@v0.6.1/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/tklauser/numcpus@v0.8.0/LICENSE: Apache License @@ -15505,11 +15505,11 @@ Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/auto/sdk@v1.1. -------------------------------------------------------------------------------- Dependency : go.opentelemetry.io/collector/consumer -Version: v1.22.0 +Version: v1.28.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/collector/consumer@v1.22.0/LICENSE: +Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/collector/consumer@v1.28.0/LICENSE: Apache License @@ -15717,11 +15717,11 @@ Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/collector/cons -------------------------------------------------------------------------------- Dependency : go.opentelemetry.io/collector/semconv -Version: v0.119.0 +Version: v0.121.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/collector/semconv@v0.119.0/LICENSE: +Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/collector/semconv@v0.121.0/LICENSE: Apache License diff --git a/go.mod b/go.mod index a14aa9e77f1..db66d63a3a5 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/dustin/go-humanize v1.0.1 github.com/elastic/apm-aggregation v1.3.0 github.com/elastic/apm-data v1.18.0 - github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250325090137-0c4e2d0af92c + github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250424141521-26cce27fe81e github.com/elastic/elastic-agent-client/v7 v7.17.2 github.com/elastic/elastic-agent-libs v0.19.2 github.com/elastic/elastic-agent-system-metrics v0.11.11 @@ -93,7 +93,7 @@ require ( github.com/eapache/go-resiliency v1.7.0 // indirect github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect github.com/eapache/queue v1.1.0 // indirect - github.com/ebitengine/purego v0.8.1 // indirect + github.com/ebitengine/purego v0.8.2 // indirect github.com/elastic/apm-perf v0.0.0-20250207152505-1dbeb202ff22 // indirect github.com/elastic/apm-tools v0.0.0-20250124173757-336011228dbe // indirect github.com/elastic/go-elasticsearch/v8 v8.17.1 // indirect @@ -180,14 +180,14 @@ require ( github.com/oklog/run v1.1.0 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect - github.com/pierrec/lz4/v4 v4.1.21 // indirect + github.com/pierrec/lz4/v4 v4.1.22 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect github.com/prometheus/client_golang v1.20.5 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.60.1 // indirect + github.com/prometheus/common v0.62.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.13.1 // indirect @@ -195,7 +195,7 @@ require ( github.com/sagikazarmark/locafero v0.6.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect - github.com/shirou/gopsutil/v4 v4.24.10 // indirect + github.com/shirou/gopsutil/v4 v4.25.1 // indirect github.com/shopspring/decimal v1.4.0 // indirect github.com/skeema/knownhosts v1.3.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect @@ -211,7 +211,7 @@ require ( github.com/tidwall/pretty v1.2.1 // indirect github.com/tidwall/sjson v1.2.5 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect - github.com/tklauser/numcpus v0.6.1 // indirect + github.com/tklauser/numcpus v0.8.0 // indirect github.com/ulikunitz/xz v0.5.12 // indirect github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect @@ -226,8 +226,8 @@ require ( go.elastic.co/ecszap v1.0.3 // indirect go.elastic.co/go-licence-detector v0.7.0 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect - go.opentelemetry.io/collector/consumer v1.22.0 // indirect - go.opentelemetry.io/collector/semconv v0.119.0 // indirect + go.opentelemetry.io/collector/consumer v1.28.0 // indirect + go.opentelemetry.io/collector/semconv v0.121.0 // indirect go.opentelemetry.io/otel/sdk v1.35.0 // indirect go.opentelemetry.io/otel/trace v1.35.0 // indirect go.uber.org/multierr v1.11.0 // indirect @@ -263,3 +263,5 @@ tool ( gotest.tools/gotestsum honnef.co/go/tools/cmd/staticcheck ) + +replace github.com/elastic/elastic-agent-libs => ../elastic-agent-libs diff --git a/go.sum b/go.sum index a6dc3d79848..ff5611100c1 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,8 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xP github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4 v4.8.0 h1:0nGmzwBv5ougvzfGPCO2ljFRHvun57KpNrVCMrlk0ns= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4 v4.8.0/go.mod h1:gYq8wyDgv6JLhGbAU6gg8amCPgQWRE+aCvrV2gyzdfs= -github.com/AzureAD/microsoft-authentication-library-for-go v1.3.3 h1:H5xDQaE3XowWfhZRUpnfC+rGZMEVoSiji+b+/HFAPU4= -github.com/AzureAD/microsoft-authentication-library-for-go v1.3.3/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= +github.com/AzureAD/microsoft-authentication-library-for-go v1.4.0 h1:MUkXAnvvDHgvPItl0nBj0hgk0f7hnnQbGm0h0+YxbN4= +github.com/AzureAD/microsoft-authentication-library-for-go v1.4.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/DataDog/zstd v1.5.6 h1:LbEglqepa/ipmmQJUDnSsfvA8e8IStVcGaFWDuxvGOY= @@ -159,8 +159,8 @@ github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4A github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0= github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/ebitengine/purego v0.8.1 h1:sdRKd6plj7KYW33EH5As6YKfe8m9zbN9JMrOjNVF/BE= -github.com/ebitengine/purego v0.8.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= +github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I= +github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/elastic/apm-aggregation v1.3.0 h1:C9HsLq2yCDe/FfT2al4BuFNfAxwR13guAVBzpAu9vuM= github.com/elastic/apm-aggregation v1.3.0/go.mod h1:WQCllP+XacDo+pY12dxH9pLJpFq3qG+8sV4k/hXJs18= github.com/elastic/apm-data v1.18.0 h1:GaWnrIoh7+UPmsbkQGls3tSCVk54sJng2v2YCYGpwyM= @@ -169,14 +169,12 @@ github.com/elastic/apm-perf v0.0.0-20250207152505-1dbeb202ff22 h1:br+XeQOcxNFSv+ github.com/elastic/apm-perf v0.0.0-20250207152505-1dbeb202ff22/go.mod h1:gE+FV7xXv0/nBenviCvpvnvTpUkjJXtuOWs2UT+ZRtw= github.com/elastic/apm-tools v0.0.0-20250124173757-336011228dbe h1:LDtn/A8Tsfz8DQlbXtmDud9ha9oOGriwJGB7V0Ozik8= github.com/elastic/apm-tools v0.0.0-20250124173757-336011228dbe/go.mod h1:SIlGcpTnnosxZ3OvoRC7ADxhHdlsu/nwUdVMF9OkgYc= -github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250325090137-0c4e2d0af92c h1:W7PIPw+b887scUpMWO+9l8PVWZAJ1YmBWXyOGc5loyA= -github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250325090137-0c4e2d0af92c/go.mod h1:Mn1B/tiUKRTodNVBjGlmDbfKy5PbJl0MGPUnPKfGLMM= +github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250424141521-26cce27fe81e h1:pGAtXOxSp/P+P2MtClKGuTURrEWS0rzpGSJwytXn03Q= +github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250424141521-26cce27fe81e/go.mod h1:aMTmS4PStEA9SXSbujjnyCmrCzS4BYoPQY80LRuDEE8= github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0JojNasPgYIA47gpuuns= github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4= github.com/elastic/elastic-agent-client/v7 v7.17.2 h1:Cl2TeABqWZgW40t5fchGWT/sRk4MDDLWA0d8iHHOxLA= github.com/elastic/elastic-agent-client/v7 v7.17.2/go.mod h1:5irRFqp6HLqtu1S+OeY0jg8x7K6PLL+DW+PwVk1vJnk= -github.com/elastic/elastic-agent-libs v0.19.2 h1:uOLUF/KQQf9t6iKr5mfp3jO7CxVZToCJKbb2iSWMswU= -github.com/elastic/elastic-agent-libs v0.19.2/go.mod h1:1HNxREH8C27kGrJCtKZh/ot8pV8joH8VREP21+FrH5s= github.com/elastic/elastic-agent-system-metrics v0.11.11 h1:Qjh3Zef23PfGlG91AF+9ciNLNQf/8cDJ4CalnLZtV3g= github.com/elastic/elastic-agent-system-metrics v0.11.11/go.mod h1:GNqmKfvOt8PwORjbS6GllNdMfkLpOWyTa7P8oQq4E5o= github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= @@ -233,6 +231,8 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= +github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= github.com/getsentry/sentry-go v0.29.1 h1:DyZuChN8Hz3ARxGVV8ePaNXh1dQ7d76AiB117xcREwA= github.com/getsentry/sentry-go v0.29.1/go.mod h1:x3AtIzN01d6SiWkderzaH28Tm0lgkafpJ5Bm3li39O0= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9 h1:r5GgOLGbza2wVHRzK7aAj6lWZjfbAwiu/RDCVOKjRyM= @@ -274,8 +274,8 @@ github.com/gofrs/uuid/v5 v5.3.2 h1:2jfO8j3XgSwlz/wHqemAEugfnTlikAYHhnqQ8Xh4fE0= github.com/gofrs/uuid/v5 v5.3.2/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= -github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= +github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -475,8 +475,8 @@ github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2D github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= -github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= -github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU= +github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= @@ -499,8 +499,8 @@ github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+ github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= -github.com/prometheus/common v0.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc= -github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= +github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io= +github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= @@ -523,8 +523,8 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= -github.com/shirou/gopsutil/v4 v4.24.10 h1:7VOzPtfw/5YDU+jLEoBwXwxJbQetULywoSV4RYY7HkM= -github.com/shirou/gopsutil/v4 v4.24.10/go.mod h1:s4D/wg+ag4rG0WO7AiTj2BeYCRhym0vM7DHbZRxnIT8= +github.com/shirou/gopsutil/v4 v4.25.1 h1:QSWkTc+fu9LTAWfkZwZ6j8MSUk4A2LV7rbH0ZqmLjXs= +github.com/shirou/gopsutil/v4 v4.25.1/go.mod h1:RoUCUpndaJFtT+2zsZzzmhvbfGoDCJ7nFXKJf8GqJbI= github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= @@ -584,13 +584,16 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= -github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY= +github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE= github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc= github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc= github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= @@ -641,14 +644,14 @@ go.elastic.co/go-licence-detector v0.7.0 h1:qC31sfyfNcNx/zMYcLABU0ac3MbGHZgksCAb go.elastic.co/go-licence-detector v0.7.0/go.mod h1:f5ty8pjynzQD8BcS+s0qtlOGKc35/HKQxCVi8SHhV5k= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= -go.opentelemetry.io/collector/consumer v1.22.0 h1:QmfnNizyNZFt0uK3GG/EoT5h6PvZJ0dgVTc5hFEc1l0= -go.opentelemetry.io/collector/consumer v1.22.0/go.mod h1:tiz2khNceFAPokxxfzAuFfIpShBasMT2AL2Sbc7+m0I= +go.opentelemetry.io/collector/consumer v1.28.0 h1:3JzDm7EFAF9ws4O3vVou5n8egdGZtrRN3xVw6AjNtqE= +go.opentelemetry.io/collector/consumer v1.28.0/go.mod h1:Ge1HGm5aRYTW+SXggM+US9phb/BQR2of4FZ8r/3OH3Y= go.opentelemetry.io/collector/pdata v1.30.0 h1:j3jyq9um436r6WzWySzexP2nLnFdmL5uVBYAlyr9nDM= go.opentelemetry.io/collector/pdata v1.30.0/go.mod h1:0Bxu1ktuj4wE7PIASNSvd0SdBscQ1PLtYasymJ13/Cs= -go.opentelemetry.io/collector/semconv v0.119.0 h1:xo+V3a7hnK0I6fxAWCXT8BIT1PCBYd4emolhoKSDUlI= -go.opentelemetry.io/collector/semconv v0.119.0/go.mod h1:N6XE8Q0JKgBN2fAhkUQtqK9LT7rEGR6+Wu/Rtbal1iI= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0/go.mod h1:qxuZLtbq5QDtdeSHsS7bcf6EH6uO6jUAgk764zd3rhM= +go.opentelemetry.io/collector/semconv v0.121.0 h1:dtdgh5TsKWGZXIBMsyCMVrY1VgmyWlXHgWx/VH9tL1U= +go.opentelemetry.io/collector/semconv v0.121.0/go.mod h1:te6VQ4zZJO5Lp8dM2XIhDxDiL45mwX0YAQQWRQ0Qr9U= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 h1:CV7UdSGJt/Ao6Gp4CXckLxVRRsRgDHoI8XjbL3PDl8s= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0/go.mod h1:FRmFuRJfag1IZ2dPkHnEoSFVgTVPUd2qf5Vi69hLb8I= go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ= go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y= go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M= @@ -853,18 +856,18 @@ honnef.co/go/tools v0.6.0 h1:TAODvD3knlq75WCp2nyGJtT4LeRV/o7NN9nYPeVJXf8= honnef.co/go/tools v0.6.0/go.mod h1:3puzxxljPCe8RGJX7BIy1plGbxEOZni5mR2aXe3/uk4= howett.net/plist v1.0.1 h1:37GdZ8tP09Q35o9ych3ehygcsL+HqKSwzctveSlarvM= howett.net/plist v1.0.1/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= -k8s.io/api v0.29.5 h1:levS+umUigHCfI3riD36pMY1vQEbrzh4r1ivVWAhHaI= -k8s.io/api v0.29.5/go.mod h1:7b18TtPcJzdjk7w5zWyIHgoAtpGeRvGGASxlS7UZXdQ= -k8s.io/apimachinery v0.29.5 h1:Hofa2BmPfpoT+IyDTlcPdCHSnHtEQMoJYGVoQpRTfv4= -k8s.io/apimachinery v0.29.5/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y= -k8s.io/client-go v0.29.5 h1:nlASXmPQy190qTteaVP31g3c/wi2kycznkTP7Sv1zPc= -k8s.io/client-go v0.29.5/go.mod h1:aY5CnqUUvXYccJhm47XHoPcRyX6vouHdIBHaKZGTbK4= +k8s.io/api v0.31.1 h1:Xe1hX/fPW3PXYYv8BlozYqw63ytA92snr96zMW9gWTU= +k8s.io/api v0.31.1/go.mod h1:sbN1g6eY6XVLeqNsZGLnI5FwVseTrZX7Fv3O26rhAaI= +k8s.io/apimachinery v0.31.1 h1:mhcUBbj7KUjaVhyXILglcVjuS4nYXiwC+KKFBgIVy7U= +k8s.io/apimachinery v0.31.1/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= +k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0= +k8s.io/client-go v0.31.1/go.mod h1:sKI8871MJN2OyeqRlmA4W4KM9KBdBUpDLu/43eGemCg= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= -k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= -k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A= +k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= kernel.org/pub/linux/libs/security/libcap/cap v1.2.57 h1:2nmqI+aw7EQZuelYktkQHBE4jESD2tOR+lOJEnv/Apo= kernel.org/pub/linux/libs/security/libcap/cap v1.2.57/go.mod h1:uI99C3r4SXvJeuqoEtx/eWt7UbmfqqZ80H8q+9t/A7I= kernel.org/pub/linux/libs/security/libcap/psx v1.2.57 h1:NOFATXSf5z/cMR3HIwQ3Xrd3nwnWl5xThmNr5U/F0pI= @@ -875,5 +878,5 @@ sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMm sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= +sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/internal/agentcfg/elasticsearch.go b/internal/agentcfg/elasticsearch.go index 2b2f425222c..19a30bdabad 100644 --- a/internal/agentcfg/elasticsearch.go +++ b/internal/agentcfg/elasticsearch.go @@ -88,6 +88,7 @@ func NewElasticsearchFetcher( fetcher Fetcher, tracer *apm.Tracer, mp metric.MeterProvider, + logger *logp.Logger, ) *ElasticsearchFetcher { meter := mp.Meter("github.com/elastic/apm-server/internal/agentcfg") @@ -99,7 +100,7 @@ func NewElasticsearchFetcher( esCacheRefreshSuccesses, _ := meter.Int64Counter("apm-server.agentcfg.elasticsearch.cache.refresh.successes") esCacheRefreshFailures, _ := meter.Int64Counter("apm-server.agentcfg.elasticsearch.cache.refresh.failures") - logger := logp.NewLogger("agentcfg") + logger = logger.Named("agentcfg") return &ElasticsearchFetcher{ client: client, cacheDuration: cacheDuration, diff --git a/internal/agentcfg/elasticsearch_test.go b/internal/agentcfg/elasticsearch_test.go index df86db50e26..2a6685f1c02 100644 --- a/internal/agentcfg/elasticsearch_test.go +++ b/internal/agentcfg/elasticsearch_test.go @@ -33,6 +33,7 @@ import ( "go.opentelemetry.io/otel/metric/noop" "github.com/elastic/apm-server/internal/elasticsearch" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) var sampleHits = []map[string]interface{}{ @@ -105,7 +106,7 @@ func newElasticsearchFetcher( w.WriteHeader(200) w.Write(b) i += searchSize - }), time.Second, nil, rt, noop.NewMeterProvider()) + }), time.Second, nil, rt, noop.NewMeterProvider(), logptest.NewTestingLogger(t, "")) fetcher.searchSize = searchSize return fetcher } @@ -195,6 +196,7 @@ func TestFetchUseFallback(t *testing.T) { fallbackFetcher, apmtest.NewRecordingTracer().Tracer, noop.NewMeterProvider(), + logptest.NewTestingLogger(t, ""), ) fetcher.refreshCache(context.Background()) @@ -211,6 +213,7 @@ func TestFetchNoFallbackInvalidESCfg(t *testing.T) { nil, apmtest.NewRecordingTracer().Tracer, noop.NewMeterProvider(), + logptest.NewTestingLogger(t, ""), ) err := fetcher.refreshCache(context.Background()) @@ -228,6 +231,7 @@ func TestFetchNoFallback(t *testing.T) { nil, apmtest.NewRecordingTracer().Tracer, noop.NewMeterProvider(), + logptest.NewTestingLogger(t, ""), ) err := fetcher.refreshCache(context.Background()) diff --git a/internal/agentcfg/kibana.go b/internal/agentcfg/kibana.go index 05ccbbdf001..c067cf9e55b 100644 --- a/internal/agentcfg/kibana.go +++ b/internal/agentcfg/kibana.go @@ -52,11 +52,11 @@ type KibanaFetcher struct { // NewKibanaFetcher returns a KibanaFetcher instance. // // NewKibanaFetcher will return an error if passed a nil client. -func NewKibanaFetcher(client *kibana.Client, cacheExpiration time.Duration) (*KibanaFetcher, error) { +func NewKibanaFetcher(client *kibana.Client, cacheExpiration time.Duration, logger *logp.Logger) (*KibanaFetcher, error) { if client == nil { return nil, errors.New("client is required") } - logger := logp.NewLogger("agentcfg") + logger = logger.Named("agentcfg") cache, err := newCache(logger, cacheExpiration) if err != nil { return nil, err diff --git a/internal/agentcfg/kibana_test.go b/internal/agentcfg/kibana_test.go index b36d32085e0..f2e1c9719db 100644 --- a/internal/agentcfg/kibana_test.go +++ b/internal/agentcfg/kibana_test.go @@ -29,6 +29,7 @@ import ( "github.com/stretchr/testify/require" "github.com/elastic/apm-server/internal/kibana" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func query(name string) Query { @@ -63,7 +64,7 @@ func TestKibanaFetcher(t *testing.T) { statusCode = http.StatusExpectationFailed response = map[string]interface{}{"error": "an error"} - kf, err := NewKibanaFetcher(client, testExpiration) + kf, err := NewKibanaFetcher(client, testExpiration, logptest.NewTestingLogger(t, "")) require.NoError(t, err) _, err = kf.Fetch(context.Background(), query(t.Name())) require.Error(t, err) @@ -74,7 +75,7 @@ func TestKibanaFetcher(t *testing.T) { statusCode = http.StatusNotFound response = map[string]interface{}{} - kf, err := NewKibanaFetcher(client, testExpiration) + kf, err := NewKibanaFetcher(client, testExpiration, logptest.NewTestingLogger(t, "")) require.NoError(t, err) result, err := kf.Fetch(context.Background(), query(t.Name())) require.NoError(t, err) @@ -88,7 +89,7 @@ func TestKibanaFetcher(t *testing.T) { b, err := json.Marshal(response) expectedResult, err := newResult(b, err) require.NoError(t, err) - kf, err := NewKibanaFetcher(client, testExpiration) + kf, err := NewKibanaFetcher(client, testExpiration, logptest.NewTestingLogger(t, "")) require.NoError(t, err) result, err := kf.Fetch(context.Background(), query(t.Name())) require.NoError(t, err) @@ -97,7 +98,7 @@ func TestKibanaFetcher(t *testing.T) { t.Run("FetchFromCache", func(t *testing.T) { - fetcher, err := NewKibanaFetcher(client, time.Minute) + fetcher, err := NewKibanaFetcher(client, time.Minute, logptest.NewTestingLogger(t, "")) require.NoError(t, err) fetch := func(kibanaSamplingRate, expectedSamplingRate float64) { statusCode = http.StatusOK diff --git a/internal/agentcfg/reporter.go b/internal/agentcfg/reporter.go index 9b3943455cb..3b5f011f72e 100644 --- a/internal/agentcfg/reporter.go +++ b/internal/agentcfg/reporter.go @@ -34,13 +34,12 @@ type Reporter struct { resultc chan Result } -func NewReporter(f Fetcher, batchProcessor modelpb.BatchProcessor, interval time.Duration) Reporter { - logger := logp.NewLogger("agentcfg") +func NewReporter(f Fetcher, batchProcessor modelpb.BatchProcessor, interval time.Duration, logger *logp.Logger) Reporter { return Reporter{ f: f, p: batchProcessor, interval: interval, - logger: logger, + logger: logger.Named("agentcfg"), resultc: make(chan Result), } } diff --git a/internal/agentcfg/reporter_test.go b/internal/agentcfg/reporter_test.go index c912316f77f..abadb0b2f3d 100644 --- a/internal/agentcfg/reporter_test.go +++ b/internal/agentcfg/reporter_test.go @@ -30,6 +30,7 @@ import ( "google.golang.org/protobuf/testing/protocmp" "github.com/elastic/apm-data/model/modelpb" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestReportFetch(t *testing.T) { @@ -37,7 +38,7 @@ func TestReportFetch(t *testing.T) { receivedc := make(chan struct{}) defer close(receivedc) bp := &batchProcessor{receivedc: receivedc} - r := NewReporter(fauxFetcher{}, bp, interval) + r := NewReporter(fauxFetcher{}, bp, interval, logptest.NewTestingLogger(t, "")) var g errgroup.Group ctx, cancel := context.WithCancel(context.Background()) diff --git a/internal/beatcmd/beat.go b/internal/beatcmd/beat.go index c81abb1d7f0..201b31cb746 100644 --- a/internal/beatcmd/beat.go +++ b/internal/beatcmd/beat.go @@ -167,16 +167,17 @@ func (b *Beat) init() error { if err := configureLogging(b.Config); err != nil { return fmt.Errorf("failed to configure logging: %w", err) } + b.Beat.Info.Logger = logp.NewLogger("") // log paths values to help with troubleshooting - logp.Info("%s", paths.Paths.String()) + b.Info.Logger.Info("%s", paths.Paths.String()) // Load the unique ID and "first start" info from meta.json. metaPath := paths.Resolve(paths.Data, "meta.json") if err := b.loadMeta(metaPath); err != nil { return err } - logp.Info("Beat ID: %v", b.Info.ID) + b.Info.Logger.Info("Beat ID: %v", b.Info.ID) // Initialize central config manager. manager, err := management.NewManager(b.Config.Management, b.Registry) @@ -186,11 +187,11 @@ func (b *Beat) init() error { b.Manager = manager if maxProcs := b.Config.MaxProcs; maxProcs > 0 { - logp.Info("Set max procs limit: %v", maxProcs) + b.Info.Logger.Info("Set max procs limit: %v", maxProcs) runtime.GOMAXPROCS(maxProcs) } if gcPercent := b.Config.GCPercent; gcPercent > 0 { - logp.Info("Set gc percentage to: %v", gcPercent) + b.Info.Logger.Info("Set gc percentage to: %v", gcPercent) debug.SetGCPercent(gcPercent) } return nil @@ -202,7 +203,7 @@ func (b *Beat) loadMeta(metaPath string) error { FirstStart time.Time `json:"first_start"` } - logp.Debug("beat", "Beat metadata path: %v", metaPath) + b.Info.Logger.Debug("beat", "Beat metadata path: %v", metaPath) f, err := openRegular(metaPath) if err != nil && !os.IsNotExist(err) { return fmt.Errorf("meta file failed to open: %w", err) @@ -281,25 +282,23 @@ func openRegular(filename string) (*os.File, error) { } func (b *Beat) Run(ctx context.Context) error { - defer logp.Sync() + defer b.Info.Logger.Sync() defer func() { if r := recover(); r != nil { - logp.NewLogger("").Fatalw("exiting due to panic", + b.Info.Logger.Fatalw("exiting due to panic", "panic", r, zap.Stack("stack"), ) } }() - defer logp.Info("%s stopped.", b.Info.Beat) - - logger := logp.NewLogger("") + defer b.Info.Logger.Info("%s stopped.", b.Info.Beat) if runtime.GOOS == "darwin" { if host, err := sysinfo.Host(); err != nil { - logger.Warnf("failed to retrieve kernel version, ignoring potential deprecation warning: %v", err) + b.Info.Logger.Warnf("failed to retrieve kernel version, ignoring potential deprecation warning: %v", err) } else if strings.HasPrefix(host.Info().KernelVersion, "19.") { // macOS 10.15.x (catalina) means darwin kernel 19.y - logger.Warn("deprecation notice: support for macOS 10.15 will be removed in an upcoming version") + b.Info.Logger.Warn("deprecation notice: support for macOS 10.15 will be removed in an upcoming version") } } @@ -325,7 +324,7 @@ func (b *Beat) Run(ctx context.Context) error { var apiServer *api.Server if b.Config.HTTP.Enabled() { var err error - apiServer, err = api.NewWithDefaultRoutes(logp.NewLogger(""), b.Config.HTTP, api.NamespaceLookupFunc()) + apiServer, err = api.NewWithDefaultRoutes(b.Info.Logger, b.Config.HTTP, api.NamespaceLookupFunc()) if err != nil { return fmt.Errorf("could not start the HTTP server for the API: %w", err) } @@ -371,10 +370,10 @@ func (b *Beat) Run(ctx context.Context) error { } g.Go(func() error { - return adjustMaxProcs(ctx, 30*time.Second, logger) + return adjustMaxProcs(ctx, 30*time.Second, b.Info.Logger) }) - slogger := slog.New(zapslog.NewHandler(logger.Core())) + slogger := slog.New(zapslog.NewHandler(b.Info.Logger.Core())) if err := adjustMemlimit(30*time.Second, slogger); err != nil { return err } @@ -393,7 +392,7 @@ func (b *Beat) Run(ctx context.Context) error { } defer cleanup() - if err := metricreport.SetupMetrics(logp.NewLogger("metrics"), b.Info.Beat, b.Info.Version); err != nil { + if err := metricreport.SetupMetrics(b.Info.Logger.Named("metrics"), b.Info.Beat, b.Info.Version); err != nil { return err } @@ -416,7 +415,7 @@ func (b *Beat) Run(ctx context.Context) error { runner, err := b.newRunner(RunnerParams{ Config: b.rawConfig, Info: b.Info, - Logger: logp.NewLogger(""), + Logger: b.Info.Logger, MeterProvider: b.meterProvider, MetricsGatherer: b.metricGatherer, }) @@ -425,7 +424,7 @@ func (b *Beat) Run(ctx context.Context) error { } g.Go(func() error { return runner.Run(ctx) }) } - logp.Info("%s started.", b.Info.Beat) + b.Info.Logger.Info("%s started.", b.Info.Beat) if err := g.Wait(); err != nil && !errors.Is(err, context.Canceled) { return err } @@ -831,9 +830,9 @@ func (b *Beat) setupMonitoring() (report.Reporter, error) { // runtime, host, and process. If any of the data is not available it will be // omitted. func logSystemInfo(info beat.Info) { - defer logp.Recover("An unexpected error occurred while collecting " + + defer info.Logger.Recover("An unexpected error occurred while collecting " + "information about the system.") - log := logp.NewLogger("beat").With(logp.Namespace("system_info")) + log := info.Logger.Named("beat").With(logp.Namespace("system_info")) // Beat beat := mapstr.M{ diff --git a/internal/beatcmd/beat_test.go b/internal/beatcmd/beat_test.go index 74bb91572e6..ce34ce30ec7 100644 --- a/internal/beatcmd/beat_test.go +++ b/internal/beatcmd/beat_test.go @@ -47,6 +47,7 @@ import ( "github.com/elastic/elastic-agent-client/v7/pkg/proto" "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/elastic/elastic-agent-libs/monitoring" "github.com/elastic/elastic-agent-libs/paths" "github.com/elastic/go-docappender/v2" @@ -389,7 +390,9 @@ func TestRunManager_Reloader(t *testing.T) { registry := reload.NewRegistry() - reloader, err := NewReloader(beat.Info{}, registry, func(p RunnerParams) (Runner, error) { + reloader, err := NewReloader(beat.Info{ + Logger: logptest.NewTestingLogger(t, ""), + }, registry, func(p RunnerParams) (Runner, error) { return runnerFunc(func(ctx context.Context) error { revision, err := p.Config.Int("revision", -1) require.NoError(t, err) @@ -525,7 +528,9 @@ func TestRunManager_Reloader_newRunnerError(t *testing.T) { registry := reload.NewRegistry() - _, err := NewReloader(beat.Info{}, registry, func(_ RunnerParams) (Runner, error) { + _, err := NewReloader(beat.Info{ + Logger: logptest.NewTestingLogger(t, ""), + }, registry, func(_ RunnerParams) (Runner, error) { return nil, errors.New("newRunner error") }, nil, nil) require.NoError(t, err) diff --git a/internal/beatcmd/maxprocs_test.go b/internal/beatcmd/maxprocs_test.go index 7c0df283ec7..7bd2fd65c35 100644 --- a/internal/beatcmd/maxprocs_test.go +++ b/internal/beatcmd/maxprocs_test.go @@ -29,7 +29,7 @@ import ( "go.uber.org/zap/zaptest/observer" "golang.org/x/sync/errgroup" - "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestAdjustMaxProcs(t *testing.T) { @@ -39,7 +39,7 @@ func TestAdjustMaxProcs(t *testing.T) { defer cancel() core, observedLogs := observer.New(zapcore.DebugLevel) - logger := logp.NewLogger("", zap.WrapCore(func(in zapcore.Core) zapcore.Core { + logger := logptest.NewTestingLogger(t, "", zap.WrapCore(func(in zapcore.Core) zapcore.Core { return zapcore.NewTee(in, core) })) diff --git a/internal/beatcmd/reloader.go b/internal/beatcmd/reloader.go index 169415e526b..e77f18271f3 100644 --- a/internal/beatcmd/reloader.go +++ b/internal/beatcmd/reloader.go @@ -77,7 +77,7 @@ type Runner interface { func NewReloader(info beat.Info, registry *reload.Registry, newRunner NewRunnerFunc, meterProvider metric.MeterProvider, metricGatherer *apmotel.Gatherer) (*Reloader, error) { r := &Reloader{ info: info, - logger: logp.NewLogger(""), + logger: info.Logger, newRunner: newRunner, stopped: make(chan struct{}), diff --git a/internal/beatcmd/reloader_test.go b/internal/beatcmd/reloader_test.go index 14acf19b338..d7d310a210a 100644 --- a/internal/beatcmd/reloader_test.go +++ b/internal/beatcmd/reloader_test.go @@ -30,6 +30,7 @@ import ( "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/libbeat/common/reload" "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestReloader(t *testing.T) { @@ -57,7 +58,9 @@ func TestReloader(t *testing.T) { registry := reload.NewRegistry() - reloader, err := NewReloader(beat.Info{}, registry, func(args RunnerParams) (Runner, error) { + reloader, err := NewReloader(beat.Info{ + Logger: logptest.NewTestingLogger(t, ""), + }, registry, func(args RunnerParams) (Runner, error) { if shouldError, _ := args.Config.Bool("error", -1); shouldError { return nil, errors.New("no runner for you") } @@ -149,7 +152,11 @@ func TestReloaderNewRunnerParams(t *testing.T) { registry := reload.NewRegistry() calls := make(chan RunnerParams, 1) - info := beat.Info{Beat: "not-apm-server", Version: "0.0.1"} + info := beat.Info{ + Beat: "not-apm-server", + Version: "0.0.1", + Logger: logptest.NewTestingLogger(t, ""), + } reloader, err := NewReloader(info, registry, func(args RunnerParams) (Runner, error) { calls <- args return runnerFunc(func(ctx context.Context) error { diff --git a/internal/beatcmd/testcmd.go b/internal/beatcmd/testcmd.go index fa86543dd38..b317895a0f1 100644 --- a/internal/beatcmd/testcmd.go +++ b/internal/beatcmd/testcmd.go @@ -24,6 +24,7 @@ import ( "github.com/elastic/beats/v7/libbeat/outputs" "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/testing" beaterconfig "github.com/elastic/apm-server/internal/beater/config" @@ -54,7 +55,7 @@ var testConfigCommand = &cobra.Command{ if cfg.Output.Name() == "elasticsearch" { esOutputConfig = cfg.Output.Config() } - if _, err := beaterconfig.NewConfig(cfg.APMServer, esOutputConfig); err != nil { + if _, err := beaterconfig.NewConfig(cfg.APMServer, esOutputConfig, logp.NewLogger("")); err != nil { return err } @@ -72,7 +73,7 @@ func newTestOutputCommand(beatParams BeatParams) *cobra.Command { if err != nil { return err } - indexSupporter := idxmgmt.NewSupporter(nil, beat.rawConfig) + indexSupporter := idxmgmt.NewSupporter(beat.Info.Logger, beat.rawConfig) output, err := outputs.Load( indexSupporter, beat.Info, nil, beat.Config.Output.Name(), beat.Config.Output.Config(), ) diff --git a/internal/beater/api/config/agent/handler_test.go b/internal/beater/api/config/agent/handler_test.go index c95417d73e3..fabb1028325 100644 --- a/internal/beater/api/config/agent/handler_test.go +++ b/internal/beater/api/config/agent/handler_test.go @@ -38,6 +38,7 @@ import ( "github.com/elastic/apm-server/internal/beater/headers" "github.com/elastic/apm-server/internal/beater/request" "github.com/elastic/apm-server/internal/kibana" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) var ( @@ -402,7 +403,7 @@ func newSanitizingKibanaFetcher(t testing.TB, h http.HandlerFunc) agentcfg.Fetch t.Cleanup(srv.Close) client, err := kibana.NewClient(kibana.ClientConfig{Host: srv.URL}) require.NoError(t, err) - kf, err := agentcfg.NewKibanaFetcher(client, time.Nanosecond) + kf, err := agentcfg.NewKibanaFetcher(client, time.Nanosecond, logptest.NewTestingLogger(t, "")) require.NoError(t, err) return agentcfg.SanitizingFetcher{Fetcher: kf} } diff --git a/internal/beater/api/mux.go b/internal/beater/api/mux.go index 2e4dc8439c5..4ed1ea20fee 100644 --- a/internal/beater/api/mux.go +++ b/internal/beater/api/mux.go @@ -90,9 +90,10 @@ func NewMux( publishReady func() bool, semaphore input.Semaphore, meterProvider metric.MeterProvider, + logger *logp.Logger, ) (*mux.Router, error) { pool := request.NewContextPool() - logger := logp.NewLogger(logs.Handler) + logger = logger.Named(logs.Handler) router := mux.NewRouter() router.NotFoundHandler = pool.HTTPHandler(notFoundHandler) @@ -103,6 +104,7 @@ func NewMux( ratelimitStore: ratelimitStore, sourcemapFetcher: sourcemapFetcher, intakeSemaphore: semaphore, + logger: logger, } zapLogger := zap.New(logger.Core(), zap.WithCaller(true)) @@ -169,12 +171,13 @@ type routeBuilder struct { sourcemapFetcher sourcemap.Fetcher intakeProcessor *elasticapm.Processor intakeSemaphore input.Semaphore + logger *logp.Logger } func (r *routeBuilder) backendIntakeHandler(metricsPrefix string, mp metric.MeterProvider) func() (request.Handler, error) { return func() (request.Handler, error) { h := intake.Handler(mp, r.intakeProcessor, backendRequestMetadataFunc(r.cfg), r.batchProcessor) - return middleware.Wrap(h, backendMiddleware(r.cfg, r.authenticator, r.ratelimitStore, metricsPrefix, mp)...) + return middleware.Wrap(h, backendMiddleware(r.cfg, r.authenticator, r.ratelimitStore, metricsPrefix, mp, r.logger)...) } } @@ -183,7 +186,7 @@ func (r *routeBuilder) otlpHandler(handler http.HandlerFunc, metricsPrefix strin h := func(c *request.Context) { handler(c.ResponseWriter, c.Request) } - return middleware.Wrap(h, backendMiddleware(r.cfg, r.authenticator, r.ratelimitStore, metricsPrefix, mp)...) + return middleware.Wrap(h, backendMiddleware(r.cfg, r.authenticator, r.ratelimitStore, metricsPrefix, mp, r.logger)...) } } @@ -196,7 +199,7 @@ func (r *routeBuilder) rumIntakeHandler(mp metric.MeterProvider) func() (request batchProcessors = append(batchProcessors, sourcemap.BatchProcessor{ Fetcher: r.sourcemapFetcher, Timeout: r.cfg.RumConfig.SourceMapping.Timeout, - Logger: logp.NewLogger(logs.Stacktrace), + Logger: r.logger.Named(logs.Stacktrace), }) } if r.cfg.RumConfig.LibraryPattern != "" { @@ -218,7 +221,7 @@ func (r *routeBuilder) rumIntakeHandler(mp metric.MeterProvider) func() (request } batchProcessors = append(batchProcessors, r.batchProcessor) // r.batchProcessor always goes last h := intake.Handler(mp, r.intakeProcessor, rumRequestMetadataFunc(r.cfg), batchProcessors) - return middleware.Wrap(h, rumMiddleware(r.cfg, r.authenticator, r.ratelimitStore, "apm-server.server.", mp)...) + return middleware.Wrap(h, rumMiddleware(r.cfg, r.authenticator, r.ratelimitStore, "apm-server.server.", mp, r.logger)...) } } @@ -228,23 +231,23 @@ func (r *routeBuilder) rootHandler(publishReady func() bool, mp metric.MeterProv Version: version.VersionWithQualifier(), PublishReady: publishReady, }) - return middleware.Wrap(h, rootMiddleware(r.cfg, r.authenticator, mp)...) + return middleware.Wrap(h, rootMiddleware(r.cfg, r.authenticator, mp, r.logger)...) } } func (r *routeBuilder) backendAgentConfigHandler(f agentcfg.Fetcher, mp metric.MeterProvider) func() (request.Handler, error) { return func() (request.Handler, error) { - return agentConfigHandler(r.cfg, r.authenticator, r.ratelimitStore, backendMiddleware, f, mp) + return agentConfigHandler(r.cfg, r.authenticator, r.ratelimitStore, backendMiddleware, f, mp, r.logger) } } func (r *routeBuilder) rumAgentConfigHandler(f agentcfg.Fetcher, mp metric.MeterProvider) func() (request.Handler, error) { return func() (request.Handler, error) { - return agentConfigHandler(r.cfg, r.authenticator, r.ratelimitStore, rumMiddleware, f, mp) + return agentConfigHandler(r.cfg, r.authenticator, r.ratelimitStore, rumMiddleware, f, mp, r.logger) } } -type middlewareFunc func(*config.Config, *auth.Authenticator, *ratelimit.Store, string, metric.MeterProvider) []middleware.Middleware +type middlewareFunc func(*config.Config, *auth.Authenticator, *ratelimit.Store, string, metric.MeterProvider, *logp.Logger) []middleware.Middleware func agentConfigHandler( cfg *config.Config, @@ -253,22 +256,23 @@ func agentConfigHandler( middlewareFunc middlewareFunc, f agentcfg.Fetcher, mp metric.MeterProvider, + logger *logp.Logger, ) (request.Handler, error) { - mw := middlewareFunc(cfg, authenticator, ratelimitStore, "apm-server.acm.", mp) + mw := middlewareFunc(cfg, authenticator, ratelimitStore, "apm-server.acm.", mp, logger) h := agent.NewHandler(f, cfg.AgentConfig.Cache.Expiration, cfg.DefaultServiceEnvironment, cfg.AgentAuth.Anonymous.AllowAgent) return middleware.Wrap(h, mw...) } -func apmMiddleware(mp metric.MeterProvider, metricsPrefix string) []middleware.Middleware { +func apmMiddleware(mp metric.MeterProvider, metricsPrefix string, logger *logp.Logger) []middleware.Middleware { return []middleware.Middleware{ - middleware.LogMiddleware(), + middleware.LogMiddleware(logger), middleware.RecoverPanicMiddleware(), middleware.MonitoringMiddleware(metricsPrefix, mp), } } -func backendMiddleware(cfg *config.Config, authenticator *auth.Authenticator, ratelimitStore *ratelimit.Store, metricsPrefix string, mp metric.MeterProvider) []middleware.Middleware { - backendMiddleware := append(apmMiddleware(mp, metricsPrefix), +func backendMiddleware(cfg *config.Config, authenticator *auth.Authenticator, ratelimitStore *ratelimit.Store, metricsPrefix string, mp metric.MeterProvider, logger *logp.Logger) []middleware.Middleware { + backendMiddleware := append(apmMiddleware(mp, metricsPrefix, logger), middleware.ResponseHeadersMiddleware(cfg.ResponseHeaders), middleware.AuthMiddleware(authenticator, true), middleware.AnonymousRateLimitMiddleware(ratelimitStore), @@ -276,11 +280,11 @@ func backendMiddleware(cfg *config.Config, authenticator *auth.Authenticator, ra return backendMiddleware } -func rumMiddleware(cfg *config.Config, authenticator *auth.Authenticator, ratelimitStore *ratelimit.Store, metricsPrefix string, mp metric.MeterProvider) []middleware.Middleware { +func rumMiddleware(cfg *config.Config, authenticator *auth.Authenticator, ratelimitStore *ratelimit.Store, metricsPrefix string, mp metric.MeterProvider, logger *logp.Logger) []middleware.Middleware { msg := "RUM endpoint is disabled. " + "Configure the `apm-server.rum` section in apm-server.yml to enable ingestion of RUM events. " + "If you are not using the RUM agent, you can safely ignore this error." - rumMiddleware := append(apmMiddleware(mp, metricsPrefix), + rumMiddleware := append(apmMiddleware(mp, metricsPrefix, logger), middleware.ResponseHeadersMiddleware(cfg.ResponseHeaders), middleware.ResponseHeadersMiddleware(cfg.RumConfig.ResponseHeaders), middleware.CORSMiddleware(cfg.RumConfig.AllowOrigins, cfg.RumConfig.AllowHeaders), @@ -290,8 +294,8 @@ func rumMiddleware(cfg *config.Config, authenticator *auth.Authenticator, rateli return append(rumMiddleware, middleware.KillSwitchMiddleware(cfg.RumConfig.Enabled, msg)) } -func rootMiddleware(cfg *config.Config, authenticator *auth.Authenticator, mp metric.MeterProvider) []middleware.Middleware { - return append(apmMiddleware(mp, "apm-server.root."), +func rootMiddleware(cfg *config.Config, authenticator *auth.Authenticator, mp metric.MeterProvider, logger *logp.Logger) []middleware.Middleware { + return append(apmMiddleware(mp, "apm-server.root.", logger), middleware.ResponseHeadersMiddleware(cfg.ResponseHeaders), middleware.AuthMiddleware(authenticator, false), ) diff --git a/internal/beater/api/mux_config_agent_test.go b/internal/beater/api/mux_config_agent_test.go index 3a947c51b7b..93575c3d8e8 100644 --- a/internal/beater/api/mux_config_agent_test.go +++ b/internal/beater/api/mux_config_agent_test.go @@ -33,7 +33,7 @@ func TestConfigAgentHandler_AuthorizationMiddleware(t *testing.T) { t.Run("Unauthorized", func(t *testing.T) { cfg := configEnabledConfigAgent() cfg.AgentAuth.SecretToken = "1234" - rec, err := requestToMuxerWithPattern(cfg, AgentConfigPath) + rec, err := requestToMuxerWithPattern(t, cfg, AgentConfigPath) require.NoError(t, err) require.Equal(t, http.StatusUnauthorized, rec.Code) assert.JSONEq(t, @@ -48,7 +48,7 @@ func TestConfigAgentHandler_AuthorizationMiddleware(t *testing.T) { header := map[string]string{headers.Authorization: "Bearer 1234"} queryString := map[string]string{"service.name": "service1"} - rec, err := requestToMuxerWithHeaderAndQueryString(cfg, AgentConfigPath, http.MethodGet, header, queryString) + rec, err := requestToMuxerWithHeaderAndQueryString(t, cfg, AgentConfigPath, http.MethodGet, header, queryString) require.NoError(t, err) require.NotEqual(t, http.StatusUnauthorized, rec.Code) assert.JSONEq(t, "{}", rec.Body.String()) diff --git a/internal/beater/api/mux_expvar_test.go b/internal/beater/api/mux_expvar_test.go index 5b16c40af81..179f99d3ae6 100644 --- a/internal/beater/api/mux_expvar_test.go +++ b/internal/beater/api/mux_expvar_test.go @@ -30,7 +30,7 @@ import ( func TestExpvarDefaultDisabled(t *testing.T) { cfg := config.DefaultConfig() - recorder, err := requestToMuxerWithPattern(cfg, "/debug/vars") + recorder, err := requestToMuxerWithPattern(t, cfg, "/debug/vars") require.NoError(t, err) assert.Equal(t, http.StatusNotFound, recorder.Code) assert.Equal(t, `{"error":"404 page not found"}`+"\n", recorder.Body.String()) @@ -39,7 +39,7 @@ func TestExpvarDefaultDisabled(t *testing.T) { func TestExpvarEnabled(t *testing.T) { cfg := config.DefaultConfig() cfg.Expvar.Enabled = true - recorder, err := requestToMuxerWithPattern(cfg, "/debug/vars") + recorder, err := requestToMuxerWithPattern(t, cfg, "/debug/vars") require.NoError(t, err) assert.Equal(t, http.StatusOK, recorder.Code) diff --git a/internal/beater/api/mux_intake_backend_test.go b/internal/beater/api/mux_intake_backend_test.go index a2329bfa49a..c88011ed235 100644 --- a/internal/beater/api/mux_intake_backend_test.go +++ b/internal/beater/api/mux_intake_backend_test.go @@ -34,7 +34,7 @@ func TestIntakeBackendHandler_AuthorizationMiddleware(t *testing.T) { t.Run("Unauthorized", func(t *testing.T) { cfg := config.DefaultConfig() cfg.AgentAuth.SecretToken = "1234" - rec, err := requestToMuxerWithPattern(cfg, IntakePath) + rec, err := requestToMuxerWithPattern(t, cfg, IntakePath) require.NoError(t, err) assert.Equal(t, http.StatusUnauthorized, rec.Code) @@ -48,7 +48,7 @@ func TestIntakeBackendHandler_AuthorizationMiddleware(t *testing.T) { cfg := config.DefaultConfig() cfg.AgentAuth.SecretToken = "1234" h := map[string]string{headers.Authorization: "Bearer 1234"} - rec, err := requestToMuxerWithHeader(cfg, IntakePath, http.MethodGet, h) + rec, err := requestToMuxerWithHeader(t, cfg, IntakePath, http.MethodGet, h) require.NoError(t, err) require.NotEqual(t, http.StatusUnauthorized, rec.Code) diff --git a/internal/beater/api/mux_intake_rum_test.go b/internal/beater/api/mux_intake_rum_test.go index 977aea40ae9..92647d50aea 100644 --- a/internal/beater/api/mux_intake_rum_test.go +++ b/internal/beater/api/mux_intake_rum_test.go @@ -33,6 +33,7 @@ import ( "github.com/elastic/apm-server/internal/beater/middleware" "github.com/elastic/apm-server/internal/beater/ratelimit" "github.com/elastic/apm-server/internal/beater/request" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestOPTIONS(t *testing.T) { @@ -49,7 +50,7 @@ func TestOPTIONS(t *testing.T) { requestTaken <- struct{}{} <-done }, - rumMiddleware(cfg, authenticator, ratelimitStore, "", noop.NewMeterProvider())...) + rumMiddleware(cfg, authenticator, ratelimitStore, "", noop.NewMeterProvider(), logptest.NewTestingLogger(t, ""))...) // use this to block the single allowed concurrent requests go func() { @@ -73,14 +74,14 @@ func TestOPTIONS(t *testing.T) { func TestRUMHandler_NoAuthorizationRequired(t *testing.T) { cfg := cfgEnabledRUM() cfg.AgentAuth.SecretToken = "1234" - rec, err := requestToMuxerWithPattern(cfg, IntakeRUMPath) + rec, err := requestToMuxerWithPattern(t, cfg, IntakeRUMPath) require.NoError(t, err) assert.Equal(t, http.StatusAccepted, rec.Code) } func TestRUMHandler_KillSwitchMiddleware(t *testing.T) { t.Run("OffRum", func(t *testing.T) { - rec, err := requestToMuxerWithPattern(config.DefaultConfig(), IntakeRUMPath) + rec, err := requestToMuxerWithPattern(t, config.DefaultConfig(), IntakeRUMPath) require.NoError(t, err) assert.Equal(t, http.StatusForbidden, rec.Code) @@ -90,7 +91,7 @@ func TestRUMHandler_KillSwitchMiddleware(t *testing.T) { }) t.Run("On", func(t *testing.T) { - rec, err := requestToMuxerWithPattern(cfgEnabledRUM(), IntakeRUMPath) + rec, err := requestToMuxerWithPattern(t, cfgEnabledRUM(), IntakeRUMPath) require.NoError(t, err) assert.Equal(t, http.StatusAccepted, rec.Code) }) diff --git a/internal/beater/api/mux_root_test.go b/internal/beater/api/mux_root_test.go index 5c814786abd..556f1f18f87 100644 --- a/internal/beater/api/mux_root_test.go +++ b/internal/beater/api/mux_root_test.go @@ -38,7 +38,7 @@ func TestRootHandler_AuthorizationMiddleware(t *testing.T) { cfg.AgentAuth.SecretToken = "1234" t.Run("No auth", func(t *testing.T) { - rec, err := requestToMuxerWithHeader(cfg, RootPath, http.MethodGet, nil) + rec, err := requestToMuxerWithHeader(t, cfg, RootPath, http.MethodGet, nil) require.NoError(t, err) assert.Equal(t, http.StatusOK, rec.Code) assert.Empty(t, rec.Body.String()) @@ -46,7 +46,7 @@ func TestRootHandler_AuthorizationMiddleware(t *testing.T) { t.Run("Authorized", func(t *testing.T) { h := map[string]string{headers.Authorization: "Bearer 1234"} - rec, err := requestToMuxerWithHeader(cfg, RootPath, http.MethodGet, h) + rec, err := requestToMuxerWithHeader(t, cfg, RootPath, http.MethodGet, h) require.NoError(t, err) assert.Equal(t, http.StatusOK, rec.Code) assert.Contains(t, rec.Body.String(), "build_date") diff --git a/internal/beater/api/mux_test.go b/internal/beater/api/mux_test.go index f4ee1e78c1e..dd02887deeb 100644 --- a/internal/beater/api/mux_test.go +++ b/internal/beater/api/mux_test.go @@ -41,6 +41,8 @@ import ( "github.com/elastic/apm-server/internal/beater/ratelimit" "github.com/elastic/apm-server/internal/beater/request" "github.com/elastic/apm-server/internal/sourcemap" + "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestBackendRequestMetadata(t *testing.T) { @@ -76,14 +78,14 @@ func TestRUMRequestMetadata(t *testing.T) { assert.Equal(t, &modelpb.UserAgent{Original: c.UserAgent}, event.UserAgent) } -func requestToMuxerWithPattern(cfg *config.Config, pattern string) (*httptest.ResponseRecorder, error) { +func requestToMuxerWithPattern(t *testing.T, cfg *config.Config, pattern string) (*httptest.ResponseRecorder, error) { r := httptest.NewRequest(http.MethodPost, pattern, nil) - return requestToMuxer(cfg, r) + return requestToMuxer(t, cfg, r) } -func requestToMuxerWithHeader(cfg *config.Config, pattern string, method string, header map[string]string) (*httptest.ResponseRecorder, error) { +func requestToMuxerWithHeader(t *testing.T, cfg *config.Config, pattern string, method string, header map[string]string) (*httptest.ResponseRecorder, error) { r := httptest.NewRequest(method, pattern, nil) - return requestToMuxer(cfg, requestWithHeader(r, header)) + return requestToMuxer(t, cfg, requestWithHeader(r, header)) } func requestWithHeader(r *http.Request, header map[string]string) *http.Request { @@ -103,6 +105,7 @@ func requestWithQueryString(r *http.Request, queryString map[string]string) *htt } func requestToMuxerWithHeaderAndQueryString( + t *testing.T, cfg *config.Config, pattern, method string, header, queryString map[string]string, @@ -110,11 +113,13 @@ func requestToMuxerWithHeaderAndQueryString( r := httptest.NewRequest(method, pattern, nil) r = requestWithQueryString(r, queryString) r = requestWithHeader(r, header) - return requestToMuxer(cfg, r) + return requestToMuxer(t, cfg, r) } -func requestToMuxer(cfg *config.Config, r *http.Request) (*httptest.ResponseRecorder, error) { - _, mux, err := muxBuilder{}.build(cfg) +func requestToMuxer(t *testing.T, cfg *config.Config, r *http.Request) (*httptest.ResponseRecorder, error) { + _, mux, err := muxBuilder{ + Logger: logptest.NewTestingLogger(t, ""), + }.build(cfg) if err != nil { return nil, err } @@ -143,7 +148,9 @@ func testMonitoringMiddleware(t *testing.T, urlPath string, expectedMetrics map[ } func newTestMux(t *testing.T, cfg *config.Config) (http.Handler, sdkmetric.Reader) { - reader, mux, err := muxBuilder{}.build(cfg) + reader, mux, err := muxBuilder{ + Logger: logptest.NewTestingLogger(t, ""), + }.build(cfg) require.NoError(t, err) return mux, reader } @@ -151,6 +158,7 @@ func newTestMux(t *testing.T, cfg *config.Config) (http.Handler, sdkmetric.Reade type muxBuilder struct { SourcemapFetcher sourcemap.Fetcher Managed bool + Logger *logp.Logger } func (m muxBuilder) build(cfg *config.Config) (sdkmetric.Reader, http.Handler, error) { @@ -174,6 +182,7 @@ func (m muxBuilder) build(cfg *config.Config) (sdkmetric.Reader, http.Handler, e func() bool { return true }, semaphore.NewWeighted(1), mp, + m.Logger, ) return reader, r, err } diff --git a/internal/beater/beater.go b/internal/beater/beater.go index d9122e0485f..4dbe7eeaaa6 100644 --- a/internal/beater/beater.go +++ b/internal/beater/beater.go @@ -133,7 +133,7 @@ func NewRunner(args RunnerParams) (*Runner, error) { if unpackedConfig.Output.Name() == "elasticsearch" { elasticsearchOutputConfig = unpackedConfig.Output.Config() } - cfg, err := config.NewConfig(unpackedConfig.APMServer, elasticsearchOutputConfig) + cfg, err := config.NewConfig(unpackedConfig.APMServer, elasticsearchOutputConfig, args.Logger) if err != nil { return nil, err } @@ -260,7 +260,7 @@ func (s *Runner) Run(ctx context.Context) error { if s.config.JavaAttacherConfig.Enabled { if !inElasticCloud { go func() { - attacher, err := javaattacher.New(s.config.JavaAttacherConfig) + attacher, err := javaattacher.New(s.config.JavaAttacherConfig, s.logger) if err != nil { s.logger.Errorf("failed to start java attacher: %v", err) return @@ -274,7 +274,7 @@ func (s *Runner) Run(ctx context.Context) error { } } - instrumentation, err := newInstrumentation(s.rawConfig) + instrumentation, err := newInstrumentation(s.rawConfig, s.logger) if err != nil { return err } @@ -341,6 +341,7 @@ func (s *Runner) Run(ctx context.Context) error { s.config.RumConfig.SourceMapping, kibanaClient, newElasticsearchClient, tracer, + s.logger, ) if err != nil { return err @@ -382,7 +383,7 @@ func (s *Runner) Run(ctx context.Context) error { // Create the BatchProcessor chain that is used to process all events, // including the metrics aggregated by APM Server. finalBatchProcessor, closeFinalBatchProcessor, err := s.newFinalBatchProcessor( - tracer, newElasticsearchClient, memLimitGB, + tracer, newElasticsearchClient, memLimitGB, s.logger, ) if err != nil { return err @@ -418,6 +419,7 @@ func (s *Runner) Run(ctx context.Context) error { newElasticsearchClient, tracer, s.meterProvider, + s.logger, ) if err != nil { return err @@ -431,6 +433,7 @@ func (s *Runner) Run(ctx context.Context) error { agentConfigReporter := agentcfg.NewReporter( agentConfigFetcher, batchProcessor, 30*time.Second, + s.logger, ) g.Go(func() error { return agentConfigReporter.Run(ctx) @@ -523,7 +526,7 @@ func (s *Runner) Run(ctx context.Context) error { // newInstrumentation is a thin wrapper around libbeat instrumentation that // sets missing tracer configuration from elastic agent. -func newInstrumentation(rawConfig *agentconfig.C) (instrumentation.Instrumentation, error) { +func newInstrumentation(rawConfig *agentconfig.C, logger *logp.Logger) (instrumentation.Instrumentation, error) { // This config struct contains missing fields from elastic agent APMConfig // https://github.com/elastic/elastic-agent/blob/main/internal/pkg/core/monitoring/config/config.go#L127 // that are not directly handled by libbeat instrumentation below. @@ -545,7 +548,7 @@ func newInstrumentation(rawConfig *agentconfig.C) (instrumentation.Instrumentati cfg, err := rawConfig.Child("instrumentation", -1) if err != nil || !cfg.Enabled() { // Fallback to instrumentation.New if the configs are not present or disabled. - return instrumentation.New(rawConfig, "apm-server", version.VersionWithQualifier()) + return instrumentation.New(rawConfig, "apm-server", version.VersionWithQualifier(), logger) } if err := cfg.Unpack(&apmCfg); err != nil { return nil, err @@ -588,7 +591,7 @@ func newInstrumentation(rawConfig *agentconfig.C) (instrumentation.Instrumentati os.Setenv(envSamplingRate, strconv.FormatFloat(float64(r), 'f', -1, 32)) defer os.Unsetenv(envSamplingRate) } - return instrumentation.New(rawConfig, "apm-server", version.VersionWithQualifier()) + return instrumentation.New(rawConfig, "apm-server", version.VersionWithQualifier(), logger) } func maxConcurrentDecoders(memLimitGB float64) uint { @@ -686,11 +689,12 @@ func (s *Runner) newFinalBatchProcessor( tracer *apm.Tracer, newElasticsearchClient func(cfg *elasticsearch.Config) (*elasticsearch.Client, error), memLimit float64, + logger *logp.Logger, ) (modelpb.BatchProcessor, func(context.Context) error, error) { if s.elasticsearchOutputConfig == nil { monitoring.Default.Remove("libbeat") libbeatMonitoringRegistry := monitoring.Default.NewRegistry("libbeat") - return s.newLibbeatFinalBatchProcessor(tracer, libbeatMonitoringRegistry) + return s.newLibbeatFinalBatchProcessor(tracer, libbeatMonitoringRegistry, logger) } stateRegistry := monitoring.GetNamespace("state").GetRegistry() @@ -817,6 +821,7 @@ func docappenderConfig( func (s *Runner) newLibbeatFinalBatchProcessor( tracer *apm.Tracer, libbeatMonitoringRegistry *monitoring.Registry, + logger *logp.Logger, ) (modelpb.BatchProcessor, func(context.Context) error, error) { // When the publisher stops cleanly it will close its pipeline client, // calling the acker's Close method and unblock Wait. @@ -830,6 +835,7 @@ func (s *Runner) newLibbeatFinalBatchProcessor( Version: version.VersionWithQualifier(), Hostname: hostname, Name: hostname, + Logger: logger, } stateRegistry := monitoring.GetNamespace("state").GetRegistry() @@ -837,14 +843,14 @@ func (s *Runner) newLibbeatFinalBatchProcessor( monitors := pipeline.Monitors{ Metrics: libbeatMonitoringRegistry, Telemetry: stateRegistry, - Logger: logp.L().Named("publisher"), + Logger: logger.Named("publisher"), Tracer: tracer, } outputFactory := func(stats outputs.Observer) (string, outputs.Group, error) { if !s.outputConfig.IsSet() { return "", outputs.Group{}, nil } - indexSupporter := idxmgmt.NewSupporter(nil, s.rawConfig) + indexSupporter := idxmgmt.NewSupporter(logger, s.rawConfig) outputName := s.outputConfig.Name() output, err := outputs.Load(indexSupporter, beatInfo, stats, outputName, s.outputConfig.Config()) return outputName, output, err @@ -886,6 +892,7 @@ func newSourcemapFetcher( kibanaClient *kibana.Client, newElasticsearchClient func(*elasticsearch.Config) (*elasticsearch.Client, error), tracer *apm.Tracer, + logger *logp.Logger, ) (sourcemap.Fetcher, context.CancelFunc, error) { esClient, err := newElasticsearchClient(cfg.ESConfig) if err != nil { @@ -896,24 +903,24 @@ func newSourcemapFetcher( // start background sync job ctx, cancel := context.WithCancel(context.Background()) - metadataFetcher, invalidationChan := sourcemap.NewMetadataFetcher(ctx, esClient, sourcemapIndex, tracer) + metadataFetcher, invalidationChan := sourcemap.NewMetadataFetcher(ctx, esClient, sourcemapIndex, tracer, logger) - esFetcher := sourcemap.NewElasticsearchFetcher(esClient, sourcemapIndex) + esFetcher := sourcemap.NewElasticsearchFetcher(esClient, sourcemapIndex, logger) size := 128 - cachingFetcher, err := sourcemap.NewBodyCachingFetcher(esFetcher, size, invalidationChan) + cachingFetcher, err := sourcemap.NewBodyCachingFetcher(esFetcher, size, invalidationChan, logger) if err != nil { cancel() return nil, nil, err } - sourcemapFetcher := sourcemap.NewSourcemapFetcher(metadataFetcher, cachingFetcher) + sourcemapFetcher := sourcemap.NewSourcemapFetcher(metadataFetcher, cachingFetcher, logger) fetchers = append(fetchers, sourcemapFetcher) if kibanaClient != nil { - fetchers = append(fetchers, sourcemap.NewKibanaFetcher(kibanaClient)) + fetchers = append(fetchers, sourcemap.NewKibanaFetcher(kibanaClient, logger)) } - chained := sourcemap.NewChainedFetcher(fetchers) + chained := sourcemap.NewChainedFetcher(fetchers, logger) return chained, cancel, nil } diff --git a/internal/beater/beater_test.go b/internal/beater/beater_test.go index dd0aa73d7af..86aefb67af7 100644 --- a/internal/beater/beater_test.go +++ b/internal/beater/beater_test.go @@ -78,6 +78,7 @@ func TestStoreUsesRUMElasticsearchConfig(t *testing.T) { cfg.RumConfig.SourceMapping, nil, elasticsearch.NewClient, apmtest.NewRecordingTracer().Tracer, + logptest.NewTestingLogger(t, ""), ) require.NoError(t, err) defer cancel() @@ -280,7 +281,7 @@ func TestNewInstrumentation(t *testing.T) { "globallabels": "k1=val,k2=new val", }, }) - i, err := newInstrumentation(cfg) + i, err := newInstrumentation(cfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) tracer := i.Tracer() tracer.StartTransaction("name", "type").End() @@ -290,7 +291,7 @@ func TestNewInstrumentation(t *testing.T) { } func TestNewInstrumentationWithSampling(t *testing.T) { - runSampled := func(rate float32) { + runSampled := func(t *testing.T, rate float32) { var events int s := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/intake/v2/events" { @@ -312,7 +313,7 @@ func TestNewInstrumentationWithSampling(t *testing.T) { "samplingrate": fmt.Sprintf("%f", rate), }, }) - i, err := newInstrumentation(cfg) + i, err := newInstrumentation(cfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) tracer := i.Tracer() tr := tracer.StartTransaction("name", "type") @@ -322,10 +323,10 @@ func TestNewInstrumentationWithSampling(t *testing.T) { assert.Equal(t, int(rate), events) } t.Run("100% sampling", func(t *testing.T) { - runSampled(1.0) + runSampled(t, 1.0) }) t.Run("0% sampling", func(t *testing.T) { - runSampled(0.0) + runSampled(t, 0.0) }) } diff --git a/internal/beater/beatertest/server.go b/internal/beater/beatertest/server.go index 10eba224a71..8f1cf3e9837 100644 --- a/internal/beater/beatertest/server.go +++ b/internal/beater/beatertest/server.go @@ -37,7 +37,7 @@ import ( "github.com/elastic/apm-server/internal/beater" agentconfig "github.com/elastic/elastic-agent-libs/config" - "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) // Server runs the core APM Server that, by default, listens on a system-chosen port @@ -80,7 +80,7 @@ func NewServer(t testing.TB, opts ...option) *Server { // The server's Start method should be called to start the server. func NewUnstartedServer(t testing.TB, opts ...option) *Server { core, observedLogs := observer.New(zapcore.DebugLevel) - logger := logp.NewLogger("", zap.WrapCore(func(in zapcore.Core) zapcore.Core { + logger := logptest.NewTestingLogger(t, "", zap.WrapCore(func(in zapcore.Core) zapcore.Core { return zapcore.NewTee(in, core) })) diff --git a/internal/beater/config/agentconfig_test.go b/internal/beater/config/agentconfig_test.go index 23b004f6b36..3aa3c1fcd89 100644 --- a/internal/beater/config/agentconfig_test.go +++ b/internal/beater/config/agentconfig_test.go @@ -25,24 +25,25 @@ import ( "github.com/stretchr/testify/require" "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) // TestAgentConfig tests server configuration the Elasticsearch-based or legacy Kibana-based agent config implementation. func TestAgentConfig(t *testing.T) { t.Run("InvalidValueTooSmall", func(t *testing.T) { - cfg, err := NewConfig(config.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "123ms"}), nil) + cfg, err := NewConfig(config.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "123ms"}), nil, logptest.NewTestingLogger(t, "")) require.Error(t, err) assert.Nil(t, cfg) }) t.Run("InvalidUnit", func(t *testing.T) { - cfg, err := NewConfig(config.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "1230ms"}), nil) + cfg, err := NewConfig(config.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "1230ms"}), nil, logptest.NewTestingLogger(t, "")) require.Error(t, err) assert.Nil(t, cfg) }) t.Run("Valid", func(t *testing.T) { - cfg, err := NewConfig(config.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "123000ms"}), nil) + cfg, err := NewConfig(config.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "123000ms"}), nil, logptest.NewTestingLogger(t, "")) require.NoError(t, err) assert.Equal(t, time.Second*123, cfg.AgentConfig.Cache.Expiration) }) diff --git a/internal/beater/config/aggregation_test.go b/internal/beater/config/aggregation_test.go index f4ab5f212ec..6713c21dc08 100644 --- a/internal/beater/config/aggregation_test.go +++ b/internal/beater/config/aggregation_test.go @@ -24,10 +24,11 @@ import ( "github.com/stretchr/testify/require" "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestAggregationConfigDefault(t *testing.T) { - cfg, err := NewConfig(config.MustNewConfigFrom(map[string]interface{}{}), nil) + cfg, err := NewConfig(config.MustNewConfigFrom(map[string]interface{}{}), nil, logptest.NewTestingLogger(t, "")) require.NoError(t, err) assert.Equal(t, defaultAggregationConfig(), cfg.Aggregation) } diff --git a/internal/beater/config/auth_test.go b/internal/beater/config/auth_test.go index 4cc813e4a3a..45c337962a5 100644 --- a/internal/beater/config/auth_test.go +++ b/internal/beater/config/auth_test.go @@ -26,6 +26,7 @@ import ( "github.com/elastic/apm-server/internal/elasticsearch" "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestAPIKeyAgentAuth_ESConfig(t *testing.T) { @@ -95,7 +96,7 @@ func TestAPIKeyAgentAuth_ESConfig(t *testing.T) { if tc.cfg != nil { input.SetChild("auth.api_key", -1, tc.cfg) } - cfg, err := NewConfig(input, tc.esCfg) + cfg, err := NewConfig(input, tc.esCfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) assert.Equal(t, tc.expectedConfig, cfg.AgentAuth.APIKey) }) @@ -153,7 +154,7 @@ func TestAnonymousAgentAuth(t *testing.T) { }, } { t.Run(name, func(t *testing.T) { - cfg, err := NewConfig(tc.cfg, nil) + cfg, err := NewConfig(tc.cfg, nil, logptest.NewTestingLogger(t, "")) require.NoError(t, err) assert.Equal(t, tc.expectedConfig, cfg.AgentAuth.Anonymous) }) @@ -175,7 +176,7 @@ func TestSecretTokenAuth(t *testing.T) { }, } { t.Run(name, func(t *testing.T) { - cfg, err := NewConfig(tc.cfg, nil) + cfg, err := NewConfig(tc.cfg, nil, logptest.NewTestingLogger(t, "")) require.NoError(t, err) assert.Equal(t, tc.expected, cfg.AgentAuth.SecretToken) }) diff --git a/internal/beater/config/config.go b/internal/beater/config/config.go index 23c411450c5..85d7daf2f68 100644 --- a/internal/beater/config/config.go +++ b/internal/beater/config/config.go @@ -80,8 +80,8 @@ type Config struct { } // NewConfig creates a Config struct based on the default config and the given input params -func NewConfig(ucfg *config.C, outputESCfg *config.C) (*Config, error) { - logger := logp.NewLogger(logs.Config) +func NewConfig(ucfg *config.C, outputESCfg *config.C, logger *logp.Logger) (*Config, error) { + logger = logger.Named(logs.Config) c := DefaultConfig() if err := ucfg.Unpack(c); err != nil { return nil, errors.Wrap(err, "Error processing configuration") diff --git a/internal/beater/config/config_test.go b/internal/beater/config/config_test.go index a220723565e..056d026386d 100644 --- a/internal/beater/config/config_test.go +++ b/internal/beater/config/config_test.go @@ -28,6 +28,7 @@ import ( "github.com/stretchr/testify/require" "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/elastic/elastic-agent-libs/transport/tlscommon" "github.com/elastic/apm-server/internal/elasticsearch" @@ -650,7 +651,7 @@ func TestUnpackConfig(t *testing.T) { assert.NoError(t, err) } - cfg, err := NewConfig(inpCfg, inpOutputESCfg) + cfg, err := NewConfig(inpCfg, inpOutputESCfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) require.NotNil(t, cfg) @@ -715,7 +716,7 @@ func TestTLSSettings(t *testing.T) { ucfgCfg, err := config.NewConfigFrom(tc.config) require.NoError(t, err) - cfg, err := NewConfig(ucfgCfg, nil) + cfg, err := NewConfig(ucfgCfg, nil, logptest.NewTestingLogger(t, "")) require.NoError(t, err) assert.Equal(t, tc.tls.ClientAuth, cfg.TLS.ClientAuth) }) @@ -752,7 +753,7 @@ func TestNewConfig_ESConfig(t *testing.T) { require.NoError(t, err) // no es config given - cfg, err := NewConfig(ucfg, nil) + cfg, err := NewConfig(ucfg, nil, logptest.NewTestingLogger(t, "")) require.NoError(t, err) assert.Equal(t, elasticsearch.DefaultConfig(), cfg.RumConfig.SourceMapping.ESConfig) assert.Equal(t, elasticsearch.DefaultConfig(), cfg.AgentAuth.APIKey.ESConfig) @@ -760,7 +761,7 @@ func TestNewConfig_ESConfig(t *testing.T) { // with es config outputESCfg := config.MustNewConfigFrom(`{"hosts":["192.0.0.168:9200"]}`) - cfg, err = NewConfig(ucfg, outputESCfg) + cfg, err = NewConfig(ucfg, outputESCfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) assert.NotNil(t, cfg.RumConfig.SourceMapping.ESConfig) assert.Equal(t, []string{"192.0.0.168:9200"}, []string(cfg.RumConfig.SourceMapping.ESConfig.Hosts)) diff --git a/internal/beater/config/sampling_test.go b/internal/beater/config/sampling_test.go index 342d944b2d3..854681d24d2 100644 --- a/internal/beater/config/sampling_test.go +++ b/internal/beater/config/sampling_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestSamplingPoliciesValidation(t *testing.T) { @@ -31,13 +32,13 @@ func TestSamplingPoliciesValidation(t *testing.T) { "sampling.tail.policies": []map[string]interface{}{{ "sample_rate": 0.5, }}, - }), nil) + }), nil, logptest.NewTestingLogger(t, "")) assert.NoError(t, err) }) t.Run("NoPolicies", func(t *testing.T) { c, err := NewConfig(config.MustNewConfigFrom(map[string]interface{}{ "sampling.tail.enabled": true, - }), nil) + }), nil, logptest.NewTestingLogger(t, "")) assert.NoError(t, err) assert.False(t, c.Sampling.Tail.Enabled) }) @@ -47,7 +48,7 @@ func TestSamplingPoliciesValidation(t *testing.T) { "service.name": "foo", "sample_rate": 0.5, }}, - }), nil) + }), nil, logptest.NewTestingLogger(t, "")) assert.NoError(t, err) assert.False(t, c.Sampling.Tail.Enabled) }) diff --git a/internal/beater/interceptors/logging_test.go b/internal/beater/interceptors/logging_test.go index 2fd9e95f21a..d3dd04ce4fe 100644 --- a/internal/beater/interceptors/logging_test.go +++ b/internal/beater/interceptors/logging_test.go @@ -30,7 +30,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestLogging(t *testing.T) { @@ -70,10 +70,9 @@ func TestLogging(t *testing.T) { }, } { observedCore, observedLogs := observer.New(zapcore.InfoLevel) - wrapCore := zap.WrapCore(func(core zapcore.Core) zapcore.Core { + logger := logptest.NewTestingLogger(t, "interceptor.logging.test", zap.WrapCore(func(core zapcore.Core) zapcore.Core { return observedCore - }) - logger := logp.NewLogger("interceptor.logging.test", wrapCore) + })) i := Logging(logger) _, err := i(ctx, nil, info, tc.f) diff --git a/internal/beater/java_attacher/java_attacher.go b/internal/beater/java_attacher/java_attacher.go index 6c526d8a131..b964ba4f44a 100644 --- a/internal/beater/java_attacher/java_attacher.go +++ b/internal/beater/java_attacher/java_attacher.go @@ -68,8 +68,7 @@ type JavaAttacher struct { tmpAttacherLock sync.Mutex } -func New(cfg config.JavaAttacherConfig) (*JavaAttacher, error) { - logger := logp.NewLogger("java-attacher") +func New(cfg config.JavaAttacherConfig, logger *logp.Logger) (*JavaAttacher, error) { if _, err := os.Stat(bundledJavaAttacher); err != nil { return nil, err } @@ -81,7 +80,7 @@ func New(cfg config.JavaAttacherConfig) (*JavaAttacher, error) { "meaning no JVM can be attached to") } attacher := &JavaAttacher{ - logger: logger, + logger: logger.Named("java-attacher"), enabled: cfg.Enabled, agentConfigs: cfg.Config, downloadAgentVersion: cfg.DownloadAgentVersion, diff --git a/internal/beater/java_attacher/java_attacher_nonwindows_test.go b/internal/beater/java_attacher/java_attacher_nonwindows_test.go index 054f67c4e84..70bf168841a 100644 --- a/internal/beater/java_attacher/java_attacher_nonwindows_test.go +++ b/internal/beater/java_attacher/java_attacher_nonwindows_test.go @@ -29,6 +29,7 @@ import ( "strings" "testing" + "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -39,7 +40,7 @@ func TestBuildInvalidCommand(t *testing.T) { require.NoError(t, err) defer os.Remove(f.Name()) - attacher, err := New(cfg) + attacher, err := New(cfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) defer attacher.cleanResources() @@ -61,7 +62,7 @@ func TestBuildCommandWithTempJar(t *testing.T) { require.NoError(t, err) defer os.Remove(f.Name()) - attacher, err := New(cfg) + attacher, err := New(cfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) defer attacher.cleanResources() @@ -87,7 +88,7 @@ func TestBuildCommandWithTempJar(t *testing.T) { assert.Equal(t, want, cmdArgs) cfg.Config["service_name"] = "my-cool-service" - attacher, err = New(cfg) + attacher, err = New(cfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) defer attacher.cleanResources() @@ -103,7 +104,7 @@ func TestTempDirCreation(t *testing.T) { f, err := os.Create(bundledJavaAttacher) require.NoError(t, err) defer os.Remove(f.Name()) - attacher, err := New(cfg) + attacher, err := New(cfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) defer attacher.cleanResources() diff --git a/internal/beater/java_attacher/java_attacher_test.go b/internal/beater/java_attacher/java_attacher_test.go index 6184d0514d5..f2682d92bd9 100644 --- a/internal/beater/java_attacher/java_attacher_test.go +++ b/internal/beater/java_attacher/java_attacher_test.go @@ -26,13 +26,14 @@ import ( "github.com/stretchr/testify/require" "github.com/elastic/apm-server/internal/beater/config" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestNoAttacherCreatedWithoutDiscoveryRules(t *testing.T) { cfg := config.JavaAttacherConfig{ Enabled: true, } - _, err := New(cfg) + _, err := New(cfg, logptest.NewTestingLogger(t, "")) require.Error(t, err) } @@ -68,7 +69,7 @@ func TestDiscoveryRulesAllowlist(t *testing.T) { f, err := os.Create(bundledJavaAttacher) require.NoError(t, err) defer os.Remove(f.Name()) - javaAttacher, err := New(cfg) + javaAttacher, err := New(cfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) defer javaAttacher.cleanResources() discoveryRules := javaAttacher.discoveryRules @@ -94,7 +95,7 @@ func TestConfig(t *testing.T) { f, err := os.Create(bundledJavaAttacher) require.NoError(t, err) defer os.Remove(f.Name()) - javaAttacher, err := New(cfg) + javaAttacher, err := New(cfg, logptest.NewTestingLogger(t, "")) require.NoError(t, err) defer javaAttacher.cleanResources() require.True(t, javaAttacher.enabled) diff --git a/internal/beater/middleware/log_middleware.go b/internal/beater/middleware/log_middleware.go index 1198fa83271..dcd7ec0e167 100644 --- a/internal/beater/middleware/log_middleware.go +++ b/internal/beater/middleware/log_middleware.go @@ -32,10 +32,11 @@ import ( ) // LogMiddleware returns a middleware taking care of logging processing a request in the middleware and the request handler -func LogMiddleware() Middleware { +func LogMiddleware(logger *logp.Logger) Middleware { + logger = logger.Named(logs.Request) return func(h request.Handler) (request.Handler, error) { return func(c *request.Context) { - c.Logger = loggerWithRequestContext(c) + c.Logger = loggerWithRequestContext(logger, c) var err error if c.Logger, err = loggerWithTraceContext(c); err != nil { id := request.IDResponseErrorsInternal @@ -64,8 +65,8 @@ func LogMiddleware() Middleware { } } -func loggerWithRequestContext(c *request.Context) *logp.Logger { - logger := logp.NewLogger(logs.Request).With( +func loggerWithRequestContext(logger *logp.Logger, c *request.Context) *logp.Logger { + logger = logger.With( "url.original", c.Request.URL.String(), "http.request.method", c.Request.Method, "user_agent.original", c.Request.Header.Get(headers.UserAgent), diff --git a/internal/beater/middleware/log_middleware_test.go b/internal/beater/middleware/log_middleware_test.go index 997841f2cfd..71bae37efa7 100644 --- a/internal/beater/middleware/log_middleware_test.go +++ b/internal/beater/middleware/log_middleware_test.go @@ -25,13 +25,14 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/zap" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" "go.elastic.co/apm/v2" "go.elastic.co/apm/v2/apmtest" - "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/elastic/elastic-agent-libs/mapstr" "github.com/elastic/apm-server/internal/beater/headers" @@ -98,15 +99,10 @@ func TestLogMiddleware(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // log setup - observedCore, observedLogs := observer.New(zapcore.DebugLevel) - err := logp.ConfigureWithOutputs(logp.Config{ - Level: logp.DebugLevel, - ToStderr: false, - ToSyslog: false, - ToFiles: false, - ToEventLog: false, - }, observedCore) - require.NoError(t, err) + core, observedLogs := observer.New(zapcore.DebugLevel) + logger := logptest.NewTestingLogger(t, "", zap.WrapCore(func(in zapcore.Core) zapcore.Core { + return zapcore.NewTee(in, core) + })) // prepare and record request c, rec := DefaultContextWithResponseRecorder() @@ -116,7 +112,7 @@ func TestLogMiddleware(t *testing.T) { c.Request = c.Request.WithContext(apm.ContextWithTransaction(c.Request.Context(), tx)) defer tx.End() } - Apply(LogMiddleware(), tc.handler)(c) + Apply(LogMiddleware(logger), tc.handler)(c) // check log lines assert.Equal(t, tc.code, rec.Code) @@ -145,22 +141,17 @@ func TestLogMiddleware(t *testing.T) { } func TestLogMiddlewareRequestBodyBytes(t *testing.T) { - observedCore, observedLogs := observer.New(zapcore.DebugLevel) - err := logp.ConfigureWithOutputs(logp.Config{ - Level: logp.DebugLevel, - ToStderr: false, - ToSyslog: false, - ToFiles: false, - ToEventLog: false, - }, observedCore) - require.NoError(t, err) + core, observedLogs := observer.New(zapcore.DebugLevel) + logger := logptest.NewTestingLogger(t, "", zap.WrapCore(func(in zapcore.Core) zapcore.Core { + return zapcore.NewTee(in, core) + })) c := request.NewContext() c.Reset( httptest.NewRecorder(), httptest.NewRequest(http.MethodGet, "/", strings.NewReader("content")), ) - Apply(LogMiddleware(), HandlerIdle)(c) + Apply(LogMiddleware(logger), HandlerIdle)(c) entries := observedLogs.All() require.Equal(t, 1, len(entries)) diff --git a/internal/beater/otlp/http_test.go b/internal/beater/otlp/http_test.go index 93ab0d32ce0..2926c81f1bb 100644 --- a/internal/beater/otlp/http_test.go +++ b/internal/beater/otlp/http_test.go @@ -44,6 +44,7 @@ import ( "github.com/elastic/apm-server/internal/beater/config" "github.com/elastic/apm-server/internal/beater/monitoringtest" "github.com/elastic/apm-server/internal/beater/ratelimit" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestConsumeTracesHTTP(t *testing.T) { @@ -179,6 +180,7 @@ func newHTTPServer(t *testing.T, batchProcessor modelpb.BatchProcessor) (string, func() bool { return true }, semaphore.NewWeighted(1), mp, + logptest.NewTestingLogger(t, ""), ) require.NoError(t, err) srv := http.Server{Handler: router} diff --git a/internal/beater/server.go b/internal/beater/server.go index 5f721068b6a..49fdbcdd59e 100644 --- a/internal/beater/server.go +++ b/internal/beater/server.go @@ -180,6 +180,7 @@ func newServer(args ServerParams, listener net.Listener) (server, error) { publishReady, args.Semaphore, args.MeterProvider, + args.Logger, ) if err != nil { return server{}, err @@ -239,6 +240,7 @@ func newAgentConfigFetcher( newElasticsearchClient func(*elasticsearch.Config) (*elasticsearch.Client, error), tracer *apm.Tracer, mp metric.MeterProvider, + logger *logp.Logger, ) (agentcfg.Fetcher, func(context.Context) error, error) { // Always use ElasticsearchFetcher, and as a fallback, use: // 1. no fallback if Elasticsearch is explicitly configured @@ -251,7 +253,7 @@ func newAgentConfigFetcher( // Disable fallback because agent config Elasticsearch is explicitly configured. case kibanaClient != nil: var err error - fallbackFetcher, err = agentcfg.NewKibanaFetcher(kibanaClient, cfg.AgentConfig.Cache.Expiration) + fallbackFetcher, err = agentcfg.NewKibanaFetcher(kibanaClient, cfg.AgentConfig.Cache.Expiration, logger) if err != nil { return nil, nil, err } @@ -263,6 +265,6 @@ func newAgentConfigFetcher( if err != nil { return nil, nil, err } - esFetcher := agentcfg.NewElasticsearchFetcher(esClient, cfg.AgentConfig.Cache.Expiration, fallbackFetcher, tracer, mp) + esFetcher := agentcfg.NewElasticsearchFetcher(esClient, cfg.AgentConfig.Cache.Expiration, fallbackFetcher, tracer, mp, logger) return agentcfg.SanitizingFetcher{Fetcher: esFetcher}, esFetcher.Run, nil } diff --git a/internal/beater/server_test.go b/internal/beater/server_test.go index 19766be1518..9a61afea305 100644 --- a/internal/beater/server_test.go +++ b/internal/beater/server_test.go @@ -52,7 +52,6 @@ import ( _ "github.com/elastic/beats/v7/libbeat/outputs/console" _ "github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue" agentconfig "github.com/elastic/elastic-agent-libs/config" - "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/apm-data/model/modelpb" @@ -579,16 +578,7 @@ func TestWrapServerAPMInstrumentationTimeout(t *testing.T) { mp := sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader)) escfg, _ := beatertest.ElasticsearchOutputConfig(t) - observedCore, observedLogs := observer.New(zapcore.DebugLevel) - err := logp.ConfigureWithOutputs(logp.Config{ - Level: logp.DebugLevel, - ToStderr: false, - ToSyslog: false, - ToFiles: false, - ToEventLog: false, - }, observedCore) - require.NoError(t, err) - + srv := beatertest.NewServer(t, beatertest.WithMeterProvider(mp), beatertest.WithConfig(escfg, agentconfig.MustNewConfigFrom( map[string]interface{}{ "instrumentation.enabled": true, @@ -636,7 +626,7 @@ func TestWrapServerAPMInstrumentationTimeout(t *testing.T) { // Assert that logs contain expected values: // - Original error with the status code. // - Request timeout is logged separately with the the original error status code. - logs := observedLogs.Filter(func(l observer.LoggedEntry) bool { + logs := srv.Logs.Filter(func(l observer.LoggedEntry) bool { return l.Level == zapcore.ErrorLevel }).AllUntimed() assert.Len(t, logs, 1) diff --git a/internal/beater/tracing.go b/internal/beater/tracing.go index 3d6705299d0..dcd48460c5b 100644 --- a/internal/beater/tracing.go +++ b/internal/beater/tracing.go @@ -54,6 +54,7 @@ func newTracerServer(cfg *config.Config, listener net.Listener, logger *logp.Log func() bool { return true }, // ready for publishing semaphore, noop.NewMeterProvider(), + logger, ) if err != nil { return nil, err diff --git a/internal/idxmgmt/supporter_factory.go b/internal/idxmgmt/supporter_factory.go index b73aef5b846..34f67838823 100644 --- a/internal/idxmgmt/supporter_factory.go +++ b/internal/idxmgmt/supporter_factory.go @@ -33,13 +33,8 @@ import ( // to data streams. The given root config will be checked for deprecated/removed // configuration, and if any are present warnings will be logged. func NewSupporter(log *logp.Logger, configRoot *config.C) idxmgmt.Supporter { - if log == nil { - log = logp.NewLogger(logs.IndexManagement) - } else { - log = log.Named(logs.IndexManagement) - } if configRoot != nil { - logWarnings(log, configRoot) + logWarnings(log.Named(logs.IndexManagement), configRoot) } return dataStreamsSupporter{} } diff --git a/internal/idxmgmt/supporter_factory_test.go b/internal/idxmgmt/supporter_factory_test.go index d9ebd38784f..807137d4ab9 100644 --- a/internal/idxmgmt/supporter_factory_test.go +++ b/internal/idxmgmt/supporter_factory_test.go @@ -30,11 +30,11 @@ import ( "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/libbeat/idxmgmt" "github.com/elastic/elastic-agent-libs/config" - "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestNewSupporter(t *testing.T) { - supporter := NewSupporter(nil, config.MustNewConfigFrom(map[string]interface{}{})) + supporter := NewSupporter(logptest.NewTestingLogger(t, ""), config.MustNewConfigFrom(map[string]interface{}{})) // The data streams supporter does not set up templates or ILM. These // are expected to be set up externally, typically by Fleet. @@ -62,7 +62,7 @@ func TestNewSupporter(t *testing.T) { func TestNewSupporterWarnings(t *testing.T) { core, observed := observer.New(zapcore.DebugLevel) - logger := logp.NewLogger("", zap.WrapCore(func(in zapcore.Core) zapcore.Core { + logger := logptest.NewTestingLogger(t, "", zap.WrapCore(func(in zapcore.Core) zapcore.Core { return zapcore.NewTee(in, core) })) diff --git a/internal/logs/ratelimit_test.go b/internal/logs/ratelimit_test.go index 01e8e827c71..fa3a130be64 100644 --- a/internal/logs/ratelimit_test.go +++ b/internal/logs/ratelimit_test.go @@ -27,12 +27,12 @@ import ( "go.uber.org/zap/zaptest/observer" "github.com/elastic/apm-server/internal/logs" - "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestWithRateLimit(t *testing.T) { core, observed := observer.New(zapcore.DebugLevel) - logger := logp.NewLogger("bo", zap.WrapCore(func(in zapcore.Core) zapcore.Core { + logger := logptest.NewTestingLogger(t, "bo", zap.WrapCore(func(in zapcore.Core) zapcore.Core { return zapcore.NewTee(in, core) })) diff --git a/internal/publish/pub_test.go b/internal/publish/pub_test.go index c314075ca5f..db68853ad34 100644 --- a/internal/publish/pub_test.go +++ b/internal/publish/pub_test.go @@ -140,7 +140,7 @@ func BenchmarkPublisher(b *testing.B) { srv := httptest.NewServer(mux) defer srv.Close() - supporter, err := idxmgmt.DefaultSupport(logptest.NewTestingLogger(b, "beater_test"), beat.Info{}, nil) + supporter, err := idxmgmt.DefaultSupport(beat.Info{}, nil) require.NoError(b, err) outputGroup, err := outputs.Load(supporter, beat.Info{}, nil, "elasticsearch", config.MustNewConfigFrom(map[string]interface{}{ "hosts": []interface{}{srv.URL}, @@ -157,7 +157,9 @@ func BenchmarkPublisher(b *testing.B) { require.NoError(b, err) pipeline, err := pipeline.New( - beat.Info{}, + beat.Info{ + Logger: logptest.NewTestingLogger(b, "beat"), + }, pipeline.Monitors{ Logger: logptest.NewTestingLogger(b, "monitor"), }, @@ -211,7 +213,9 @@ func newBlockingPipeline(t testing.TB) (*pipeline.Pipeline, *mockClient) { require.NoError(t, err) pipeline, err := pipeline.New( - beat.Info{}, + beat.Info{ + Logger: logptest.NewTestingLogger(t, "beat"), + }, pipeline.Monitors{}, namespace, outputs.Group{Clients: []outputs.Client{client}}, diff --git a/internal/sourcemap/body_caching.go b/internal/sourcemap/body_caching.go index de31d046c35..b41d6e0f19f 100644 --- a/internal/sourcemap/body_caching.go +++ b/internal/sourcemap/body_caching.go @@ -46,8 +46,9 @@ func NewBodyCachingFetcher( backend Fetcher, cacheSize int, invalidationChan <-chan []identifier, + logger *logp.Logger, ) (*BodyCachingFetcher, error) { - logger := logp.NewLogger(logs.Sourcemap) + logger = logger.Named(logs.Sourcemap) lruCache, err := freelru.NewSharded[identifier, *sourcemap.Consumer](uint32(cacheSize), hashStringXXHASH) if err != nil { diff --git a/internal/sourcemap/body_caching_test.go b/internal/sourcemap/body_caching_test.go index 252ddf5d0ee..1ded8bbf9e7 100644 --- a/internal/sourcemap/body_caching_test.go +++ b/internal/sourcemap/body_caching_test.go @@ -27,6 +27,7 @@ import ( "github.com/stretchr/testify/require" "github.com/elastic/apm-server/internal/elasticsearch" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) var unsupportedVersionSourcemap = `{ @@ -45,10 +46,10 @@ func Test_NewCachingFetcher(t *testing.T) { ch := make(chan []identifier) close(ch) - _, err := NewBodyCachingFetcher(nil, -1, ch) + _, err := NewBodyCachingFetcher(nil, -1, ch, logptest.NewTestingLogger(t, "")) require.Error(t, err) - f, err := NewBodyCachingFetcher(nil, 100, ch) + f, err := NewBodyCachingFetcher(nil, 100, ch, logptest.NewTestingLogger(t, "")) require.NoError(t, err) assert.NotNil(t, f.cache) } @@ -160,8 +161,8 @@ func testCachingFetcher(t *testing.T, client *elasticsearch.Client) *BodyCaching ch := make(chan []identifier) close(ch) - esFetcher := NewElasticsearchFetcher(client, "apm-*sourcemap*") - cachingFetcher, err := NewBodyCachingFetcher(esFetcher, 100, ch) + esFetcher := NewElasticsearchFetcher(client, "apm-*sourcemap*", logptest.NewTestingLogger(t, "")) + cachingFetcher, err := NewBodyCachingFetcher(esFetcher, 100, ch, logptest.NewTestingLogger(t, "")) require.NoError(t, err) return cachingFetcher } diff --git a/internal/sourcemap/chained.go b/internal/sourcemap/chained.go index 8d29f11486f..e0617f7b973 100644 --- a/internal/sourcemap/chained.go +++ b/internal/sourcemap/chained.go @@ -33,9 +33,8 @@ type ChainedFetcher struct { logger *logp.Logger } -func NewChainedFetcher(fetchers []Fetcher) *ChainedFetcher { - logger := logp.NewLogger(logs.Sourcemap) - return &ChainedFetcher{logger: logger, fetchers: fetchers} +func NewChainedFetcher(fetchers []Fetcher, logger *logp.Logger) *ChainedFetcher { + return &ChainedFetcher{logger: logger.Named(logs.Sourcemap), fetchers: fetchers} } // Fetch fetches a source map from Kibana. diff --git a/internal/sourcemap/elasticsearch.go b/internal/sourcemap/elasticsearch.go index 7f2eea0551c..5afb86911f4 100644 --- a/internal/sourcemap/elasticsearch.go +++ b/internal/sourcemap/elasticsearch.go @@ -60,9 +60,8 @@ type esGetSourcemapResponse struct { } // NewElasticsearchFetcher returns a Fetcher for fetching source maps stored in Elasticsearch. -func NewElasticsearchFetcher(c *elasticsearch.Client, index string) Fetcher { - logger := logp.NewLogger(logs.Sourcemap) - return &esFetcher{c, index, logger} +func NewElasticsearchFetcher(c *elasticsearch.Client, index string, logger *logp.Logger) Fetcher { + return &esFetcher{c, index, logger.Named(logs.Sourcemap)} } // Fetch fetches a source map from Elasticsearch. diff --git a/internal/sourcemap/kibana.go b/internal/sourcemap/kibana.go index 1e7e1660cea..deef63f56a7 100644 --- a/internal/sourcemap/kibana.go +++ b/internal/sourcemap/kibana.go @@ -51,9 +51,8 @@ type kibanaSourceMapArtifact struct { } // NewKibanaFetcher returns a Fetcher that fetches source maps stored by Kibana. -func NewKibanaFetcher(c *kibana.Client) Fetcher { - logger := logp.NewLogger(logs.Sourcemap) - return &kibanaFetcher{c, logger} +func NewKibanaFetcher(c *kibana.Client, logger *logp.Logger) Fetcher { + return &kibanaFetcher{c, logger.Named(logs.Sourcemap)} } // Fetch fetches a source map from Kibana. diff --git a/internal/sourcemap/kibana_test.go b/internal/sourcemap/kibana_test.go index f7636000a3e..243cd0aa5a2 100644 --- a/internal/sourcemap/kibana_test.go +++ b/internal/sourcemap/kibana_test.go @@ -29,6 +29,7 @@ import ( "github.com/stretchr/testify/require" libkibana "github.com/elastic/elastic-agent-libs/kibana" + "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/elastic/apm-server/internal/kibana" ) @@ -144,5 +145,5 @@ func newTestKibanaFetcher(t testing.TB, h http.HandlerFunc) Fetcher { Host: srv.Listener.Addr().String(), }) require.NoError(t, err) - return NewKibanaFetcher(kibanaClient) + return NewKibanaFetcher(kibanaClient, logptest.NewTestingLogger(t, "")) } diff --git a/internal/sourcemap/metadata_fetcher.go b/internal/sourcemap/metadata_fetcher.go index d0e44ed3407..7f342b3c39e 100644 --- a/internal/sourcemap/metadata_fetcher.go +++ b/internal/sourcemap/metadata_fetcher.go @@ -54,6 +54,7 @@ func NewMetadataFetcher( esClient *elasticsearch.Client, index string, tracer *apm.Tracer, + logger *logp.Logger, ) (MetadataFetcher, <-chan []identifier) { invalidationCh := make(chan []identifier) @@ -62,7 +63,7 @@ func NewMetadataFetcher( index: index, set: make(map[identifier]string), alias: make(map[identifier]*identifier), - logger: logp.NewLogger(logs.Sourcemap), + logger: logger.Named(logs.Sourcemap), init: make(chan struct{}), invalidationChan: invalidationCh, tracer: tracer, diff --git a/internal/sourcemap/metadata_fetcher_test.go b/internal/sourcemap/metadata_fetcher_test.go index c976533b1c9..ea9e7c8f156 100644 --- a/internal/sourcemap/metadata_fetcher_test.go +++ b/internal/sourcemap/metadata_fetcher_test.go @@ -29,10 +29,8 @@ import ( "github.com/stretchr/testify/require" "go.elastic.co/apm/v2/apmtest" "go.elastic.co/apm/v2/transport/transporttest" - "go.uber.org/zap/zapcore" - "go.uber.org/zap/zaptest/observer" - "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/elastic/apm-server/internal/elasticsearch" ) @@ -129,7 +127,7 @@ func TestMetadataFetcher(t *testing.T) { defer cancel() tracer, recorder := transporttest.NewRecorderTracer() - fetcher, _ := NewMetadataFetcher(ctx, esClient, ".apm-source-map", tracer) + fetcher, _ := NewMetadataFetcher(ctx, esClient, ".apm-source-map", tracer, logptest.NewTestingLogger(t, "")) <-fetcher.ready() if tc.expectErr { @@ -218,23 +216,6 @@ func TestInvalidation(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - observedCore, observedLogs := observer.New(zapcore.DebugLevel) - err := logp.ConfigureWithOutputs(logp.Config{ - Level: logp.DebugLevel, - ToStderr: false, - ToSyslog: false, - ToFiles: false, - ToEventLog: false, - }, observedCore) - require.NoError(t, err) - - t.Cleanup(func() { - if t.Failed() { - for _, le := range observedLogs.All() { - t.Log(le) - } - } - }) c := make(chan struct{}) ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -275,7 +256,7 @@ func TestInvalidation(t *testing.T) { defer cancel() rt := apmtest.NewRecordingTracer() - fetcher, invalidationChan := NewMetadataFetcher(ctx, esClient, ".apm-source-map", rt.Tracer) + fetcher, invalidationChan := NewMetadataFetcher(ctx, esClient, ".apm-source-map", rt.Tracer, logptest.NewTestingLogger(t, "")) invCh := make(chan struct{}) go func() { diff --git a/internal/sourcemap/processor_test.go b/internal/sourcemap/processor_test.go index 21d56f546de..766d6be26df 100644 --- a/internal/sourcemap/processor_test.go +++ b/internal/sourcemap/processor_test.go @@ -33,7 +33,6 @@ import ( "google.golang.org/protobuf/testing/protocmp" "github.com/elastic/apm-data/model/modelpb" - "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/elastic/apm-server/internal/elasticsearch" @@ -45,8 +44,8 @@ func TestBatchProcessor(t *testing.T) { close(ch) client := newMockElasticsearchClient(t, http.StatusOK, sourcemapESResponseBody(true, validSourcemap)) - esFetcher := NewElasticsearchFetcher(client, "index") - fetcher, err := NewBodyCachingFetcher(esFetcher, 100, ch) + esFetcher := NewElasticsearchFetcher(client, "index", logptest.NewTestingLogger(t, "")) + fetcher, err := NewBodyCachingFetcher(esFetcher, 100, ch, logptest.NewTestingLogger(t, "")) require.NoError(t, err) originalLinenoWithFilename := uint32(1) @@ -232,7 +231,7 @@ func TestBatchProcessor(t *testing.T) { func TestBatchProcessorElasticsearchUnavailable(t *testing.T) { client := newUnavailableElasticsearchClient(t) - fetcher := NewElasticsearchFetcher(client, "index") + fetcher := NewElasticsearchFetcher(client, "index", logptest.NewTestingLogger(t, "")) nonMatchingFrame := modelpb.StacktraceFrame{ AbsPath: "bundle.js", @@ -255,14 +254,13 @@ func TestBatchProcessorElasticsearchUnavailable(t *testing.T) { } observedCore, observedLogs := observer.New(zapcore.DebugLevel) - wrapCore := zap.WrapCore(func(core zapcore.Core) zapcore.Core { - return observedCore - }) for i := 0; i < 2; i++ { processor := BatchProcessor{ Fetcher: fetcher, - Logger: logp.NewLogger(logs.Stacktrace, wrapCore), + Logger: logptest.NewTestingLogger(t, logs.Stacktrace, zap.WrapCore(func(core zapcore.Core) zapcore.Core { + return observedCore + })), } err := processor.ProcessBatch(context.Background(), &modelpb.Batch{&span, &span}) assert.NoError(t, err) @@ -293,7 +291,7 @@ func TestBatchProcessorTimeout(t *testing.T) { Transport: transport, }) require.NoError(t, err) - fetcher := NewElasticsearchFetcher(client, "index") + fetcher := NewElasticsearchFetcher(client, "index", logptest.NewTestingLogger(t, "")) frame := modelpb.StacktraceFrame{ AbsPath: "bundle.js", diff --git a/internal/sourcemap/sourcemap_fetcher.go b/internal/sourcemap/sourcemap_fetcher.go index 9b5b8700e61..10880dcf25b 100644 --- a/internal/sourcemap/sourcemap_fetcher.go +++ b/internal/sourcemap/sourcemap_fetcher.go @@ -34,11 +34,11 @@ type SourcemapFetcher struct { logger *logp.Logger } -func NewSourcemapFetcher(metadata MetadataFetcher, backend Fetcher) *SourcemapFetcher { +func NewSourcemapFetcher(metadata MetadataFetcher, backend Fetcher, logger *logp.Logger) *SourcemapFetcher { s := &SourcemapFetcher{ metadata: metadata, backend: backend, - logger: logp.NewLogger(logs.Sourcemap), + logger: logger.Named(logs.Sourcemap), } return s diff --git a/internal/sourcemap/sourcemap_fetcher_test.go b/internal/sourcemap/sourcemap_fetcher_test.go index 1d69e8f6a55..69a7b1ec624 100644 --- a/internal/sourcemap/sourcemap_fetcher_test.go +++ b/internal/sourcemap/sourcemap_fetcher_test.go @@ -22,6 +22,7 @@ import ( "fmt" "testing" + "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/go-sourcemap/sourcemap" "github.com/stretchr/testify/assert" ) @@ -105,7 +106,7 @@ func TestSourcemapFetcher(t *testing.T) { close(mFetcher.init) monitor := &monitoredFetcher{matchID: tc.expectedID} - f := NewSourcemapFetcher(&mFetcher, monitor) + f := NewSourcemapFetcher(&mFetcher, monitor, logptest.NewTestingLogger(t, "")) _, err := f.Fetch(context.Background(), tc.fetchedID.name, tc.fetchedID.version, tc.fetchedID.path) assert.NoError(t, err) // make sure we are forwarding to the backend fetcher once diff --git a/systemtest/logging_test.go b/systemtest/logging_test.go index 0d48832a975..bfeacb729ac 100644 --- a/systemtest/logging_test.go +++ b/systemtest/logging_test.go @@ -105,7 +105,7 @@ func TestAPMServerRequestLoggingValid(t *testing.T) { srv.Close() for _, entry := range srv.Logs.All() { - if entry.Logger == "request" && entry.Fields["url.original"] == "/intake/v2/events" { + if entry.Logger == "beater.handler.request" && entry.Fields["url.original"] == "/intake/v2/events" { statusCode, _ := entry.Fields["http.response.status_code"].(float64) logEntries = append(logEntries, entry) requestEntries = append(requestEntries, requestEntry{ diff --git a/x-pack/apm-server/main.go b/x-pack/apm-server/main.go index 563461c18f9..c17821a1086 100644 --- a/x-pack/apm-server/main.go +++ b/x-pack/apm-server/main.go @@ -108,7 +108,7 @@ func newTailSamplingProcessor(args beater.ServerParams) (*sampling.Processor, er } storageDir := paths.Resolve(paths.Data, tailSamplingStorageDir) - db, err := getDB(storageDir, args.MeterProvider) + db, err := getDB(storageDir, args.MeterProvider, args.Logger) if err != nil { return nil, fmt.Errorf("failed to get tail-sampling database: %w", err) } @@ -151,10 +151,10 @@ func newTailSamplingProcessor(args beater.ServerParams) (*sampling.Processor, er TTL: tailSamplingConfig.TTL, DiscardOnWriteFailure: tailSamplingConfig.DiscardOnWriteFailure, }, - }) + }, args.Logger) } -func getDB(storageDir string, mp metric.MeterProvider) (*eventstorage.StorageManager, error) { +func getDB(storageDir string, mp metric.MeterProvider, logger *logp.Logger) (*eventstorage.StorageManager, error) { dbMu.Lock() defer dbMu.Unlock() if db == nil { @@ -162,7 +162,7 @@ func getDB(storageDir string, mp metric.MeterProvider) (*eventstorage.StorageMan if mp != nil { opts = append(opts, eventstorage.WithMeterProvider(mp)) } - sm, err := eventstorage.NewStorageManager(storageDir, opts...) + sm, err := eventstorage.NewStorageManager(storageDir, logger, opts...) if err != nil { return nil, err } diff --git a/x-pack/apm-server/sampling/config_test.go b/x-pack/apm-server/sampling/config_test.go index 29a3b93e112..745db74ecc2 100644 --- a/x-pack/apm-server/sampling/config_test.go +++ b/x-pack/apm-server/sampling/config_test.go @@ -13,6 +13,7 @@ import ( "github.com/elastic/apm-data/model/modelpb" "github.com/elastic/apm-server/x-pack/apm-server/sampling" "github.com/elastic/apm-server/x-pack/apm-server/sampling/eventstorage" + "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/elastic/elastic-transport-go/v8/elastictransport" ) @@ -20,7 +21,7 @@ func TestNewProcessorConfigInvalid(t *testing.T) { var config sampling.Config assertInvalidConfigError := func(expectedError string) { t.Helper() - agg, err := sampling.NewProcessor(config) + agg, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.Error(t, err) require.Nil(t, agg) assert.EqualError(t, err, "invalid tail-sampling config: "+expectedError) diff --git a/x-pack/apm-server/sampling/eventstorage/pebble.go b/x-pack/apm-server/sampling/eventstorage/pebble.go index 5dedcd01895..0ec88ad4631 100644 --- a/x-pack/apm-server/sampling/eventstorage/pebble.go +++ b/x-pack/apm-server/sampling/eventstorage/pebble.go @@ -38,11 +38,11 @@ func eventComparer() *pebble.Comparer { return &comparer } -func OpenEventPebble(storageDir string) (*pebble.DB, error) { +func OpenEventPebble(storageDir string, logger *logp.Logger) (*pebble.DB, error) { // Option values are picked and validated in https://github.com/elastic/apm-server/issues/15568 opts := &pebble.Options{ FormatMajorVersion: pebble.FormatColumnarBlocks, - Logger: logp.NewLogger(logs.Sampling), + Logger: logger.Named(logs.Sampling), MemTableSize: 16 << 20, Levels: []pebble.LevelOptions{ { @@ -57,11 +57,11 @@ func OpenEventPebble(storageDir string) (*pebble.DB, error) { return pebble.Open(filepath.Join(storageDir, "event"), opts) } -func OpenDecisionPebble(storageDir string) (*pebble.DB, error) { +func OpenDecisionPebble(storageDir string, logger *logp.Logger) (*pebble.DB, error) { // Option values are picked and validated in https://github.com/elastic/apm-server/issues/15568 return pebble.Open(filepath.Join(storageDir, "decision"), &pebble.Options{ FormatMajorVersion: pebble.FormatColumnarBlocks, - Logger: logp.NewLogger(logs.Sampling), + Logger: logger.Named(logs.Sampling), MemTableSize: 2 << 20, // big memtables are slow to scan, and significantly slow the hot path Levels: []pebble.LevelOptions{ { diff --git a/x-pack/apm-server/sampling/eventstorage/prefix_test.go b/x-pack/apm-server/sampling/eventstorage/prefix_test.go index b54696e6a3e..54311d32d12 100644 --- a/x-pack/apm-server/sampling/eventstorage/prefix_test.go +++ b/x-pack/apm-server/sampling/eventstorage/prefix_test.go @@ -15,10 +15,11 @@ import ( "github.com/elastic/apm-data/model/modelpb" "github.com/elastic/apm-server/x-pack/apm-server/sampling/eventstorage" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func newEventPebble(t *testing.T) *pebble.DB { - db, err := eventstorage.OpenEventPebble(t.TempDir()) + db, err := eventstorage.OpenEventPebble(t.TempDir(), logptest.NewTestingLogger(t, "")) require.NoError(t, err) t.Cleanup(func() { db.Close() @@ -27,7 +28,7 @@ func newEventPebble(t *testing.T) *pebble.DB { } func newDecisionPebble(t *testing.T) *pebble.DB { - db, err := eventstorage.OpenDecisionPebble(t.TempDir()) + db, err := eventstorage.OpenDecisionPebble(t.TempDir(), logptest.NewTestingLogger(t, "")) require.NoError(t, err) t.Cleanup(func() { db.Close() diff --git a/x-pack/apm-server/sampling/eventstorage/storage_manager.go b/x-pack/apm-server/sampling/eventstorage/storage_manager.go index c1d7f221302..656b2e716f7 100644 --- a/x-pack/apm-server/sampling/eventstorage/storage_manager.go +++ b/x-pack/apm-server/sampling/eventstorage/storage_manager.go @@ -133,11 +133,11 @@ type StorageManager struct { } // NewStorageManager returns a new StorageManager with pebble DB at storageDir. -func NewStorageManager(storageDir string, opts ...StorageManagerOptions) (*StorageManager, error) { +func NewStorageManager(storageDir string, logger *logp.Logger, opts ...StorageManagerOptions) (*StorageManager, error) { sm := &StorageManager{ storageDir: storageDir, runCh: make(chan struct{}, 1), - logger: logp.NewLogger(logs.Sampling), + logger: logger.Named(logs.Sampling), codec: ProtobufCodec{}, getDiskUsage: func() (DiskUsage, error) { usage, err := vfs.Default.GetDiskUsage(storageDir) @@ -176,13 +176,13 @@ func NewStorageManager(storageDir string, opts ...StorageManagerOptions) (*Stora // reset initializes db and storage. func (sm *StorageManager) reset() error { - eventDB, err := OpenEventPebble(sm.storageDir) + eventDB, err := OpenEventPebble(sm.storageDir, sm.logger) if err != nil { return fmt.Errorf("open event db error: %w", err) } sm.eventDB = eventDB - decisionDB, err := OpenDecisionPebble(sm.storageDir) + decisionDB, err := OpenDecisionPebble(sm.storageDir, sm.logger) if err != nil { return fmt.Errorf("open decision db error: %w", err) } diff --git a/x-pack/apm-server/sampling/eventstorage/storage_manager_test.go b/x-pack/apm-server/sampling/eventstorage/storage_manager_test.go index 4c1cf2d85a3..ef566282131 100644 --- a/x-pack/apm-server/sampling/eventstorage/storage_manager_test.go +++ b/x-pack/apm-server/sampling/eventstorage/storage_manager_test.go @@ -15,6 +15,7 @@ import ( "github.com/elastic/apm-data/model/modelpb" "github.com/elastic/apm-server/x-pack/apm-server/sampling/eventstorage" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func newStorageManager(tb testing.TB, opts ...eventstorage.StorageManagerOptions) *eventstorage.StorageManager { @@ -24,7 +25,7 @@ func newStorageManager(tb testing.TB, opts ...eventstorage.StorageManagerOptions } func newStorageManagerNoCleanup(tb testing.TB, path string, opts ...eventstorage.StorageManagerOptions) *eventstorage.StorageManager { - sm, err := eventstorage.NewStorageManager(path, opts...) + sm, err := eventstorage.NewStorageManager(path, logptest.NewTestingLogger(tb, ""), opts...) if err != nil { tb.Fatal(err) } diff --git a/x-pack/apm-server/sampling/processor.go b/x-pack/apm-server/sampling/processor.go index 12af14db494..0fde14b9f05 100644 --- a/x-pack/apm-server/sampling/processor.go +++ b/x-pack/apm-server/sampling/processor.go @@ -58,14 +58,14 @@ type eventMetrics struct { } // NewProcessor returns a new Processor, for tail-sampling trace events. -func NewProcessor(config Config) (*Processor, error) { +func NewProcessor(config Config, logger *logp.Logger) (*Processor, error) { if err := config.Validate(); err != nil { return nil, errors.Wrap(err, "invalid tail-sampling config") } meter := config.MeterProvider.Meter("github.com/elastic/apm-server/x-pack/apm-server/sampling") - logger := logp.NewLogger(logs.Sampling) + logger = logger.Named(logs.Sampling) p := &Processor{ config: config, logger: logger, diff --git a/x-pack/apm-server/sampling/processor_bench_test.go b/x-pack/apm-server/sampling/processor_bench_test.go index 4ae725bcd2a..29938710427 100644 --- a/x-pack/apm-server/sampling/processor_bench_test.go +++ b/x-pack/apm-server/sampling/processor_bench_test.go @@ -17,10 +17,11 @@ import ( "github.com/elastic/apm-data/model/modelpb" "github.com/elastic/apm-server/x-pack/apm-server/sampling" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func BenchmarkProcess(b *testing.B) { - processor, err := sampling.NewProcessor(newTempdirConfig(b).Config) + processor, err := sampling.NewProcessor(newTempdirConfig(b).Config, logptest.NewTestingLogger(b, "")) require.NoError(b, err) go processor.Run() b.Cleanup(func() { processor.Stop(context.Background()) }) diff --git a/x-pack/apm-server/sampling/processor_test.go b/x-pack/apm-server/sampling/processor_test.go index c3a50e0cec9..1ef2cf1a287 100644 --- a/x-pack/apm-server/sampling/processor_test.go +++ b/x-pack/apm-server/sampling/processor_test.go @@ -27,10 +27,11 @@ import ( "github.com/elastic/apm-server/x-pack/apm-server/sampling" "github.com/elastic/apm-server/x-pack/apm-server/sampling/eventstorage" "github.com/elastic/apm-server/x-pack/apm-server/sampling/pubsub/pubsubtest" + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestProcessUnsampled(t *testing.T) { - processor, err := sampling.NewProcessor(newTempdirConfig(t).Config) + processor, err := sampling.NewProcessor(newTempdirConfig(t).Config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) go processor.Run() defer processor.Stop(context.Background()) @@ -73,7 +74,7 @@ func TestProcessAlreadyTailSampled(t *testing.T) { require.NoError(t, config.DB.Flush()) - processor, err := sampling.NewProcessor(config) + processor, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) go processor.Run() defer processor.Stop(context.Background()) @@ -159,7 +160,7 @@ func TestProcessLocalTailSampling(t *testing.T) { published := make(chan string) config.Elasticsearch = pubsubtest.Client(pubsubtest.PublisherChan(published), nil) - processor, err := sampling.NewProcessor(config) + processor, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) trace1 := modelpb.Trace{Id: "0102030405060708090a0b0c0d0e0f10"} @@ -274,7 +275,7 @@ func TestProcessLocalTailSamplingUnsampled(t *testing.T) { tempdirConfig := newTempdirConfig(t) config := tempdirConfig.Config config.FlushInterval = time.Minute - processor, err := sampling.NewProcessor(config) + processor, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) go processor.Run() defer processor.Stop(context.Background()) @@ -341,7 +342,7 @@ func TestProcessLocalTailSamplingPolicyOrder(t *testing.T) { published := make(chan string) config.Elasticsearch = pubsubtest.Client(pubsubtest.PublisherChan(published), nil) - processor, err := sampling.NewProcessor(config) + processor, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) // Send transactions which would match either policy defined above. @@ -417,7 +418,7 @@ func TestProcessRemoteTailSampling(t *testing.T) { } }) - processor, err := sampling.NewProcessor(config) + processor, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) go processor.Run() defer processor.Stop(context.Background()) @@ -525,7 +526,7 @@ func TestProcessDiscardOnWriteFailure(t *testing.T) { config := newTempdirConfig(t).Config config.DiscardOnWriteFailure = discard config.Storage = errorRW{err: errors.New("boom")} - processor, err := sampling.NewProcessor(config) + processor, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) go processor.Run() defer processor.Stop(context.Background()) @@ -561,7 +562,7 @@ func TestGroupsMonitoring(t *testing.T) { config.FlushInterval = time.Minute config.Policies[0].SampleRate = 0.99 - processor, err := sampling.NewProcessor(config) + processor, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) go processor.Run() defer processor.Stop(context.Background()) @@ -610,7 +611,7 @@ func TestStorageMonitoring(t *testing.T) { tempdirConfig := newTempdirConfig(t) config := tempdirConfig.Config - processor, err := sampling.NewProcessor(config) + processor, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) go processor.Run() for i := 0; i < 100; i++ { @@ -648,7 +649,7 @@ func TestStorageLimit(t *testing.T) { // minute, we store some span events, close and re-open the database, so // the size is updated. writeBatch := func(n int, c sampling.Config, assertBatch func(b modelpb.Batch)) *sampling.Processor { - processor, err := sampling.NewProcessor(c) + processor, err := sampling.NewProcessor(c, logptest.NewTestingLogger(t, "")) require.NoError(t, err) go processor.Run() defer processor.Stop(context.Background()) @@ -712,7 +713,7 @@ func TestProcessRemoteTailSamplingPersistence(t *testing.T) { subscriber := pubsubtest.SubscriberChan(subscriberChan) config.Elasticsearch = pubsubtest.Client(nil, subscriber) - processor, err := sampling.NewProcessor(config) + processor, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) go processor.Run() defer processor.Stop(context.Background()) @@ -733,7 +734,7 @@ func TestGracefulShutdown(t *testing.T) { config.Policies = []sampling.Policy{{SampleRate: sampleRate}} config.FlushInterval = time.Minute // disable finalize - processor, err := sampling.NewProcessor(config) + processor, err := sampling.NewProcessor(config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) go processor.Run() @@ -785,7 +786,7 @@ func newTempdirConfig(tb testing.TB) testConfig { )) mp := sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader)) - db, err := eventstorage.NewStorageManager(tempdir, eventstorage.WithMeterProvider(mp)) + db, err := eventstorage.NewStorageManager(tempdir, logptest.NewTestingLogger(tb, ""), eventstorage.WithMeterProvider(mp)) require.NoError(tb, err) tb.Cleanup(func() { db.Close() }) diff --git a/x-pack/apm-server/sampling/pubsub/pubsub.go b/x-pack/apm-server/sampling/pubsub/pubsub.go index b72b3a966c6..77aad25122b 100644 --- a/x-pack/apm-server/sampling/pubsub/pubsub.go +++ b/x-pack/apm-server/sampling/pubsub/pubsub.go @@ -52,9 +52,7 @@ func New(config Config) (*Pubsub, error) { if err := config.Validate(); err != nil { return nil, fmt.Errorf("invalid pubsub config: %w", err) } - if config.Logger == nil { - config.Logger = logp.NewLogger(logs.Sampling) - } + config.Logger = config.Logger.Named(logs.Sampling) return &Pubsub{config: config}, nil } diff --git a/x-pack/apm-server/sampling/pubsub/pubsub_integration_test.go b/x-pack/apm-server/sampling/pubsub/pubsub_integration_test.go index c0c143a2e08..ad4bb06c66e 100644 --- a/x-pack/apm-server/sampling/pubsub/pubsub_integration_test.go +++ b/x-pack/apm-server/sampling/pubsub/pubsub_integration_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/sync/errgroup" + "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/elastic/elastic-transport-go/v8/elastictransport" "github.com/elastic/apm-server/x-pack/apm-server/sampling/pubsub" @@ -54,6 +55,7 @@ func TestElasticsearchIntegration_PublishSampledTraceIDs(t *testing.T) { ServerID: localServerID, FlushInterval: 100 * time.Millisecond, SearchInterval: time.Minute, + Logger: logptest.NewTestingLogger(t, ""), }) require.NoError(t, err) @@ -147,6 +149,7 @@ func TestElasticsearchIntegration_SubscribeSampledTraceIDs(t *testing.T) { ServerID: localServerID, FlushInterval: time.Minute, SearchInterval: 100 * time.Millisecond, + Logger: logptest.NewTestingLogger(t, ""), }) require.NoError(t, err) diff --git a/x-pack/apm-server/sampling/pubsub/pubsub_test.go b/x-pack/apm-server/sampling/pubsub/pubsub_test.go index 90516ff73ae..a3f7687c094 100644 --- a/x-pack/apm-server/sampling/pubsub/pubsub_test.go +++ b/x-pack/apm-server/sampling/pubsub/pubsub_test.go @@ -24,6 +24,7 @@ import ( "golang.org/x/sync/errgroup" "github.com/elastic/apm-server/x-pack/apm-server/sampling/pubsub" + "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/elastic/elastic-transport-go/v8/elastictransport" ) @@ -306,6 +307,7 @@ func newPubsub(t testing.TB, srv *httptest.Server, flushInterval, searchInterval ServerID: serverID, FlushInterval: flushInterval, SearchInterval: searchInterval, + Logger: logptest.NewTestingLogger(t, ""), }) require.NoError(t, err) return sub From 64c24eb8291c9aff88106845c78441df37bb79f3 Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Thu, 24 Apr 2025 19:58:26 +0200 Subject: [PATCH 02/10] Update go.mod --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index db66d63a3a5..2191561b2e0 100644 --- a/go.mod +++ b/go.mod @@ -263,5 +263,3 @@ tool ( gotest.tools/gotestsum honnef.co/go/tools/cmd/staticcheck ) - -replace github.com/elastic/elastic-agent-libs => ../elastic-agent-libs From 502f8cad24ef3b1be61af860c5c48f3cb8624bfb Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Thu, 24 Apr 2025 20:12:02 +0200 Subject: [PATCH 03/10] lint: update logger to use correct methods --- internal/beatcmd/beat.go | 14 +++++++------- x-pack/apm-server/sampling/processor.go | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/beatcmd/beat.go b/internal/beatcmd/beat.go index 201b31cb746..78b43465e54 100644 --- a/internal/beatcmd/beat.go +++ b/internal/beatcmd/beat.go @@ -170,14 +170,14 @@ func (b *Beat) init() error { b.Beat.Info.Logger = logp.NewLogger("") // log paths values to help with troubleshooting - b.Info.Logger.Info("%s", paths.Paths.String()) + b.Info.Logger.Infof("%s", paths.Paths.String()) // Load the unique ID and "first start" info from meta.json. metaPath := paths.Resolve(paths.Data, "meta.json") if err := b.loadMeta(metaPath); err != nil { return err } - b.Info.Logger.Info("Beat ID: %v", b.Info.ID) + b.Info.Logger.Infof("Beat ID: %v", b.Info.ID) // Initialize central config manager. manager, err := management.NewManager(b.Config.Management, b.Registry) @@ -187,11 +187,11 @@ func (b *Beat) init() error { b.Manager = manager if maxProcs := b.Config.MaxProcs; maxProcs > 0 { - b.Info.Logger.Info("Set max procs limit: %v", maxProcs) + b.Info.Logger.Infof("Set max procs limit: %v", maxProcs) runtime.GOMAXPROCS(maxProcs) } if gcPercent := b.Config.GCPercent; gcPercent > 0 { - b.Info.Logger.Info("Set gc percentage to: %v", gcPercent) + b.Info.Logger.Infof("Set gc percentage to: %v", gcPercent) debug.SetGCPercent(gcPercent) } return nil @@ -203,7 +203,7 @@ func (b *Beat) loadMeta(metaPath string) error { FirstStart time.Time `json:"first_start"` } - b.Info.Logger.Debug("beat", "Beat metadata path: %v", metaPath) + b.Info.Logger.Debugf("beat", "Beat metadata path: %v", metaPath) f, err := openRegular(metaPath) if err != nil && !os.IsNotExist(err) { return fmt.Errorf("meta file failed to open: %w", err) @@ -291,7 +291,7 @@ func (b *Beat) Run(ctx context.Context) error { ) } }() - defer b.Info.Logger.Info("%s stopped.", b.Info.Beat) + defer b.Info.Logger.Infof("%s stopped.", b.Info.Beat) if runtime.GOOS == "darwin" { if host, err := sysinfo.Host(); err != nil { @@ -424,7 +424,7 @@ func (b *Beat) Run(ctx context.Context) error { } g.Go(func() error { return runner.Run(ctx) }) } - b.Info.Logger.Info("%s started.", b.Info.Beat) + b.Info.Logger.Infof("%s started.", b.Info.Beat) if err := g.Wait(); err != nil && !errors.Is(err, context.Canceled) { return err } diff --git a/x-pack/apm-server/sampling/processor.go b/x-pack/apm-server/sampling/processor.go index 0fde14b9f05..6c8afd39f90 100644 --- a/x-pack/apm-server/sampling/processor.go +++ b/x-pack/apm-server/sampling/processor.go @@ -337,7 +337,7 @@ func (p *Processor) Run() error { return context.Canceled case pos := <-subscriberPositions: if err := writeSubscriberPosition(p.config.DB, pos); err != nil { - p.rateLimitedLogger.With(logp.Error(err)).With(logp.Reflect("position", pos)).Warn( + p.rateLimitedLogger.With(logp.Error(err)).With(logp.Reflect("position", pos)).Warnf( "failed to write subscriber position: %s", err, ) } From 6fbab1820e5a778295e864cb3c4367b01c1a4a49 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Thu, 24 Apr 2025 20:15:14 +0200 Subject: [PATCH 04/10] lint: fix linter issues --- go.sum | 2 ++ internal/beater/java_attacher/java_attacher_nonwindows_test.go | 3 ++- internal/beater/server_test.go | 2 +- internal/sourcemap/sourcemap_fetcher_test.go | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/go.sum b/go.sum index ff5611100c1..754701c9ca0 100644 --- a/go.sum +++ b/go.sum @@ -175,6 +175,8 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0 github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4= github.com/elastic/elastic-agent-client/v7 v7.17.2 h1:Cl2TeABqWZgW40t5fchGWT/sRk4MDDLWA0d8iHHOxLA= github.com/elastic/elastic-agent-client/v7 v7.17.2/go.mod h1:5irRFqp6HLqtu1S+OeY0jg8x7K6PLL+DW+PwVk1vJnk= +github.com/elastic/elastic-agent-libs v0.19.2 h1:uOLUF/KQQf9t6iKr5mfp3jO7CxVZToCJKbb2iSWMswU= +github.com/elastic/elastic-agent-libs v0.19.2/go.mod h1:1HNxREH8C27kGrJCtKZh/ot8pV8joH8VREP21+FrH5s= github.com/elastic/elastic-agent-system-metrics v0.11.11 h1:Qjh3Zef23PfGlG91AF+9ciNLNQf/8cDJ4CalnLZtV3g= github.com/elastic/elastic-agent-system-metrics v0.11.11/go.mod h1:GNqmKfvOt8PwORjbS6GllNdMfkLpOWyTa7P8oQq4E5o= github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= diff --git a/internal/beater/java_attacher/java_attacher_nonwindows_test.go b/internal/beater/java_attacher/java_attacher_nonwindows_test.go index 70bf168841a..4a9bd6bac83 100644 --- a/internal/beater/java_attacher/java_attacher_nonwindows_test.go +++ b/internal/beater/java_attacher/java_attacher_nonwindows_test.go @@ -29,9 +29,10 @@ import ( "strings" "testing" - "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestBuildInvalidCommand(t *testing.T) { diff --git a/internal/beater/server_test.go b/internal/beater/server_test.go index 9a61afea305..f89de81632d 100644 --- a/internal/beater/server_test.go +++ b/internal/beater/server_test.go @@ -578,7 +578,7 @@ func TestWrapServerAPMInstrumentationTimeout(t *testing.T) { mp := sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader)) escfg, _ := beatertest.ElasticsearchOutputConfig(t) - + srv := beatertest.NewServer(t, beatertest.WithMeterProvider(mp), beatertest.WithConfig(escfg, agentconfig.MustNewConfigFrom( map[string]interface{}{ "instrumentation.enabled": true, diff --git a/internal/sourcemap/sourcemap_fetcher_test.go b/internal/sourcemap/sourcemap_fetcher_test.go index 69a7b1ec624..6e964705c4b 100644 --- a/internal/sourcemap/sourcemap_fetcher_test.go +++ b/internal/sourcemap/sourcemap_fetcher_test.go @@ -22,9 +22,10 @@ import ( "fmt" "testing" - "github.com/elastic/elastic-agent-libs/logp/logptest" "github.com/go-sourcemap/sourcemap" "github.com/stretchr/testify/assert" + + "github.com/elastic/elastic-agent-libs/logp/logptest" ) func TestSourcemapFetcher(t *testing.T) { From 4f75175ca3e1923a43dbdcc418827d13ca79ee15 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Fri, 25 Apr 2025 01:46:16 +0200 Subject: [PATCH 05/10] lint: bump elastic-agent-libs to 0.19.3 --- NOTICE-fips.txt | 4 ++-- NOTICE.txt | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/NOTICE-fips.txt b/NOTICE-fips.txt index 3a6cd9871f6..3ca34ec5623 100644 --- a/NOTICE-fips.txt +++ b/NOTICE-fips.txt @@ -711,11 +711,11 @@ SOFTWARE -------------------------------------------------------------------------------- Dependency : github.com/elastic/elastic-agent-libs -Version: v0.19.2 +Version: v0.19.3 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.19.2/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.19.3/LICENSE: Apache License Version 2.0, January 2004 diff --git a/NOTICE.txt b/NOTICE.txt index 3c1e0fa6953..f7c6206ce44 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -711,11 +711,11 @@ SOFTWARE -------------------------------------------------------------------------------- Dependency : github.com/elastic/elastic-agent-libs -Version: v0.19.2 +Version: v0.19.3 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.19.2/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.19.3/LICENSE: Apache License Version 2.0, January 2004 diff --git a/go.mod b/go.mod index 2191561b2e0..05009102422 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/elastic/apm-data v1.18.0 github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250424141521-26cce27fe81e github.com/elastic/elastic-agent-client/v7 v7.17.2 - github.com/elastic/elastic-agent-libs v0.19.2 + github.com/elastic/elastic-agent-libs v0.19.3 github.com/elastic/elastic-agent-system-metrics v0.11.11 github.com/elastic/elastic-transport-go/v8 v8.7.0 github.com/elastic/gmux v0.3.2 diff --git a/go.sum b/go.sum index 754701c9ca0..b5d85dd300f 100644 --- a/go.sum +++ b/go.sum @@ -175,8 +175,8 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0 github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4= github.com/elastic/elastic-agent-client/v7 v7.17.2 h1:Cl2TeABqWZgW40t5fchGWT/sRk4MDDLWA0d8iHHOxLA= github.com/elastic/elastic-agent-client/v7 v7.17.2/go.mod h1:5irRFqp6HLqtu1S+OeY0jg8x7K6PLL+DW+PwVk1vJnk= -github.com/elastic/elastic-agent-libs v0.19.2 h1:uOLUF/KQQf9t6iKr5mfp3jO7CxVZToCJKbb2iSWMswU= -github.com/elastic/elastic-agent-libs v0.19.2/go.mod h1:1HNxREH8C27kGrJCtKZh/ot8pV8joH8VREP21+FrH5s= +github.com/elastic/elastic-agent-libs v0.19.3 h1:DuSVJMowcV3tHbW44SDzCbVJv3Y696GTBRikcAxwr2A= +github.com/elastic/elastic-agent-libs v0.19.3/go.mod h1:1HNxREH8C27kGrJCtKZh/ot8pV8joH8VREP21+FrH5s= github.com/elastic/elastic-agent-system-metrics v0.11.11 h1:Qjh3Zef23PfGlG91AF+9ciNLNQf/8cDJ4CalnLZtV3g= github.com/elastic/elastic-agent-system-metrics v0.11.11/go.mod h1:GNqmKfvOt8PwORjbS6GllNdMfkLpOWyTa7P8oQq4E5o= github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= From dffaa41a15aac9350ba0eef7f260c906785351a1 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Mon, 28 Apr 2025 18:16:25 +0200 Subject: [PATCH 06/10] fix: resolve a few goroutine leaks in tests --- internal/beater/beater.go | 6 +++++- internal/beater/tracing_test.go | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/beater/beater.go b/internal/beater/beater.go index 4dbe7eeaaa6..98e62a72f00 100644 --- a/internal/beater/beater.go +++ b/internal/beater/beater.go @@ -902,8 +902,12 @@ func newSourcemapFetcher( var fetchers []sourcemap.Fetcher // start background sync job - ctx, cancel := context.WithCancel(context.Background()) + ctx, ctxCancel := context.WithCancel(context.Background()) metadataFetcher, invalidationChan := sourcemap.NewMetadataFetcher(ctx, esClient, sourcemapIndex, tracer, logger) + cancel := func() { + ctxCancel() + <-invalidationChan + } esFetcher := sourcemap.NewElasticsearchFetcher(esClient, sourcemapIndex, logger) size := 128 diff --git a/internal/beater/tracing_test.go b/internal/beater/tracing_test.go index aaf9a3508e3..ee8d3c0571d 100644 --- a/internal/beater/tracing_test.go +++ b/internal/beater/tracing_test.go @@ -100,6 +100,10 @@ func TestServerTracingEnabled(t *testing.T) { if !enabled { assert.False(t, traced) } + + // also close the server to be extra sure leftover request goroutine do not leak after the + // test is over + srv.Close() }) } } From ac2e26e269abf6a02a1cff4a9a4cf962c073ec94 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:15:48 +0200 Subject: [PATCH 07/10] lint: fix compile errors --- x-pack/apm-server/sampling/processor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/apm-server/sampling/processor_test.go b/x-pack/apm-server/sampling/processor_test.go index f8a99658542..cfd4c5ffeb8 100644 --- a/x-pack/apm-server/sampling/processor_test.go +++ b/x-pack/apm-server/sampling/processor_test.go @@ -764,7 +764,7 @@ func TestReadSubscriberPositionFile(t *testing.T) { err := tc.setupFile(filepath.Join(tempdirConfig.tempDir, "subscriber_position.json")) require.NoError(t, err) - processor, err := sampling.NewProcessor(tempdirConfig.Config) + processor, err := sampling.NewProcessor(tempdirConfig.Config, logptest.NewTestingLogger(t, "")) require.NoError(t, err) ret := make(chan error) From 2f1dd22f636d2054c85bc94de4917826255aa568 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:31:01 +0200 Subject: [PATCH 08/10] lint: log debug before starting body caching goroutine --- internal/sourcemap/body_caching.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/sourcemap/body_caching.go b/internal/sourcemap/body_caching.go index b41d6e0f19f..26e2a8165d2 100644 --- a/internal/sourcemap/body_caching.go +++ b/internal/sourcemap/body_caching.go @@ -58,9 +58,9 @@ func NewBodyCachingFetcher( logger.Debugf("Removed id %v", key) }) - go func() { - logger.Debug("listening for invalidation...") + logger.Debug("listening for invalidation...") + go func() { for arr := range invalidationChan { for _, id := range arr { logger.Debugf("Invalidating id %v", id) From bf2a8ff19bc17b6792f077c3730964b2e44b17b0 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:55:27 +0200 Subject: [PATCH 09/10] test: resolve TestInvalidation goroutine leak --- internal/sourcemap/metadata_fetcher_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/sourcemap/metadata_fetcher_test.go b/internal/sourcemap/metadata_fetcher_test.go index ea9e7c8f156..3d99fc13f04 100644 --- a/internal/sourcemap/metadata_fetcher_test.go +++ b/internal/sourcemap/metadata_fetcher_test.go @@ -295,6 +295,9 @@ func TestInvalidation(t *testing.T) { t.Fatal("timed out waiting for invalidations") } } + + cancel() + <-invCh }) } } From ade036cec9f01015dddc4aae3df2a2ec293d7007 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Fri, 2 May 2025 15:43:27 +0200 Subject: [PATCH 10/10] feat: bump beats --- NOTICE-fips.txt | 35 ++--------------------------------- NOTICE.txt | 35 ++--------------------------------- go.mod | 3 +-- go.sum | 10 ++++------ 4 files changed, 9 insertions(+), 74 deletions(-) diff --git a/NOTICE-fips.txt b/NOTICE-fips.txt index a4beb9eb285..cd604e5b5eb 100644 --- a/NOTICE-fips.txt +++ b/NOTICE-fips.txt @@ -455,11 +455,11 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/apm-data@v1.18. -------------------------------------------------------------------------------- Dependency : github.com/elastic/beats/v7 -Version: v7.0.0-alpha2.0.20250424141521-26cce27fe81e +Version: v7.0.0-alpha2.0.20250502132831-ef4bf7d20f61 Licence type (autodetected): Elastic -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/beats/v7@v7.0.0-alpha2.0.20250424141521-26cce27fe81e/LICENSE.txt: +Contents of probable licence file $GOMODCACHE/github.com/elastic/beats/v7@v7.0.0-alpha2.0.20250502132831-ef4bf7d20f61/LICENSE.txt: Source code in this repository is variously licensed under the Apache License Version 2.0, an Apache compatible license, or the Elastic License. Outside of @@ -10631,37 +10631,6 @@ Contents of probable licence file $GOMODCACHE/github.com/inconshreveable/mousetr limitations under the License. --------------------------------------------------------------------------------- -Dependency : github.com/joeshaw/multierror -Version: v0.0.0-20140124173710-69b34d4ec901 -Licence type (autodetected): MIT --------------------------------------------------------------------------------- - -Contents of probable licence file $GOMODCACHE/github.com/joeshaw/multierror@v0.0.0-20140124173710-69b34d4ec901/LICENSE: - -The MIT License (MIT) - -Copyright (c) 2014 Joe Shaw - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - - -------------------------------------------------------------------------------- Dependency : github.com/json-iterator/go Version: v1.1.12 diff --git a/NOTICE.txt b/NOTICE.txt index 33824f33e8f..5ffd01ebbe3 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -455,11 +455,11 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/apm-data@v1.18. -------------------------------------------------------------------------------- Dependency : github.com/elastic/beats/v7 -Version: v7.0.0-alpha2.0.20250424141521-26cce27fe81e +Version: v7.0.0-alpha2.0.20250502132831-ef4bf7d20f61 Licence type (autodetected): Elastic -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/beats/v7@v7.0.0-alpha2.0.20250424141521-26cce27fe81e/LICENSE.txt: +Contents of probable licence file $GOMODCACHE/github.com/elastic/beats/v7@v7.0.0-alpha2.0.20250502132831-ef4bf7d20f61/LICENSE.txt: Source code in this repository is variously licensed under the Apache License Version 2.0, an Apache compatible license, or the Elastic License. Outside of @@ -12128,37 +12128,6 @@ Contents of probable licence file $GOMODCACHE/github.com/jcmturner/rpc/v2@v2.0.3 limitations under the License. --------------------------------------------------------------------------------- -Dependency : github.com/joeshaw/multierror -Version: v0.0.0-20140124173710-69b34d4ec901 -Licence type (autodetected): MIT --------------------------------------------------------------------------------- - -Contents of probable licence file $GOMODCACHE/github.com/joeshaw/multierror@v0.0.0-20140124173710-69b34d4ec901/LICENSE: - -The MIT License (MIT) - -Copyright (c) 2014 Joe Shaw - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - - -------------------------------------------------------------------------------- Dependency : github.com/json-iterator/go Version: v1.1.12 diff --git a/go.mod b/go.mod index a2d4fde6af3..edb9311bf8f 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/dustin/go-humanize v1.0.1 github.com/elastic/apm-aggregation v1.3.0 github.com/elastic/apm-data v1.18.0 - github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250424141521-26cce27fe81e + github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250502132831-ef4bf7d20f61 github.com/elastic/elastic-agent-client/v7 v7.17.2 github.com/elastic/elastic-agent-libs v0.19.3 github.com/elastic/elastic-agent-system-metrics v0.11.11 @@ -150,7 +150,6 @@ require ( github.com/jcmturner/goidentity/v6 v6.0.1 // indirect github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect github.com/jcmturner/rpc/v2 v2.0.3 // indirect - github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect github.com/josephspurrier/goversioninfo v1.4.1 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/kamstrup/intmap v0.5.1 // indirect diff --git a/go.sum b/go.sum index c63244944bf..b10e4bb0397 100644 --- a/go.sum +++ b/go.sum @@ -169,8 +169,8 @@ github.com/elastic/apm-perf v0.0.0-20250207152505-1dbeb202ff22 h1:br+XeQOcxNFSv+ github.com/elastic/apm-perf v0.0.0-20250207152505-1dbeb202ff22/go.mod h1:gE+FV7xXv0/nBenviCvpvnvTpUkjJXtuOWs2UT+ZRtw= github.com/elastic/apm-tools v0.0.0-20250124173757-336011228dbe h1:LDtn/A8Tsfz8DQlbXtmDud9ha9oOGriwJGB7V0Ozik8= github.com/elastic/apm-tools v0.0.0-20250124173757-336011228dbe/go.mod h1:SIlGcpTnnosxZ3OvoRC7ADxhHdlsu/nwUdVMF9OkgYc= -github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250424141521-26cce27fe81e h1:pGAtXOxSp/P+P2MtClKGuTURrEWS0rzpGSJwytXn03Q= -github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250424141521-26cce27fe81e/go.mod h1:aMTmS4PStEA9SXSbujjnyCmrCzS4BYoPQY80LRuDEE8= +github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250502132831-ef4bf7d20f61 h1:GxvdwvQ58zOGrWXaqVFgw2iK5W7LUm6Ovb1OtImHjMc= +github.com/elastic/beats/v7 v7.0.0-alpha2.0.20250502132831-ef4bf7d20f61/go.mod h1:avKhL3XuQ26a9uF3EO3F3zyZtsD1rN1E7SRSkzhIEso= github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0JojNasPgYIA47gpuuns= github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4= github.com/elastic/elastic-agent-client/v7 v7.17.2 h1:Cl2TeABqWZgW40t5fchGWT/sRk4MDDLWA0d8iHHOxLA= @@ -377,8 +377,6 @@ github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJk github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= -github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= -github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= github.com/josephspurrier/goversioninfo v1.4.1 h1:5LvrkP+n0tg91J9yTkoVnt/QgNnrI1t4uSsWjIonrqY= github.com/josephspurrier/goversioninfo v1.4.1/go.mod h1:JWzv5rKQr+MmW+LvM412ToT/IkYDZjaclF2pKDss8IY= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -723,8 +721,8 @@ golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= -golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE= -golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M= +golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=