Skip to content

Commit

Permalink
Merge branch 'main' into andrew.glaude/apiNoBind
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgajg1134 committed Jul 16, 2024
2 parents a2c4ffb + fd3f4ff commit bf3f77e
Show file tree
Hide file tree
Showing 30 changed files with 247 additions and 291 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ variables:
GITLAB_SCHEDULER_TOKEN_SSM_NAME: ci.datadog-agent.gitlab_pipelines_scheduler_token # ci-cd
GITLAB_READ_API_TOKEN_SSM_NAME: ci.datadog-agent.gitlab_read_api_token # ci-cd
GITLAB_FULL_API_TOKEN_SSM_NAME: ci.datadog-agent.gitlab_full_api_token # ci-cd
INSTALL_SCRIPT_API_KEY_SSM_NAME: ci.agent-linux-install-script.datadog_api_key # agent-delivery
INSTALL_SCRIPT_API_KEY_SSM_NAME: ci.agent-linux-install-script.datadog_api_key_2 # agent-delivery
JIRA_READ_API_TOKEN_SSM_NAME: ci.datadog-agent.jira_read_api_token # agent-devx-infra
MACOS_GITHUB_APP_ID_SSM_NAME: ci.datadog-agent.macos_github_app_id # agent-devx-infra
MACOS_GITHUB_INSTALLATION_ID_SSM_NAME: ci.datadog-agent.macos_github_installation_id # agent-devx-infra
Expand Down
2 changes: 1 addition & 1 deletion .gitlab/kitchen_testing/new-e2e_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@
TEAM: agent-delivery
EXTRA_PARAMS: --osversion $E2E_OSVERS --platform $E2E_PLATFORM --arch $E2E_ARCH
script:
- export DATADOG_AGENT_API_KEY=$($CI_PROJECT_DIR/tools/ci/aws_ssm_get_wrapper.sh ci.agent-linux-install-script.datadog_api_key)
- export DATADOG_AGENT_API_KEY=$($CI_PROJECT_DIR/tools/ci/aws_ssm_get_wrapper.sh $INSTALL_SCRIPT_API_KEY_SSM_NAME)
- inv -e new-e2e-tests.run --targets $TARGETS --junit-tar "junit-${CI_JOB_ID}.tgz" ${EXTRA_PARAMS}
26 changes: 23 additions & 3 deletions cmd/serverless-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ package main

