Skip to content

Commit

Permalink
use GetMetaCollector() directly inside pkg/flare
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Nov 5, 2024
1 parent 11a699b commit 7350f1a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
14 changes: 7 additions & 7 deletions pkg/flare/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/flare/archive_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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)
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/flare/archive_nodocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 1 addition & 3 deletions test/integration/utils/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7350f1a

Please sign in to comment.