From 7350f1a35723e5df7795674241baf7a344c9fbd6 Mon Sep 17 00:00:00 2001 From: Gustavo Caso Date: Tue, 5 Nov 2024 17:00:13 +0100 Subject: [PATCH] use GetMetaCollector() directly inside pkg/flare --- pkg/flare/archive.go | 14 +++++++------- pkg/flare/archive_docker.go | 9 ++++----- pkg/flare/archive_nodocker.go | 7 +------ test/integration/utils/compose.go | 4 +--- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/pkg/flare/archive.go b/pkg/flare/archive.go index 76f5d3d6bc0007..78332727bdbe1d 100644 --- a/pkg/flare/archive.go +++ b/pkg/flare/archive.go @@ -73,7 +73,7 @@ func ExtraFlareProviders(diagnoseDeps diagnose.SuitesDeps) []flaretypes.FlareCal provideInstallInfo, provideAuthTokenPerm, provideDiagnoses(diagnoseDeps), - provideContainers(diagnoseDeps), + provideContainers(), } pprofURL := fmt.Sprintf("http://127.0.0.1:%s/debug/pprof/goroutine?debug=2", @@ -95,13 +95,13 @@ func ExtraFlareProviders(diagnoseDeps diagnose.SuitesDeps) []flaretypes.FlareCal return providers } -func provideContainers(diagnoseDeps diagnose.SuitesDeps) func(fb flaretypes.FlareBuilder) error { +func provideContainers() func(fb flaretypes.FlareBuilder) error { return func(fb flaretypes.FlareBuilder) error { - fb.AddFileFromFunc("docker_ps.log", getDockerPs) //nolint:errcheck - fb.AddFileFromFunc("k8s/kubelet_config.yaml", getKubeletConfig) //nolint:errcheck - fb.AddFileFromFunc("k8s/kubelet_pods.yaml", getKubeletPods) //nolint:errcheck - fb.AddFileFromFunc("ecs_metadata.json", getECSMeta) //nolint:errcheck - fb.AddFileFromFunc("docker_inspect.log", func() ([]byte, error) { return getDockerSelfInspect(diagnoseDeps.GetWMeta()) }) //nolint:errcheck + fb.AddFileFromFunc("docker_ps.log", getDockerPs) //nolint:errcheck + fb.AddFileFromFunc("k8s/kubelet_config.yaml", getKubeletConfig) //nolint:errcheck + fb.AddFileFromFunc("k8s/kubelet_pods.yaml", getKubeletPods) //nolint:errcheck + fb.AddFileFromFunc("ecs_metadata.json", getECSMeta) //nolint:errcheck + fb.AddFileFromFunc("docker_inspect.log", func() ([]byte, error) { return getDockerSelfInspect() }) //nolint:errcheck return nil } diff --git a/pkg/flare/archive_docker.go b/pkg/flare/archive_docker.go index 4b9b67c0139c82..867f21a9119c3e 100644 --- a/pkg/flare/archive_docker.go +++ b/pkg/flare/archive_docker.go @@ -16,18 +16,17 @@ import ( "strings" "text/tabwriter" - workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" + "github.com/docker/docker/api/types/container" + "github.com/DataDog/datadog-agent/pkg/config/env" "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/docker" "github.com/DataDog/datadog-agent/pkg/util/log" - "github.com/DataDog/datadog-agent/pkg/util/optional" - "github.com/docker/docker/api/types/container" ) const dockerCommandMaxLength = 29 -func getDockerSelfInspect(wmeta optional.Option[workloadmeta.Component]) ([]byte, error) { +func getDockerSelfInspect() ([]byte, error) { if !env.IsContainerized() { return nil, fmt.Errorf("The Agent is not containerized") } @@ -37,7 +36,7 @@ func getDockerSelfInspect(wmeta optional.Option[workloadmeta.Component]) ([]byte return nil, err } - selfContainerID, err := metrics.GetProvider(wmeta).GetMetaCollector().GetSelfContainerID() + selfContainerID, err := metrics.GetMetaCollector().GetSelfContainerID() if err != nil { return nil, fmt.Errorf("Unable to determine self container id, err: %w", err) } diff --git a/pkg/flare/archive_nodocker.go b/pkg/flare/archive_nodocker.go index 431d2ebd3826b7..80795c472066f3 100644 --- a/pkg/flare/archive_nodocker.go +++ b/pkg/flare/archive_nodocker.go @@ -7,12 +7,7 @@ package flare -import ( - workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" - "github.com/DataDog/datadog-agent/pkg/util/optional" -) - -func getDockerSelfInspect(_ optional.Option[workloadmeta.Component]) ([]byte, error) { +func getDockerSelfInspect() ([]byte, error) { return nil, nil } diff --git a/test/integration/utils/compose.go b/test/integration/utils/compose.go index 5fff81ab886a5a..8ae01eb4dc9508 100644 --- a/test/integration/utils/compose.go +++ b/test/integration/utils/compose.go @@ -16,10 +16,8 @@ import ( log "github.com/cihub/seelog" - workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/docker" - "github.com/DataDog/datadog-agent/pkg/util/optional" ) type ComposeConf struct { @@ -139,7 +137,7 @@ func getNetworkMode() (string, error) { } // Get container id if containerized - selfContainerID, err := metrics.GetProvider(optional.NewNoneOption[workloadmeta.Component]()).GetMetaCollector().GetSelfContainerID() + selfContainerID, err := metrics.GetMetaCollector().GetSelfContainerID() if err != nil { return "host", nil }