import (
"context"
"errors"
"os"
"os/exec"
"sync"
"time"

Expand Down Expand Up @@ -87,18 +89,22 @@ func main() {

if err != nil {
log.Error(err)
os.Exit(-1)
exitCode := errorExitCode(err)
log.Flush()
os.Exit(exitCode)
}
}

// removing these unused dependencies will cause silent crash due to fx framework
func run(_ secrets.Component, _ autodiscovery.Component, _ healthprobeDef.Component) {
func run(_ secrets.Component, _ autodiscovery.Component, _ healthprobeDef.Component) error {
cloudService, logConfig, traceAgent, metricAgent, logsAgent := setup(modeConf)

modeConf.Runner(logConfig)
err := modeConf.Runner(logConfig)

metric.AddShutdownMetric(cloudService.GetPrefix(), metricAgent.GetExtraTags(), time.Now(), metricAgent.Demux)
lastFlush(logConfig.FlushTimeout, metricAgent, traceAgent, logsAgent)

return err
}

func setup(mode.Conf) (cloudservice.CloudService, *serverlessInitLog.Config, trace.ServerlessTraceAgent, *metrics.ServerlessMetricAgent, logsAgent.ServerlessLogsAgent) {
Expand Down Expand Up @@ -235,3 +241,17 @@ func setEnvWithoutOverride(envToSet map[string]string) {
}
}
}

func errorExitCode(err error) int {
// if error is of type exec.ExitError then propagate the exit code
var exitError *exec.ExitError
if errors.As(err, &exitError) {
exitCode := exitError.ExitCode()
log.Debugf("propagating exit code %v", exitCode)
return exitCode
}

// use exit code 1 if there is no exit code in the error to propagate
log.Debug("using default exit code 1")
return 1
}
28 changes: 28 additions & 0 deletions cmd/serverless-init/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
package main

import (
"errors"
"os/exec"
"testing"
"time"

Expand Down Expand Up @@ -83,3 +85,29 @@ func TestFlushTimeout(t *testing.T) {
assert.Equal(t, false, metricAgent.hasBeenCalled)
assert.Equal(t, false, mockLogsAgent.DidFlush())
}
func TestExitCodePropagationGenericError(t *testing.T) {
err := errors.New("test error")

exitCode := errorExitCode(err)
assert.Equal(t, 1, exitCode)
}

func TestExitCodePropagationExitError(t *testing.T) {
cmd := exec.Command("bash", "-c", "exit 2")
err := cmd.Run()

exitCode := errorExitCode(err)
assert.Equal(t, 2, exitCode)
}

func TestExitCodePropagationJoinedExitError(t *testing.T) {
genericError := errors.New("test error")

cmd := exec.Command("bash", "-c", "exit 3")
exitCodeError := cmd.Run()

errs := errors.Join(genericError, exitCodeError)

exitCode := errorExitCode(errs)
assert.Equal(t, 3, exitCode)
}
11 changes: 7 additions & 4 deletions cmd/serverless-init/mode/initcontainer_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
package mode

import (
serverlessLog "github.com/DataDog/datadog-agent/cmd/serverless-init/log"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/spf13/afero"
"io"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"

serverlessLog "github.com/DataDog/datadog-agent/cmd/serverless-init/log"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/spf13/afero"
)

// Run is the entrypoint of the init process. It will spawn the customer process
func RunInit(logConfig *serverlessLog.Config) {
func RunInit(logConfig *serverlessLog.Config) error {
if len(os.Args) < 2 {
panic("[datadog init process] invalid argument count, did you forget to set CMD ?")
}
Expand All @@ -32,7 +33,9 @@ func RunInit(logConfig *serverlessLog.Config) {
err := execute(logConfig, args)
if err != nil {
log.Debugf("Error exiting: %v\n", err)
return err
}
return nil
}

func execute(logConfig *serverlessLog.Config, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/serverless-init/mode/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// Conf contains the configuration for the mode in which the serverless-init agent should run
type Conf struct {
LoggerName string
Runner func(logConfig *serverlessLog.Config)
Runner func(logConfig *serverlessLog.Config) error
TagVersionMode string
EnvDefaults map[string]string
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/serverless-init/mode/sidecarcontainer_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
package mode

import (
serverlessLog "github.com/DataDog/datadog-agent/cmd/serverless-init/log"
"github.com/DataDog/datadog-agent/pkg/util/log"
"os"
"os/signal"
"syscall"

serverlessLog "github.com/DataDog/datadog-agent/cmd/serverless-init/log"
"github.com/DataDog/datadog-agent/pkg/util/log"
)

// Run is the entrypoint of the init process. It will spawn the customer process
func RunSidecar(logConfig *serverlessLog.Config) {
func RunSidecar(logConfig *serverlessLog.Config) error {
stopCh := make(chan struct{})
go handleTerminationSignals(stopCh, signal.Notify)
<-stopCh

return nil
}

func handleTerminationSignals(stopCh chan struct{}, notify func(c chan<- os.Signal, sig ...os.Signal)) {
Expand Down
2 changes: 1 addition & 1 deletion comp/core/workloadmeta/collectors/internal/ecs/v4parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *collector) parseTasksFromV4Endpoint(ctx context.Context) ([]workloadmet
return c.setLastSeenEntitiesAndUnsetEvents(events, seen), nil
}

// getTaskWithTagsFromV4Endpoint fetches task and tasks from the metadata v4 API
// getTaskWithTagsFromV4Endpoint fetches task and tags from the metadata v4 API
func (c *collector) getTaskWithTagsFromV4Endpoint(ctx context.Context, task v1.Task) (v3or4.Task, error) {
var metaURI string
for _, taskContainer := range task.Containers {
Expand Down
21 changes: 18 additions & 3 deletions comp/process/agent/agent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@
package agent

import (
"slices"

"github.com/DataDog/datadog-agent/comp/core/config"
logComponent "github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/process/types"
"github.com/DataDog/datadog-agent/pkg/process/checks"
"github.com/DataDog/datadog-agent/pkg/util/flavor"
)

// List of check names for process checks
var processCheckNames = []string{
checks.ProcessCheckName,
checks.ContainerCheckName,
checks.DiscoveryCheckName,
}

// Enabled determines whether the process agent is enabled based on the configuration.
// The process-agent component on linux can be run in the core agent or as a standalone process-agent
// depending on the configuration.
Expand All @@ -26,10 +35,13 @@ func Enabled(config config.Component, checkComponents []types.CheckComponent, lo
runInCoreAgent := config.GetBool("process_config.run_in_core_agent.enabled")

var npmEnabled bool
var processEnabled bool
for _, check := range checkComponents {
if check.Object().Name() == checks.ConnectionsCheckName && check.Object().IsEnabled() {
npmEnabled = true
break
}
if slices.Contains(processCheckNames, check.Object().Name()) && check.Object().IsEnabled() {
processEnabled = true
}
}

Expand All @@ -40,14 +52,17 @@ func Enabled(config config.Component, checkComponents []types.CheckComponent, lo
log.Info("Network Performance Monitoring is not supported in the core agent. " +
"The process-agent will be enabled as a standalone agent")
}
return true
}

if runInCoreAgent {
log.Info("The process checks will run in the core agent")
} else if processEnabled {
log.Info("Process/Container Collection in the Process Agent will be deprecated in a future release " +
"and will instead be run in the Core Agent. " +
"Set process_config.run_in_core_agent.enabled to true to switch now.")
}

return !runInCoreAgent
return !runInCoreAgent || npmEnabled
case flavor.DefaultAgent:
if npmEnabled && runInCoreAgent {
log.Info("Network Performance Monitoring is not supported in the core agent. " +
Expand Down
8 changes: 8 additions & 0 deletions comp/process/agent/agentimpl/agent_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ func TestProcessAgentComponentOnLinux(t *testing.T) {
runInCoreAgentConfig: true,
expected: true,
},
{
name: "process-agent with connections check enabled and run in core-agent mode disabled",
agentFlavor: flavor.ProcessAgent,
checksEnabled: true,
checkName: checks.ConnectionsCheckName,
runInCoreAgentConfig: false,
expected: true,
},
{
name: "core agent with process check enabled and run in core-agent mode enabled",
agentFlavor: flavor.DefaultAgent,
Expand Down

This file was deleted.

7 changes: 1 addition & 6 deletions pkg/proto/pbgo/trace/decoder_v05.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func (z *Span) UnmarshalMsgDictionary(bts []byte, dict []string) ([]byte, error)
delete(z.Meta, key)
}
}
hook, hookok := MetaHook()
for sz > 0 {
sz--
var key, val string
Expand All @@ -171,11 +170,7 @@ func (z *Span) UnmarshalMsgDictionary(bts []byte, dict []string) ([]byte, error)
if err != nil {
return bts, err
}
if hookok {
z.Meta[key] = hook(key, val)
} else {
z.Meta[key] = val
}
z.Meta[key] = val
}
// Metrics (10)
sz, bts, err = safeReadHeaderBytes(bts, msgp.ReadMapHeaderBytes)
Expand Down
33 changes: 0 additions & 33 deletions pkg/proto/pbgo/trace/hook.go

This file was deleted.

Loading

0 comments on commit bf3f77e

Please sign in to comment.