From 78eedd5e9ddfbaa97b2203385b82fc9b118ea945 Mon Sep 17 00:00:00 2001 From: Travis Stark Date: Fri, 18 Jul 2025 08:17:59 -0400 Subject: [PATCH] setting default collection interval to -1 --- go.mod | 8 ++++---- go.sum | 14 ++++++-------- translator/translate/otel/common/common.go | 10 ++++++++++ .../otel/receiver/adapter/translator.go | 4 ++-- .../receiver/awscontainerinsight/translator.go | 3 +-- .../awscontainerinsight/translator_test.go | 18 +++++++++--------- .../awscontainerinsightskueue/translator.go | 5 ++--- .../translator_test.go | 2 +- 8 files changed, 35 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index 1ba8f4737d..d92dc5c5c6 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ replace ( replace ( github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil => github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/awsutil v0.0.0-20250717174233-f514045fc484 - github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight => github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/containerinsight v0.0.0-20250717174233-f514045fc484 + github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight => github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/containerinsight v0.0.0-20250722193355-2e41d3b81be3 github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs => github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/cwlogs v0.0.0-20250717174233-f514045fc484 github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s => github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/k8s v0.0.0-20250717174233-f514045fc484 github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/metrics => github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/metrics v0.0.0-20250717174233-f514045fc484 @@ -42,11 +42,11 @@ replace ( replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor => github.com/amazon-contributing/opentelemetry-collector-contrib/processor/resourcedetectionprocessor v0.0.0-20250717174233-f514045fc484 replace ( - github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver => github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver v0.0.0-20250717174233-f514045fc484 - github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightskueuereceiver => github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightskueuereceiver v0.0.0-20250717174233-f514045fc484 + github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver => github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver v0.0.0-20250722193355-2e41d3b81be3 + github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightskueuereceiver => github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightskueuereceiver v0.0.0-20250722193355-2e41d3b81be3 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsxrayreceiver => github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awsxrayreceiver v0.0.0-20250717174233-f514045fc484 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jmxreceiver => github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/jmxreceiver v0.0.0-20250717174233-f514045fc484 - github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver => github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.0.0-20250717174233-f514045fc484 + github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver => github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.0.0-20250722193355-2e41d3b81be3 ) // Temporary fix, pending PR https://github.com/shirou/gopsutil/pull/957 diff --git a/go.sum b/go.sum index c99b018ff7..b25eae484e 100644 --- a/go.sum +++ b/go.sum @@ -199,8 +199,6 @@ github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsprox github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsproxy v0.0.0-20250717174233-f514045fc484/go.mod h1:IaVVx5+2dXba7dDVfnCAZkqBc3fE7XX5UnehsGmf+mw= github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/awsutil v0.0.0-20250717174233-f514045fc484 h1:34a19sMva8wCzo9OMMMdK26woQy5WKG3wKGe4Xt6tYM= github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/awsutil v0.0.0-20250717174233-f514045fc484/go.mod h1:AbdplNaM4g1LnEbDczU5tDqnF1xhzlgBvpB1xwEUlhg= -github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/containerinsight v0.0.0-20250717174233-f514045fc484 h1:gs9fAS213niCP4k2sPeqsEfOgSrXI6eDsn2REPeKDJw= -github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/containerinsight v0.0.0-20250717174233-f514045fc484/go.mod h1:9bL/kFVrHh9yDtTUQwxkVl7gRA0PfTmt87CBzC/ihBM= github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/cwlogs v0.0.0-20250717174233-f514045fc484 h1:cRB7SfM84zjadY92D1s2ywEAsO7+YKAFBDXUlpveh10= github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/cwlogs v0.0.0-20250717174233-f514045fc484/go.mod h1:XK8ww4E/9UaVR0wz3mS1HRr+qFEfA/FBZoSRZjVnJRs= github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/k8s v0.0.0-20250717174233-f514045fc484 h1:36mpJBt/c/mZYE7R2+z2anERw0vmc7tf22SJ9FkRJf8= @@ -229,16 +227,16 @@ github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/translator/pr github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/translator/prometheus v0.0.0-20250717174233-f514045fc484/go.mod h1:7prJseoHF7mXXAPdU+q1zoZdVOclFZsgNhoBriqBIp0= github.com/amazon-contributing/opentelemetry-collector-contrib/processor/resourcedetectionprocessor v0.0.0-20250717174233-f514045fc484 h1:cFRXqozAwclrrSJD/1fwrrebwNNVL8sAPvewZSmYl0k= github.com/amazon-contributing/opentelemetry-collector-contrib/processor/resourcedetectionprocessor v0.0.0-20250717174233-f514045fc484/go.mod h1:K8inysgi51ecddal8W6MPqrYcjh65wm1PsVDV+zgCEA= -github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver v0.0.0-20250717174233-f514045fc484 h1:KkQR49FSmepOqBfze1zNBmAi06DUUSQzOS+lzQkSPTY= -github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver v0.0.0-20250717174233-f514045fc484/go.mod h1:78qZtZnv6jO7K56d1OUMtgTcH0rPcb4N8Zp4/EiMJ0o= -github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightskueuereceiver v0.0.0-20250717174233-f514045fc484 h1:NqDlh14x1674xIAnLC3iCvEmaLeGEorAzzWopMKAW9o= -github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightskueuereceiver v0.0.0-20250717174233-f514045fc484/go.mod h1:GipgrS7Hgv0MgjQ6c2CrEti5kWKsXSaqB+E2XrHmiy4= +github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver v0.0.0-20250722185957-5561c58c81fd h1:Vg8NFRXprGAgmLvsrxP5etgVgTFT4aKluPOGWFRB+b8= +github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver v0.0.0-20250722185957-5561c58c81fd/go.mod h1:78qZtZnv6jO7K56d1OUMtgTcH0rPcb4N8Zp4/EiMJ0o= +github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightskueuereceiver v0.0.0-20250722185957-5561c58c81fd h1:nwrxRfSQ3wQ5udVCh+vEQsW8i5cYWWUZOA7kCQsXDG0= +github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightskueuereceiver v0.0.0-20250722185957-5561c58c81fd/go.mod h1:GipgrS7Hgv0MgjQ6c2CrEti5kWKsXSaqB+E2XrHmiy4= github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awsxrayreceiver v0.0.0-20250717174233-f514045fc484 h1:7Eq8GHafdPwuj/zruhctXzYyhtXUmp0FVAcsHX0V6Co= github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awsxrayreceiver v0.0.0-20250717174233-f514045fc484/go.mod h1:iNL2C4bugyDA/nYSAu4O68xD859BudOWGd0+03+lWVs= github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/jmxreceiver v0.0.0-20250717174233-f514045fc484 h1:ot2Q8zo4EQBwhCIOht3XkuRYkBsJhddWBQrng37LFWQ= github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/jmxreceiver v0.0.0-20250717174233-f514045fc484/go.mod h1:tEB7CZP8f7qVEWH9y3F2sbI5EcvICSW3sZOFwXRge5U= -github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.0.0-20250717174233-f514045fc484 h1:hh+kKCO1UBFIvDIF4pxiwSbixO3AfbjOc36z6uuXujE= -github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.0.0-20250717174233-f514045fc484/go.mod h1:Tc/PSUfe91PN6BoGKEHFo6V0gb23gxp7QLTdsrK2meI= +github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.0.0-20250722185957-5561c58c81fd h1:O8ea/g1SGPLV34xU5rRMW5XYTvAvP9BHvKrzJhhqXVI= +github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.0.0-20250722185957-5561c58c81fd/go.mod h1:Tc/PSUfe91PN6BoGKEHFo6V0gb23gxp7QLTdsrK2meI= github.com/amir/raidman v0.0.0-20170415203553-1ccc43bfb9c9 h1:FXrPTd8Rdlc94dKccl7KPmdmIbVh/OjelJ8/vgMRzcQ= github.com/amir/raidman v0.0.0-20170415203553-1ccc43bfb9c9/go.mod h1:eliMa/PW+RDr2QLWRmLH1R1ZA4RInpmvOzDDXtaIZkc= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= diff --git a/translator/translate/otel/common/common.go b/translator/translate/otel/common/common.go index 3b2eba8dda..af619b0dfe 100644 --- a/translator/translate/otel/common/common.go +++ b/translator/translate/otel/common/common.go @@ -399,6 +399,16 @@ func GetOrDefaultNumber(conf *confmap.Conf, key string, defaultVal float64) floa return value } +// GetOrDefaultCollectionInterval gets the collection interval from the configuration. +// If the interval is not specified or is <= 0, it returns the component's default interval. +func GetOrDefaultCollectionInterval(conf *confmap.Conf, key string, componentDefault time.Duration) time.Duration { + interval, ok := GetDuration(conf, key) + if !ok || interval <= 0 { + return componentDefault + } + return interval +} + // GetDuration gets the value for the key and calls ParseDuration on it. // If the key is missing, it is unable to parse the duration, or the // duration is set to 0, then the returned bool will be false. diff --git a/translator/translate/otel/receiver/adapter/translator.go b/translator/translate/otel/receiver/adapter/translator.go index 77a971a63a..9892611d4b 100644 --- a/translator/translate/otel/receiver/adapter/translator.go +++ b/translator/translate/otel/receiver/adapter/translator.go @@ -24,11 +24,11 @@ type translator struct { // See otel.ConfigKey. cfgKey string - // preferMetricCollectionInterval is an option to using the preferaable metric collection interval before + // preferMetricCollectionInterval is an option to using the preferable metric collection interval before // using the interval key chain and defaultMetricCollectionInterval preferMetricCollectionInterval time.Duration - // defaultMetricCollectionInterval is the fallback interval if it + // defaultMetricCollectionInterval is the fallback interval if // it is not present in the interval keychain. defaultMetricCollectionInterval time.Duration } diff --git a/translator/translate/otel/receiver/awscontainerinsight/translator.go b/translator/translate/otel/receiver/awscontainerinsight/translator.go index ba3566c801..8f2d3ab5a2 100644 --- a/translator/translate/otel/receiver/awscontainerinsight/translator.go +++ b/translator/translate/otel/receiver/awscontainerinsight/translator.go @@ -8,7 +8,6 @@ import ( "fmt" "os" "strings" - "time" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver" "go.opentelemetry.io/collector/component" @@ -32,7 +31,7 @@ const ( ecs = "ecs" eks = "eks" - defaultMetricsCollectionInterval = time.Minute + defaultMetricsCollectionInterval = -1 // default to -1 to use default value defined in receiver defaultLeaderLockName = "cwagent-clusterleader" // To maintain backwards compatability with https://github.com/aws/amazon-cloudwatch-agent/blob/2dd89abaab4590cffbbc31ef89319b62809b09d1/plugins/inputs/k8sapiserver/k8sapiserver.go#L30 ) diff --git a/translator/translate/otel/receiver/awscontainerinsight/translator_test.go b/translator/translate/otel/receiver/awscontainerinsight/translator_test.go index 09570dcf46..cace419a6d 100644 --- a/translator/translate/otel/receiver/awscontainerinsight/translator_test.go +++ b/translator/translate/otel/receiver/awscontainerinsight/translator_test.go @@ -43,7 +43,7 @@ func TestTranslator(t *testing.T) { }, want: &awscontainerinsightreceiver.Config{ ContainerOrchestrator: ecs, - CollectionInterval: time.Minute, + CollectionInterval: defaultMetricsCollectionInterval, LeaderLockName: "otel-container-insight-clusterleader", TagService: true, }, @@ -130,7 +130,7 @@ func TestTranslator(t *testing.T) { }, want: &awscontainerinsightreceiver.Config{ ContainerOrchestrator: eks, - CollectionInterval: 60 * time.Second, + CollectionInterval: defaultMetricsCollectionInterval, TagService: false, LeaderLockName: defaultLeaderLockName, LeaderLockUsingConfigMapOnly: true, @@ -153,7 +153,7 @@ func TestTranslator(t *testing.T) { }, want: &awscontainerinsightreceiver.Config{ ContainerOrchestrator: eks, - CollectionInterval: 60 * time.Second, + CollectionInterval: defaultMetricsCollectionInterval, CollectionRole: awscontainerinsightreceiver.LEADER, TagService: true, LeaderLockName: defaultLeaderLockName, @@ -177,7 +177,7 @@ func TestTranslator(t *testing.T) { }, want: &awscontainerinsightreceiver.Config{ ContainerOrchestrator: eks, - CollectionInterval: 60 * time.Second, + CollectionInterval: defaultMetricsCollectionInterval, CollectionRole: awscontainerinsightreceiver.NODE, TagService: true, LeaderLockName: defaultLeaderLockName, @@ -199,7 +199,7 @@ func TestTranslator(t *testing.T) { }, want: &awscontainerinsightreceiver.Config{ ContainerOrchestrator: eks, - CollectionInterval: 60 * time.Second, + CollectionInterval: defaultMetricsCollectionInterval, PrefFullPodName: true, LeaderLockName: defaultLeaderLockName, LeaderLockUsingConfigMapOnly: true, @@ -224,7 +224,7 @@ func TestTranslator(t *testing.T) { }, want: &awscontainerinsightreceiver.Config{ ContainerOrchestrator: eks, - CollectionInterval: 60 * time.Second, + CollectionInterval: defaultMetricsCollectionInterval, LeaderLockName: defaultLeaderLockName, LeaderLockUsingConfigMapOnly: true, ClusterName: "TestCluster", @@ -248,7 +248,7 @@ func TestTranslator(t *testing.T) { }, want: &awscontainerinsightreceiver.Config{ ContainerOrchestrator: eks, - CollectionInterval: 60 * time.Second, + CollectionInterval: defaultMetricsCollectionInterval, PrefFullPodName: true, LeaderLockName: defaultLeaderLockName, LeaderLockUsingConfigMapOnly: true, @@ -273,7 +273,7 @@ func TestTranslator(t *testing.T) { }, want: &awscontainerinsightreceiver.Config{ ContainerOrchestrator: eks, - CollectionInterval: 60 * time.Second, + CollectionInterval: defaultMetricsCollectionInterval, PrefFullPodName: true, LeaderLockName: defaultLeaderLockName, LeaderLockUsingConfigMapOnly: true, @@ -322,7 +322,7 @@ func TestTranslator(t *testing.T) { isSystemd: true, want: &awscontainerinsightreceiver.Config{ ContainerOrchestrator: eks, - CollectionInterval: 60 * time.Second, + CollectionInterval: defaultMetricsCollectionInterval, PrefFullPodName: false, LeaderLockName: defaultLeaderLockName, LeaderLockUsingConfigMapOnly: true, diff --git a/translator/translate/otel/receiver/awscontainerinsightskueue/translator.go b/translator/translate/otel/receiver/awscontainerinsightskueue/translator.go index e62600380f..6c0613765e 100644 --- a/translator/translate/otel/receiver/awscontainerinsightskueue/translator.go +++ b/translator/translate/otel/receiver/awscontainerinsightskueue/translator.go @@ -5,7 +5,6 @@ package awscontainerinsightskueue import ( "errors" - "time" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightskueuereceiver" "go.opentelemetry.io/collector/component" @@ -16,7 +15,7 @@ import ( ) const ( - defaultMetricsCollectionInterval = time.Minute + defaultMetricsCollectionInterval = -1 // default to -1 to use default value defined in receiver ) type translator struct { @@ -42,7 +41,7 @@ func (t *translator) ID() component.ID { return component.NewIDWithName(t.factory.Type(), t.name) } -// Translate creates an aws container insights receiver config if either +// Translate creates an aws container insights kueue receiver config if either // of the sections defined in the services exist. func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) { cfg := t.factory.CreateDefaultConfig().(*awscontainerinsightskueuereceiver.Config) diff --git a/translator/translate/otel/receiver/awscontainerinsightskueue/translator_test.go b/translator/translate/otel/receiver/awscontainerinsightskueue/translator_test.go index 1216605538..eefc9a315a 100644 --- a/translator/translate/otel/receiver/awscontainerinsightskueue/translator_test.go +++ b/translator/translate/otel/receiver/awscontainerinsightskueue/translator_test.go @@ -36,7 +36,7 @@ func TestTranslator(t *testing.T) { }, isSystemd: true, want: &awscontainerinsightskueuereceiver.Config{ - CollectionInterval: 60 * time.Second, + CollectionInterval: defaultMetricsCollectionInterval, ClusterName: "TestCluster", }, },