Skip to content

Commit 398d999

Browse files
committed
refactor
1 parent 1a4b2ce commit 398d999

File tree

11 files changed

+605
-40
lines changed

11 files changed

+605
-40
lines changed

translator/config/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,13 @@
13901390
"type": "string",
13911391
"minLength": 1,
13921392
"maxLength": 259
1393+
},
1394+
"log_group_name": {
1395+
"description": "CloudWatch log group name for OTLP metrics",
1396+
"type": "string"
1397+
},
1398+
"emf_processor": {
1399+
"$ref": "#/definitions/emfProcessorDefinition"
13931400
}
13941401
},
13951402
"additionalProperties": false

translator/tocwconfig/sampleConfig/otlp_metrics_cloudwatchlogs_config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
"tls": {
99
"cert_file": "/path/to/cert.pem",
1010
"key_file": "/path/to/key.pem"
11+
},
12+
"log_group_name": "/aws/application/otlp",
13+
"emf_processor": {
14+
"metric_namespace": "MyApplication/OTLP",
15+
"metric_unit": {
16+
"request_duration": "Milliseconds",
17+
"request_count": "Count"
18+
}
1119
}
1220
}
1321
}

translator/tocwconfig/sampleConfig/otlp_metrics_cloudwatchlogs_config.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ exporters:
1111
external_id: ""
1212
imds_retries: 1
1313
local_mode: false
14-
log_group_name: /aws/cwagent
14+
log_group_name: /aws/application/otlp
1515
log_retention: 0
1616
log_stream_name: ""
1717
max_retries: 2
18+
metric_descriptors:
19+
- metric_name: request_count
20+
overwrite: false
21+
unit: Count
22+
- metric_name: request_duration
23+
overwrite: false
24+
unit: Milliseconds
1825
middleware: agenthealth/logs
19-
namespace: CWAgent
26+
namespace: MyApplication/OTLP
2027
no_verify_ssl: false
2128
num_workers: 8
2229
output_destination: cloudwatch
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package otlp
5+
6+
import (
7+
parent "github.com/aws/amazon-cloudwatch-agent/translator/translate/logs/metrics_collected"
8+
)
9+
10+
type Otlp struct {
11+
}
12+
13+
const SectionKey = "otlp"
14+
15+
func GetCurPath() string {
16+
curPath := parent.GetCurPath() + SectionKey + "/"
17+
return curPath
18+
}
19+
20+
func (o *Otlp) ApplyRule(input interface{}) (returnKey string, returnVal interface{}) {
21+
im := input.(map[string]interface{})
22+
result := map[string]map[string]interface{}{}
23+
inputs := map[string]interface{}{}
24+
processors := map[string]interface{}{}
25+
26+
// Check if this plugin exists in the input instance
27+
if _, ok := im[SectionKey]; !ok {
28+
returnKey = ""
29+
returnVal = ""
30+
} else {
31+
// OTLP configuration is handled by the OTEL pipeline translator
32+
// This rule just validates the configuration exists
33+
result["inputs"] = inputs
34+
result["processors"] = processors
35+
returnKey = SectionKey
36+
returnVal = result
37+
}
38+
return
39+
}
40+
41+
func init() {
42+
o := new(Otlp)
43+
parent.RegisterLinuxRule(SectionKey, o)
44+
parent.RegisterDarwinRule(SectionKey, o)
45+
parent.RegisterWindowsRule(SectionKey, o)
46+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package awsemf
5+
6+
import (
7+
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter"
8+
"go.opentelemetry.io/collector/confmap"
9+
10+
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common"
11+
)
12+
13+
var (
14+
otlpBasePathKey = common.OTLPLogsKey
15+
otlpEMFProcessorPathKey = common.ConfigKey(otlpBasePathKey, common.EMFProcessorKey)
16+
)
17+
18+
// setOTLPFields configures the EMF exporter for OTLP metrics
19+
func setOTLPFields(conf *confmap.Conf, cfg *awsemfexporter.Config) error {
20+
// Set log group name if provided
21+
setOTLPLogGroup(conf, cfg)
22+
23+
// Set EMF processor fields if provided
24+
if conf.IsSet(otlpEMFProcessorPathKey) {
25+
if err := setOTLPNamespace(conf, cfg); err != nil {
26+
return err
27+
}
28+
if err := setOTLPMetricDescriptors(conf, cfg); err != nil {
29+
return err
30+
}
31+
}
32+
33+
return nil
34+
}
35+
36+
// setOTLPLogGroup sets the log group name for OTLP metrics
37+
// If not set, use the default from awsemf_default_generic.yaml (/aws/cwagent)
38+
func setOTLPLogGroup(conf *confmap.Conf, cfg *awsemfexporter.Config) {
39+
if logGroupName, ok := common.GetString(conf, common.ConfigKey(otlpBasePathKey, common.LogGroupName)); ok {
40+
cfg.LogGroupName = logGroupName
41+
}
42+
}
43+
44+
// setOTLPNamespace sets the metric namespace for OTLP metrics
45+
func setOTLPNamespace(conf *confmap.Conf, cfg *awsemfexporter.Config) error {
46+
return setNamespaceWithDefault(conf, common.ConfigKey(otlpEMFProcessorPathKey, metricNamespace), "", cfg)
47+
}
48+
49+
// setOTLPMetricDescriptors sets the metric units for OTLP metrics
50+
func setOTLPMetricDescriptors(conf *confmap.Conf, cfg *awsemfexporter.Config) error {
51+
return setMetricDescriptors(conf, common.ConfigKey(otlpEMFProcessorPathKey, metricUnit), cfg)
52+
}

0 commit comments

Comments
 (0)