Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure appsignals processor on EKS with cluster name #980

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
bjrara marked this conversation as resolved.
Show resolved Hide resolved
// 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")
sky333999 marked this conversation as resolved.
Show resolved Hide resolved
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{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a use case when we have a default resolver? What happens then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would never expect the default resolver to be initied for real use case. In case it happens, it will fail the config validation with unknown resolver error.

}
}

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