Skip to content

Commit faa5b95

Browse files
authored
Merge branch 'main' into dominic-ttl
2 parents f0c014b + c2765b6 commit faa5b95

File tree

15 files changed

+525
-7
lines changed

15 files changed

+525
-7
lines changed

.github/workflows/deploy-canary.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242

4343
- name: Install Terraform
4444
uses: hashicorp/setup-terraform@v3
45+
with:
46+
terraform_version: 1.12.0
4547

4648
- name: Terminate Last Canary
4749
run: |

.github/workflows/ec2-integration-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ jobs:
7474
7575
- name: Install Terraform
7676
uses: hashicorp/setup-terraform@v3
77+
with:
78+
terraform_version: 1.12.0
7779

7880
- name: Verify Terraform version
7981
run: terraform --version

.github/workflows/eks-e2e-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ jobs:
9999

100100
- name: Install Terraform
101101
uses: hashicorp/setup-terraform@v3
102+
with:
103+
terraform_version: 1.12.0
102104

103105
- name: Verify Terraform version
104106
run: terraform --version

.github/workflows/soak-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ jobs:
8181

8282
- name: Install Terraform
8383
uses: hashicorp/setup-terraform@v3
84+
with:
85+
terraform_version: 1.12.0
8486

8587
- name: Verify Terraform version
8688
run: terraform --version

.github/workflows/start-localstack.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ jobs:
6262

6363
- name: Install Terraform
6464
uses: hashicorp/setup-terraform@v3
65+
with:
66+
terraform_version: 1.12.0
6567

6668
- name: Verify Terraform version
6769
run: terraform --version

.github/workflows/stop-localstack.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ jobs:
5555

5656
- name: Install Terraform
5757
uses: hashicorp/setup-terraform@v3
58+
with:
59+
terraform_version: 1.12.0
5860

5961
- name: Verify Terraform version
6062
run: terraform --version

.github/workflows/test-artifacts.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ jobs:
285285

286286
- name: Install Terraform
287287
uses: hashicorp/setup-terraform@v3
288+
with:
289+
terraform_version: 1.12.0
288290

289291
- name: Verify Terraform version
290292
run: terraform --version
@@ -475,6 +477,8 @@ jobs:
475477

476478
- name: Install Terraform
477479
uses: hashicorp/setup-terraform@v3
480+
with:
481+
terraform_version: 1.12.0
478482

479483
- name: Verify Terraform version
480484
run: terraform --version
@@ -552,6 +556,8 @@ jobs:
552556

553557
- name: Install Terraform
554558
uses: hashicorp/setup-terraform@v3
559+
with:
560+
terraform_version: 1.12.0
555561

556562
- name: Verify Terraform version
557563
run: terraform --version
@@ -682,6 +688,8 @@ jobs:
682688

683689
- name: Install Terraform
684690
uses: hashicorp/setup-terraform@v3
691+
with:
692+
terraform_version: 1.12.0
685693

686694
- name: Verify Terraform version
687695
run: terraform --version
@@ -758,6 +766,8 @@ jobs:
758766

759767
- name: Install Terraform
760768
uses: hashicorp/setup-terraform@v3
769+
with:
770+
terraform_version: 1.12.0
761771

762772
- name: Verify Terraform version
763773
run: terraform --version
@@ -830,6 +840,8 @@ jobs:
830840

831841
- name: Install Terraform
832842
uses: hashicorp/setup-terraform@v3
843+
with:
844+
terraform_version: 1.12.0
833845

834846
- name: Verify Terraform version
835847
run: terraform --version
@@ -905,6 +917,8 @@ jobs:
905917

906918
- name: Install Terraform
907919
uses: hashicorp/setup-terraform@v3
920+
with:
921+
terraform_version: 1.12.0
908922

909923
- name: Verify Terraform version
910924
run: terraform --version
@@ -973,6 +987,8 @@ jobs:
973987

974988
- name: Install Terraform
975989
uses: hashicorp/setup-terraform@v3
990+
with:
991+
terraform_version: 1.12.0
976992

