Skip to content

Commit 2feb4cc

Browse files
committed
fixing make tests
1 parent 47e88ac commit 2feb4cc

7 files changed

Lines changed: 78 additions & 13 deletions

File tree

translator/tocwconfig/sampleConfig/prometheus_combined_config_linux.yaml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
exporters:
2+
awscloudwatch:
3+
force_flush_interval: 1m0s
4+
max_datums_per_call: 1000
5+
max_values_per_datum: 150
6+
middleware: agenthealth/metrics
7+
namespace: CWAgent
8+
region: us-west-2
9+
resource_to_telemetry_conversion:
10+
enabled: true
211
awsemf/prometheus:
312
add_entity: false
413
certificate_file_path: ""
@@ -107,6 +116,14 @@ extensions:
107116
usage_flags:
108117
mode: EC2
109118
region_type: ACJ
119+
agenthealth/metrics:
120+
is_usage_data_enabled: true
121+
stats:
122+
operations:
123+
- PutMetricData
124+
usage_flags:
125+
mode: EC2
126+
region_type: ACJ
110127
agenthealth/statuscode:
111128
is_status_code_enabled: true
112129
is_usage_data_enabled: true
@@ -127,11 +144,23 @@ processors:
127144
send_batch_max_size: 0
128145
send_batch_size: 8192
129146
timeout: 1m0s
147+
batch/prometheus/cloudwatch:
148+
metadata_cardinality_limit: 1000
149+
send_batch_max_size: 0
150+
send_batch_size: 8192
151+
timeout: 1m0s
130152
batch/prometheus/cloudwatchlogs:
131153
metadata_cardinality_limit: 1000
132154
send_batch_max_size: 0
133155
send_batch_size: 8192
134156
timeout: 30s
157+
cumulativetodelta/prometheus/cloudwatch:
158+
exclude:
159+
match_type: ""
160+
include:
161+
match_type: ""
162+
initial_value: 2
163+
max_staleness: 0s
135164
deltatocumulative/prometheus/amp:
136165
max_stale: 336h0m0s
137166
max_streams: 9223372036854775807
@@ -179,9 +208,10 @@ receivers:
179208
timeout: 0s
180209
service:
181210
extensions:
182-
- agenthealth/logs
211+
- agenthealth/metrics
183212
- agenthealth/statuscode
184213
- sigv4auth
214+
- agenthealth/logs
185215
- entitystore
186216
pipelines:
187217
metrics/prometheus/amp:
@@ -192,6 +222,14 @@ service:
192222
- deltatocumulative/prometheus/amp
193223
receivers:
194224
- prometheus
225+
metrics/prometheus/cloudwatch:
226+
exporters:
227+
- awscloudwatch
228+
processors:
229+
- batch/prometheus/cloudwatch
230+
- cumulativetodelta/prometheus/cloudwatch
231+
receivers:
232+
- prometheus
195233
metrics/prometheus/cloudwatchlogs:
196234
exporters:
197235
- awsemf/prometheus

