Skip to content

Commit

Permalink
Fixing logic for when to enable APM (DataDog#31805)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosroman authored Dec 5, 2024
1 parent 0db869d commit 48cbbbf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/config/utils/miscellaneous.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ func IsCoreAgentEnabled(cfg pkgconfigmodel.Reader) bool {
// Error Tracking standalone only via the apm_config.error_tracking_standalone.enabled option instead of requiring
// to enable also apm_config.enabled.
func IsAPMEnabled(cfg pkgconfigmodel.Reader) bool {
return (cfg.GetBool("apm_config.enabled") && IsCoreAgentEnabled(cfg)) ||
return cfg.GetBool("apm_config.enabled") ||
cfg.GetBool("apm_config.error_tracking_standalone.enabled")
}
46 changes: 45 additions & 1 deletion pkg/config/utils/miscellaneous_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
package utils

import (
"github.com/stretchr/testify/assert"
"testing"

configmock "github.com/DataDog/datadog-agent/pkg/config/mock"
"github.com/DataDog/datadog-agent/pkg/config/model"

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

func TestIsCoreAgentEnabled(t *testing.T) {
Expand Down Expand Up @@ -64,3 +65,46 @@ func TestIsCoreAgentEnabled(t *testing.T) {
})
}
}

func TestIsAPMEnabled(t *testing.T) {
tests := []struct {
name string
apmEnabled, errorTrackingEnable, expected bool
}{
{
name: "APM enabled and Error Tracking standalone disabled",
apmEnabled: false,
errorTrackingEnable: false,
expected: false,
},
{
name: "APM enabled and Error Tracking standalone disabled",
apmEnabled: true,
errorTrackingEnable: false,
expected: true,
},
{
name: "APM disabled and Error Tracking standalone enabled",
apmEnabled: false,
errorTrackingEnable: true,
expected: true,
},
{
name: "APM enabled and Error Tracking standalone enabled",
apmEnabled: true,
errorTrackingEnable: true,
expected: true,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
mockConfig := configmock.New(t)
mockConfig.SetWithoutSource("apm_config.enabled", test.apmEnabled)
mockConfig.SetWithoutSource("apm_config.error_tracking_standalone.enabled", test.errorTrackingEnable)
assert.Equal(t,
test.expected, IsAPMEnabled(mockConfig),
"Was expecting IsAPMEnabled to return", test.expected)
})
}
}

0 comments on commit 48cbbbf

Please sign in to comment.