977993
- name: Verify Terraform version
978994
run: terraform --version
@@ -1035,6 +1051,8 @@ jobs:
10351051

10361052
- name: Install Terraform
10371053
uses: hashicorp/setup-terraform@v3
1054+
with:
1055+
terraform_version: 1.12.0
10381056

10391057
- name: Verify Terraform version
10401058
run: terraform --version
@@ -1097,6 +1115,8 @@ jobs:
10971115

10981116
- name: Install Terraform
10991117
uses: hashicorp/setup-terraform@v3
1118+
with:
1119+
terraform_version: 1.12.0
11001120

11011121
- name: Verify Terraform version
11021122
run: terraform --version
@@ -1161,6 +1181,8 @@ jobs:
11611181

11621182
- name: Install Terraform
11631183
uses: hashicorp/setup-terraform@v3
1184+
with:
1185+
terraform_version: 1.12.0
11641186

11651187
- name: Verify Terraform version
11661188
run: terraform --version
@@ -1226,6 +1248,8 @@ jobs:
12261248

12271249
- name: Install Terraform
12281250
uses: hashicorp/setup-terraform@v3
1251+
with:
1252+
terraform_version: 1.12.0
12291253

12301254
- name: Verify Terraform version
12311255
run: terraform --version

internal/entity/entity.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package entity
5+
6+
// KeyPair represents a key-value pair for entity attributes
7+
type KeyPair struct {
8+
Key string `mapstructure:"key"`
9+
Value string `mapstructure:"value"`
10+
}
11+
12+
// Transform contains configuration for overriding entity attributes
13+
type Transform struct {
14+
KeyAttributes []KeyPair `mapstructure:"key_attributes"`
15+
Attributes []KeyPair `mapstructure:"attributes"`
16+
}

plugins/processors/awsentity/config.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
package awsentity
55

66
import (
7+
"errors"
8+
79
"go.opentelemetry.io/collector/component"
10+
11+
"github.com/aws/amazon-cloudwatch-agent/internal/entity"
12+
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsentity/entityattributes"
813
)
914

1015
type Config struct {
@@ -23,11 +28,34 @@ type Config struct {
2328
// EntityType determines the type of entity processing done for
2429
// telemetry. Possible values are Service and Resource
2530
EntityType string `mapstructure:"entity_type,omitempty"`
31+
// TransformEntity contains configuration for overriding entity attributes
32+
TransformEntity *entity.Transform `mapstructure:"transform_entity,omitempty"`
2633
}
2734

2835
// Verify Config implements Processor interface.
2936
var _ component.Config = (*Config)(nil)
3037

3138
func (cfg *Config) Validate() error {
39+
if cfg.TransformEntity != nil {
40+
// Validate key attributes
41+
for _, keyAttr := range cfg.TransformEntity.KeyAttributes {
42+
if !entityattributes.IsAllowedKeyAttribute(keyAttr.Key) {
43+
return errors.New("Invalid key attribute name for entity: " + keyAttr.Key)
44+
}
45+
if keyAttr.Value == "" {
46+
return errors.New("empty value for entity key attribute")
47+
}
48+
}
49+
50+
// Validate regular attributes
51+
for _, attr := range cfg.TransformEntity.Attributes {
52+
if !entityattributes.IsAllowedAttribute(attr.Key) {
53+
return errors.New("Invalid attribute name for entity: " + attr.Key)
54+
}
55+
if attr.Value == "" {
56+
return errors.New("empty value for entity attribute")
57+
}
58+
}
59+
}
3260
return nil
3361
}

plugins/processors/awsentity/config_test.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88

99
"github.com/stretchr/testify/assert"
1010
"go.opentelemetry.io/collector/confmap"
11+
12+
"github.com/aws/amazon-cloudwatch-agent/internal/entity"
13+
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsentity/entityattributes"
1114
)
1215

