Skip to content

Commit

Permalink
Configure appsignals processor on EKS with cluster name (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjrara authored Dec 21, 2023
1 parent c17c309 commit f2e1251
Show file tree
Hide file tree
Showing 30 changed files with 463 additions and 173 deletions.
1 change: 1 addition & 0 deletions cmd/config-translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestLogWindowsEventConfig(t *testing.T) {
func TestMetricsConfig(t *testing.T) {
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/validLinuxMetrics.json", true, map[string]int{})
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/validWindowsMetrics.json", true, map[string]int{})
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/validMetricsWithAppSignals.json", true, map[string]int{})
expectedErrorMap := map[string]int{}
expectedErrorMap["invalid_type"] = 2
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/invalidMetricsWithInvalidAggregationDimensions.json", false, expectedErrorMap)
Expand Down
18 changes: 0 additions & 18 deletions plugins/processors/awsappsignals/config.go

This file was deleted.

33 changes: 33 additions & 0 deletions plugins/processors/awsappsignals/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package config

import (
"errors"

"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/rules"
)

type Config struct {
Resolvers []Resolver `mapstructure:"resolvers"`
Rules []rules.Rule `mapstructure:"rules"`
}

func (cfg *Config) Validate() error {
if len(cfg.Resolvers) == 0 {
return errors.New("resolvers must not be empty")
}
for _, resolver := range cfg.Resolvers {
switch resolver.Platform {
case PlatformEKS:
if resolver.Name == "" {
return errors.New("name must not be empty for eks resolver")
}
case PlatformGeneric:
default:
return errors.New("unknown resolver")
}
}
return nil
}
34 changes: 34 additions & 0 deletions plugins/processors/awsappsignals/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package config

import (
"testing"

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

func TestValidatePassed(t *testing.T) {
config := Config{
Resolvers: []Resolver{NewEKSResolver("test"), NewGenericResolver("")},
Rules: nil,
}
assert.Nil(t, config.Validate())
}

func TestValidateFailedOnEmptyResolver(t *testing.T) {
config := Config{
Resolvers: []Resolver{},
Rules: nil,
}
assert.NotNil(t, config.Validate())
}

func TestValidateFailedOnEmptyClusterName(t *testing.T) {
config := Config{
Resolvers: []Resolver{NewEKSResolver("")},
Rules: nil,
}
assert.NotNil(t, config.Validate())
}
30 changes: 30 additions & 0 deletions plugins/processors/awsappsignals/config/resolvers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package config

const (
// PlatformGeneric Platforms other than Amazon EKS
PlatformGeneric = "generic"
// PlatformEKS Amazon EKS platform
PlatformEKS = "eks"
)

type Resolver struct {
Name string `mapstructure:"name"`
Platform string `mapstructure:"platform"`
}

func NewEKSResolver(name string) Resolver {
return Resolver{
Name: name,
Platform: PlatformEKS,
}
}

func NewGenericResolver(name string) Resolver {
return Resolver{
Name: name,
Platform: PlatformGeneric,
}
}
20 changes: 20 additions & 0 deletions plugins/processors/awsappsignals/config/resolvers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package config

import (
"testing"

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

func TestNewEKSResolver(t *testing.T) {
resolver := NewEKSResolver("test")
assert.Equal(t, "eks", resolver.Platform)
}

func TestNewGenericResolver(t *testing.T) {
resolver := NewGenericResolver("")
assert.Equal(t, "generic", resolver.Platform)
}
104 changes: 0 additions & 104 deletions plugins/processors/awsappsignals/config_test.go

This file was deleted.

9 changes: 5 additions & 4 deletions plugins/processors/awsappsignals/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"

appsignalsconfig "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/config"
)

const (
Expand All @@ -33,9 +35,8 @@ func NewFactory() processor.Factory {
}

func createDefaultConfig() component.Config {
return &Config{
// TODO: change default config when other resolvers are supported
Resolvers: []string{"eks"},
return &appsignalsconfig.Config{
Resolvers: []appsignalsconfig.Resolver{},
}
}

Expand Down Expand Up @@ -87,7 +88,7 @@ func createProcessor(
params processor.CreateSettings,
cfg component.Config,
) (*awsappsignalsprocessor, error) {
pCfg, ok := cfg.(*Config)
pCfg, ok := cfg.(*appsignalsconfig.Config)
if !ok {
return nil, errors.New("could not initialize awsappsignalsprocessor")
}
Expand Down
Loading

0 comments on commit f2e1251

Please sign in to comment.