From 3af3f1499f60b142c675c1de3089347118c37316 Mon Sep 17 00:00:00 2001 From: okankoAMZ <107267850+okankoAMZ@users.noreply.github.com> Date: Wed, 28 Feb 2024 15:27:35 -0500 Subject: [PATCH] [Application Signals] [TLS] Translate CWAgent Receiver JSON Config to take in TLS settings (#1028) --- translator/cmdutil/translatorutil.go | 27 +++++- translator/config/schema.json | 68 ++++++++++++--- .../appsignals_and_eks_config.json | 4 + .../appsignals_and_eks_config.yaml | 25 ++++-- .../sampleConfig/complete_darwin_config.yaml | 7 +- .../sampleConfig/complete_linux_config.yaml | 7 +- .../sampleConfig/complete_windows_config.yaml | 7 +- .../sampleConfig/trace_config_linux.yaml | 4 +- .../sampleConfig/trace_config_windows.yaml | 4 +- translator/translate/otel/common/common.go | 1 + .../otel/pipeline/host/translator.go | 19 +++- .../otel/pipeline/xray/translator_test.go | 4 +- .../otel/receiver/adapter/translators.go | 10 +++ .../otel/receiver/otlp/appsignals_config.yaml | 5 -- .../otel/receiver/otlp/translator.go | 86 +++++++++++++------ .../otel/receiver/otlp/translator_test.go | 52 ++++++++++- translator/translate/otel/translate_otel.go | 1 - .../translate/otel/translate_otel_test.go | 19 ++++ 18 files changed, 274 insertions(+), 76 deletions(-) delete mode 100644 translator/translate/otel/receiver/otlp/appsignals_config.yaml diff --git a/translator/cmdutil/translatorutil.go b/translator/cmdutil/translatorutil.go index b9d52d77fc..70f54e4499 100644 --- a/translator/cmdutil/translatorutil.go +++ b/translator/cmdutil/translatorutil.go @@ -23,6 +23,7 @@ import ( "github.com/aws/amazon-cloudwatch-agent/translator/tocwconfig/toyamlconfig" "github.com/aws/amazon-cloudwatch-agent/translator/translate" "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel" + "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common" translatorUtil "github.com/aws/amazon-cloudwatch-agent/translator/util" ) @@ -224,7 +225,31 @@ func TranslateJsonMapToYamlConfig(jsonConfigValue interface{}) (interface{}, err if err = conf.Marshal(cfg); err != nil { return nil, err } - return conf.ToStringMap(), nil + strMap := conf.ToStringMap() + RemoveTLSRedacted(strMap) + return strMap, nil +} + +func RemoveTLSRedacted(stringMap map[string]interface{}) { + type Node struct { + isTLSParent bool + data map[string]interface{} + } + root := Node{isTLSParent: false, data: stringMap} + queue := []Node{root} + // Using BFS search through string Map and find sub settings of TLS + // Then delete REDACTED settings under TLS + for len(queue) > 0 { + node := queue[0] + queue = queue[1:] + for key, child := range node.data { + if childMap, ok := child.(map[string]interface{}); ok { + queue = append(queue, Node{key == common.TlsKey, childMap}) + } else if child == "[REDACTED]" && node.isTLSParent { + delete(node.data, key) + } + } + } } func ConfigToTomlFile(config interface{}, tomlConfigFilePath string) error { diff --git a/translator/config/schema.json b/translator/config/schema.json index 0ab4e1d17d..eb7a62eea5 100644 --- a/translator/config/schema.json +++ b/translator/config/schema.json @@ -323,6 +323,29 @@ }, "additionalProperties": false }, + "tlsDefinitions": { + "type": "object", + "properties": { + "ca_file": { + "type": "string", + "minLength": 1, + "maxLength": 255 + }, + "cert_file": { + "type": "string", + "minLength": 1, + "maxLength": 255 + }, + "key_file": { + "type": "string", + "minLength": 1, + "maxLength": 255 + }, + "insecure": { + "type": "boolean" + } + } + }, "swapDefinitions": { "$ref": "#/definitions/metricsDefinition/definitions/basicMetricDefinition" }, @@ -590,6 +613,9 @@ } } }, + "tls": { + "$ref": "#/definitions/metricsDefinition/definitions/tlsDefinitions" + }, "additionalProperties": true }, "ecs": { @@ -913,7 +939,10 @@ "$ref": "#/definitions/tracesDefinition/definitions/xrayDefinition" }, "otlp": { - "$ref": "#/definitions/tracesDefinition/definitions/otlpDefinition" + "tls": { + "$ref": "#/definitions/metricsDefinition/definitions/tlsDefinitions" + }, + "$ref": "#/definitions/tracesDefinition/definitions/otlpDefinitions" } }, "minProperties": 1, @@ -977,19 +1006,20 @@ }, "additionalProperties": false }, - "otlpDefinition": { - "type": "object", - "properties": { - "grpc_endpoint": { - "description": "gRPC endpoint to use to listen for OTLP protobuf traces", - "$ref": "#/definitions/endpointOverrideDefinition" + "otlpDefinitions": { + "oneOf": [ + { + "type": "array", + "minItems": 1, + "maxItems": 255, + "items": { + "$ref": "#/definitions/otlpObjectDefinition" + } }, - "http_endpoint": { - "description": "HTTP endpoint to use to listen for OTLP JSON traces", - "$ref": "#/definitions/endpointOverrideDefinition" + { + "$ref": "#/definitions/otlpObjectDefinition" } - }, - "additionalProperties": false + ] } } }, @@ -1045,6 +1075,20 @@ }, "additionalProperties": false }, + "otlpObjectDefinition": { + "type": "object", + "properties": { + "grpc_endpoint": { + "description": "gRPC endpoint to use to listen for OTLP protobuf information", + "$ref": "#/definitions/endpointOverrideDefinition" + }, + "http_endpoint": { + "description": "HTTP endpoint to use to listen for OTLP JSON information", + "$ref": "#/definitions/endpointOverrideDefinition" + } + }, + "additionalProperties": false + }, "ecsServiceDiscoveryDefinition": { "type": "object", "descriptions": "Define ECS service discovery for Prometheus", diff --git a/translator/tocwconfig/sampleConfig/appsignals_and_eks_config.json b/translator/tocwconfig/sampleConfig/appsignals_and_eks_config.json index 2e517be541..5aa31646d1 100644 --- a/translator/tocwconfig/sampleConfig/appsignals_and_eks_config.json +++ b/translator/tocwconfig/sampleConfig/appsignals_and_eks_config.json @@ -5,6 +5,10 @@ "logs": { "metrics_collected": { "app_signals": { + "tls": { + "cert_file": "path/to/cert.crt", + "key_file": "path/to/key.key" + }, "hosted_in": "TestCluster", "limiter": { "log_dropped_metrics": true, diff --git a/translator/tocwconfig/sampleConfig/appsignals_and_eks_config.yaml b/translator/tocwconfig/sampleConfig/appsignals_and_eks_config.yaml index ddab5ff221..7fd98fa432 100644 --- a/translator/tocwconfig/sampleConfig/appsignals_and_eks_config.yaml +++ b/translator/tocwconfig/sampleConfig/appsignals_and_eks_config.yaml @@ -260,11 +260,11 @@ exporters: - aws.local.operation - aws.remote.service - aws.remote.operation - - HostedIn.EKS.Cluster - HostedIn.K8s.Namespace - K8s.RemoteNamespace - aws.remote.target - HostedIn.Environment + - HostedIn.EKS.Cluster local_mode: false max_retries: 2 middleware: agenthealth/traces @@ -559,13 +559,10 @@ processors: enabled: true tls: ca_file: "" - ca_pem: '[REDACTED]' cert_file: "" - cert_pem: '[REDACTED]' insecure: false insecure_skip_verify: false key_file: "" - key_pem: '[REDACTED]' max_version: "" min_version: "" reload_interval: 0s @@ -636,7 +633,15 @@ receivers: max_concurrent_streams: 0 max_recv_msg_size_mib: 0 read_buffer_size: 524288 - tls: null + tls: + cert_file: path/to/cert.crt + key_file: path/to/key.key + ca_file: "" + client_ca_file: "" + client_ca_file_reload: false + max_version: "" + min_version: "" + reload_interval: 0s transport: tcp write_buffer_size: 0 http: @@ -648,7 +653,15 @@ receivers: max_request_body_size: 0 metrics_url_path: /v1/metrics response_headers: {} - tls: null + tls: + cert_file: path/to/cert.crt + key_file: path/to/key.key + client_ca_file: "" + client_ca_file_reload: false + ca_file: "" + max_version: "" + min_version: "" + reload_interval: 0s traces_url_path: /v1/traces service: extensions: diff --git a/translator/tocwconfig/sampleConfig/complete_darwin_config.yaml b/translator/tocwconfig/sampleConfig/complete_darwin_config.yaml index 7899904400..000007b654 100644 --- a/translator/tocwconfig/sampleConfig/complete_darwin_config.yaml +++ b/translator/tocwconfig/sampleConfig/complete_darwin_config.yaml @@ -149,19 +149,16 @@ receivers: role_arn: trace_role_arn_value_test tls: ca_file: "" - ca_pem: '[REDACTED]' cert_file: "" - cert_pem: '[REDACTED]' insecure: true insecure_skip_verify: false key_file: "" - key_pem: '[REDACTED]' max_version: "" min_version: "" reload_interval: 0s server_name_override: "" transport: udp - otlp: + otlp/traces: protocols: grpc: auth: null @@ -295,7 +292,7 @@ service: - batch/xray receivers: - awsxray - - otlp + - otlp/traces telemetry: logs: development: false diff --git a/translator/tocwconfig/sampleConfig/complete_linux_config.yaml b/translator/tocwconfig/sampleConfig/complete_linux_config.yaml index f05a5c1134..8a3b2d5452 100644 --- a/translator/tocwconfig/sampleConfig/complete_linux_config.yaml +++ b/translator/tocwconfig/sampleConfig/complete_linux_config.yaml @@ -152,19 +152,16 @@ receivers: role_arn: trace_role_arn_value_test tls: ca_file: "" - ca_pem: '[REDACTED]' cert_file: "" - cert_pem: '[REDACTED]' insecure: true insecure_skip_verify: false key_file: "" - key_pem: '[REDACTED]' max_version: "" min_version: "" reload_interval: 0s server_name_override: "" transport: udp - otlp: + otlp/traces: protocols: grpc: auth: null @@ -298,7 +295,7 @@ service: - batch/xray receivers: - awsxray - - otlp + - otlp/traces telemetry: logs: development: false diff --git a/translator/tocwconfig/sampleConfig/complete_windows_config.yaml b/translator/tocwconfig/sampleConfig/complete_windows_config.yaml index 2d069ca631..dab12c0fa4 100644 --- a/translator/tocwconfig/sampleConfig/complete_windows_config.yaml +++ b/translator/tocwconfig/sampleConfig/complete_windows_config.yaml @@ -135,19 +135,16 @@ receivers: role_arn: trace_role_arn_value_test tls: ca_file: "" - ca_pem: "[REDACTED]" cert_file: "" - cert_pem: "[REDACTED]" insecure: true insecure_skip_verify: false key_file: "" - key_pem: "[REDACTED]" max_version: "" min_version: "" reload_interval: 0s server_name_override: "" transport: udp - otlp: + otlp/traces: protocols: grpc: auth: null @@ -269,7 +266,7 @@ service: - batch/xray receivers: - awsxray - - otlp + - otlp/traces telemetry: logs: development: false diff --git a/translator/tocwconfig/sampleConfig/trace_config_linux.yaml b/translator/tocwconfig/sampleConfig/trace_config_linux.yaml index b283eff8a0..1bd17c75c4 100644 --- a/translator/tocwconfig/sampleConfig/trace_config_linux.yaml +++ b/translator/tocwconfig/sampleConfig/trace_config_linux.yaml @@ -47,7 +47,7 @@ receivers: region: us-west-2 role_arn: "" transport: udp - otlp: + otlp/traces: protocols: grpc: auth: null @@ -82,7 +82,7 @@ service: - batch/xray receivers: - awsxray - - otlp + - otlp/traces telemetry: logs: development: false diff --git a/translator/tocwconfig/sampleConfig/trace_config_windows.yaml b/translator/tocwconfig/sampleConfig/trace_config_windows.yaml index f477df8101..bc285f4da2 100644 --- a/translator/tocwconfig/sampleConfig/trace_config_windows.yaml +++ b/translator/tocwconfig/sampleConfig/trace_config_windows.yaml @@ -47,7 +47,7 @@ receivers: region: us-west-2 role_arn: "" transport: udp - otlp: + otlp/traces: protocols: grpc: auth: null @@ -82,7 +82,7 @@ service: - batch/xray receivers: - awsxray - - otlp + - otlp/traces telemetry: logs: development: false diff --git a/translator/translate/otel/common/common.go b/translator/translate/otel/common/common.go index 1e1bef0e73..501ce34a41 100644 --- a/translator/translate/otel/common/common.go +++ b/translator/translate/otel/common/common.go @@ -53,6 +53,7 @@ const ( ServiceAddress = "service_address" Udp = "udp" Tcp = "tcp" + TlsKey = "tls" Region = "region" LogGroupName = "log_group_name" LogStreamName = "log_stream_name" diff --git a/translator/translate/otel/pipeline/host/translator.go b/translator/translate/otel/pipeline/host/translator.go index 4b126341fe..bb82a82bf4 100644 --- a/translator/translate/otel/pipeline/host/translator.go +++ b/translator/translate/otel/pipeline/host/translator.go @@ -15,6 +15,7 @@ import ( "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/processor/cumulativetodeltaprocessor" "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/processor/ec2taggerprocessor" "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/processor/metricsdecorator" + otlpReceiver "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/receiver/otlp" ) type translator struct { @@ -42,7 +43,23 @@ func (t translator) ID() component.ID { func (t translator) Translate(conf *confmap.Conf) (*common.ComponentTranslators, error) { if conf == nil || !conf.IsSet(common.MetricsKey) { return nil, &common.MissingKeyError{ID: t.ID(), JsonKey: common.MetricsKey} - } else if t.receivers.Len() == 0 { + } + + hostReceivers := t.receivers + if common.PipelineNameHost == t.name { + switch v := conf.Get(common.ConfigKey(common.MetricsKey, common.MetricsCollectedKey, common.OtlpKey)).(type) { + case []interface{}: + for index, _ := range v { + hostReceivers.Set(otlpReceiver.NewTranslator( + otlpReceiver.WithDataType(component.DataTypeMetrics), + otlpReceiver.WithInstanceNum(index))) + } + case map[string]interface{}: + hostReceivers.Set(otlpReceiver.NewTranslator(otlpReceiver.WithDataType(component.DataTypeMetrics))) + } + } + + if hostReceivers.Len() == 0 { log.Printf("D! pipeline %s has no receivers", t.name) return nil, nil } diff --git a/translator/translate/otel/pipeline/xray/translator_test.go b/translator/translate/otel/pipeline/xray/translator_test.go index 450db8ff54..888c7c1775 100644 --- a/translator/translate/otel/pipeline/xray/translator_test.go +++ b/translator/translate/otel/pipeline/xray/translator_test.go @@ -58,7 +58,7 @@ func TestTranslator(t *testing.T) { }, }, want: &want{ - receivers: []string{"otlp"}, + receivers: []string{"otlp/traces"}, processors: []string{"batch/xray"}, exporters: []string{"awsxray"}, extensions: []string{"agenthealth/traces"}, @@ -74,7 +74,7 @@ func TestTranslator(t *testing.T) { }, }, want: &want{ - receivers: []string{"awsxray", "otlp"}, + receivers: []string{"awsxray", "otlp/traces"}, processors: []string{"batch/xray"}, exporters: []string{"awsxray"}, extensions: []string{"agenthealth/traces"}, diff --git a/translator/translate/otel/receiver/adapter/translators.go b/translator/translate/otel/receiver/adapter/translators.go index a60b9fc7d9..5419fbb5c6 100644 --- a/translator/translate/otel/receiver/adapter/translators.go +++ b/translator/translate/otel/receiver/adapter/translators.go @@ -22,6 +22,7 @@ import ( "github.com/aws/amazon-cloudwatch-agent/translator/translate/metrics/metrics_collect/procstat" "github.com/aws/amazon-cloudwatch-agent/translator/translate/metrics/metrics_collect/statsd" "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common" + "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/receiver/otlp" ) const ( @@ -66,6 +67,12 @@ var ( defaultCollectionIntervalMap = map[string]time.Duration{ statsd.SectionKey: 10 * time.Second, } + + // OtelReceivers is used for receivers that need to be in the same pipeline that + // exports to Cloudwatch while not having to follow the adapter rules + OtelReceivers = map[string]common.Translator[component.Config]{ + common.OtlpKey: otlp.NewTranslator(otlp.WithDataType(component.DataTypeMetrics)), + } ) // FindReceiversInConfig looks in the metrics and logs sections to determine which @@ -115,6 +122,9 @@ func fromWindowsMetrics(conf *confmap.Conf) common.TranslatorMap[component.Confi translators := common.NewTranslatorMap[component.Config]() if inputs, ok := conf.Get(metricKey).(map[string]interface{}); ok { for inputName := range inputs { + if _, ok := OtelReceivers[inputName]; ok { + continue + } if windowsInputSet.Contains(inputName) { cfgKey := common.ConfigKey(metricKey, inputName) translators.Set(NewTranslator(toAlias(inputName), cfgKey, collections.GetOrDefault( diff --git a/translator/translate/otel/receiver/otlp/appsignals_config.yaml b/translator/translate/otel/receiver/otlp/appsignals_config.yaml deleted file mode 100644 index 560470c3a2..0000000000 --- a/translator/translate/otel/receiver/otlp/appsignals_config.yaml +++ /dev/null @@ -1,5 +0,0 @@ -protocols: - grpc: - endpoint: 0.0.0.0:4315 - http: - endpoint: 0.0.0.0:4316 \ No newline at end of file diff --git a/translator/translate/otel/receiver/otlp/translator.go b/translator/translate/otel/receiver/otlp/translator.go index 48c86c0fd3..7199af5b0e 100644 --- a/translator/translate/otel/receiver/otlp/translator.go +++ b/translator/translate/otel/receiver/otlp/translator.go @@ -6,8 +6,10 @@ package otlp import ( _ "embed" "fmt" + "strconv" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/receiver/otlpreceiver" @@ -16,23 +18,24 @@ import ( ) const ( - defaultGrpcEndpoint = "127.0.0.1:4317" - defaultHttpEndpoint = "127.0.0.1:4318" + defaultGrpcEndpoint = "127.0.0.1:4317" + defaultHttpEndpoint = "127.0.0.1:4318" + defaultAppSignalsGrpcEndpoint = "0.0.0.0:4315" + defaultAppSignalsHttpEndpoint = "0.0.0.0:4316" ) var ( configKeys = map[component.DataType]string{ - component.DataTypeTraces: common.ConfigKey(common.TracesKey, common.TracesCollectedKey, common.OtlpKey), + component.DataTypeTraces: common.ConfigKey(common.TracesKey, common.TracesCollectedKey), + component.DataTypeMetrics: common.ConfigKey(common.LogsKey, common.MetricsCollectedKey), } - - //go:embed appsignals_config.yaml - appSignalsConfig string ) type translator struct { - name string - dataType component.DataType - factory receiver.Factory + name string + dataType component.DataType + instanceNum int + factory receiver.Factory } type Option interface { @@ -52,22 +55,29 @@ func WithDataType(dataType component.DataType) Option { t.dataType = dataType }) } +func WithInstanceNum(instanceNum int) Option { + return optionFunc(func(t *translator) { + t.instanceNum = instanceNum + }) +} var _ common.Translator[component.Config] = (*translator)(nil) func NewTranslator(opts ...Option) common.Translator[component.Config] { - t := &translator{factory: otlpreceiver.NewFactory()} - for _, opt := range opts { - opt.apply(t) - } - return t + return NewTranslatorWithName("", opts...) } func NewTranslatorWithName(name string, opts ...Option) common.Translator[component.Config] { - t := &translator{name: name, factory: otlpreceiver.NewFactory()} + t := &translator{name: name, instanceNum: -1, factory: otlpreceiver.NewFactory()} for _, opt := range opts { opt.apply(t) } + if name == "" && t.dataType != "" { + t.name = string(t.dataType) + if t.instanceNum != -1 { + t.name += strconv.Itoa(t.instanceNum) + } + } return t } @@ -77,26 +87,46 @@ func (t *translator) ID() component.ID { func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) { cfg := t.factory.CreateDefaultConfig().(*otlpreceiver.Config) - - // TODO: Should follow pattern done in awsemf and awsexray exporter translations (i.e should be integrated with standard otlp translation) - if t.name == common.AppSignals { - return common.GetYamlFileToYamlConfig(cfg, appSignalsConfig) - } - - configKey, ok := configKeys[t.dataType] + // init default configuration + configBase, ok := configKeys[t.dataType] if !ok { return nil, fmt.Errorf("no config key defined for data type: %s", t.dataType) } + configKey := common.ConfigKey(configBase, common.OtlpKey) + cfg.GRPC.NetAddr.Endpoint = defaultGrpcEndpoint + cfg.HTTP.Endpoint = defaultHttpEndpoint + if t.name == common.AppSignals { + configKey = common.ConfigKey(configKeys[t.dataType], common.AppSignals) + cfg.GRPC.NetAddr.Endpoint = defaultAppSignalsGrpcEndpoint + cfg.HTTP.Endpoint = defaultAppSignalsHttpEndpoint + } if conf == nil || !conf.IsSet(configKey) { return nil, &common.MissingKeyError{ID: t.ID(), JsonKey: configKey} } - cfg.GRPC.NetAddr.Endpoint = defaultGrpcEndpoint - cfg.HTTP.Endpoint = defaultHttpEndpoint - if endpoint, ok := common.GetString(conf, common.ConfigKey(configKey, "grpc_endpoint")); ok { - cfg.GRPC.NetAddr.Endpoint = endpoint + + var otlpKeyMap map[string]interface{} + if otlpSlice := common.GetArray[any](conf, configKey); t.instanceNum != -1 && len(otlpSlice) > t.instanceNum { + otlpKeyMap = otlpSlice[t.instanceNum].(map[string]interface{}) + } else { + otlpKeyMap = conf.Get(configKey).(map[string]interface{}) + } + var tlsSettings *configtls.TLSServerSetting + if tls, ok := otlpKeyMap["tls"].(map[string]interface{}); ok { + tlsSettings = &configtls.TLSServerSetting{} + tlsSettings.CertFile = tls["cert_file"].(string) + tlsSettings.KeyFile = tls["key_file"].(string) + } + cfg.GRPC.TLSSetting = tlsSettings + cfg.HTTP.TLSSetting = tlsSettings + + grpcEndpoint, grpcOk := otlpKeyMap["grpc_endpoint"] + httpEndpoint, httpOk := otlpKeyMap["http_endpoint"] + + if grpcOk { + cfg.GRPC.NetAddr.Endpoint = grpcEndpoint.(string) } - if endpoint, ok := common.GetString(conf, common.ConfigKey(configKey, "http_endpoint")); ok { - cfg.HTTP.Endpoint = endpoint + if httpOk { + cfg.HTTP.Endpoint = httpEndpoint.(string) } return cfg, nil } diff --git a/translator/translate/otel/receiver/otlp/translator_test.go b/translator/translate/otel/receiver/otlp/translator_test.go index 06a6672a1e..1bbf12ad11 100644 --- a/translator/translate/otel/receiver/otlp/translator_test.go +++ b/translator/translate/otel/receiver/otlp/translator_test.go @@ -40,7 +40,7 @@ func TestTracesTranslator(t *testing.T) { }, }, "WithDefault": { - input: map[string]interface{}{"traces": map[string]interface{}{"traces_collected": map[string]interface{}{"otlp": nil}}}, + input: map[string]interface{}{"traces": map[string]interface{}{"traces_collected": map[string]interface{}{"otlp": map[string]interface{}{}}}}, want: confmap.NewFromStringMap(map[string]interface{}{ "protocols": map[string]interface{}{ "grpc": map[string]interface{}{ @@ -52,6 +52,25 @@ func TestTracesTranslator(t *testing.T) { }, }), }, + "WithTLS": { + input: map[string]interface{}{ + "protocols": map[string]interface{}{ + "grpc": map[string]interface{}{ + "endpoint": "127.0.0.1:4317", + }, + "http": map[string]interface{}{ + "endpoint": "127.0.0.1:4318", + }, + "tls": map[string]interface{}{ + "cert_file": "path/to/cert.crt", + "key_file": "path/to/key.key", + }, + }}, + wantErr: &common.MissingKeyError{ + ID: tt.ID(), + JsonKey: common.ConfigKey(common.TracesKey, common.TracesCollectedKey, common.OtlpKey), + }, + }, "WithCompleteConfig": { input: testutil.GetJson(t, filepath.Join("testdata", "traces", "config.json")), want: testutil.GetConf(t, filepath.Join("testdata", "traces", "config.yaml")), @@ -100,6 +119,37 @@ func TestTranslateAppSignals(t *testing.T) { }, }), }, + "WithAppSignalsEnabledTracesWithTLS": { + input: map[string]interface{}{ + "traces": map[string]interface{}{ + "traces_collected": map[string]interface{}{ + "app_signals": map[string]interface{}{ + "tls": map[string]interface{}{ + "cert_file": "path/to/cert.crt", + "key_file": "path/to/key.key", + }, + }, + }, + }}, + want: confmap.NewFromStringMap(map[string]interface{}{ + "protocols": map[string]interface{}{ + "grpc": map[string]interface{}{ + "endpoint": "0.0.0.0:4315", + "tls": map[string]interface{}{ + "cert_file": "path/to/cert.crt", + "key_file": "path/to/key.key", + }, + }, + "http": map[string]interface{}{ + "endpoint": "0.0.0.0:4316", + "tls": map[string]interface{}{ + "cert_file": "path/to/cert.crt", + "key_file": "path/to/key.key", + }, + }, + }, + }), + }, } factory := otlpreceiver.NewFactory() for name, testCase := range testCases { diff --git a/translator/translate/otel/translate_otel.go b/translator/translate/otel/translate_otel.go index d5731620f4..4cdc8540c1 100644 --- a/translator/translate/otel/translate_otel.go +++ b/translator/translate/otel/translate_otel.go @@ -66,7 +66,6 @@ func Translate(jsonConfig interface{}, os string) (*otelcol.Config, error) { hostReceivers.Set(translator) } }) - translators := common.NewTranslatorMap( appsignals.NewTranslator(component.DataTypeTraces), appsignals.NewTranslator(component.DataTypeMetrics), diff --git a/translator/translate/otel/translate_otel_test.go b/translator/translate/otel/translate_otel_test.go index f7e0ee630a..f3759b437c 100644 --- a/translator/translate/otel/translate_otel_test.go +++ b/translator/translate/otel/translate_otel_test.go @@ -86,6 +86,25 @@ func TestTranslator(t *testing.T) { detector: common.TestEKSDetector, isEKSDataStore: common.TestIsEKSCacheEKS, }, + "WithAppSignalsMultipleMetricsReceiversConfig": { + input: map[string]interface{}{ + "logs": map[string]interface{}{ + "metrics_collected": map[string]interface{}{ + "app_signals": map[string]interface{}{}, + "cpu": map[string]interface{}{}, + }, + }, + "traces": map[string]interface{}{ + "traces_collected": map[string]interface{}{ + "app_signals": map[string]interface{}{}, + "otlp": map[string]interface{}{}, + "otlp2": map[string]interface{}{}, + }, + }, + }, + detector: common.TestEKSDetector, + isEKSDataStore: common.TestIsEKSCacheEKS, + }, } for name, testCase := range testCases { t.Run(name, func(t *testing.T) {