From 125a2924073e4232b9d3806f08b268971c8293e6 Mon Sep 17 00:00:00 2001 From: Gustavo Caso Date: Mon, 19 Aug 2024 09:43:22 +0200 Subject: [PATCH] [ASCII-2155] add custom go linter to check usage of pkgconfig inside component folder (#28382) Co-authored-by: FlorentClarret --- .custom-gcl.yml | 7 + .github/CODEOWNERS | 3 + .github/workflows/codeql-analysis.yml | 2 +- .golangci.yml | 512 +++++++++++++++++- .../subcommands/dogstatsdstats/command.go | 3 +- cmd/agent/subcommands/integrations/command.go | 2 +- cmd/agent/subcommands/launchgui/command.go | 4 +- .../subcommands/status/command.go | 3 +- .../subcommands/runtime/activity_dump.go | 2 +- .../subcommands/status/command.go | 3 +- cmd/system-probe/subcommands/debug/command.go | 3 +- .../subcommands/runtime/activity_dump.go | 2 +- comp/autoscaling/datadogclient/impl/none.go | 5 +- .../providers/kube_endpoints_test.go | 3 +- .../providers/kube_services_test.go | 3 +- comp/core/flare/helpers/send_flare.go | 3 +- comp/core/gui/guiimpl/agent.go | 12 +- comp/core/gui/guiimpl/checks.go | 10 +- comp/core/tagger/taggerimpl/tagger.go | 4 +- .../internal/containerd/containerd.go | 4 +- .../collectors/internal/docker/docker.go | 8 +- comp/dogstatsd/server/server.go | 2 +- .../collector/impl-pipeline/flare_filler.go | 6 +- comp/otelcol/otlp/collector.go | 5 +- comp/rdnsquerier/impl/rdnsquerier_test.go | 2 +- .../systray/systrayimpl/doconfigure.go | 4 +- pkg/api/security/security.go | 2 +- pkg/api/util/doget.go | 6 +- pkg/cli/subcommands/clusterchecks/command.go | 5 +- pkg/cli/subcommands/health/command.go | 3 +- .../kubelet/common/testing/utils.go | 6 +- pkg/collector/corechecks/loader.go | 4 +- .../portlist/portlist_linux.go | 2 +- .../snmp/internal/discovery/discovery.go | 2 +- pkg/collector/corechecks/systemd/systemd.go | 4 +- pkg/collector/python/init.go | 3 +- pkg/compliance/evaluator_rego.go | 3 +- pkg/config/settings/http/client.go | 5 +- pkg/config/setup/config.go | 2 +- pkg/jmxfetch/jmxfetch.go | 2 +- pkg/linters/components/pkgconfigusage/go.mod | 17 + pkg/linters/components/pkgconfigusage/go.sum | 20 + .../pkgconfigusage/pkgconfigusage.go | 72 +++ .../pkgconfigusage/pkgconfigusage_test.go | 41 ++ pkg/linters/testdata/src/comp/a.go | 9 + .../decoder/legacy_auto_multiline_handler.go | 4 +- pkg/logs/launchers/listener/tcp_test.go | 8 +- pkg/logs/launchers/listener/udp_nix_test.go | 8 +- pkg/logs/launchers/listener/udp_test.go | 2 +- pkg/logs/tailers/windowsevent/tailer_test.go | 12 +- pkg/metrics/metric_test.go | 3 +- pkg/network/tracer/utils_linux.go | 2 +- pkg/security/module/server_linux.go | 10 +- pkg/security/probe/field_handlers_ebpf.go | 2 +- pkg/security/resolvers/netns/resolver.go | 12 +- pkg/security/resolvers/sbom/resolver.go | 2 +- .../security_profile/dump/remote_storage.go | 6 +- pkg/snmp/gosnmplib/gosnmp_log.go | 2 +- pkg/trace/api/api_test.go | 6 +- pkg/trace/api/telemetry_test.go | 6 +- pkg/util/containers/filter.go | 2 +- pkg/util/kubernetes/autoscalers/processor.go | 2 +- pkg/util/pdhutil/pdhhelper.go | 9 +- tasks/install_tasks.py | 39 +- tasks/libs/common/check_tools_version.py | 12 +- tasks/linter.py | 17 +- tasks/modules.py | 1 + .../agent-platform/common/agent_behaviour.go | 2 +- test/new-e2e/tests/npm/test_helpers.go | 2 +- 69 files changed, 873 insertions(+), 123 deletions(-) create mode 100644 .custom-gcl.yml create mode 100644 pkg/linters/components/pkgconfigusage/go.mod create mode 100644 pkg/linters/components/pkgconfigusage/go.sum create mode 100644 pkg/linters/components/pkgconfigusage/pkgconfigusage.go create mode 100644 pkg/linters/components/pkgconfigusage/pkgconfigusage_test.go create mode 100644 pkg/linters/testdata/src/comp/a.go diff --git a/.custom-gcl.yml b/.custom-gcl.yml new file mode 100644 index 0000000000000..45466d9aef0ce --- /dev/null +++ b/.custom-gcl.yml @@ -0,0 +1,7 @@ +version: v1.59.1 + +name: golangci-lint + +plugins: + - module: 'github.com/DataDog/datadog-agent/pkg/linters/components/pkgconfigusage' + path: ./pkg/linters/components/pkgconfigusage diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 5667225e22ed8..98b377a033069 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -19,6 +19,7 @@ /.go-version @DataDog/agent-shared-components @DataDog/agent-delivery # Go linters and pre-commit config /.golangci.yml @DataDog/agent-devx-loops +/.custom-gcl.yml @DataDog/agent-devx-loops /.pre-commit-config.yaml @DataDog/agent-devx-loops /CHANGELOG.rst @DataDog/agent-delivery @@ -426,6 +427,8 @@ /pkg/util/testutil/flake @DataDog/agent-devx-loops /pkg/util/trie @DataDog/container-integrations /pkg/languagedetection @DataDog/processes @DataDog/universal-service-monitoring +/pkg/linters/ @DataDog/agent-devx-loops +/pkg/linters/components/ @DataDog/agent-shared-components /pkg/logs/ @DataDog/agent-metrics-logs /pkg/logs/launchers/windowsevent @DataDog/agent-metrics-logs @DataDog/windows-agent /pkg/logs/tailers/windowsevent @DataDog/agent-metrics-logs @DataDog/windows-agent diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 5ac98f7c6cd52..cb1d0be9db095 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -54,7 +54,7 @@ jobs: - name: Build DataDog agent run: | - invoke install-tools + invoke install-tools --no-custom-golangci-lint invoke deps invoke agent.build --build-exclude=systemd diff --git a/.golangci.yml b/.golangci.yml index b74881792e806..47d6301319f54 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -59,7 +59,512 @@ issues: # We are using it and it's not clear how to replace it. - text: "Temporary has been deprecated since Go 1.18" linters: [staticcheck] - + # Treat this list as a TODO for fixing issues with pkgconfigusage custom linter + # DO NOT ADD NEW ENTRIES + - path: comp/api/api/apiimpl/internal/config/endpoint.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/component.go + linters: + - pkgconfigusage + - path: comp/process/forwarders/forwardersimpl/forwarders.go + linters: + - pkgconfigusage + - path: comp/process/profiler/profilerimpl/profiler.go + linters: + - pkgconfigusage + - path: comp/logs/agent/agentimpl/agent.go + linters: + - pkgconfigusage + - path: comp/logs/agent/agentimpl/agent_core_init.go + linters: + - pkgconfigusage + - path: comp/logs/agent/agentimpl/serverless.go + linters: + - pkgconfigusage + - path: comp/logs/agent/agentimpl/agent_test.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/cloudfoundry/vm/cf_vm.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/kubemetadata/kubemetadata.go + linters: + - pkgconfigusage + - path: comp/trace/config/component.go + linters: + - pkgconfigusage + - path: comp/trace/config/config.go + linters: + - pkgconfigusage + - path: comp/trace/config/config_mock.go + linters: + - pkgconfigusage + - path: comp/trace/config/hostname.go + linters: + - pkgconfigusage + - path: comp/trace/config/remote.go + linters: + - pkgconfigusage + - path: comp/trace/config/setup.go + linters: + - pkgconfigusage + - path: comp/trace/config/config_test.go + linters: + - pkgconfigusage + - path: comp/remote-config/rcclient/rcclientimpl/rcclient.go + linters: + - pkgconfigusage + - path: comp/remote-config/rcclient/rcclientimpl/rcclient_test.go + linters: + - pkgconfigusage + - path: comp/agent/cloudfoundrycontainer/cloudfoundrycontainerimpl/cloudfoundrycontainer.go + linters: + - pkgconfigusage + - path: comp/metadata/internal/util/inventory_enabled.go + linters: + - pkgconfigusage + - path: comp/process/expvars/expvarsimpl/expvars.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/cloudfoundry/container/cf_container.go + linters: + - pkgconfigusage + - path: comp/api/api/apiimpl/listener.go + linters: + - pkgconfigusage + - path: comp/api/api/apiimpl/server.go + linters: + - pkgconfigusage + - path: comp/api/api/apiimpl/server_cmd.go + linters: + - pkgconfigusage + - path: comp/api/api/apiimpl/server_ipc.go + linters: + - pkgconfigusage + - path: comp/metadata/host/hostimpl/utils/common.go + linters: + - pkgconfigusage + - path: comp/metadata/host/hostimpl/utils/host.go + linters: + - pkgconfigusage + - path: comp/metadata/host/hostimpl/utils/meta.go + linters: + - pkgconfigusage + - path: comp/metadata/host/hostimpl/utils/host_test.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/remote/processcollector/process_collector.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/remote/processcollector/process_collector_test.go + linters: + - pkgconfigusage + - path: comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go + linters: + - pkgconfigusage + - path: comp/metadata/host/hostimpl/host.go + linters: + - pkgconfigusage + - path: comp/metadata/host/hostimpl/payload.go + linters: + - pkgconfigusage + - path: comp/core/tagger/taggerimpl/collectors/ecs_common.go + linters: + - pkgconfigusage + - path: comp/core/tagger/taggerimpl/collectors/workloadmeta_extract.go + linters: + - pkgconfigusage + - path: comp/core/tagger/taggerimpl/collectors/workloadmeta_main.go + linters: + - pkgconfigusage + - path: comp/core/tagger/taggerimpl/collectors/ecs_common_test.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/kubelet/kubelet.go + linters: + - pkgconfigusage + - path: comp/metadata/inventoryotel/inventoryotelimpl/inventoryotel_test.go + linters: + - pkgconfigusage + - path: comp/metadata/host/hostimpl/hosttags/tags.go + linters: + - pkgconfigusage + - path: comp/metadata/host/hostimpl/hosttags/tags_test.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/listeners/ratelimit/mem_based_rate_limiter.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/cloudfoundry.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/clusterchecks.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/config_reader.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/consul.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/container.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/endpointschecks.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/etcd.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_endpoints.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_endpoints_file.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_services.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_services_file.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/prometheus_common.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/prometheus_pods.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/prometheus_services.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/providers.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/remote_config.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/utils.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/zookeeper.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/file_test.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_endpoints_test.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_services_test.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/prometheus_common_test.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/prometheus_services_test.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/utils_test.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/listeners/named_pipe_nowindows.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/listeners/udp.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/listeners/uds_common.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/listeners/uds_datagram.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/listeners/uds_stream.go + linters: + - pkgconfigusage + - path: comp/metadata/inventoryagent/inventoryagentimpl/inventoryagent_test.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/common/utils/container_collect_all.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/common/utils/prometheus.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/common/utils/prometheus_apiserver_test.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/common/utils/prometheus_kubelet_test.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/serverDebug/serverdebugimpl/debug.go + linters: + - pkgconfigusage + - path: comp/otelcol/otlp/collector_test.go + linters: + - pkgconfigusage + - path: comp/core/hostname/remotehostnameimpl/hostname.go + linters: + - pkgconfigusage + - path: comp/trace/agent/impl/agent.go + linters: + - pkgconfigusage + - path: comp/trace/agent/impl/run.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/server/batch.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/server/float64_list_pool.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/server/parse.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/server/server.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/server/serverless.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/server/server_bench_test.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/server/server_test.go + linters: + - pkgconfigusage + - path: comp/process/agent/agentimpl/agent.go + linters: + - pkgconfigusage + - path: comp/process/apiserver/apiserver.go + linters: + - pkgconfigusage + - path: comp/remote-config/rcservice/rcserviceimpl/rcservice.go + linters: + - pkgconfigusage + - path: comp/netflow/config/config_test.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/listeners/common.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/listeners/container.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/listeners/environment.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/listeners/kubelet.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/listeners/service.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/listeners/staticconfig.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/listeners/snmp_test.go + linters: + - pkgconfigusage + - path: comp/core/tagger/params.go + linters: + - pkgconfigusage + - path: comp/remote-config/rcservicemrf/rcservicemrfimpl/rcservicemrf.go + linters: + - pkgconfigusage + - path: comp/process/status/statusimpl/status.go + linters: + - pkgconfigusage + - path: comp/agent/jmxlogger/jmxloggerimpl/jmxlogger.go + linters: + - pkgconfigusage + - path: comp/core/tagger/taggerimpl/remote/tagger.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/mapper/mapper.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/mapper/mapper_test.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/remote/workloadmeta/workloadmeta.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/remote/workloadmeta/workloadmeta_test.go + linters: + - pkgconfigusage + - path: comp/forwarder/eventplatform/eventplatformimpl/epforwarder.go + linters: + - pkgconfigusage + - path: comp/core/gui/guiimpl/checks.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/replay/impl/capture.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/autodiscoveryimpl/autoconfig.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/autodiscoveryimpl/secrets.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/autodiscoveryimpl/autoconfig_test.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/packets/pool.go + linters: + - pkgconfigusage + - path: comp/process/agent/status.go + linters: + - pkgconfigusage + - path: comp/core/sysprobeconfig/component.go + linters: + - pkgconfigusage + - path: comp/core/tagger/taglist/taglist.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/remote/generic.go + linters: + - pkgconfigusage + - path: comp/core/hostname/hostnameimpl/service_test.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/status/status.go + linters: + - pkgconfigusage + - path: comp/core/sysprobeconfig/sysprobeconfigimpl/config.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/docker/docker.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/docker/image_sbom_trivy.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/containerd/containerd.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/containerd/image_sbom_trivy.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/containerd/network_linux.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/ecs/ecs.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/ecsfargate/ecsfargate.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/podman/podman.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/internal/process/process_collector.go + linters: + - pkgconfigusage + - path: comp/core/workloadmeta/collectors/util/process_util_linux.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/listeners/ratelimit/cgroup_memory_usage_linux.g + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/cloudfoundry_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/consul_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/endpointschecks_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/etcd_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_endpoints_file_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_endpoints_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_services_file_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_services_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/prometheus_pods_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/prometheus_services_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/zookeeper_nop.go + linters: + - pkgconfigusage + - path: comp/otelcol/otlp/no_otlp.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/cloudfoundry_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/consul_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/etcd_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_endpoints_file_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_endpoints_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_services_file_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_services_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/prometheus_services_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/zookeeper_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/cloudfoundry_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/endpointschecks_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_endpoints_file_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_endpoints_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_services_file_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/kube_services_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/prometheus_pods_nop.go + linters: + - pkgconfigusage + - path: comp/core/autodiscovery/providers/prometheus_services_nop.go + linters: + - pkgconfigusage + - path: comp/systray/systray/systrayimpl/doflare.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/listeners/named_pipe_windows.go + linters: + - pkgconfigusage + - path: comp/dogstatsd/packets/packet_manager_windows.go + linters: + - pkgconfigusage linters: disable-all: true enable: @@ -76,6 +581,7 @@ linters: - bodyclose # checks whether HTTP response body is closed successfully - gosimple # Linter for Go source code that specializes in simplifying code. - gocheckcompilerdirectives # Checks Go compiler directives syntax + - pkgconfigusage # Linter for checking usage of pkgconfig inside components folder linters-settings: depguard: @@ -156,3 +662,7 @@ linters-settings: - name: var-naming # non-default rules: - name: duplicated-imports + custom: + pkgconfigusage: + type: "module" + description: "Check usage of pkgconfig in components folder" \ No newline at end of file diff --git a/cmd/agent/subcommands/dogstatsdstats/command.go b/cmd/agent/subcommands/dogstatsdstats/command.go index 5b5cfdbbd43ff..c8c12ce29f9da 100644 --- a/cmd/agent/subcommands/dogstatsdstats/command.go +++ b/cmd/agent/subcommands/dogstatsdstats/command.go @@ -9,6 +9,7 @@ package dogstatsdstats import ( "bytes" "encoding/json" + "errors" "fmt" "os" @@ -88,7 +89,7 @@ func requestDogstatsdStats(_ log.Component, config config.Component, cliParams * json.Unmarshal(r, &errMap) //nolint:errcheck // If the error has been marshalled into a json object, check it and return it properly if err, found := errMap["error"]; found { - e = fmt.Errorf(err) + e = errors.New(err) } if len(errMap["error_type"]) > 0 { diff --git a/cmd/agent/subcommands/integrations/command.go b/cmd/agent/subcommands/integrations/command.go index 9bcf4b7dc63a1..867f85bfa945b 100644 --- a/cmd/agent/subcommands/integrations/command.go +++ b/cmd/agent/subcommands/integrations/command.go @@ -860,7 +860,7 @@ func moveConfigurationFiles(srcFolder string, dstFolder string) error { ))) } if errorMsg != "" { - return fmt.Errorf(errorMsg) + return errors.New(errorMsg) } return nil } diff --git a/cmd/agent/subcommands/launchgui/command.go b/cmd/agent/subcommands/launchgui/command.go index c88c53f5a98a0..dda6794fb7c2a 100644 --- a/cmd/agent/subcommands/launchgui/command.go +++ b/cmd/agent/subcommands/launchgui/command.go @@ -66,9 +66,9 @@ func launchGui(config config.Component, _ *cliParams, _ log.Component) error { // Open the GUI in a browser, passing the authorization tokens as parameters err = open("http://127.0.0.1:" + guiPort + "/auth?intent=" + string(intentToken)) if err != nil { - return fmt.Errorf("error opening GUI: " + err.Error()) + return fmt.Errorf("error opening GUI: %s", err.Error()) } - fmt.Printf("GUI opened at 127.0.0.1:" + guiPort + "\n") + fmt.Printf("GUI opened at 127.0.0.1:%s\n", guiPort) return nil } diff --git a/cmd/cluster-agent/subcommands/status/command.go b/cmd/cluster-agent/subcommands/status/command.go index 5d547bec4c6fd..7f4e3084cb6f8 100644 --- a/cmd/cluster-agent/subcommands/status/command.go +++ b/cmd/cluster-agent/subcommands/status/command.go @@ -11,6 +11,7 @@ package status import ( "bytes" "encoding/json" + "errors" "fmt" "net/url" "os" @@ -96,7 +97,7 @@ func run(log log.Component, config config.Component, cliParams *cliParams) error json.Unmarshal(r, &errMap) //nolint:errcheck // If the error has been marshalled into a json object, check it and return it properly if err, found := errMap["error"]; found { - e = fmt.Errorf(err) + e = errors.New(err) } fmt.Printf(` diff --git a/cmd/security-agent/subcommands/runtime/activity_dump.go b/cmd/security-agent/subcommands/runtime/activity_dump.go index 158a42648cf6b..46465a0986dd2 100644 --- a/cmd/security-agent/subcommands/runtime/activity_dump.go +++ b/cmd/security-agent/subcommands/runtime/activity_dump.go @@ -134,7 +134,7 @@ func generateDumpCommands(globalParams *command.GlobalParams) []*cobra.Command { activityDumpGenerateDumpCmd := &cobra.Command{ Use: "dump", Short: "generate an activity dump", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { return fxutil.OneShot(generateActivityDump, fx.Supply(cliParams), fx.Supply(core.BundleParams{ diff --git a/cmd/security-agent/subcommands/status/command.go b/cmd/security-agent/subcommands/status/command.go index d64a016f6b0af..5b03ffac1913d 100644 --- a/cmd/security-agent/subcommands/status/command.go +++ b/cmd/security-agent/subcommands/status/command.go @@ -9,6 +9,7 @@ package status import ( "bytes" "encoding/json" + "errors" "fmt" "net/url" "os" @@ -94,7 +95,7 @@ func runStatus(_ log.Component, config config.Component, _ secrets.Component, pa json.Unmarshal(r, &errMap) //nolint:errcheck // If the error has been marshalled into a json object, check it and return it properly if err, found := errMap["error"]; found { - e = fmt.Errorf(err) + e = errors.New(err) } fmt.Printf(` diff --git a/cmd/system-probe/subcommands/debug/command.go b/cmd/system-probe/subcommands/debug/command.go index ec220f144cd2c..454749bfcf2cd 100644 --- a/cmd/system-probe/subcommands/debug/command.go +++ b/cmd/system-probe/subcommands/debug/command.go @@ -8,6 +8,7 @@ package debug import ( "encoding/json" + "errors" "fmt" "strconv" @@ -79,7 +80,7 @@ func debugRuntime(sysprobeconfig sysprobeconfig.Component, cliParams *cliParams) _ = json.Unmarshal(r, &errMap) // If the error has been marshalled into a json object, check it and return it properly if e, found := errMap["error"]; found { - return fmt.Errorf(e) + return errors.New(e) } return fmt.Errorf("Could not reach system-probe: %s\nMake sure system-probe is running before running this command and contact support if you continue having issues", err) diff --git a/cmd/system-probe/subcommands/runtime/activity_dump.go b/cmd/system-probe/subcommands/runtime/activity_dump.go index 60ba970cdfa6a..72096d1160bbd 100644 --- a/cmd/system-probe/subcommands/runtime/activity_dump.go +++ b/cmd/system-probe/subcommands/runtime/activity_dump.go @@ -133,7 +133,7 @@ func generateDumpCommands(globalParams *command.GlobalParams) []*cobra.Command { activityDumpGenerateDumpCmd := &cobra.Command{ Use: "dump", Short: "generate an activity dump", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { return fxutil.OneShot(generateActivityDump, fx.Supply(cliParams), fx.Supply(core.BundleParams{ diff --git a/comp/autoscaling/datadogclient/impl/none.go b/comp/autoscaling/datadogclient/impl/none.go index 18181f8d6961b..cfd669d4eb155 100644 --- a/comp/autoscaling/datadogclient/impl/none.go +++ b/comp/autoscaling/datadogclient/impl/none.go @@ -7,8 +7,9 @@ package datadogclientimpl import ( - datadogclient "github.com/DataDog/datadog-agent/comp/autoscaling/datadogclient/def" "gopkg.in/zorkian/go-datadog-api.v2" + + datadogclient "github.com/DataDog/datadog-agent/comp/autoscaling/datadogclient/def" ) // ImplNone is a noop datadogclient implementation @@ -22,7 +23,7 @@ func NewNone() datadogclient.Component { } // QueryMetrics does nothing for the noop datadogclient implementation -func (d *ImplNone) QueryMetrics(from, to int64, query string) ([]datadog.Series, error) { +func (d *ImplNone) QueryMetrics(_, _ int64, _ string) ([]datadog.Series, error) { // noop return nil, nil } diff --git a/comp/core/autodiscovery/providers/kube_endpoints_test.go b/comp/core/autodiscovery/providers/kube_endpoints_test.go index 36b78d68d8add..3ea35201e26a0 100644 --- a/comp/core/autodiscovery/providers/kube_endpoints_test.go +++ b/comp/core/autodiscovery/providers/kube_endpoints_test.go @@ -9,7 +9,6 @@ package providers import ( "context" - "fmt" "strings" "testing" "time" @@ -463,7 +462,7 @@ func TestGenerateConfigs(t *testing.T) { }, }, } { - t.Run(fmt.Sprintf(tc.name), func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { cfgs := generateConfigs(tc.template, tc.resolveMode, tc.endpoints) assert.EqualValues(t, tc.expectedOut, cfgs) }) diff --git a/comp/core/autodiscovery/providers/kube_services_test.go b/comp/core/autodiscovery/providers/kube_services_test.go index fcecd31581219..57da4676c08f1 100644 --- a/comp/core/autodiscovery/providers/kube_services_test.go +++ b/comp/core/autodiscovery/providers/kube_services_test.go @@ -9,7 +9,6 @@ package providers import ( "context" - "fmt" "strings" "testing" "time" @@ -241,7 +240,7 @@ func TestParseKubeServiceAnnotations(t *testing.T) { }, }, } { - t.Run(fmt.Sprintf(tc.name), func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { cfg := config.NewConfig("datadog", "DD", strings.NewReplacer(".", "_")) if tc.hybrid { cfg.SetWithoutSource("cluster_checks.support_hybrid_ignore_ad_tags", true) diff --git a/comp/core/flare/helpers/send_flare.go b/comp/core/flare/helpers/send_flare.go index be2d06b157a32..5246ee5306469 100644 --- a/comp/core/flare/helpers/send_flare.go +++ b/comp/core/flare/helpers/send_flare.go @@ -8,6 +8,7 @@ package helpers import ( "context" "encoding/json" + "errors" "fmt" "io" "mime/multipart" @@ -184,7 +185,7 @@ func analyzeResponse(r *http.Response, apiKey string) (string, error) { if res.Error != "" { response := fmt.Sprintf("An error occurred while uploading the flare: %s. Please contact support by email.", res.Error) - return response, fmt.Errorf("%s", res.Error) + return response, errors.New(res.Error) } return fmt.Sprintf("Your logs were successfully uploaded. For future reference, your internal case id is %d", res.CaseID), nil diff --git a/comp/core/gui/guiimpl/agent.go b/comp/core/gui/guiimpl/agent.go index 8604467c25e18..e75b92b66946c 100644 --- a/comp/core/gui/guiimpl/agent.go +++ b/comp/core/gui/guiimpl/agent.go @@ -67,7 +67,7 @@ func getStatus(w http.ResponseWriter, r *http.Request, statusComponent status.Co } if err != nil { - log.Errorf("Error getting status: " + err.Error()) + log.Errorf("Error getting status: %s", err.Error()) w.Write([]byte("Error getting status: " + err.Error())) return } @@ -81,7 +81,7 @@ func getStatus(w http.ResponseWriter, r *http.Request, statusComponent status.Co func getVersion(w http.ResponseWriter, _ *http.Request) { version, e := version.Agent() if e != nil { - log.Errorf("Error getting version: " + e.Error()) + log.Errorf("Error getting version: %s", e.Error()) w.Write([]byte("Error: " + e.Error())) return } @@ -95,7 +95,7 @@ func getVersion(w http.ResponseWriter, _ *http.Request) { func getHostname(w http.ResponseWriter, r *http.Request) { hname, e := hostname.Get(r.Context()) if e != nil { - log.Errorf("Error getting hostname: " + e.Error()) + log.Errorf("Error getting hostname: %s", e.Error()) w.Write([]byte("Error: " + e.Error())) return } @@ -153,19 +153,19 @@ func makeFlare(w http.ResponseWriter, r *http.Request, flare flare.Component) { filePath, e := flare.Create(nil, nil) if e != nil { w.Write([]byte("Error creating flare zipfile: " + e.Error())) - log.Errorf("Error creating flare zipfile: " + e.Error()) + log.Errorf("Error creating flare zipfile: %s", e.Error()) return } res, e := flare.Send(filePath, payload.CaseID, payload.Email, helpers.NewLocalFlareSource()) if e != nil { w.Write([]byte("Flare zipfile successfully created: " + filePath + "

" + e.Error())) - log.Errorf("Flare zipfile successfully created: " + filePath + "\n" + e.Error()) + log.Errorf("Flare zipfile successfully created: %s\n%s", filePath, e.Error()) return } w.Write([]byte("Flare zipfile successfully created: " + filePath + "

" + res)) - log.Errorf("Flare zipfile successfully created: " + filePath + "\n" + res) + log.Infof("Flare zipfile successfully created: %s\n%s", filePath, res) } // Restarts the agent using the appropriate (platform-specific) restart function diff --git a/comp/core/gui/guiimpl/checks.go b/comp/core/gui/guiimpl/checks.go index a66ba66a93d45..c72a4e8f39c64 100644 --- a/comp/core/gui/guiimpl/checks.go +++ b/comp/core/gui/guiimpl/checks.go @@ -83,7 +83,7 @@ func runCheckHandler(collector collector.Component, ac autodiscovery.Component) for _, ch := range instances { collector.RunCheck(ch) //nolint:errcheck } - log.Infof("Scheduled new check: " + name) + log.Infof("Scheduled new check: %s", name) } } @@ -156,14 +156,14 @@ func reloadCheckHandler(collector collector.Component, ac autodiscovery.Componen name := html.EscapeString(mux.Vars(r)["name"]) instances := pkgcollector.GetChecksByNameForConfigs(name, ac.GetAllConfigs()) if len(instances) == 0 { - log.Errorf("Can't reload " + name + ": check has no new instances.") + log.Errorf("Can't reload %s: check has no new instances.", name) w.Write([]byte("Can't reload " + name + ": check has no new instances")) return } killed, e := collector.ReloadAllCheckInstances(name, instances) if e != nil { - log.Errorf("Error reloading check: " + e.Error()) + log.Errorf("Error reloading check: %s", e.Error()) w.Write([]byte("Error reloading check: " + e.Error())) return } @@ -309,7 +309,7 @@ func setCheckConfigFile(w http.ResponseWriter, r *http.Request) { return } - log.Infof("Successfully wrote new " + fileName + " config file.") + log.Infof("Successfully wrote new %s config file.", fileName) w.Write([]byte("Success")) } else if r.Method == "DELETE" { // Attempt to write new configs to custom checks directory @@ -336,7 +336,7 @@ func setCheckConfigFile(w http.ResponseWriter, r *http.Request) { return } - log.Infof("Successfully disabled integration " + fileName + " config file.") + log.Infof("Successfully disabled integration %s config file.", fileName) w.Write([]byte("Success")) } } diff --git a/comp/core/tagger/taggerimpl/tagger.go b/comp/core/tagger/taggerimpl/tagger.go index 0292acddf03b4..65e75abe51ddd 100644 --- a/comp/core/tagger/taggerimpl/tagger.go +++ b/comp/core/tagger/taggerimpl/tagger.go @@ -437,7 +437,7 @@ func (t *TaggerClient) EnrichTags(tb tagset.TagsAccumulator, originInfo taggerty if originInfo.FromUDS != packets.NoOrigin && (originInfo.FromTag == "" || !t.datadogConfig.dogstatsdEntityIDPrecedenceEnabled) { if err := t.AccumulateTagsFor(originInfo.FromUDS, cardinality, tb); err != nil { - t.log.Errorf(err.Error()) + t.log.Errorf("%s", err.Error()) } } @@ -462,7 +462,7 @@ func (t *TaggerClient) EnrichTags(tb tagset.TagsAccumulator, originInfo taggerty // Tag using Local Data if originInfo.FromUDS != packets.NoOrigin { if err := t.AccumulateTagsFor(originInfo.FromUDS, cardinality, tb); err != nil { - t.log.Errorf(err.Error()) + t.log.Errorf("%s", err.Error()) } } diff --git a/comp/core/workloadmeta/collectors/internal/containerd/containerd.go b/comp/core/workloadmeta/collectors/internal/containerd/containerd.go index 553f414551041..1cf223bcbc1a8 100644 --- a/comp/core/workloadmeta/collectors/internal/containerd/containerd.go +++ b/comp/core/workloadmeta/collectors/internal/containerd/containerd.go @@ -189,7 +189,7 @@ func (c *collector) stream(ctx context.Context) { case ev := <-c.eventsChan: if err := c.handleEvent(ctx, ev); err != nil { - log.Warnf(err.Error()) + log.Warnf("%s", err.Error()) } case err := <-c.errorsChan: @@ -261,7 +261,7 @@ func (c *collector) generateInitialContainerEvents(namespace string) ([]workload ev, err := createSetEvent(container, namespace, c.containerdClient, c.store) if err != nil { - log.Warnf(err.Error()) + log.Warnf("%s", err.Error()) continue } diff --git a/comp/core/workloadmeta/collectors/internal/docker/docker.go b/comp/core/workloadmeta/collectors/internal/docker/docker.go index f0d2de3527e9a..ef2af0107c0dd 100644 --- a/comp/core/workloadmeta/collectors/internal/docker/docker.go +++ b/comp/core/workloadmeta/collectors/internal/docker/docker.go @@ -149,13 +149,13 @@ func (c *collector) stream(ctx context.Context) { case ev := <-c.containerEventsCh: err := c.handleContainerEvent(ctx, ev) if err != nil { - log.Warnf(err.Error()) + log.Warnf("%s", err.Error()) } case ev := <-c.imageEventsCh: err := c.handleImageEvent(ctx, ev, nil) if err != nil { - log.Warnf(err.Error()) + log.Warnf("%s", err.Error()) } case <-ctx.Done(): @@ -195,7 +195,7 @@ func (c *collector) generateEventsFromContainerList(ctx context.Context, filter Action: events.ActionStart, }) if err != nil { - log.Warnf(err.Error()) + log.Warnf("%s", err.Error()) continue } @@ -220,7 +220,7 @@ func (c *collector) generateEventsFromImageList(ctx context.Context) error { for _, img := range images { imgMetadata, err := c.getImageMetadata(ctx, img.ID, nil) if err != nil { - log.Warnf(err.Error()) + log.Warnf("%s", err.Error()) continue } diff --git a/comp/dogstatsd/server/server.go b/comp/dogstatsd/server/server.go index b1f97ef2f34db..c187855c648db 100644 --- a/comp/dogstatsd/server/server.go +++ b/comp/dogstatsd/server/server.go @@ -393,7 +393,7 @@ func (s *server) start(context.Context) error { if s.config.GetString("dogstatsd_port") == listeners.RandomPortName || s.config.GetInt("dogstatsd_port") > 0 { udpListener, err := listeners.NewUDPListener(packetsChannel, sharedPacketPoolManager, s.config, s.tCapture, s.listernersTelemetry, s.packetsTelemetry) if err != nil { - s.log.Errorf(err.Error()) + s.log.Errorf("%s", err.Error()) } else { tmpListeners = append(tmpListeners, udpListener) s.udpLocalAddr = udpListener.LocalAddr() diff --git a/comp/otelcol/collector/impl-pipeline/flare_filler.go b/comp/otelcol/collector/impl-pipeline/flare_filler.go index faee05d972332..e4ea9a8a011d9 100644 --- a/comp/otelcol/collector/impl-pipeline/flare_filler.go +++ b/comp/otelcol/collector/impl-pipeline/flare_filler.go @@ -12,6 +12,7 @@ import ( "context" "crypto/tls" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -19,10 +20,11 @@ import ( "strings" "time" + "github.com/gocolly/colly/v2" + flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" extension "github.com/DataDog/datadog-agent/comp/otelcol/extension/def" "github.com/DataDog/datadog-agent/pkg/util/log" - "github.com/gocolly/colly/v2" ) func (c *collectorImpl) fillFlare(fb flaretypes.FlareBuilder) error { @@ -160,7 +162,7 @@ func (c *collectorImpl) requestOtelConfigInfo(endpointURL string) ([]byte, error return nil, err } if res.StatusCode >= 400 { - return nil, fmt.Errorf("%s", body) + return nil, errors.New(string(body)) } return body, nil } diff --git a/comp/otelcol/otlp/collector.go b/comp/otelcol/otlp/collector.go index ae3f84e587243..e3978764031e5 100644 --- a/comp/otelcol/otlp/collector.go +++ b/comp/otelcol/otlp/collector.go @@ -27,6 +27,8 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" + otlpmetrics "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics" + "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/tagger" "github.com/DataDog/datadog-agent/comp/core/tagger/types" @@ -42,7 +44,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/util/log" zapAgent "github.com/DataDog/datadog-agent/pkg/util/log/zap" "github.com/DataDog/datadog-agent/pkg/version" - otlpmetrics "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics" ) var pipelineError = atomic.NewError(nil) @@ -247,7 +248,7 @@ func recoverAndStoreError() { if r := recover(); r != nil { err := fmt.Errorf("OTLP pipeline had a panic: %v", r) pipelineError.Store(err) - log.Errorf(err.Error()) + log.Errorf("%s", err.Error()) } } diff --git a/comp/rdnsquerier/impl/rdnsquerier_test.go b/comp/rdnsquerier/impl/rdnsquerier_test.go index 54ecbdc8d8fc4..fb5102e511815 100644 --- a/comp/rdnsquerier/impl/rdnsquerier_test.go +++ b/comp/rdnsquerier/impl/rdnsquerier_test.go @@ -678,7 +678,7 @@ func TestRetriesExceeded(t *testing.T) { func(_ string) { assert.FailNow(t, "Sync callback should not be called") }, - func(hostname string, err error) { + func(_ string, err error) { assert.Error(t, err) wg.Done() }, diff --git a/comp/systray/systray/systrayimpl/doconfigure.go b/comp/systray/systray/systrayimpl/doconfigure.go index 76917b51df7f0..253217c13a550 100644 --- a/comp/systray/systray/systrayimpl/doconfigure.go +++ b/comp/systray/systray/systrayimpl/doconfigure.go @@ -41,9 +41,9 @@ func doConfigure(s *systrayImpl) error { // Open the GUI in a browser, passing the authorization tokens as parameters err = open("http://127.0.0.1:" + guiPort + "/auth?intent=" + string(intentToken)) if err != nil { - return fmt.Errorf("error opening GUI: " + err.Error()) + return fmt.Errorf("error opening GUI: %s", err.Error()) } - s.log.Debugf("GUI opened at 127.0.0.1:" + guiPort + "\n") + s.log.Debugf("GUI opened at 127.0.0.1:%s\n", guiPort) return nil } diff --git a/pkg/api/security/security.go b/pkg/api/security/security.go index d4aefbc38a81c..40b1310c2f79c 100644 --- a/pkg/api/security/security.go +++ b/pkg/api/security/security.go @@ -157,7 +157,7 @@ func fetchAuthToken(config configModel.Reader, tokenCreationAllowed bool) (strin // Read the token authTokenRaw, e := os.ReadFile(authTokenFile) if e != nil { - return "", fmt.Errorf("unable to read authentication token file: " + e.Error()) + return "", fmt.Errorf("unable to read authentication token file: %s", e.Error()) } // Do some basic validation diff --git a/pkg/api/util/doget.go b/pkg/api/util/doget.go index f7a9bd84593a4..9304932124b7f 100644 --- a/pkg/api/util/doget.go +++ b/pkg/api/util/doget.go @@ -8,7 +8,7 @@ package util import ( "context" "crypto/tls" - "fmt" + "errors" "io" "net/http" ) @@ -81,7 +81,7 @@ func DoGetWithOptions(c *http.Client, url string, options *ReqOptions) (body []b return body, e } if r.StatusCode >= 400 { - return body, fmt.Errorf("%s", body) + return body, errors.New(string(body)) } return body, nil } @@ -105,7 +105,7 @@ func DoPost(c *http.Client, url string, contentType string, body io.Reader) (res return resp, e } if r.StatusCode >= 400 { - return resp, fmt.Errorf("%s", resp) + return resp, errors.New(string(resp)) } return resp, nil } diff --git a/pkg/cli/subcommands/clusterchecks/command.go b/pkg/cli/subcommands/clusterchecks/command.go index 061b62c0d67c3..6a29ac12c7cd3 100644 --- a/pkg/cli/subcommands/clusterchecks/command.go +++ b/pkg/cli/subcommands/clusterchecks/command.go @@ -9,6 +9,7 @@ package clusterchecks import ( "bytes" "encoding/json" + "errors" "fmt" "github.com/fatih/color" @@ -153,7 +154,7 @@ func rebalance(_ log.Component, config config.Component, cliParams *cliParams) e json.Unmarshal(r, &errMap) //nolint:errcheck // If the error has been marshalled into a json object, check it and return it properly if e, found := errMap["error"]; found { - err = fmt.Errorf(e) + err = errors.New(e) } fmt.Printf(` @@ -196,7 +197,7 @@ func isolate(_ log.Component, config config.Component, cliParams *cliParams) err json.Unmarshal(r, &errMap) //nolint:errcheck // If the error has been marshalled into a json object, check it and return it properly if e, found := errMap["error"]; found { - err = fmt.Errorf(e) + err = errors.New(e) } fmt.Printf(` diff --git a/pkg/cli/subcommands/health/command.go b/pkg/cli/subcommands/health/command.go index e921ae6031293..f4d1233d61d99 100644 --- a/pkg/cli/subcommands/health/command.go +++ b/pkg/cli/subcommands/health/command.go @@ -9,6 +9,7 @@ package health import ( "context" "encoding/json" + "errors" "fmt" "sort" "strconv" @@ -99,7 +100,7 @@ func requestHealth(_ log.Component, config config.Component, cliParams *cliParam json.Unmarshal(r, &errMap) //nolint:errcheck // If the error has been marshalled into a json object, check it and return it properly if e, found := errMap["error"]; found { - err = fmt.Errorf(e) + err = errors.New(e) } return fmt.Errorf("could not reach agent: %v \nMake sure the agent is running before requesting the status and contact support if you continue having issues", err) diff --git a/pkg/collector/corechecks/containers/kubelet/common/testing/utils.go b/pkg/collector/corechecks/containers/kubelet/common/testing/utils.go index e62a694ea6ac2..5054431177d18 100644 --- a/pkg/collector/corechecks/containers/kubelet/common/testing/utils.go +++ b/pkg/collector/corechecks/containers/kubelet/common/testing/utils.go @@ -147,7 +147,7 @@ func CreateKubeletMock(response EndpointResponse, endpoint string) (*mock.Kubele if response.filename != "" { content, err = os.ReadFile(response.filename) if err != nil { - return nil, fmt.Errorf(fmt.Sprintf("unable to read test file at: %s, Err: %v", response.filename, err)) + return nil, fmt.Errorf("unable to read test file at: %s, Err: %w", response.filename, err) } } kubeletMock.MockReplies[endpoint] = &mock.HTTPReplyMock{ @@ -166,12 +166,12 @@ func StorePopulatedFromFile(store workloadmetamock.Mock, filename string, podUti podList, err := os.ReadFile(filename) if err != nil { - return fmt.Errorf(fmt.Sprintf("unable to load pod list, Err: %v", err)) + return fmt.Errorf("unable to load pod list, Err: %w", err) } var pods *kubelet.PodList err = json.Unmarshal(podList, &pods) if err != nil { - return fmt.Errorf(fmt.Sprintf("unable to load pod list, Err: %v", err)) + return fmt.Errorf("unable to load pod list, Err: %w", err) } for _, pod := range pods.Items { diff --git a/pkg/collector/corechecks/loader.go b/pkg/collector/corechecks/loader.go index eb09c0cefb49c..31eab283f1fe5 100644 --- a/pkg/collector/corechecks/loader.go +++ b/pkg/collector/corechecks/loader.go @@ -61,7 +61,7 @@ func (gl *GoCheckLoader) Load(senderManger sender.SenderManager, config integrat factory, found := catalog[config.Name] if !found { msg := fmt.Sprintf("Check %s not found in Catalog", config.Name) - return c, fmt.Errorf(msg) + return c, errors.New(msg) } c = factory() @@ -71,7 +71,7 @@ func (gl *GoCheckLoader) Load(senderManger sender.SenderManager, config integrat } log.Errorf("core.loader: could not configure check %s: %s", c, err) msg := fmt.Sprintf("Could not configure check %s: %s", c, err) - return c, fmt.Errorf(msg) + return c, errors.New(msg) } return c, nil diff --git a/pkg/collector/corechecks/servicediscovery/portlist/portlist_linux.go b/pkg/collector/corechecks/servicediscovery/portlist/portlist_linux.go index 918d9e6fc7a36..dffe0a5f83110 100644 --- a/pkg/collector/corechecks/servicediscovery/portlist/portlist_linux.go +++ b/pkg/collector/corechecks/servicediscovery/portlist/portlist_linux.go @@ -308,7 +308,7 @@ func (li *linuxImpl) findProcessNames(need map[string]*portMeta) error { targetBuf := make([]byte, 64) // plenty big for "socket:[165614651]" linkPath := li.readlinkPathBuf[:0] - linkPath = fmt.Appendf(linkPath, li.procMountPath+"/") + linkPath = fmt.Append(linkPath, li.procMountPath+"/") linkPath = mem.Append(linkPath, pid) linkPath = append(linkPath, "/fd/"...) linkPath = mem.Append(linkPath, fd) diff --git a/pkg/collector/corechecks/snmp/internal/discovery/discovery.go b/pkg/collector/corechecks/snmp/internal/discovery/discovery.go index 6347d190b1244..f8c3337308ea8 100644 --- a/pkg/collector/corechecks/snmp/internal/discovery/discovery.go +++ b/pkg/collector/corechecks/snmp/internal/discovery/discovery.go @@ -101,7 +101,7 @@ func (d *Discovery) runWorker(w int, jobs <-chan checkDeviceJob) { log.Debugf("subnet %s: Handling IP %s", d.config.Network, job.currentIP.String()) err := d.checkDevice(job) if err != nil { - log.Errorf(err.Error()) + log.Errorf("%s", err.Error()) } } } diff --git a/pkg/collector/corechecks/systemd/systemd.go b/pkg/collector/corechecks/systemd/systemd.go index e1596d6653e5d..3db37ea9f9751 100644 --- a/pkg/collector/corechecks/systemd/systemd.go +++ b/pkg/collector/corechecks/systemd/systemd.go @@ -411,9 +411,9 @@ func (c *SystemdCheck) submitPropertyMetricsAsGauge(sender sender.Sender, conn * if err != nil { msg := fmt.Sprintf("Cannot send property '%s' for unit '%s': %v", service.propertyName, unit.Name, err) if service.optional { - log.Debugf(msg) + log.Debugf("%s", msg) } else { - log.Warnf(msg) + log.Warnf("%s", msg) } } } diff --git a/pkg/collector/python/init.go b/pkg/collector/python/init.go index 3cc6c140ae432..5b905debba7ba 100644 --- a/pkg/collector/python/init.go +++ b/pkg/collector/python/init.go @@ -8,6 +8,7 @@ package python import ( + "errors" "expvar" "fmt" "os" @@ -258,7 +259,7 @@ func addExpvarPythonInitErrors(msg string) error { defer pyInitLock.Unlock() pyInitErrors = append(pyInitErrors, msg) - return fmt.Errorf(msg) + return errors.New(msg) } func sendTelemetry(pythonVersion string) { diff --git a/pkg/compliance/evaluator_rego.go b/pkg/compliance/evaluator_rego.go index 2e2106e88e234..a6456ad0f2242 100644 --- a/pkg/compliance/evaluator_rego.go +++ b/pkg/compliance/evaluator_rego.go @@ -8,6 +8,7 @@ package compliance import ( "context" "encoding/json" + "errors" "fmt" "os" "strconv" @@ -117,7 +118,7 @@ func newCheckEventFromRegoResult(data interface{}, rule *Rule, resolvedInputs Re if errMsg == "" { errMsg = "unknown" } - errReason = fmt.Errorf(errMsg) + errReason = errors.New(errMsg) default: errReason = fmt.Errorf("rego result invalid: bad status %q", status) } diff --git a/pkg/config/settings/http/client.go b/pkg/config/settings/http/client.go index 748ad5834fbd4..6d9a8ff42236b 100644 --- a/pkg/config/settings/http/client.go +++ b/pkg/config/settings/http/client.go @@ -9,6 +9,7 @@ package http import ( "bytes" "encoding/json" + "errors" "fmt" "html" "net/http" @@ -37,7 +38,7 @@ func (rc *runtimeSettingsHTTPClient) doGet(url string, formatError bool) (string _ = json.Unmarshal(r, &errMap) // If the error has been marshalled into a json object, check it and return it properly if e, found := errMap["error"]; found { - return "", fmt.Errorf(e) + return "", errors.New(e) } if formatError { return "", fmt.Errorf("Could not reach %s: %v \nMake sure the %s is running before requesting the runtime configuration and contact support if you continue having issues", rc.targetProcessName, err, rc.targetProcessName) @@ -130,7 +131,7 @@ func (rc *runtimeSettingsHTTPClient) Set(key string, value string) (bool, error) _ = json.Unmarshal(r, &errMap) // If the error has been marshalled into a json object, check it and return it properly if e, found := errMap["error"]; found { - return false, fmt.Errorf(e) + return false, errors.New(e) } return false, err } diff --git a/pkg/config/setup/config.go b/pkg/config/setup/config.go index ba058fe9715a9..0c6fa60a9afca 100644 --- a/pkg/config/setup/config.go +++ b/pkg/config/setup/config.go @@ -1949,7 +1949,7 @@ func LoadCustom(config pkgconfigmodel.Config, additionalKnownEnvVars []string) e } for _, warningMsg := range findUnexpectedUnicode(config) { - log.Warnf(warningMsg) + log.Warnf("%s", warningMsg) } return nil diff --git a/pkg/jmxfetch/jmxfetch.go b/pkg/jmxfetch/jmxfetch.go index 7c39684e06a8e..2f0fb0537beca 100644 --- a/pkg/jmxfetch/jmxfetch.go +++ b/pkg/jmxfetch/jmxfetch.go @@ -138,7 +138,7 @@ func (j *JMXFetch) Monitor() { if !limiter.canRestart(time.Now()) { msg := fmt.Sprintf("Too many JMXFetch restarts (%v) in time interval (%vs) - giving up", limiter.maxRestarts, limiter.interval) - log.Errorf(msg) + log.Errorf("%s", msg) s := jmxStatus.StartupError{LastError: msg, Timestamp: time.Now().Unix()} jmxStatus.SetStartupError(s) return diff --git a/pkg/linters/components/pkgconfigusage/go.mod b/pkg/linters/components/pkgconfigusage/go.mod new file mode 100644 index 0000000000000..94737011484cb --- /dev/null +++ b/pkg/linters/components/pkgconfigusage/go.mod @@ -0,0 +1,17 @@ +module github.com/DataDog/datadog-agent/pkg/linters/components/pkgconfigusage + +go 1.22.0 + +require ( + github.com/golangci/plugin-module-register v0.1.1 + github.com/stretchr/testify v1.9.0 + golang.org/x/tools v0.24.0 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/mod v0.20.0 // indirect + golang.org/x/sync v0.8.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/pkg/linters/components/pkgconfigusage/go.sum b/pkg/linters/components/pkgconfigusage/go.sum new file mode 100644 index 0000000000000..e4381e0e55b8d --- /dev/null +++ b/pkg/linters/components/pkgconfigusage/go.sum @@ -0,0 +1,20 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golangci/plugin-module-register v0.1.1 h1:TCmesur25LnyJkpsVrupv1Cdzo+2f7zX0H6Jkw1Ol6c= +github.com/golangci/plugin-module-register v0.1.1/go.mod h1:TTpqoB6KkwOJMV8u7+NyXMrkwwESJLOkfl9TxR1DGFc= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= +golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/linters/components/pkgconfigusage/pkgconfigusage.go b/pkg/linters/components/pkgconfigusage/pkgconfigusage.go new file mode 100644 index 0000000000000..9699c50dd87fb --- /dev/null +++ b/pkg/linters/components/pkgconfigusage/pkgconfigusage.go @@ -0,0 +1,72 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package pkgconfigusage provides a linter for ensuring pkg/config is not used inside comp folder +package pkgconfigusage + +import ( + "strings" + + "github.com/golangci/plugin-module-register/register" + "golang.org/x/tools/go/analysis" +) + +// We can replace it during tests +var componentPath = "github.com/DataDog/datadog-agent/comp/" + +func init() { + register.Plugin("pkgconfigusage", New) +} + +type pkgconfigUsagePlugin struct { +} + +// New returns a new config linter plugin +func New(any) (register.LinterPlugin, error) { + return &pkgconfigUsagePlugin{}, nil +} + +// BuildAnalyzers returns the analyzers for the plugin +func (f *pkgconfigUsagePlugin) BuildAnalyzers() ([]*analysis.Analyzer, error) { + return []*analysis.Analyzer{ + { + Name: "pkgconfigusage", + Doc: "ensure github.com/DataDog/datadog-agent/pkg/config is not used inside the components folder", + Run: f.run, + }, + }, nil +} + +// GetLoadMode returns the load mode for the plugin +func (f *pkgconfigUsagePlugin) GetLoadMode() string { + return register.LoadModeSyntax +} + +func (f *pkgconfigUsagePlugin) run(pass *analysis.Pass) (interface{}, error) { + for _, file := range pass.Files { + + if !strings.HasPrefix(pass.Pkg.Path(), componentPath) { + continue + } + + for _, imp := range file.Imports { + if imp.Path.Value == `"github.com/DataDog/datadog-agent/pkg/config"` { + pass.Report(analysis.Diagnostic{ + Pos: imp.Pos(), + End: imp.End(), + Category: "components", + Message: "github.com/DataDog/datadog-agent/pkg/config should not be used inside comp folder", + SuggestedFixes: []analysis.SuggestedFix{ + { + Message: "Use the config component instead, by declaring it as part of your component's dependencies.", + }, + }, + }) + } + } + } + + return nil, nil +} diff --git a/pkg/linters/components/pkgconfigusage/pkgconfigusage_test.go b/pkg/linters/components/pkgconfigusage/pkgconfigusage_test.go new file mode 100644 index 0000000000000..03d2c2afe160e --- /dev/null +++ b/pkg/linters/components/pkgconfigusage/pkgconfigusage_test.go @@ -0,0 +1,41 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +package pkgconfigusage + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "golang.org/x/tools/go/analysis/analysistest" +) + +func TestAll(t *testing.T) { + wd, err := os.Getwd() + if err != nil { + t.Fatalf("Failed to get wd: %s", err) + } + + originalComponentPath := componentPath + componentPath = "comp" + + t.Cleanup(func() { + componentPath = originalComponentPath + }) + + testdata := filepath.Join(filepath.Dir(filepath.Dir(wd)), "testdata") + plugin := &pkgconfigUsagePlugin{} + analyzers, err := plugin.BuildAnalyzers() + assert.NoError(t, err) + + analyzer := analyzers[0] + // We do this to skip issues with import or other errors. + // We only care about parsing the test file and run the analyzer. + analyzer.RunDespiteErrors = true + + analysistest.Run(t, testdata, analyzer, "comp/...") +} diff --git a/pkg/linters/testdata/src/comp/a.go b/pkg/linters/testdata/src/comp/a.go new file mode 100644 index 0000000000000..6a7cdf211fb57 --- /dev/null +++ b/pkg/linters/testdata/src/comp/a.go @@ -0,0 +1,9 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package a is a test package to test the linter +package a + +import _ "github.com/DataDog/datadog-agent/pkg/config" // want "pkg/config should not be used inside comp folder" diff --git a/pkg/logs/internal/decoder/legacy_auto_multiline_handler.go b/pkg/logs/internal/decoder/legacy_auto_multiline_handler.go index 61d9011103463..8e7b0a1321764 100644 --- a/pkg/logs/internal/decoder/legacy_auto_multiline_handler.go +++ b/pkg/logs/internal/decoder/legacy_auto_multiline_handler.go @@ -185,7 +185,7 @@ func (h *LegacyAutoMultilineHandler) processAndTry(message *message.Message) { if matchRatio >= h.matchThreshold { h.autoMultiLineStatus.SetMessage("state", "State: Using multi-line handler") h.autoMultiLineStatus.SetMessage("message", fmt.Sprintf("Pattern %v matched %d lines with a ratio of %f", topMatch.regexp.String(), topMatch.score, matchRatio)) - log.Debug(fmt.Sprintf("Pattern %v matched %d lines with a ratio of %f - using multi-line handler", topMatch.regexp.String(), topMatch.score, matchRatio)) + log.Debugf("Pattern %v matched %d lines with a ratio of %f - using multi-line handler", topMatch.regexp.String(), topMatch.score, matchRatio) telemetry.GetStatsTelemetryProvider().Count(autoMultiLineTelemetryMetricName, 1, []string{"success:true"}) h.detectedPattern.Set(topMatch.regexp) @@ -193,7 +193,7 @@ func (h *LegacyAutoMultilineHandler) processAndTry(message *message.Message) { } else { h.autoMultiLineStatus.SetMessage("state", "State: Using single-line handler") h.autoMultiLineStatus.SetMessage("message", fmt.Sprintf("No pattern met the line match threshold: %f during multiline auto detection. Top match was %v with a match ratio of: %f", h.matchThreshold, topMatch.regexp.String(), matchRatio)) - log.Debugf(fmt.Sprintf("No pattern met the line match threshold: %f during multiline auto detection. Top match was %v with a match ratio of: %f - using single-line handler", h.matchThreshold, topMatch.regexp.String(), matchRatio)) + log.Debugf("No pattern met the line match threshold: %f during multiline auto detection. Top match was %v with a match ratio of: %f - using single-line handler", h.matchThreshold, topMatch.regexp.String(), matchRatio) telemetry.GetStatsTelemetryProvider().Count(autoMultiLineTelemetryMetricName, 1, []string{"success:false"}) // Stay with the single line handler and no longer attempt to detect multiline matches. diff --git a/pkg/logs/launchers/listener/tcp_test.go b/pkg/logs/launchers/listener/tcp_test.go index 031369bab63f9..202d203b8174d 100644 --- a/pkg/logs/launchers/listener/tcp_test.go +++ b/pkg/logs/launchers/listener/tcp_test.go @@ -32,7 +32,7 @@ func TestTCPShouldReceivesMessages(t *testing.T) { defer conn.Close() var msg *message.Message - fmt.Fprintf(conn, "hello world\n") + fmt.Fprint(conn, "hello world\n") msg = <-msgChan assert.Equal(t, "hello world", string(msg.GetContent())) assert.Equal(t, 1, len(listener.tailers)) @@ -50,15 +50,15 @@ func TestTCPDoesNotTruncateMessagesThatAreBiggerThanTheReadBufferSize(t *testing assert.Nil(t, err) var msg *message.Message - fmt.Fprintf(conn, strings.Repeat("a", 80)+"\n") + fmt.Fprint(conn, strings.Repeat("a", 80)+"\n") msg = <-msgChan assert.Equal(t, strings.Repeat("a", 80), string(msg.GetContent())) - fmt.Fprintf(conn, strings.Repeat("a", 200)+"\n") + fmt.Fprint(conn, strings.Repeat("a", 200)+"\n") msg = <-msgChan assert.Equal(t, strings.Repeat("a", 200), string(msg.GetContent())) - fmt.Fprintf(conn, strings.Repeat("a", 70)+"\n") + fmt.Fprint(conn, strings.Repeat("a", 70)+"\n") msg = <-msgChan assert.Equal(t, strings.Repeat("a", 70), string(msg.GetContent())) diff --git a/pkg/logs/launchers/listener/udp_nix_test.go b/pkg/logs/launchers/listener/udp_nix_test.go index bce53e04fcfbc..7423ad918042d 100644 --- a/pkg/logs/launchers/listener/udp_nix_test.go +++ b/pkg/logs/launchers/listener/udp_nix_test.go @@ -47,7 +47,7 @@ func TestUDPShoulProperlyCollectLogSplitPerDatadgram(t *testing.T) { msg = <-msgChan assert.Equal(t, strings.Repeat("a", 10), string(msg.GetContent())) - fmt.Fprintf(conn, strings.Repeat("a", 10)+"\n"+strings.Repeat("a", 10)+"\n") + fmt.Fprint(conn, strings.Repeat("a", 10)+"\n"+strings.Repeat("a", 10)+"\n") msg = <-msgChan assert.Equal(t, strings.Repeat("a", 10), string(msg.GetContent())) msg = <-msgChan @@ -99,13 +99,13 @@ func TestUDPShoulDropTooBigMessages(t *testing.T) { var msg *message.Message - fmt.Fprintf(conn, strings.Repeat("a", maxUDPFrameLen-100)+"\n") + fmt.Fprint(conn, strings.Repeat("a", maxUDPFrameLen-100)+"\n") msg = <-msgChan assert.Equal(t, strings.Repeat("a", maxUDPFrameLen-100), string(msg.GetContent())) // the first frame should be dropped as it's too big compare to the limit. - fmt.Fprintf(conn, strings.Repeat("a", maxUDPFrameLen+100)+"\n") - fmt.Fprintf(conn, strings.Repeat("a", maxUDPFrameLen-200)+"\n") + fmt.Fprint(conn, strings.Repeat("a", maxUDPFrameLen+100)+"\n") + fmt.Fprint(conn, strings.Repeat("a", maxUDPFrameLen-200)+"\n") msg = <-msgChan assert.Equal(t, strings.Repeat("a", maxUDPFrameLen-200), string(msg.GetContent())) diff --git a/pkg/logs/launchers/listener/udp_test.go b/pkg/logs/launchers/listener/udp_test.go index 07a0db2ed3850..638574571548b 100644 --- a/pkg/logs/launchers/listener/udp_test.go +++ b/pkg/logs/launchers/listener/udp_test.go @@ -32,7 +32,7 @@ func TestUDPShouldReceiveMessage(t *testing.T) { var msg *message.Message - fmt.Fprintf(conn, "hello world\n") + fmt.Fprint(conn, "hello world\n") msg = <-msgChan assert.Equal(t, "hello world", string(msg.GetContent())) diff --git a/pkg/logs/tailers/windowsevent/tailer_test.go b/pkg/logs/tailers/windowsevent/tailer_test.go index 2d842877acd12..5c8c635314edb 100644 --- a/pkg/logs/tailers/windowsevent/tailer_test.go +++ b/pkg/logs/tailers/windowsevent/tailer_test.go @@ -8,13 +8,15 @@ package windowsevent import ( + "errors" "fmt" "testing" "time" - pkglog "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/cihub/seelog" + pkglog "github.com/DataDog/datadog-agent/pkg/util/log" + "github.com/cenkalti/backoff" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -23,8 +25,8 @@ import ( "github.com/DataDog/datadog-agent/pkg/logs/message" "github.com/DataDog/datadog-agent/pkg/logs/sources" "github.com/DataDog/datadog-agent/pkg/util/testutil/flake" - "github.com/DataDog/datadog-agent/pkg/util/winutil/eventlog/api" - "github.com/DataDog/datadog-agent/pkg/util/winutil/eventlog/test" + evtapi "github.com/DataDog/datadog-agent/pkg/util/winutil/eventlog/api" + eventlog_test "github.com/DataDog/datadog-agent/pkg/util/winutil/eventlog/test" ) type ReadEventsSuite struct { @@ -89,7 +91,7 @@ func newtailer(evtapi evtapi.API, tailerconfig *Config, bookmark string, msgChan if source.Status.IsSuccess() { return nil } else if source.Status.IsError() { - return fmt.Errorf(source.Status.GetError()) + return errors.New(source.Status.GetError()) } return fmt.Errorf("start pending") }, backoff.NewConstantBackOff(50*time.Millisecond)) @@ -198,7 +200,7 @@ func (s *ReadEventsSuite) TestRecoverFromBrokenSubscription() { if tailer.source.Status.IsSuccess() { return nil } else if tailer.source.Status.IsError() { - return fmt.Errorf(tailer.source.Status.GetError()) + return errors.New(tailer.source.Status.GetError()) } return fmt.Errorf("start pending") }, backoff.NewConstantBackOff(50*time.Millisecond)) diff --git a/pkg/metrics/metric_test.go b/pkg/metrics/metric_test.go index bced04754329e..530062011e52e 100644 --- a/pkg/metrics/metric_test.go +++ b/pkg/metrics/metric_test.go @@ -7,7 +7,6 @@ package metrics import ( "encoding/json" - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -35,7 +34,7 @@ func TestAPIMetricTypeMarshal(t *testing.T) { `{"type":"rate"}`, }, } { - t.Run(fmt.Sprintf(tc.Out), func(t *testing.T) { + t.Run(tc.Out, func(t *testing.T) { out, err := json.Marshal(tc.In) assert.NoError(t, err) assert.Equal(t, tc.Out, string(out)) diff --git a/pkg/network/tracer/utils_linux.go b/pkg/network/tracer/utils_linux.go index 2477b60ea38a1..5315b10785a00 100644 --- a/pkg/network/tracer/utils_linux.go +++ b/pkg/network/tracer/utils_linux.go @@ -81,5 +81,5 @@ func verifyOSVersion(kernelCode kernel.Version, platform string, exclusionList [ } errMsg := fmt.Sprintf("Kernel unsupported (%s) - ", kernelCode) errMsg += fmt.Sprintf("required functions missing: %s", strings.Join(missingFuncs, ", ")) - return false, fmt.Errorf(errMsg) + return false, errors.New(errMsg) } diff --git a/pkg/security/module/server_linux.go b/pkg/security/module/server_linux.go index e7cea21a88a07..c4d1d9556cd11 100644 --- a/pkg/security/module/server_linux.go +++ b/pkg/security/module/server_linux.go @@ -56,7 +56,7 @@ func (a *APIServer) ListActivityDumps(_ context.Context, params *api.ActivityDum if managers := p.GetProfileManagers(); managers != nil { msg, err := managers.ListActivityDumps(params) if err != nil { - seclog.Errorf(err.Error()) + seclog.Errorf("%s", err.Error()) } return msg, nil } @@ -74,7 +74,7 @@ func (a *APIServer) StopActivityDump(_ context.Context, params *api.ActivityDump if managers := p.GetProfileManagers(); managers != nil { msg, err := managers.StopActivityDump(params) if err != nil { - seclog.Errorf(err.Error()) + seclog.Errorf("%s", err.Error()) } return msg, nil } @@ -92,7 +92,7 @@ func (a *APIServer) TranscodingRequest(_ context.Context, params *api.Transcodin if managers := p.GetProfileManagers(); managers != nil { msg, err := managers.GenerateTranscoding(params) if err != nil { - seclog.Errorf(err.Error()) + seclog.Errorf("%s", err.Error()) } return msg, nil } @@ -110,7 +110,7 @@ func (a *APIServer) ListSecurityProfiles(_ context.Context, params *api.Security if managers := p.GetProfileManagers(); managers != nil { msg, err := managers.ListSecurityProfiles(params) if err != nil { - seclog.Errorf(err.Error()) + seclog.Errorf("%s", err.Error()) } return msg, nil } @@ -128,7 +128,7 @@ func (a *APIServer) SaveSecurityProfile(_ context.Context, params *api.SecurityP if managers := p.GetProfileManagers(); managers != nil { msg, err := managers.SaveSecurityProfile(params) if err != nil { - seclog.Errorf(err.Error()) + seclog.Errorf("%s", err.Error()) } return msg, nil } diff --git a/pkg/security/probe/field_handlers_ebpf.go b/pkg/security/probe/field_handlers_ebpf.go index d65e55e430921..b9cb03e12cfc7 100644 --- a/pkg/security/probe/field_handlers_ebpf.go +++ b/pkg/security/probe/field_handlers_ebpf.go @@ -538,7 +538,7 @@ func (fh *EBPFFieldHandlers) ResolveCGroupID(ev *model.Event, e *model.CGroupCon } // ResolveCGroupManager resolves the manager of the cgroup -func (fh *EBPFFieldHandlers) ResolveCGroupManager(ev *model.Event, e *model.CGroupContext) string { +func (fh *EBPFFieldHandlers) ResolveCGroupManager(ev *model.Event, _ *model.CGroupContext) string { if entry, _ := fh.ResolveProcessCacheEntry(ev); entry != nil { if manager := containerutils.CGroupManager(entry.CGroup.CGroupFlags); manager != 0 { return manager.String() diff --git a/pkg/security/resolvers/netns/resolver.go b/pkg/security/resolvers/netns/resolver.go index fe0caef888a41..73a5d92f8920c 100644 --- a/pkg/security/resolvers/netns/resolver.go +++ b/pkg/security/resolvers/netns/resolver.go @@ -657,7 +657,7 @@ func (nr *Resolver) DumpNetworkNamespaces(params *api.DumpNetworkNamespaceParams dumpFile, err := newTmpFile("network-namespace-dump-*.json") if err != nil { resp.Error = fmt.Sprintf("couldn't create temporary file: %v", err) - seclog.Warnf(resp.Error) + seclog.Warnf("%s", err.Error()) return resp } defer dumpFile.Close() @@ -667,13 +667,13 @@ func (nr *Resolver) DumpNetworkNamespaces(params *api.DumpNetworkNamespaceParams encoder := json.NewEncoder(dumpFile) if err = encoder.Encode(dump); err != nil { resp.Error = fmt.Sprintf("couldn't encode list of network namespace: %v", err) - seclog.Warnf(resp.Error) + seclog.Warnf("%s", err.Error()) return resp } if err = dumpFile.Close(); err != nil { resp.Error = fmt.Sprintf("could not close file [%s]: %s", dumpFile.Name(), err) - seclog.Warnf(resp.Error) + seclog.Warnf("%s", err.Error()) return resp } @@ -681,7 +681,7 @@ func (nr *Resolver) DumpNetworkNamespaces(params *api.DumpNetworkNamespaceParams graphFile, err := newTmpFile("network-namespace-graph-*.dot") if err != nil { resp.Error = fmt.Sprintf("couldn't create temporary file: %v", err) - seclog.Warnf(resp.Error) + seclog.Warnf("%s", err.Error()) return resp } defer graphFile.Close() @@ -690,13 +690,13 @@ func (nr *Resolver) DumpNetworkNamespaces(params *api.DumpNetworkNamespaceParams // generate dot graph if err = nr.generateGraph(dump, graphFile); err != nil { resp.Error = fmt.Sprintf("couldn't generate dot graph: %v", err) - seclog.Warnf(resp.Error) + seclog.Warnf("%s", err.Error()) return resp } if err = graphFile.Close(); err != nil { resp.Error = fmt.Sprintf("could not close file [%s]: %s", graphFile.Name(), err) - seclog.Warnf(resp.Error) + seclog.Warnf("%s", err.Error()) return resp } diff --git a/pkg/security/resolvers/sbom/resolver.go b/pkg/security/resolvers/sbom/resolver.go index c31a73ac6ab04..96c2fd12c0d50 100644 --- a/pkg/security/resolvers/sbom/resolver.go +++ b/pkg/security/resolvers/sbom/resolver.go @@ -258,7 +258,7 @@ func (r *Resolver) Start(ctx context.Context) error { if err := retry.Do(func() error { return r.analyzeWorkload(sbom) }, retry.Attempts(maxSBOMGenerationRetries), retry.Delay(200*time.Millisecond)); err != nil { - seclog.Errorf(err.Error()) + seclog.Errorf("%s", err.Error()) } } } diff --git a/pkg/security/security_profile/dump/remote_storage.go b/pkg/security/security_profile/dump/remote_storage.go index b770651503cf1..9c9c8958eb303 100644 --- a/pkg/security/security_profile/dump/remote_storage.go +++ b/pkg/security/security_profile/dump/remote_storage.go @@ -12,6 +12,7 @@ import ( "bytes" "compress/gzip" "encoding/json" + "errors" "fmt" "mime/multipart" "net/http" @@ -20,6 +21,8 @@ import ( "go.uber.org/atomic" + "github.com/DataDog/datadog-go/v5/statsd" + logsconfig "github.com/DataDog/datadog-agent/comp/logs/agent/config" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/security/config" @@ -27,7 +30,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/security/seclog" "github.com/DataDog/datadog-agent/pkg/security/utils" ddhttputil "github.com/DataDog/datadog-agent/pkg/util/http" - "github.com/DataDog/datadog-go/v5/statsd" ) type tooLargeEntityStatsEntry struct { @@ -176,7 +178,7 @@ func (storage *ActivityDumpRemoteStorage) sendToEndpoint(url string, apiKey stri } storage.tooLargeEntities[entry].Inc() } - return fmt.Errorf(resp.Status) + return errors.New(resp.Status) } // Persist saves the provided buffer to the persistent storage diff --git a/pkg/snmp/gosnmplib/gosnmp_log.go b/pkg/snmp/gosnmplib/gosnmp_log.go index ff8dec9d845d3..908c2a0d99838 100644 --- a/pkg/snmp/gosnmplib/gosnmp_log.go +++ b/pkg/snmp/gosnmplib/gosnmp_log.go @@ -52,6 +52,6 @@ func (sw *TraceLevelLogWriter) Write(logInput []byte) (n int, err error) { logInput = replacer.Regex.ReplaceAll(logInput, replacer.Repl) } } - log.Tracef(string(logInput)) + log.Trace(string(logInput)) return len(logInput), nil } diff --git a/pkg/trace/api/api_test.go b/pkg/trace/api/api_test.go index a922f2f7d57e7..6d035f12bdd6f 100644 --- a/pkg/trace/api/api_test.go +++ b/pkg/trace/api/api_test.go @@ -219,7 +219,7 @@ func TestLegacyReceiver(t *testing.T) { } for _, tc := range testCases { - t.Run(fmt.Sprintf(tc.name), func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { // start testing server server := httptest.NewServer( tc.r.handleWithVersion(tc.apiVersion, tc.r.handleTraces), @@ -284,7 +284,7 @@ func TestReceiverJSONDecoder(t *testing.T) { } for _, tc := range testCases { - t.Run(fmt.Sprintf(tc.name), func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { // start testing server server := httptest.NewServer( tc.r.handleWithVersion(tc.apiVersion, tc.r.handleTraces), @@ -344,7 +344,7 @@ func TestReceiverMsgpackDecoder(t *testing.T) { } for _, tc := range testCases { - t.Run(fmt.Sprintf(tc.name), func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { // start testing server server := httptest.NewServer( tc.r.handleWithVersion(tc.apiVersion, tc.r.handleTraces), diff --git a/pkg/trace/api/telemetry_test.go b/pkg/trace/api/telemetry_test.go index e5c76bc14524f..5c37737da22ae 100644 --- a/pkg/trace/api/telemetry_test.go +++ b/pkg/trace/api/telemetry_test.go @@ -295,7 +295,7 @@ func TestMaxInflightBytes(t *testing.T) { done := make(chan struct{}) - srv := assertingServer(t, func(req *http.Request, body []byte) error { + srv := assertingServer(t, func(req *http.Request, _ []byte) error { assert.Equal("test_apikey", req.Header.Get("DD-API-KEY")) assert.Equal("test_hostname", req.Header.Get("DD-Agent-Hostname")) assert.Equal("test_env", req.Header.Get("DD-Agent-Env")) @@ -339,7 +339,7 @@ func TestInflightBytesReset(t *testing.T) { done := make(chan struct{}) - srv := assertingServer(t, func(req *http.Request, body []byte) error { + srv := assertingServer(t, func(req *http.Request, _ []byte) error { assert.Equal("test_apikey", req.Header.Get("DD-API-KEY")) assert.Equal("test_hostname", req.Header.Get("DD-Agent-Hostname")) assert.Equal("test_env", req.Header.Get("DD-Agent-Env")) @@ -397,7 +397,7 @@ func TestActualServer(t *testing.T) { done := make(chan struct{}) - intakeMockServer := assertingServer(t, func(req *http.Request, body []byte) error { + intakeMockServer := assertingServer(t, func(req *http.Request, _ []byte) error { assert.Equal("test_apikey", req.Header.Get("DD-API-KEY")) assert.Equal("test_hostname", req.Header.Get("DD-Agent-Hostname")) assert.Equal("test_env", req.Header.Get("DD-Agent-Env")) diff --git a/pkg/util/containers/filter.go b/pkg/util/containers/filter.go index b9994718702e4..a0c389dfdde63 100644 --- a/pkg/util/containers/filter.go +++ b/pkg/util/containers/filter.go @@ -134,7 +134,7 @@ func parseFilters(filters []string) (imageFilters, nameFilters, namespaceFilters namespaceFilters = append(namespaceFilters, r) default: warnmsg := fmt.Sprintf("Container filter %q is unknown, ignoring it. The supported filters are 'image', 'name' and 'kube_namespace'", filter) - log.Warnf(warnmsg) + log.Warn(warnmsg) filterWarnings = append(filterWarnings, warnmsg) } diff --git a/pkg/util/kubernetes/autoscalers/processor.go b/pkg/util/kubernetes/autoscalers/processor.go index 3e575e1a7eac4..3440c6ba01e2d 100644 --- a/pkg/util/kubernetes/autoscalers/processor.go +++ b/pkg/util/kubernetes/autoscalers/processor.go @@ -237,7 +237,7 @@ func makeChunks(batch []string) (chunks [][]string) { uriLength = uriLength + tempSize beyond, err := isURLBeyondLimits(uriLength, len(tempBucket)) if err != nil { - log.Errorf(fmt.Sprintf("%s: %s", err.Error(), val)) + log.Errorf("%v: %s", err, val) continue } if beyond { diff --git a/pkg/util/pdhutil/pdhhelper.go b/pkg/util/pdhutil/pdhhelper.go index a5e41503862bd..48a43f4487b58 100644 --- a/pkg/util/pdhutil/pdhhelper.go +++ b/pkg/util/pdhutil/pdhhelper.go @@ -7,6 +7,7 @@ package pdhutil import ( + "errors" "fmt" "reflect" "strconv" @@ -98,8 +99,8 @@ func refreshPdhObjectCache(forceRefresh bool) (didrefresh bool, err error) { } else if refreshInterval < 0 { // invalid value e := "windows_counter_refresh_interval cannot be a negative number" - log.Errorf(e) - return false, fmt.Errorf(e) + log.Errorf("%s", e) + return false, errors.New(e) } // Only refresh at most every refresh_interval seconds @@ -132,8 +133,8 @@ func refreshPdhObjectCache(forceRefresh bool) (didrefresh bool, err error) { uintptr(1)) // do refresh if r != PDH_MORE_DATA { e := fmt.Sprintf("Failed to refresh performance counters (%#x)", r) - log.Errorf(e) - return false, fmt.Errorf(e) + log.Errorf("%s", e) + return false, errors.New(e) } // refresh successful diff --git a/tasks/install_tasks.py b/tasks/install_tasks.py index fae395b911fd7..b5e2630202786 100644 --- a/tasks/install_tasks.py +++ b/tasks/install_tasks.py @@ -1,5 +1,6 @@ -import os.path as ospath +import os import platform +import shutil import sys import zipfile from pathlib import Path @@ -9,7 +10,7 @@ from tasks.libs.ciproviders.github_api import GithubAPI from tasks.libs.common.go import download_go_dependencies from tasks.libs.common.retry import run_command_with_retry -from tasks.libs.common.utils import environ, gitlab_section +from tasks.libs.common.utils import bin_name, environ, gitlab_section TOOL_LIST = [ 'github.com/frapposelli/wwhrd', @@ -45,7 +46,7 @@ def download_tools(ctx): @task -def install_tools(ctx: Context, max_retry: int = 3): +def install_tools(ctx: Context, max_retry: int = 3, custom_golangci_lint=True): """Install all Go tools for testing.""" with gitlab_section("Installing Go tools", collapsed=True): with environ({'GO111MODULE': 'on'}): @@ -53,6 +54,34 @@ def install_tools(ctx: Context, max_retry: int = 3): with ctx.cd(path): for tool in tools: run_command_with_retry(ctx, f"go install {tool}", max_retry=max_retry) + if custom_golangci_lint: + install_custom_golanci_lint(ctx) + + +def install_custom_golanci_lint(ctx): + res = ctx.run("golangci-lint custom -v") + if res.ok: + gopath = os.getenv('GOPATH') + gobin = os.getenv('GOBIN') + + golintci_binary = bin_name('golangci-lint') + golintci_lint_backup_binary = bin_name('golangci-lint-backup') + + if gopath is None and gobin is None: + print("Not able to install custom golangci-lint binary. golangci-lint won't work as expected") + raise Exit(code=1) + + if gobin is not None and gopath is None: + shutil.move(os.path.join(gobin, golintci_binary), os.path.join(gobin, golintci_lint_backup_binary)) + shutil.move(golintci_binary, os.path.join(gobin, golintci_binary)) + + if gopath is not None: + shutil.move( + os.path.join(gopath, "bin", golintci_binary), os.path.join(gopath, "bin", golintci_lint_backup_binary) + ) + shutil.move(golintci_binary, os.path.join(gopath, "bin", golintci_binary)) + + print("Installed custom golangci-lint binary successfully") @task @@ -102,14 +131,14 @@ def install_protoc(ctx, version="26.1"): artifact_url = f"https://github.com/protocolbuffers/protobuf/releases/download/v{version}/protoc-{version}-{platform_os}-{platform_arch}.zip" zip_path = "/tmp" zip_name = "protoc" - zip_file = ospath.join(zip_path, f"{zip_name}.zip") + zip_file = os.path.join(zip_path, f"{zip_name}.zip") gh = GithubAPI(public_repo=True) # the download_from_url expect to have the path and the name of the file separated and without the extension gh.download_from_url(artifact_url, zip_path, zip_name) # Unzip it in the target destination - destination = ospath.join(Path.home(), ".local") + destination = os.path.join(Path.home(), ".local") with zipfile.ZipFile(zip_file, "r") as zip_ref: zip_ref.extract('bin/protoc', path=destination) ctx.run(f"chmod +x {destination}/bin/protoc") diff --git a/tasks/libs/common/check_tools_version.py b/tasks/libs/common/check_tools_version.py index 6ec8b7959d22f..915e484182ac9 100644 --- a/tasks/libs/common/check_tools_version.py +++ b/tasks/libs/common/check_tools_version.py @@ -38,6 +38,13 @@ def expected_golangci_lint_repo_v(ctx: Context) -> str: return "" +def custom_golangci_v(v: str) -> str: + """ + Returns the golangci-lint version with the custom suffix. + """ + return f"{v}-custom-gcl" + + def current_golangci_lint_v(ctx: Context) -> str: """ Returns the current user golangci-lint version by running golangci-lint --version @@ -53,7 +60,10 @@ def check_tools_version(ctx: Context, tools_list: list[str]) -> bool: is_expected_versions = True tools_versions = { 'go': {'current_v': current_go_v(ctx), 'expected_v': expected_go_repo_v()}, - 'golangci-lint': {'current_v': current_golangci_lint_v(ctx), 'expected_v': expected_golangci_lint_repo_v(ctx)}, + 'golangci-lint': { + 'current_v': current_golangci_lint_v(ctx), + 'expected_v': custom_golangci_v(expected_golangci_lint_repo_v(ctx)), + }, } for tool in tools_list: if tool not in tools_versions: diff --git a/tasks/linter.py b/tasks/linter.py index 432235a47ac3c..6706611d6bb54 100644 --- a/tasks/linter.py +++ b/tasks/linter.py @@ -137,6 +137,7 @@ def go( headless_mode=False, include_sds=False, only_modified_packages=False, + verbose=False, run_on=None, # noqa: U100, F841. Used by the run_on_devcontainer decorator ): """ @@ -156,7 +157,16 @@ def go( inv linter.go --targets=./pkg/collector/check,./pkg/aggregator inv linter.go --module=. """ - if not check_tools_version(ctx, ['go', 'golangci-lint']): + if not check_tools_version(ctx, ['golangci-lint']): + print( + color_message( + "Error: The golanci-lint version you are using is not the correct one. Please run inv -e install-tools to install the correct version.", + "red", + ) + ) + raise Exit(code=1) + + if not check_tools_version(ctx, ['go']): print("Warning: If you have linter errors it might be due to version mismatches.", file=sys.stderr) modules, flavor = process_input_args( @@ -184,6 +194,7 @@ def go( golangci_lint_kwargs=golangci_lint_kwargs, headless_mode=headless_mode, include_sds=include_sds, + verbose=verbose, ) if not headless_mode: @@ -217,6 +228,7 @@ def run_lint_go( golangci_lint_kwargs="", headless_mode=False, include_sds=False, + verbose=False, ): linter_tags = build_tags or compute_build_tags_for_flavor( flavor=flavor, @@ -236,6 +248,7 @@ def run_lint_go( timeout=timeout, golangci_lint_kwargs=golangci_lint_kwargs, headless_mode=headless_mode, + verbose=verbose, ) return lint_results, execution_times @@ -251,6 +264,7 @@ def lint_flavor( timeout=None, golangci_lint_kwargs: str = "", headless_mode: bool = False, + verbose: bool = False, ): """ Runs linters for given flavor, build tags, and modules. @@ -272,6 +286,7 @@ def command(module_results, module: GoModule, module_result): timeout=timeout, golangci_lint_kwargs=golangci_lint_kwargs, headless_mode=headless_mode, + verbose=verbose, ) execution_times.extend(time_results) for lint_result in lint_results: diff --git a/tasks/modules.py b/tasks/modules.py index 50ce7f5669078..38acef956278e 100644 --- a/tasks/modules.py +++ b/tasks/modules.py @@ -215,6 +215,7 @@ def dependency_path(self, agent_version): "pkg/config/utils": GoModule("pkg/config/utils", independent=True, used_by_otel=True), "pkg/errors": GoModule("pkg/errors", independent=True), "pkg/gohai": GoModule("pkg/gohai", independent=True, importable=False), + "pkg/linters/components/pkgconfigusage": GoModule("pkg/linters/components/pkgconfigusage", should_tag=False), "pkg/logs/auditor": GoModule("pkg/logs/auditor", independent=True, used_by_otel=True), "pkg/logs/client": GoModule("pkg/logs/client", independent=True, used_by_otel=True), "pkg/logs/diagnostic": GoModule("pkg/logs/diagnostic", independent=True, used_by_otel=True), diff --git a/test/new-e2e/tests/agent-platform/common/agent_behaviour.go b/test/new-e2e/tests/agent-platform/common/agent_behaviour.go index 8b220783821f6..e747cc7bf96c6 100644 --- a/test/new-e2e/tests/agent-platform/common/agent_behaviour.go +++ b/test/new-e2e/tests/agent-platform/common/agent_behaviour.go @@ -256,7 +256,7 @@ func CheckApmEnabled(t *testing.T, client *TestClient) { if err != nil && client.Host.OSFamily == componentos.LinuxFamily { err = fmt.Errorf("%w\n%s", err, ReadJournalCtl(t, client, "trace-agent\\|datadog-agent-trace")) } - t.Fatalf(err.Error()) + t.Fatalf("%s", err.Error()) } require.EqualValues(t, "127.0.0.1", boundPort.LocalAddress(), "trace-agent should only be listening locally") diff --git a/test/new-e2e/tests/npm/test_helpers.go b/test/new-e2e/tests/npm/test_helpers.go index ca501b48258dc..2e3218e28142f 100644 --- a/test/new-e2e/tests/npm/test_helpers.go +++ b/test/new-e2e/tests/npm/test_helpers.go @@ -21,7 +21,7 @@ var helperCurrentConnection *agentmodel.Connection func helperCleanup(t *testing.T) { t.Cleanup(func() { if t.Failed() { - t.Logf(krpretty.Sprintf("test failed on host %s at connection %# v", helperCurrentHostname, helperCurrentConnection)) + t.Log(krpretty.Sprintf("test failed on host %s at connection %# v", helperCurrentHostname, helperCurrentConnection)) } }) }