Skip to content

Commit

Permalink
refactor: move SetupCoreDump to pkg/util/coredump
Browse files Browse the repository at this point in the history
  • Loading branch information
pgimalac committed Dec 13, 2024
1 parent 786bce8 commit b63683a
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions cmd/agent/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/cluster-agent/subcommands/start/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/dogstatsd/subcommands/start/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/process-agent/command/main_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/security-agent/subcommands/start/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/system-probe/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions comp/trace/agent/impl/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/util/core.go → pkg/util/coredump/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

//go:build !windows

package util
package coredump

import (
"fmt"
Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.

package util
package coredump

import (
"fmt"

"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")
}
Expand Down

0 comments on commit b63683a

Please sign in to comment.