Skip to content

Commit

Permalink
Move EMF flags to config.
Browse files Browse the repository at this point in the history
  • Loading branch information
jefchien committed Oct 20, 2023
1 parent 8bdf732 commit a6c8d2d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 87 deletions.
18 changes: 18 additions & 0 deletions exporter/awsemfexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package awsemfexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter"

import (
"strings"

"go.opentelemetry.io/collector/component"
"go.uber.org/zap"

Expand Down Expand Up @@ -142,7 +144,23 @@ func (config *Config) Validate() error {
}

return cwlogs.ValidateTagsInput(config.Tags)
}

func (config *Config) IsEnhancedContainerInsights() bool {
return false // temporarily disable, also need to rename _config to config
// return config.EnhancedContainerInsights && !config.DisableMetricExtraction
}

func (config *Config) IsPulseApmEnabled() bool {
if config.LogGroupName == "" || config.Namespace == "" {
return false
}

if config.Namespace == pulseMetricNamespace && strings.HasPrefix(config.LogGroupName, pulseLogGroupNamePrefix) {
return true
}

return false
}

func newEMFSupportedUnits() map[string]interface{} {
Expand Down
67 changes: 67 additions & 0 deletions exporter/awsemfexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,70 @@ func TestNoDimensionRollupFeatureGate(t *testing.T) {
assert.Equal(t, cfg.(*Config).DimensionRollupOption, "NoDimensionRollup")
_ = featuregate.GlobalRegistry().Set("awsemf.nodimrollupdefault", false)
}

func TestIsEnhancedContainerInsights(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
cfg.EnhancedContainerInsights = true
cfg.DisableMetricExtraction = false
assert.False(t, cfg.IsEnhancedContainerInsights())
cfg.EnhancedContainerInsights = false
assert.False(t, cfg.IsEnhancedContainerInsights())
cfg.EnhancedContainerInsights = true
cfg.DisableMetricExtraction = true
assert.False(t, cfg.IsEnhancedContainerInsights())
}

func TestIsPulseApmEnabled(t *testing.T) {
tests := []struct {
name string
metricNameSpace string
logGroupName string
expectedResult bool
}{
{
"validPulseEMF",
"AWS/APM",
"/aws/apm/eks",
true,
},
{
"invalidPulseLogsGroup",
"AWS/APM",
"/nonaws/apm/eks",
false,
},
{
"invalidPulseMetricNamespace",
"NonAWS/APM",
"/aws/apm/eks",
false,
},
{
"invalidPulseEMF",
"NonAWS/APM",
"/nonaws/apm/eks",
false,
},
{
"defaultConfig",
"",
"",
false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
if len(tc.metricNameSpace) > 0 {
cfg.Namespace = tc.metricNameSpace
}
if len(tc.logGroupName) > 0 {
cfg.LogGroupName = tc.logGroupName
}

assert.Equal(t, cfg.IsPulseApmEnabled(), tc.expectedResult)
})
}
}
21 changes: 2 additions & 19 deletions exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func newEmfExporter(config *Config, set exporter.CreateSettings) (*emfExporter,
config.LogRetention,
config.Tags,
session,
cwlogs.WithEnabledContainerInsights(isEnhancedContainerInsights(config)),
cwlogs.WithEnabledPulseApm(isPulseApmEnabled(config)),
cwlogs.WithEnabledContainerInsights(config.IsEnhancedContainerInsights()),
cwlogs.WithEnabledPulseApm(config.IsPulseApmEnabled()),
)
collectorIdentifier, err := uuid.NewRandom()

Expand Down Expand Up @@ -216,20 +216,3 @@ func wrapErrorIfBadRequest(err error) error {
}
return err
}

func isEnhancedContainerInsights(_ *Config) bool {
return false // temporarily disable, also need to rename _config to config
// return config.EnhancedContainerInsights && !config.DisableMetricExtraction
}

func isPulseApmEnabled(config *Config) bool {
if config.LogGroupName == "" || config.Namespace == "" {
return false
}

if config.Namespace == pulseMetricNamespace && strings.HasPrefix(config.LogGroupName, pulseLogGroupNamePrefix) {
return true
}

return false
}
68 changes: 0 additions & 68 deletions exporter/awsemfexporter/emf_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,71 +348,3 @@ func TestNewEmfExporterWithoutConfig(t *testing.T) {
assert.Nil(t, exp)
assert.Equal(t, settings.Logger, expCfg.logger)
}

func TestIsEnhancedContainerInsights(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
cfg.EnhancedContainerInsights = true
cfg.DisableMetricExtraction = false
assert.False(t, isEnhancedContainerInsights(cfg))
cfg.EnhancedContainerInsights = false
assert.False(t, isEnhancedContainerInsights(cfg))
cfg.EnhancedContainerInsights = true
cfg.DisableMetricExtraction = true
assert.False(t, isEnhancedContainerInsights(cfg))
}

func TestIsPulseApmEnabled(t *testing.T) {

tests := []struct {
name string
metricNameSpace string
logGroupName string
expectedResult bool
}{
{
"validPulseEMF",
"AWS/APM",
"/aws/apm/eks",
true,
},
{
"invalidPulseLogsGroup",
"AWS/APM",
"/nonaws/apm/eks",
false,
},
{
"invalidPulseMetricNamespace",
"NonAWS/APM",
"/aws/apm/eks",
false,
},
{
"invalidPulseEMF",
"NonAWS/APM",
"/nonaws/apm/eks",
false,
},
{
"defaultConfig",
"",
"",
false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
if len(tc.metricNameSpace) > 0 {
cfg.Namespace = tc.metricNameSpace
}
if len(tc.logGroupName) > 0 {
cfg.LogGroupName = tc.logGroupName
}

assert.Equal(t, isPulseApmEnabled(cfg), tc.expectedResult)
})
}
}

0 comments on commit a6c8d2d

Please sign in to comment.