1316
func TestUnmarshalDefaultConfig(t *testing.T) {
@@ -16,3 +19,126 @@ func TestUnmarshalDefaultConfig(t *testing.T) {
1619
assert.NoError(t, confmap.New().Unmarshal(cfg))
1720
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
1821
}
22+
23+
func TestUnmarshalConfig(t *testing.T) {
24+
tests := []struct {
25+
name string
26+
conf *confmap.Conf
27+
expected *Config
28+
expectError bool
29+
}{
30+
{
31+
name: "TestValidEntityTransform",
32+
conf: confmap.NewFromStringMap(map[string]interface{}{
33+
"entity_type": entityattributes.Service,
34+
"platform": "ec2",
35+
"transform_entity": map[string]interface{}{
36+
"key_attributes": []interface{}{
37+
map[string]interface{}{
38+
"key": entityattributes.ServiceName,
39+
"value": "config-service-name",
40+
},
41+
map[string]interface{}{
42+
"key": entityattributes.DeploymentEnvironment,
43+
"value": "config-environment-name",
44+
},
45+
},
46+
"attributes": []interface{}{
47+
map[string]interface{}{
48+
"key": entityattributes.ServiceNameSource,
49+
"value": "UserConfiguration",
50+
},
51+
},
52+
},
53+
}),
54+
expected: &Config{
55+
EntityType: entityattributes.Service,
56+
Platform: "ec2",
57+
TransformEntity: &entity.Transform{
58+
KeyAttributes: []entity.KeyPair{
59+
{
60+
Key: entityattributes.ServiceName,
61+
Value: "config-service-name",
62+
},
63+
{
64+
Key: entityattributes.DeploymentEnvironment,
65+
Value: "config-environment-name",
66+
},
67+
},
68+
Attributes: []entity.KeyPair{
69+
{
70+
Key: entityattributes.ServiceNameSource,
71+
Value: "UserConfiguration",
72+
},
73+
},
74+
},
75+
},
76+
expectError: false,
77+
},
78+
{
79+
name: "TestInvalidEntityTransform",
80+
conf: confmap.NewFromStringMap(map[string]interface{}{
81+
"entity_type": entityattributes.Service,
82+
"platform": "ec2",
83+
"transform_entity": map[string]interface{}{
84+
"key_attributes": []interface{}{
85+
map[string]interface{}{
86+
"key": "InvalidKey",
87+
"value": "some-value",
88+
},
89+
},
90+
},
91+
}),
92+
expectError: true,
93+
},
94+
{
95+
name: "TestEmptyEntityTransform",
96+
conf: confmap.NewFromStringMap(map[string]interface{}{
97+
"entity_type": entityattributes.Service,
98+
"platform": "ec2",
99+
}),
100+
expected: &Config{
101+
EntityType: entityattributes.Service,
102+
Platform: "ec2",
103+
},
104+
expectError: false,
105+
},
106+
{
107+
name: "TestMissingRequiredFieldEntityTransform",
108+
conf: confmap.NewFromStringMap(map[string]interface{}{
109+
"transform_entity": map[string]interface{}{
110+
"key_attributes": []interface{}{
111+
map[string]interface{}{
112+
"key": entityattributes.ServiceName,
113+
"value": "",
114+
},
115+
},
116+
},
117+
}),
118+
expectError: true,
119+
},
120+
}
121+
122+
for _, tt := range tests {
123+
t.Run(tt.name, func(t *testing.T) {
124+
factory := NewFactory()
125+
cfg := factory.CreateDefaultConfig()
126+
127+
err := tt.conf.Unmarshal(cfg)
128+
129+
assert.NoError(t, err)
130+
131+
// Validate the configuration
132+
err = cfg.(*Config).Validate()
133+
if tt.expectError {
134+
assert.Error(t, err)
135+
} else {
136+
assert.NoError(t, err)
137+
}
138+
139+
if err == nil {
140+
assert.Equal(t, tt.expected, cfg)
141+
}
142+
})
143+
}
144+
}

0 commit comments

Comments
 (0)