diff --git a/cmd/agent/subcommands/run/command.go b/cmd/agent/subcommands/run/command.go index 9c126f014aab27..76775693251e4b 100644 --- a/cmd/agent/subcommands/run/command.go +++ b/cmd/agent/subcommands/run/command.go @@ -146,8 +146,8 @@ import ( jmxStatus "github.com/DataDog/datadog-agent/pkg/status/jmx" systemprobeStatus "github.com/DataDog/datadog-agent/pkg/status/systemprobe" pkgTelemetry "github.com/DataDog/datadog-agent/pkg/telemetry" - "github.com/DataDog/datadog-agent/pkg/util" pkgcommon "github.com/DataDog/datadog-agent/pkg/util/common" + "github.com/DataDog/datadog-agent/pkg/util/coredump" "github.com/DataDog/datadog-agent/pkg/util/defaultpaths" "github.com/DataDog/datadog-agent/pkg/util/flavor" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -512,7 +512,7 @@ func startAgent( log.Infof("Starting Datadog Agent v%v", version.AgentVersion) } - if err := util.SetupCoreDump(pkgconfigsetup.Datadog()); err != nil { + if err := coredump.Setup(pkgconfigsetup.Datadog()); err != nil { log.Warnf("Can't setup core dumps: %v, core dumps might not be available after a crash", err) } diff --git a/cmd/cluster-agent/subcommands/start/command.go b/cmd/cluster-agent/subcommands/start/command.go index f43ae03615401b..aea5e4207f57cd 100644 --- a/cmd/cluster-agent/subcommands/start/command.go +++ b/cmd/cluster-agent/subcommands/start/command.go @@ -81,7 +81,7 @@ import ( hostnameStatus "github.com/DataDog/datadog-agent/pkg/status/clusteragent/hostname" endpointsStatus "github.com/DataDog/datadog-agent/pkg/status/endpoints" "github.com/DataDog/datadog-agent/pkg/status/health" - "github.com/DataDog/datadog-agent/pkg/util" + "github.com/DataDog/datadog-agent/pkg/util/coredump" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/hostname" "github.com/DataDog/datadog-agent/pkg/util/kubernetes/apiserver" @@ -241,7 +241,7 @@ func start(log log.Component, // Starting Cluster Agent sequence // Initialization order is important for multiple reasons, see comments - if err := util.SetupCoreDump(config); err != nil { + if err := coredump.Setup(config); err != nil { pkglog.Warnf("Can't setup core dumps: %v, core dumps might not be available after a crash", err) } diff --git a/cmd/dogstatsd/subcommands/start/command.go b/cmd/dogstatsd/subcommands/start/command.go index f61ae13db837da..b6e6a63361ae88 100644 --- a/cmd/dogstatsd/subcommands/start/command.go +++ b/cmd/dogstatsd/subcommands/start/command.go @@ -57,7 +57,7 @@ import ( compressionfx "github.com/DataDog/datadog-agent/comp/serializer/compression/fx" "github.com/DataDog/datadog-agent/pkg/serializer" "github.com/DataDog/datadog-agent/pkg/status/health" - "github.com/DataDog/datadog-agent/pkg/util" + "github.com/DataDog/datadog-agent/pkg/util/coredump" "github.com/DataDog/datadog-agent/pkg/util/fxutil" pkglog "github.com/DataDog/datadog-agent/pkg/util/log" pkglogsetup "github.com/DataDog/datadog-agent/pkg/util/log/setup" @@ -235,7 +235,7 @@ func RunDogstatsd(_ context.Context, cliParams *CLIParams, config config.Compone } }() - if err := util.SetupCoreDump(config); err != nil { + if err := coredump.Setup(config); err != nil { log.Warnf("Can't setup core dumps: %v, core dumps might not be available after a crash", err) } diff --git a/cmd/process-agent/command/main_common.go b/cmd/process-agent/command/main_common.go index 188c9684fd30bf..dcb9287e74f04b 100644 --- a/cmd/process-agent/command/main_common.go +++ b/cmd/process-agent/command/main_common.go @@ -61,7 +61,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/process/metadata/workloadmeta/collector" "github.com/DataDog/datadog-agent/pkg/process/util" proccontainers "github.com/DataDog/datadog-agent/pkg/process/util/containers" - ddutil "github.com/DataDog/datadog-agent/pkg/util" + "github.com/DataDog/datadog-agent/pkg/util/coredump" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/fxutil/logging" "github.com/DataDog/datadog-agent/pkg/util/log" @@ -296,7 +296,7 @@ type miscDeps struct { // Todo: (Components) WorkloadMeta, remoteTagger // Todo: move metadata/workloadmeta/collector to workloadmeta func initMisc(deps miscDeps) error { - if err := ddutil.SetupCoreDump(deps.Config); err != nil { + if err := coredump.Setup(deps.Config); err != nil { deps.Logger.Warnf("Can't setup core dumps: %v, core dumps might not be available after a crash", err) } diff --git a/cmd/security-agent/subcommands/start/command.go b/cmd/security-agent/subcommands/start/command.go index 8386100c0031ba..12a93fc4560ff0 100644 --- a/cmd/security-agent/subcommands/start/command.go +++ b/cmd/security-agent/subcommands/start/command.go @@ -63,7 +63,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/security/agent" "github.com/DataDog/datadog-agent/pkg/security/utils" "github.com/DataDog/datadog-agent/pkg/status/health" - "github.com/DataDog/datadog-agent/pkg/util" + "github.com/DataDog/datadog-agent/pkg/util/coredump" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/optional" "github.com/DataDog/datadog-agent/pkg/util/profiling" @@ -257,7 +257,7 @@ var errNoAPIKeyConfigured = errors.New("no API key configured") // RunAgent initialized resources and starts API server func RunAgent(log log.Component, config config.Component, telemetry telemetry.Component, statusComponent status.Component, settings settings.Component, wmeta workloadmeta.Component) (err error) { - if err := util.SetupCoreDump(config); err != nil { + if err := coredump.Setup(config); err != nil { log.Warnf("Can't setup core dumps: %v, core dumps might not be available after a crash", err) } diff --git a/cmd/system-probe/subcommands/run/command.go b/cmd/system-probe/subcommands/run/command.go index cd35036946e884..659f7e2fe0f524 100644 --- a/cmd/system-probe/subcommands/run/command.go +++ b/cmd/system-probe/subcommands/run/command.go @@ -61,7 +61,7 @@ import ( ebpftelemetry "github.com/DataDog/datadog-agent/pkg/ebpf/telemetry" processstatsd "github.com/DataDog/datadog-agent/pkg/process/statsd" ddruntime "github.com/DataDog/datadog-agent/pkg/runtime" - "github.com/DataDog/datadog-agent/pkg/util" + "github.com/DataDog/datadog-agent/pkg/util/coredump" "github.com/DataDog/datadog-agent/pkg/util/fxutil" pkglog "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/DataDog/datadog-agent/pkg/util/optional" @@ -333,7 +333,7 @@ func startSystemProbe(log log.Component, statsd compstatsd.Component, telemetry return ErrNotEnabled } - if err := util.SetupCoreDump(sysprobeconfig); err != nil { + if err := coredump.Setup(sysprobeconfig); err != nil { log.Warnf("cannot setup core dumps: %s, core dumps might not be available after a crash", err) } diff --git a/comp/trace/agent/impl/run.go b/comp/trace/agent/impl/run.go index df25106b78755a..20ecbc6496a1b3 100644 --- a/comp/trace/agent/impl/run.go +++ b/comp/trace/agent/impl/run.go @@ -23,7 +23,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/trace/info" "github.com/DataDog/datadog-agent/pkg/trace/telemetry" "github.com/DataDog/datadog-agent/pkg/trace/watchdog" - "github.com/DataDog/datadog-agent/pkg/util" + "github.com/DataDog/datadog-agent/pkg/util/coredump" "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/DataDog/datadog-agent/pkg/util/profiling" "github.com/DataDog/datadog-agent/pkg/version" @@ -41,7 +41,7 @@ func runAgentSidekicks(ag component) error { defer watchdog.LogOnPanic(ag.Statsd) - if err := util.SetupCoreDump(pkgconfigsetup.Datadog()); err != nil { + if err := coredump.Setup(pkgconfigsetup.Datadog()); err != nil { log.Warnf("Can't setup core dumps: %v, core dumps might not be available after a crash", err) } diff --git a/pkg/util/core.go b/pkg/util/coredump/core.go similarity index 81% rename from pkg/util/core.go rename to pkg/util/coredump/core.go index 77649ea1d53f3d..64b4f35c3a12a1 100644 --- a/pkg/util/core.go +++ b/pkg/util/coredump/core.go @@ -5,7 +5,7 @@ //go:build !windows -package util +package coredump import ( "fmt" @@ -16,8 +16,8 @@ import ( "github.com/DataDog/datadog-agent/pkg/config/model" ) -// SetupCoreDump enables core dumps and sets the core dump size limit based on configuration -func SetupCoreDump(cfg model.Reader) error { +// Setup enables core dumps and sets the core dump size limit based on configuration +func Setup(cfg model.Reader) error { if cfg.GetBool("go_core_dump") { debug.SetTraceback("crash") diff --git a/pkg/util/core_windows.go b/pkg/util/coredump/core_windows.go similarity index 73% rename from pkg/util/core_windows.go rename to pkg/util/coredump/core_windows.go index c11422c8aff2b3..3e7d3915f7636d 100644 --- a/pkg/util/core_windows.go +++ b/pkg/util/coredump/core_windows.go @@ -3,7 +3,7 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-2020 Datadog, Inc. -package util +package coredump import ( "fmt" @@ -11,8 +11,8 @@ import ( "github.com/DataDog/datadog-agent/pkg/config/model" ) -// SetupCoreDump enables core dumps and sets the core dump size limit based on configuration -func SetupCoreDump(cfg model.Reader) error { +// Setup enables core dumps and sets the core dump size limit based on configuration +func Setup(cfg model.Reader) error { if cfg.GetBool("go_core_dump") { return fmt.Errorf("Not supported on Windows") } diff --git a/pkg/util/coredump/docs.go b/pkg/util/coredump/docs.go new file mode 100644 index 00000000000000..43371b50e7dac6 --- /dev/null +++ b/pkg/util/coredump/docs.go @@ -0,0 +1,7 @@ +// 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-2020 Datadog, Inc. + +// Package coredump provides utils to enable core dumps and set core dump size limit +package coredump