translator/tocwconfig/sampleConfig/prometheus_pmd_config.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"agent": {
3-
"metrics_collection_interval": 15,
4-
"debug": true
3+
"metrics_collection_interval": 15
54
},
65
"metrics": {
7-
"namespace": "PrometheusTest123",
6+
"namespace": "CWAgent",
87
"metrics_destinations": {
98
"cloudwatch": {}
109
},

translator/tocwconfig/sampleConfig/prometheus_pmd_config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ processors:
3636
send_batch_max_size: 0
3737
send_batch_size: 8192
3838
timeout: 1m0s
39+
cumulativetodelta/prometheus/cloudwatch:
40+
exclude:
41+
match_type: ""
42+
include:
43+
match_type: ""
44+
initial_value: 2
45+
max_staleness: 0s
3946
ec2tagger:
4047
ec2_instance_tag_keys:
4148
- AutoScalingGroupName
@@ -99,6 +106,7 @@ service:
99106
- awscloudwatch
100107
processors:
101108
- batch/prometheus/cloudwatch
109+
- cumulativetodelta/prometheus/cloudwatch
102110
- rollup
103111
- ec2tagger
104112
receivers:

translator/translate/otel/pipeline/prometheus/translator.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common"
1616
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/exporter/awscloudwatch"
1717
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/exporter/awsemf"
18-
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/exporter/debug"
1918
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/exporter/prometheusremotewrite"
2019
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/extension/agenthealth"
2120
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/extension/sigv4auth"
@@ -68,7 +67,7 @@ func (t *translator) Translate(conf *confmap.Conf) (*common.ComponentTranslators
6867
// otel_prometheus - AMP
6968
// this could change in future releases to support different source/destination combinations
7069
switch t.Destination() {
71-
case common.CloudWatchKey:
70+
case common.DefaultDestination, common.CloudWatchKey:
7271
if !conf.IsSet(MetricsKey) {
7372
return nil, fmt.Errorf("pipeline (%s) is missing prometheus configuration under metrics section with destination (%s)", t.name, t.Destination())
7473
}
@@ -78,10 +77,7 @@ func (t *translator) Translate(conf *confmap.Conf) (*common.ComponentTranslators
7877
batchprocessor.NewTranslatorWithNameAndSection(t.name, common.MetricsKey),
7978
cumulativetodeltaprocessor.NewTranslator(common.WithName(t.name), cumulativetodeltaprocessor.WithDefaultKeys()),
8079
),
81-
Exporters: common.NewTranslatorMap(
82-
awscloudwatch.NewTranslator(),
83-
debug.NewTranslator(),
84-
),
80+
Exporters: common.NewTranslatorMap(awscloudwatch.NewTranslator()),
8581
Extensions: common.NewTranslatorMap(
8682
agenthealth.NewTranslator(agenthealth.MetricsName, []string{agenthealth.OperationPutMetricData}),
8783
agenthealth.NewTranslatorWithStatusCode(agenthealth.StatusCodeName, nil, true),

translator/translate/otel/pipeline/prometheus/translators.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import (
1212

1313
func NewTranslators(conf *confmap.Conf) common.PipelineTranslatorMap {
1414
translators := common.NewTranslatorMap[*common.ComponentTranslators, pipeline.ID]()
15+
1516
destinations := common.GetMetricsDestinations(conf)
17+
if conf.IsSet(LogsKey) {
18+
destinations = append(destinations, common.CloudWatchLogsKey)
19+
}
1620

1721
for _, destination := range destinations {
1822
translators.Set(NewTranslator(common.WithDestination(destination)))

translator/translate/otel/pipeline/prometheus/translators_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package prometheus
55

66
import (
7+
"log"
78
"testing"
89

910
"github.com/stretchr/testify/assert"
@@ -33,7 +34,7 @@ func TestTranslators(t *testing.T) {
3334
},
3435
},
3536
want: []pipeline.ID{
36-
pipeline.MustNewIDWithName("metrics", "prometheus/amp"),
37+
pipeline.MustNewIDWithName("metrics", "prometheus"),
3738
},
3839
},
3940
"WithLogsWithoutDestinations": {
@@ -60,7 +61,7 @@ func TestTranslators(t *testing.T) {
6061
},
6162
},
6263
want: []pipeline.ID{
63-
pipeline.MustNewIDWithName("metrics", "prometheus/amp"),
64+
pipeline.MustNewIDWithName("metrics", "prometheus/cloudwatch"),
6465
},
6566
},
6667
"WithMetricsWithAMP": {
@@ -95,6 +96,22 @@ func TestTranslators(t *testing.T) {
9596
},
9697
want: []pipeline.ID{
9798
pipeline.MustNewIDWithName("metrics", "prometheus/cloudwatchlogs"),
99+
pipeline.MustNewIDWithName("metrics", "prometheus/cloudwatch"),
100+
},
101+
},
102+
"WithMetricsAndCloudWatchDestinationOnly": {
103+
input: map[string]any{
104+
"metrics": map[string]any{
105+
"metrics_destinations": map[string]any{
106+
"cloudwatch": map[string]any{},
107+
},
108+
"metrics_collected": map[string]any{
109+
"prometheus": map[string]any{},
110+
},
111+
},
112+
},
113+
want: []pipeline.ID{
114+
pipeline.MustNewIDWithName("metrics", "prometheus/cloudwatch"),
98115
},
99116
},
100117
"WithMultiple/Destinations": {
@@ -119,6 +136,7 @@ func TestTranslators(t *testing.T) {
119136
want: []pipeline.ID{
120137
pipeline.MustNewIDWithName("metrics", "prometheus/amp"),
121138
pipeline.MustNewIDWithName("metrics", "prometheus/cloudwatchlogs"),
139+
pipeline.MustNewIDWithName("metrics", "prometheus/cloudwatch"),
122140
},
123141
},
124142
}
@@ -130,6 +148,8 @@ func TestTranslators(t *testing.T) {
130148
require.Nil(t, got)
131149
} else {
132150
require.NotNil(t, got)
151+
log.Println(testCase.want)
152+
log.Println(got)
133153
assert.Equal(t, len(testCase.want), got.Len())
134154
for _, id := range testCase.want {
135155
_, ok := got.Get(id)

translator/translate/otel/processor/cumulativetodeltaprocessor/translator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestTranslator(t *testing.T) {
3131
},
3232
},
3333
},
34-
wantErr: &common.MissingKeyError{ID: cdpTranslator.ID(), JsonKey: fmt.Sprint(diskioKey, " or ", netKey, " or ", otlpKey, " or ", otlpEmfKey)},
34+
wantErr: &common.MissingKeyError{ID: cdpTranslator.ID(), JsonKey: fmt.Sprint(diskioKey, " or ", netKey, " or ", otlpKey, " or ", otlpEmfKey, " or ", prometheusPmdKey)},
3535
},
3636
"GenerateDeltaProcessorConfigWithNet": {
3737
input: map[string]any{

0 commit comments

Comments
 (0)