Skip to content

Commit

Permalink
Correctly report single-step agent installations on Docker (#25472)
Browse files Browse the repository at this point in the history
* Report single-step agent installations on Docker

* Add copyright notice

* Address a lint comment

* Address a review comment

* Finish addressing a review comment
  • Loading branch information
yshapiro-57 committed May 8, 2024
1 parent 5966dc6 commit 93ed8f7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
17 changes: 15 additions & 2 deletions comp/trace/config/install_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import (
"path/filepath"
"time"

"github.com/DataDog/datadog-agent/pkg/config/env"
"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/google/uuid"
)

const (
defaultInstallType = "manual"
defaultInstallType = "manual"
defaultDockerInstallType = "docker_manual"
dockerSingleStepInstallType = "docker_single_step"
)

func applyOrCreateInstallSignature(c *config.AgentConfig) {
Expand Down Expand Up @@ -77,12 +80,22 @@ func generateNewInstallSignature(s *config.InstallSignatureConfig) (err error) {
}
*s = config.InstallSignatureConfig{
InstallID: installID.String(),
InstallType: defaultInstallType,
InstallType: inferInstallTypeFromEnvironment(),
InstallTime: time.Now().Unix(),
}
return nil
}

func inferInstallTypeFromEnvironment() string {
if env.IsContainerized() {
if os.Getenv("DD_APM_ENABLED") != "" {
return dockerSingleStepInstallType
}
return defaultDockerInstallType
}
return defaultInstallType
}

func writeInstallSignatureToDisk(path string, s *config.InstallSignatureConfig) error {
contents, err := json.Marshal(s)
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions comp/trace/config/install_signature_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 2024-present Datadog, Inc.

package config

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestInferInstallTypeFromEnvironment(t *testing.T) {
t.Run("Non-dockerized agent", func(t *testing.T) {
assert.Equal(t, defaultInstallType, inferInstallTypeFromEnvironment())
})

t.Run("Dockerized manual instrumentation", func(t *testing.T) {
t.Setenv("DOCKER_DD_AGENT", "true")
assert.Equal(t, defaultDockerInstallType, inferInstallTypeFromEnvironment())
})

t.Run("Dockerized single-step instrumentation", func(t *testing.T) {
t.Setenv("DOCKER_DD_AGENT", "true")
t.Setenv("DD_APM_ENABLED", "true")
assert.Equal(t, dockerSingleStepInstallType, inferInstallTypeFromEnvironment())
})

t.Run("Non-standard environment variable values", func(t *testing.T) {
t.Setenv("DOCKER_DD_AGENT", "yes")
t.Setenv("DD_APM_ENABLED", "sure")
assert.Equal(t, dockerSingleStepInstallType, inferInstallTypeFromEnvironment())
})
}

0 comments on commit 93ed8f7

Please sign in to comment.