diff --git a/.golangci.yml b/.golangci.yml index 33fff94918..71da5c3e50 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,7 +19,7 @@ run: output: # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" - format: colored-line-number + formats: colored-line-number # print lines of code with issue, default is true print-issued-lines: true diff --git a/plugins/outputs/cloudwatch/cloudwatch.go b/plugins/outputs/cloudwatch/cloudwatch.go index 124ff76d22..8acf14db60 100644 --- a/plugins/outputs/cloudwatch/cloudwatch.go +++ b/plugins/outputs/cloudwatch/cloudwatch.go @@ -174,6 +174,19 @@ func (c *CloudWatch) pushMetricDatum() { case metric := <-c.metricChan: entity, datums := c.BuildMetricDatum(metric) numberOfPartitions := len(datums) + /* We currently do not account for entity information as a part of the payload size. + This is by design and should be revisited once the SDK protocol changes. + In the meantime there has been a payload limit increase applied in the background to accommodate this decision + + Otherwise to include entity size you would do something like this: + c.metricDatumBatch.Size += calculateEntitySize(entity) + + In addition to calculating the size of the entity object, you might also need to account for any extra bytes that get + added on an individual metric level when entity data is present (depends on how the sdk protocol changes)—something like: + c.metricDatumBatch.Size += payload(datums[i], entityPresent=true) + + File diff that could be useful: https://github.com/aws/amazon-cloudwatch-agent/compare/af960d7...459ef7c + */ for i := 0; i < numberOfPartitions; i++ { entityStr := entityToString(entity) c.metricDatumBatch.Partition[entityStr] = append(c.metricDatumBatch.Partition[entityStr], datums[i]) diff --git a/plugins/outputs/cloudwatch/util.go b/plugins/outputs/cloudwatch/util.go index 6a2149365c..2f1fec4ba4 100644 --- a/plugins/outputs/cloudwatch/util.go +++ b/plugins/outputs/cloudwatch/util.go @@ -46,6 +46,19 @@ const ( valueOverheads = 47 // &MetricData.member.1.Unit=Kilobytes/Second unitOverheads = 42 + + /* Entity overheads - these would be used to calculate entity size if we decide to include it as a part of the payload. + The three main components are the KeyAttributes key/value pair, Attributes key/value pair, and StrictEntityValidation + + // &StrictEntityValidation=false + strictEntityValidationSize = 29 + // &EntityMetricData.member.100.Entity.KeyAttributes.entry.1.key= &EntityMetricData.member.100.Entity.KeyAttributes.entry.1.value= + entityKeyAttributesOverhead = 62 + 64 + // &EntityMetricData.member.100.Entity.Attributes.entry.1.key= &EntityMetricData.member.100.Entity.Attributes.entry.1.value= + entityAttributesOverhead = 59 + 61 + // EntityMetricData.member.100. + entityMetricDataPrefixOverhead = 28 + */ ) // Set seed once. diff --git a/plugins/processors/awsentity/processor.go b/plugins/processors/awsentity/processor.go index 7334bebd46..36bd4c17fb 100644 --- a/plugins/processors/awsentity/processor.go +++ b/plugins/processors/awsentity/processor.go @@ -16,6 +16,7 @@ import ( "github.com/aws/amazon-cloudwatch-agent/extension/entitystore" "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsentity/entityattributes" "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsentity/internal/k8sattributescraper" + "github.com/aws/amazon-cloudwatch-agent/plugins/processors/ec2tagger" "github.com/aws/amazon-cloudwatch-agent/translator/config" ) @@ -131,6 +132,12 @@ func (p *awsEntityProcessor) processMetrics(_ context.Context, md pmetric.Metric switch p.config.EntityType { case entityattributes.Resource: if p.config.Platform == config.ModeEC2 { + // ec2tagger processor may have picked up the ASG name from an ec2:DescribeTags call + if getAutoScalingGroupFromEntityStore() == EMPTY && p.config.ScrapeDatapointAttribute { + if autoScalingGroup := p.scrapeResourceEntityAttribute(rm.At(i).ScopeMetrics()); autoScalingGroup != EMPTY { + setAutoScalingGroup(autoScalingGroup) + } + } ec2Info = getEC2InfoFromEntityStore() if ec2Info.GetInstanceID() != EMPTY { resourceAttrs.PutStr(entityattributes.AttributeEntityType, entityattributes.AttributeEntityAWSResource) @@ -285,7 +292,8 @@ func (p *awsEntityProcessor) processMetrics(_ context.Context, md pmetric.Metric // scrapeServiceAttribute expands the datapoint attributes and search for // service name and environment attributes. This is only used for components -// that only emit attributes on datapoint level. +// that only emit attributes on datapoint level. This code block contains a lot +// of repeated code because OTEL metrics type do not have a common interface. func (p *awsEntityProcessor) scrapeServiceAttribute(scopeMetric pmetric.ScopeMetricsSlice) (string, string, string) { entityServiceName := EMPTY entityServiceNameSource := EMPTY @@ -408,6 +416,64 @@ func (p *awsEntityProcessor) scrapeServiceAttribute(scopeMetric pmetric.ScopeMet return entityServiceName, entityEnvironmentName, entityServiceNameSource } +// scrapeResourceEntityAttribute expands the datapoint attributes and search for +// resource entity related attributes. This is only used for components +// that only emit attributes on datapoint level. This code block contains a lot +// of repeated code because OTEL metrics type do not have a common interface. +func (p *awsEntityProcessor) scrapeResourceEntityAttribute(scopeMetric pmetric.ScopeMetricsSlice) string { + autoScalingGroup := EMPTY + for j := 0; j < scopeMetric.Len(); j++ { + metric := scopeMetric.At(j).Metrics() + for k := 0; k < metric.Len(); k++ { + if autoScalingGroup != EMPTY { + return autoScalingGroup + } + m := metric.At(k) + switch m.Type() { + case pmetric.MetricTypeGauge: + dps := m.Gauge().DataPoints() + for l := 0; l < dps.Len(); l++ { + if dpAutoScalingGroup, ok := dps.At(l).Attributes().Get(ec2tagger.CWDimensionASG); ok { + autoScalingGroup = dpAutoScalingGroup.Str() + } + } + case pmetric.MetricTypeSum: + dps := m.Sum().DataPoints() + for l := 0; l < dps.Len(); l++ { + if dpAutoScalingGroup, ok := dps.At(l).Attributes().Get(ec2tagger.CWDimensionASG); ok { + autoScalingGroup = dpAutoScalingGroup.Str() + } + } + case pmetric.MetricTypeHistogram: + dps := m.Histogram().DataPoints() + for l := 0; l < dps.Len(); l++ { + if dpAutoScalingGroup, ok := dps.At(l).Attributes().Get(ec2tagger.CWDimensionASG); ok { + autoScalingGroup = dpAutoScalingGroup.Str() + } + } + case pmetric.MetricTypeExponentialHistogram: + dps := m.ExponentialHistogram().DataPoints() + for l := 0; l < dps.Len(); l++ { + if dpAutoScalingGroup, ok := dps.At(l).Attributes().Get(ec2tagger.CWDimensionASG); ok { + autoScalingGroup = dpAutoScalingGroup.Str() + } + } + case pmetric.MetricTypeSummary: + dps := m.Sum().DataPoints() + for l := 0; l < dps.Len(); l++ { + if dpAutoScalingGroup, ok := dps.At(l).Attributes().Get(ec2tagger.CWDimensionASG); ok { + autoScalingGroup = dpAutoScalingGroup.Str() + } + } + default: + p.logger.Debug("Ignore unknown metric type", zap.String("type", m.Type().String())) + } + + } + } + return autoScalingGroup +} + // getServiceAttributes prioritize service name retrieval based on // following attribute priority // 1. service.name diff --git a/plugins/processors/ec2tagger/constants.go b/plugins/processors/ec2tagger/constants.go index 32a6f960c2..b0f986f8d3 100644 --- a/plugins/processors/ec2tagger/constants.go +++ b/plugins/processors/ec2tagger/constants.go @@ -61,7 +61,7 @@ const sampleConfig = ` const ( Ec2InstanceTagKeyASG = "aws:autoscaling:groupName" - cwDimensionASG = "AutoScalingGroupName" + CWDimensionASG = "AutoScalingGroupName" mdKeyInstanceId = "InstanceId" mdKeyImageId = "ImageId" mdKeyInstanceType = "InstanceType" diff --git a/plugins/processors/ec2tagger/ec2tagger.go b/plugins/processors/ec2tagger/ec2tagger.go index 89bb33a1bc..839ea21079 100644 --- a/plugins/processors/ec2tagger/ec2tagger.go +++ b/plugins/processors/ec2tagger/ec2tagger.go @@ -176,7 +176,7 @@ func (t *Tagger) updateTags() error { key := *tag.Key if Ec2InstanceTagKeyASG == key { // rename to match CW dimension as applied by AutoScaling service, not the EC2 tag - key = cwDimensionASG + key = CWDimensionASG } tags[key] = *tag.Value } @@ -249,7 +249,7 @@ func (t *Tagger) ec2TagsRetrieved() bool { if t.ec2TagCache != nil { for _, key := range t.EC2InstanceTagKeys { if key == Ec2InstanceTagKeyASG { - key = cwDimensionASG + key = CWDimensionASG } if key == "*" { continue @@ -303,7 +303,7 @@ func (t *Tagger) Start(ctx context.Context, host component.Host) error { if !useAllTags && len(t.EC2InstanceTagKeys) > 0 { // if the customer said 'AutoScalingGroupName' (the CW dimension), do what they mean not what they said for i, key := range t.EC2InstanceTagKeys { - if cwDimensionASG == key { + if CWDimensionASG == key { t.EC2InstanceTagKeys[i] = Ec2InstanceTagKeyASG } } diff --git a/translator/tocwconfig/sampleConfig/advanced_config_darwin.yaml b/translator/tocwconfig/sampleConfig/advanced_config_darwin.yaml index 2edfbbded1..bd1d153b8d 100644 --- a/translator/tocwconfig/sampleConfig/advanced_config_darwin.yaml +++ b/translator/tocwconfig/sampleConfig/advanced_config_darwin.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true cumulativetodelta/hostDeltaMetrics: exclude: match_type: strict @@ -86,8 +87,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_netstat - telegraf_swap @@ -98,9 +99,9 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - cumulativetodelta/hostDeltaMetrics - ec2tagger + - awsentity/resource receivers: - telegraf_diskio telemetry: diff --git a/translator/tocwconfig/sampleConfig/advanced_config_linux.yaml b/translator/tocwconfig/sampleConfig/advanced_config_linux.yaml index ee0877d782..792b6d5073 100644 --- a/translator/tocwconfig/sampleConfig/advanced_config_linux.yaml +++ b/translator/tocwconfig/sampleConfig/advanced_config_linux.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true cumulativetodelta/hostDeltaMetrics: exclude: match_type: strict @@ -94,8 +95,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_ethtool - telegraf_nvidia_smi @@ -108,9 +109,9 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - cumulativetodelta/hostDeltaMetrics - ec2tagger + - awsentity/resource receivers: - telegraf_diskio telemetry: diff --git a/translator/tocwconfig/sampleConfig/advanced_config_windows.yaml b/translator/tocwconfig/sampleConfig/advanced_config_windows.yaml index 7e88397a2d..4ce5959952 100644 --- a/translator/tocwconfig/sampleConfig/advanced_config_windows.yaml +++ b/translator/tocwconfig/sampleConfig/advanced_config_windows.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true ec2tagger: ec2_instance_tag_keys: - AutoScalingGroupName @@ -87,8 +88,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_win_perf_counters/2073218482 - telegraf_win_perf_counters/2039663244 diff --git a/translator/tocwconfig/sampleConfig/amp_config_linux.yaml b/translator/tocwconfig/sampleConfig/amp_config_linux.yaml index db8306774d..df5dc3fc5c 100644 --- a/translator/tocwconfig/sampleConfig/amp_config_linux.yaml +++ b/translator/tocwconfig/sampleConfig/amp_config_linux.yaml @@ -89,6 +89,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true batch/host/amp: metadata_cardinality_limit: 1000 send_batch_max_size: 0 @@ -152,9 +153,9 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger - transform + - awsentity/resource receivers: - telegraf_cpu telemetry: diff --git a/translator/tocwconfig/sampleConfig/basic_config_linux.yaml b/translator/tocwconfig/sampleConfig/basic_config_linux.yaml index a2cc400a66..8c7671dc35 100644 --- a/translator/tocwconfig/sampleConfig/basic_config_linux.yaml +++ b/translator/tocwconfig/sampleConfig/basic_config_linux.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true ec2tagger: ec2_instance_tag_keys: - AutoScalingGroupName @@ -60,8 +61,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_mem - telegraf_disk diff --git a/translator/tocwconfig/sampleConfig/basic_config_windows.yaml b/translator/tocwconfig/sampleConfig/basic_config_windows.yaml index 9583912100..335680faca 100644 --- a/translator/tocwconfig/sampleConfig/basic_config_windows.yaml +++ b/translator/tocwconfig/sampleConfig/basic_config_windows.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true ec2tagger: ec2_instance_tag_keys: - AutoScalingGroupName @@ -62,8 +63,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_win_perf_counters/1492679118 - telegraf_win_perf_counters/4283769065 diff --git a/translator/tocwconfig/sampleConfig/complete_darwin_config.yaml b/translator/tocwconfig/sampleConfig/complete_darwin_config.yaml index cb9b62b5d7..8053e8754c 100644 --- a/translator/tocwconfig/sampleConfig/complete_darwin_config.yaml +++ b/translator/tocwconfig/sampleConfig/complete_darwin_config.yaml @@ -105,6 +105,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true awsentity/service/telegraf: entity_type: Service platform: ec2 @@ -280,9 +281,9 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger - transform + - awsentity/resource receivers: - telegraf_disk - telegraf_swap @@ -305,10 +306,10 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - cumulativetodelta/hostDeltaMetrics - ec2tagger - transform + - awsentity/resource receivers: - telegraf_diskio - telegraf_net diff --git a/translator/tocwconfig/sampleConfig/complete_linux_config.yaml b/translator/tocwconfig/sampleConfig/complete_linux_config.yaml index 6105f937bc..3cc541ead6 100644 --- a/translator/tocwconfig/sampleConfig/complete_linux_config.yaml +++ b/translator/tocwconfig/sampleConfig/complete_linux_config.yaml @@ -111,6 +111,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true awsentity/service/telegraf: entity_type: Service platform: ec2 @@ -387,9 +388,9 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger - transform + - awsentity/resource receivers: - telegraf_swap - telegraf_cpu @@ -412,10 +413,10 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - cumulativetodelta/hostDeltaMetrics/cloudwatch - ec2tagger - transform + - awsentity/resource receivers: - telegraf_net - telegraf_diskio diff --git a/translator/tocwconfig/sampleConfig/complete_windows_config.yaml b/translator/tocwconfig/sampleConfig/complete_windows_config.yaml index e7fa12f152..d0274a1117 100644 --- a/translator/tocwconfig/sampleConfig/complete_windows_config.yaml +++ b/translator/tocwconfig/sampleConfig/complete_windows_config.yaml @@ -105,6 +105,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true awsentity/service/telegraf: entity_type: Service platform: ec2 @@ -267,9 +268,9 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger - transform + - awsentity/resource receivers: - telegraf_win_perf_counters/1063858558 - telegraf_nvidia_smi diff --git a/translator/tocwconfig/sampleConfig/delta_config_linux.yaml b/translator/tocwconfig/sampleConfig/delta_config_linux.yaml index 0abb2d4c66..d7125d06cd 100644 --- a/translator/tocwconfig/sampleConfig/delta_config_linux.yaml +++ b/translator/tocwconfig/sampleConfig/delta_config_linux.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true cumulativetodelta/hostDeltaMetrics: exclude: match_type: strict @@ -80,10 +81,10 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - cumulativetodelta/hostDeltaMetrics - ec2tagger - transform + - awsentity/resource receivers: - telegraf_diskio telemetry: diff --git a/translator/tocwconfig/sampleConfig/delta_net_config_linux.yaml b/translator/tocwconfig/sampleConfig/delta_net_config_linux.yaml index 57d9a066e2..93a44eb467 100644 --- a/translator/tocwconfig/sampleConfig/delta_net_config_linux.yaml +++ b/translator/tocwconfig/sampleConfig/delta_net_config_linux.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true cumulativetodelta/hostDeltaMetrics: exclude: match_type: "" @@ -63,9 +64,9 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - cumulativetodelta/hostDeltaMetrics - ec2tagger + - awsentity/resource receivers: - telegraf_net telemetry: diff --git a/translator/tocwconfig/sampleConfig/drop_origin_linux.yaml b/translator/tocwconfig/sampleConfig/drop_origin_linux.yaml index 65c7eff23e..24d603d40b 100644 --- a/translator/tocwconfig/sampleConfig/drop_origin_linux.yaml +++ b/translator/tocwconfig/sampleConfig/drop_origin_linux.yaml @@ -36,6 +36,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true ec2tagger: ec2_instance_tag_keys: - AutoScalingGroupName @@ -80,9 +81,9 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger - transform + - awsentity/resource receivers: - telegraf_cpu - telegraf_disk diff --git a/translator/tocwconfig/sampleConfig/ignore_append_dimensions.yaml b/translator/tocwconfig/sampleConfig/ignore_append_dimensions.yaml index 7605fd96e6..4ce3f21361 100644 --- a/translator/tocwconfig/sampleConfig/ignore_append_dimensions.yaml +++ b/translator/tocwconfig/sampleConfig/ignore_append_dimensions.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true ec2tagger: imds_retries: 1 middleware: agenthealth/statuscode @@ -54,8 +55,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_mem - telegraf_disk diff --git a/translator/tocwconfig/sampleConfig/invalid_input_linux.yaml b/translator/tocwconfig/sampleConfig/invalid_input_linux.yaml index ce52f0e9e5..4cb6979b8e 100644 --- a/translator/tocwconfig/sampleConfig/invalid_input_linux.yaml +++ b/translator/tocwconfig/sampleConfig/invalid_input_linux.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true ec2tagger: ec2_instance_tag_keys: - AutoScalingGroupName @@ -60,8 +61,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_mem - telegraf_disk diff --git a/translator/tocwconfig/sampleConfig/standard_config_linux.yaml b/translator/tocwconfig/sampleConfig/standard_config_linux.yaml index b8c154d320..cae3e6f3ed 100644 --- a/translator/tocwconfig/sampleConfig/standard_config_linux.yaml +++ b/translator/tocwconfig/sampleConfig/standard_config_linux.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true cumulativetodelta/hostDeltaMetrics: exclude: match_type: strict @@ -81,8 +82,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_mem - telegraf_swap @@ -92,9 +93,9 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - cumulativetodelta/hostDeltaMetrics - ec2tagger + - awsentity/resource receivers: - telegraf_diskio telemetry: diff --git a/translator/tocwconfig/sampleConfig/standard_config_linux_with_common_config.yaml b/translator/tocwconfig/sampleConfig/standard_config_linux_with_common_config.yaml index 145b8b9fa5..8da70feec4 100644 --- a/translator/tocwconfig/sampleConfig/standard_config_linux_with_common_config.yaml +++ b/translator/tocwconfig/sampleConfig/standard_config_linux_with_common_config.yaml @@ -35,6 +35,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true cumulativetodelta/hostDeltaMetrics: exclude: match_type: strict @@ -88,8 +89,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_cpu - telegraf_disk @@ -99,9 +100,9 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - cumulativetodelta/hostDeltaMetrics - ec2tagger + - awsentity/resource receivers: - telegraf_diskio telemetry: diff --git a/translator/tocwconfig/sampleConfig/standard_config_windows.yaml b/translator/tocwconfig/sampleConfig/standard_config_windows.yaml index 51e36adb81..c065028b6d 100644 --- a/translator/tocwconfig/sampleConfig/standard_config_windows.yaml +++ b/translator/tocwconfig/sampleConfig/standard_config_windows.yaml @@ -31,6 +31,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true ec2tagger: ec2_instance_tag_keys: - AutoScalingGroupName @@ -76,8 +77,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_win_perf_counters/3762679655 - telegraf_win_perf_counters/4283769065 diff --git a/translator/tocwconfig/sampleConfig/standard_config_windows_with_common_config.yaml b/translator/tocwconfig/sampleConfig/standard_config_windows_with_common_config.yaml index 7278578d40..520722cc40 100644 --- a/translator/tocwconfig/sampleConfig/standard_config_windows_with_common_config.yaml +++ b/translator/tocwconfig/sampleConfig/standard_config_windows_with_common_config.yaml @@ -35,6 +35,7 @@ processors: awsentity/resource: entity_type: Resource platform: ec2 + scrape_datapoint_attribute: true ec2tagger: ec2_instance_tag_keys: - AutoScalingGroupName @@ -83,8 +84,8 @@ service: exporters: - awscloudwatch processors: - - awsentity/resource - ec2tagger + - awsentity/resource receivers: - telegraf_win_perf_counters/3762679655 - telegraf_win_perf_counters/4283769065 diff --git a/translator/translate/otel/pipeline/host/translator.go b/translator/translate/otel/pipeline/host/translator.go index 0422b4165c..c45821b595 100644 --- a/translator/translate/otel/pipeline/host/translator.go +++ b/translator/translate/otel/pipeline/host/translator.go @@ -63,13 +63,7 @@ func (t translator) Translate(conf *confmap.Conf) (*common.ComponentTranslators, return nil, fmt.Errorf("no receivers configured in pipeline %s", t.name) } var entityProcessor common.Translator[component.Config] - if strings.HasPrefix(t.name, common.PipelineNameHostOtlpMetrics) { - entityProcessor = nil - } else if strings.HasPrefix(t.name, common.PipelineNameHostCustomMetrics) { - entityProcessor = awsentity.NewTranslatorWithEntityType(awsentity.Service, "telegraf", true) - } else if strings.HasPrefix(t.name, common.PipelineNameHost) || strings.HasPrefix(t.name, common.PipelineNameHostDeltaMetrics) { - entityProcessor = awsentity.NewTranslatorWithEntityType(awsentity.Resource, "", false) - } + var ec2TaggerEnabled bool translators := common.ComponentTranslators{ Receivers: t.receivers, @@ -77,10 +71,6 @@ func (t translator) Translate(conf *confmap.Conf) (*common.ComponentTranslators, Exporters: common.NewTranslatorMap[component.Config](), Extensions: common.NewTranslatorMap[component.Config](), } - currentContext := context.CurrentContext() - if entityProcessor != nil && currentContext.Mode() == config.ModeEC2 && !currentContext.RunInContainer() && (t.Destination() == common.CloudWatchKey || t.Destination() == common.DefaultDestination) { - translators.Processors.Set(entityProcessor) - } if strings.HasPrefix(t.name, common.PipelineNameHostDeltaMetrics) || strings.HasPrefix(t.name, common.PipelineNameHostOtlpMetrics) { log.Printf("D! delta processor required because metrics with diskio or net are set") @@ -91,6 +81,7 @@ func (t translator) Translate(conf *confmap.Conf) (*common.ComponentTranslators, if conf.IsSet(common.ConfigKey(common.MetricsKey, common.AppendDimensionsKey)) { log.Printf("D! ec2tagger processor required because append_dimensions is set") translators.Processors.Set(ec2taggerprocessor.NewTranslator()) + ec2TaggerEnabled = true } mdt := metricsdecorator.NewTranslator(metricsdecorator.WithIgnorePlugins(common.JmxKey)) @@ -100,6 +91,21 @@ func (t translator) Translate(conf *confmap.Conf) (*common.ComponentTranslators, } } + if strings.HasPrefix(t.name, common.PipelineNameHostOtlpMetrics) { + entityProcessor = nil + } else if strings.HasPrefix(t.name, common.PipelineNameHostCustomMetrics) { + entityProcessor = awsentity.NewTranslatorWithEntityType(awsentity.Service, "telegraf", true) + } else if (strings.HasPrefix(t.name, common.PipelineNameHost) || strings.HasPrefix(t.name, common.PipelineNameHostDeltaMetrics)) && ec2TaggerEnabled { + entityProcessor = awsentity.NewTranslatorWithEntityType(awsentity.Resource, "", true) + } else if strings.HasPrefix(t.name, common.PipelineNameHost) || strings.HasPrefix(t.name, common.PipelineNameHostDeltaMetrics) { + entityProcessor = awsentity.NewTranslatorWithEntityType(awsentity.Resource, "", false) + } + + currentContext := context.CurrentContext() + if entityProcessor != nil && currentContext.Mode() == config.ModeEC2 && !currentContext.RunInContainer() && (t.Destination() == common.CloudWatchKey || t.Destination() == common.DefaultDestination) { + translators.Processors.Set(entityProcessor) + } + switch t.Destination() { case common.DefaultDestination, common.CloudWatchKey: translators.Exporters.Set(awscloudwatch.NewTranslator()) diff --git a/translator/translate/otel/pipeline/host/translator_test.go b/translator/translate/otel/pipeline/host/translator_test.go index 2fbd2c60be..d0e3434278 100644 --- a/translator/translate/otel/pipeline/host/translator_test.go +++ b/translator/translate/otel/pipeline/host/translator_test.go @@ -75,7 +75,7 @@ func TestTranslator(t *testing.T) { want: &want{ pipelineID: "metrics/hostDeltaMetrics", receivers: []string{"nop", "other"}, - processors: []string{"awsentity/resource", "cumulativetodelta/hostDeltaMetrics"}, + processors: []string{"cumulativetodelta/hostDeltaMetrics", "awsentity/resource"}, exporters: []string{"awscloudwatch"}, extensions: []string{"agenthealth/metrics", "agenthealth/statuscode"}, }, @@ -137,7 +137,7 @@ func TestTranslator(t *testing.T) { want: &want{ pipelineID: "metrics/host", receivers: []string{"nop", "other"}, - processors: []string{"awsentity/resource", "transform"}, + processors: []string{"transform", "awsentity/resource"}, exporters: []string{"awscloudwatch"}, extensions: []string{"agenthealth/metrics", "agenthealth/statuscode"}, }, @@ -175,7 +175,7 @@ func TestTranslator(t *testing.T) { want: &want{ pipelineID: "metrics/host", receivers: []string{"nop", "other"}, - processors: []string{"awsentity/resource", "ec2tagger"}, + processors: []string{"ec2tagger", "awsentity/resource"}, exporters: []string{"awscloudwatch"}, extensions: []string{"agenthealth/metrics", "agenthealth/statuscode"}, },