From c74fc1407ce6b859f35bcb489c7899f1d053bad6 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Wed, 6 Sep 2023 19:46:10 +0530 Subject: [PATCH 01/11] =?UTF-8?q?feat(k8sclusterreceiver):=20=E2=9C=A8=20i?= =?UTF-8?q?ntroduce=20ignore=5Fdeprecated=5Fresource=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Prashant Shahi --- receiver/k8sclusterreceiver/config.go | 3 +++ receiver/k8sclusterreceiver/factory.go | 2 ++ receiver/k8sclusterreceiver/watcher.go | 32 +++++++++++++++----------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/receiver/k8sclusterreceiver/config.go b/receiver/k8sclusterreceiver/config.go index 40731a808da8..624312e9c259 100644 --- a/receiver/k8sclusterreceiver/config.go +++ b/receiver/k8sclusterreceiver/config.go @@ -39,6 +39,9 @@ type Config struct { // MetricsBuilderConfig allows customizing scraped metrics/attributes representation. metadata.MetricsBuilderConfig `mapstructure:",squash"` + + // Whether to ignore deprecated resources or not. + IgnoreDeprecatedResource bool `mapstructure:"ignore_deprecated_resource"` } func (cfg *Config) Validate() error { diff --git a/receiver/k8sclusterreceiver/factory.go b/receiver/k8sclusterreceiver/factory.go index 74537b52354c..b757b0115d9c 100644 --- a/receiver/k8sclusterreceiver/factory.go +++ b/receiver/k8sclusterreceiver/factory.go @@ -23,6 +23,7 @@ const ( defaultCollectionInterval = 10 * time.Second defaultDistribution = distributionKubernetes defaultMetadataCollectionInterval = 5 * time.Minute + defaultIgnoreDeprecatedResource = false ) var defaultNodeConditionsToReport = []string{"Ready"} @@ -37,6 +38,7 @@ func createDefaultConfig() component.Config { }, MetadataCollectionInterval: defaultMetadataCollectionInterval, MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), + IgnoreDeprecatedResource: defaultIgnoreDeprecatedResource, } } diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index 3f9926738fdb..0f0474976d8e 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -127,19 +127,25 @@ func (rw *resourceWatcher) prepareSharedInformerFactory() error { // informer for that kind won't be set and a warning message is thrown. // This map should be kept in sync with what can be provided by the supported k8s server versions. supportedKinds := map[string][]schema.GroupVersionKind{ - "Pod": {gvk.Pod}, - "Node": {gvk.Node}, - "Namespace": {gvk.Namespace}, - "ReplicationController": {gvk.ReplicationController}, - "ResourceQuota": {gvk.ResourceQuota}, - "Service": {gvk.Service}, - "DaemonSet": {gvk.DaemonSet}, - "Deployment": {gvk.Deployment}, - "ReplicaSet": {gvk.ReplicaSet}, - "StatefulSet": {gvk.StatefulSet}, - "Job": {gvk.Job}, - "CronJob": {gvk.CronJob, gvk.CronJobBeta}, - "HorizontalPodAutoscaler": {gvk.HorizontalPodAutoscaler, gvk.HorizontalPodAutoscalerBeta}, + "Pod": {gvk.Pod}, + "Node": {gvk.Node}, + "Namespace": {gvk.Namespace}, + "ReplicationController": {gvk.ReplicationController}, + "ResourceQuota": {gvk.ResourceQuota}, + "Service": {gvk.Service}, + "DaemonSet": {gvk.DaemonSet}, + "Deployment": {gvk.Deployment}, + "ReplicaSet": {gvk.ReplicaSet}, + "StatefulSet": {gvk.StatefulSet}, + "Job": {gvk.Job}, + } + + if !rw.config.IgnoreDeprecatedResource { + supportedKinds["CronJob"] = []schema.GroupVersionKind{gvk.CronJob, gvk.CronJobBeta} + supportedKinds["HorizontalPodAutoscaler"] = []schema.GroupVersionKind{gvk.HorizontalPodAutoscaler, gvk.HorizontalPodAutoscalerBeta} + } else { + supportedKinds["CronJob"] = []schema.GroupVersionKind{gvk.CronJob} + supportedKinds["HorizontalPodAutoscaler"] = []schema.GroupVersionKind{gvk.HorizontalPodAutoscaler} } for kind, gvks := range supportedKinds { From 0f7bd1ff94581f09d1d9834ec1ff379ef218b67d Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Thu, 7 Sep 2023 23:14:47 +0530 Subject: [PATCH 02/11] =?UTF-8?q?docs(k8scluster):=20=F0=9F=93=9D=20update?= =?UTF-8?q?=20README=20and=20example=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Prashant Shahi --- receiver/k8sclusterreceiver/README.md | 4 ++++ receiver/k8sclusterreceiver/testdata/config.yaml | 1 + 2 files changed, 5 insertions(+) diff --git a/receiver/k8sclusterreceiver/README.md b/receiver/k8sclusterreceiver/README.md index dfea42f5a03c..a342ea2bada0 100644 --- a/receiver/k8sclusterreceiver/README.md +++ b/receiver/k8sclusterreceiver/README.md @@ -67,6 +67,9 @@ The following allocatable resource types are available. - storage - `metrics`: Allows to enable/disable metrics. - `resource_attributes`: Allows to enable/disable resource attributes. +- `ignore_deprecated_resource` (default = `false`): Whether to ignore deprecated Kubernetes API resources. If set to true, + the receiver will not collect metrics for deprecated resources. This setting is useful for clusters that have deprecated + resources that are not used anymore and are causing errors or warnings in the logs. Example: @@ -81,6 +84,7 @@ Example: resource_attributes: container.id: enabled: false + ignore_deprecated_resource: true ``` The full list of settings exposed for this receiver are documented [here](./config.go) diff --git a/receiver/k8sclusterreceiver/testdata/config.yaml b/receiver/k8sclusterreceiver/testdata/config.yaml index b7d2737c4e79..dbf4000df237 100644 --- a/receiver/k8sclusterreceiver/testdata/config.yaml +++ b/receiver/k8sclusterreceiver/testdata/config.yaml @@ -5,6 +5,7 @@ k8s_cluster/all_settings: allocatable_types_to_report: [ "cpu","memory" ] metadata_exporters: [ nop ] metadata_collection_interval: 30m + ignore_deprecated_resource: false k8s_cluster/partial_settings: collection_interval: 30s distribution: openshift From 1389666a4ea28677c44de60bb812113aceee8cc4 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Fri, 8 Sep 2023 11:40:14 +0530 Subject: [PATCH 03/11] =?UTF-8?q?chore:=20=F0=9F=9A=9A=20rename=20ignore?= =?UTF-8?q?=5Fdeprecated=5Fresource=20to=20ignore=5Fdeprecated=5Fresources?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Prashant Shahi --- receiver/k8sclusterreceiver/README.md | 4 ++-- receiver/k8sclusterreceiver/config.go | 2 +- receiver/k8sclusterreceiver/factory.go | 4 ++-- receiver/k8sclusterreceiver/testdata/config.yaml | 2 +- receiver/k8sclusterreceiver/watcher.go | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/receiver/k8sclusterreceiver/README.md b/receiver/k8sclusterreceiver/README.md index a342ea2bada0..1bb79c3dd513 100644 --- a/receiver/k8sclusterreceiver/README.md +++ b/receiver/k8sclusterreceiver/README.md @@ -67,7 +67,7 @@ The following allocatable resource types are available. - storage - `metrics`: Allows to enable/disable metrics. - `resource_attributes`: Allows to enable/disable resource attributes. -- `ignore_deprecated_resource` (default = `false`): Whether to ignore deprecated Kubernetes API resources. If set to true, +- `ignore_deprecated_resources` (default = `false`): Whether to ignore deprecated Kubernetes API resources. If set to true, the receiver will not collect metrics for deprecated resources. This setting is useful for clusters that have deprecated resources that are not used anymore and are causing errors or warnings in the logs. @@ -84,7 +84,7 @@ Example: resource_attributes: container.id: enabled: false - ignore_deprecated_resource: true + ignore_deprecated_resources: true ``` The full list of settings exposed for this receiver are documented [here](./config.go) diff --git a/receiver/k8sclusterreceiver/config.go b/receiver/k8sclusterreceiver/config.go index 624312e9c259..9455b71ec9d0 100644 --- a/receiver/k8sclusterreceiver/config.go +++ b/receiver/k8sclusterreceiver/config.go @@ -41,7 +41,7 @@ type Config struct { metadata.MetricsBuilderConfig `mapstructure:",squash"` // Whether to ignore deprecated resources or not. - IgnoreDeprecatedResource bool `mapstructure:"ignore_deprecated_resource"` + IgnoreDeprecatedResources bool `mapstructure:"ignore_deprecated_resources"` } func (cfg *Config) Validate() error { diff --git a/receiver/k8sclusterreceiver/factory.go b/receiver/k8sclusterreceiver/factory.go index b757b0115d9c..63c988d668ad 100644 --- a/receiver/k8sclusterreceiver/factory.go +++ b/receiver/k8sclusterreceiver/factory.go @@ -23,7 +23,7 @@ const ( defaultCollectionInterval = 10 * time.Second defaultDistribution = distributionKubernetes defaultMetadataCollectionInterval = 5 * time.Minute - defaultIgnoreDeprecatedResource = false + defaultIgnoreDeprecatedResources = false ) var defaultNodeConditionsToReport = []string{"Ready"} @@ -38,7 +38,7 @@ func createDefaultConfig() component.Config { }, MetadataCollectionInterval: defaultMetadataCollectionInterval, MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), - IgnoreDeprecatedResource: defaultIgnoreDeprecatedResource, + IgnoreDeprecatedResources: defaultIgnoreDeprecatedResources, } } diff --git a/receiver/k8sclusterreceiver/testdata/config.yaml b/receiver/k8sclusterreceiver/testdata/config.yaml index dbf4000df237..1acd1da6c82d 100644 --- a/receiver/k8sclusterreceiver/testdata/config.yaml +++ b/receiver/k8sclusterreceiver/testdata/config.yaml @@ -5,7 +5,7 @@ k8s_cluster/all_settings: allocatable_types_to_report: [ "cpu","memory" ] metadata_exporters: [ nop ] metadata_collection_interval: 30m - ignore_deprecated_resource: false + ignore_deprecated_resources: false k8s_cluster/partial_settings: collection_interval: 30s distribution: openshift diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index 0f0474976d8e..88bb262ced44 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -140,7 +140,7 @@ func (rw *resourceWatcher) prepareSharedInformerFactory() error { "Job": {gvk.Job}, } - if !rw.config.IgnoreDeprecatedResource { + if !rw.config.IgnoreDeprecatedResources { supportedKinds["CronJob"] = []schema.GroupVersionKind{gvk.CronJob, gvk.CronJobBeta} supportedKinds["HorizontalPodAutoscaler"] = []schema.GroupVersionKind{gvk.HorizontalPodAutoscaler, gvk.HorizontalPodAutoscalerBeta} } else { From e1d1ae6e605d071de1947f008b58e1039191a021 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Fri, 8 Sep 2023 11:40:20 +0530 Subject: [PATCH 04/11] =?UTF-8?q?docs(k8scluster):=20=F0=9F=93=9D=20update?= =?UTF-8?q?=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Prashant Shahi --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48e91e2fc43e..9fceb02f926d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ If you are looking for developer-facing changes, check out [CHANGELOG-API.md](./ - `snmpreceiver`: Timeout for SNMP requests can now be configured. (#25885) - `telemetrygen`: The telemetrygen now supports setting the log's body (#26031) - `awsxrayexporter`: add `exporter.awsxray.skiptimestampvalidation` Alpha feature gate to remove xray timestamp restriction on first 32 bits of trace id (#26041) +- `k8sclusterreceiver`: Add `ignore_deprecated_resources` option to ignore deprecated Kubernetes API resources (#26516) ### 🧰 Bug fixes 🧰 From d421469102c9dfbec8e6b4ef4e24b332de439c41 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Sat, 9 Sep 2023 14:18:22 +0530 Subject: [PATCH 05/11] refactor(k8sclusterreceiver): :recycle: remove deprecated APIs and related files Signed-off-by: Prashant Shahi --- receiver/k8sclusterreceiver/config.go | 3 -- receiver/k8sclusterreceiver/factory.go | 2 - .../internal/collection/collector.go | 8 ---- .../internal/cronjob/cronjobs.go | 18 -------- .../k8sclusterreceiver/internal/gvk/gvk.go | 30 +++++++------ .../k8sclusterreceiver/internal/hpa/hpa.go | 19 --------- .../internal/testutils/objects.go | 20 --------- receiver/k8sclusterreceiver/receiver_test.go | 6 --- receiver/k8sclusterreceiver/watcher.go | 42 ++++++------------- receiver/k8sclusterreceiver/watcher_test.go | 18 -------- 10 files changed, 27 insertions(+), 139 deletions(-) diff --git a/receiver/k8sclusterreceiver/config.go b/receiver/k8sclusterreceiver/config.go index 9455b71ec9d0..40731a808da8 100644 --- a/receiver/k8sclusterreceiver/config.go +++ b/receiver/k8sclusterreceiver/config.go @@ -39,9 +39,6 @@ type Config struct { // MetricsBuilderConfig allows customizing scraped metrics/attributes representation. metadata.MetricsBuilderConfig `mapstructure:",squash"` - - // Whether to ignore deprecated resources or not. - IgnoreDeprecatedResources bool `mapstructure:"ignore_deprecated_resources"` } func (cfg *Config) Validate() error { diff --git a/receiver/k8sclusterreceiver/factory.go b/receiver/k8sclusterreceiver/factory.go index 63c988d668ad..74537b52354c 100644 --- a/receiver/k8sclusterreceiver/factory.go +++ b/receiver/k8sclusterreceiver/factory.go @@ -23,7 +23,6 @@ const ( defaultCollectionInterval = 10 * time.Second defaultDistribution = distributionKubernetes defaultMetadataCollectionInterval = 5 * time.Minute - defaultIgnoreDeprecatedResources = false ) var defaultNodeConditionsToReport = []string{"Ready"} @@ -38,7 +37,6 @@ func createDefaultConfig() component.Config { }, MetadataCollectionInterval: defaultMetadataCollectionInterval, MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), - IgnoreDeprecatedResources: defaultIgnoreDeprecatedResources, } } diff --git a/receiver/k8sclusterreceiver/internal/collection/collector.go b/receiver/k8sclusterreceiver/internal/collection/collector.go index aa4685286f5f..c32a2fa57042 100644 --- a/receiver/k8sclusterreceiver/internal/collection/collector.go +++ b/receiver/k8sclusterreceiver/internal/collection/collector.go @@ -12,9 +12,7 @@ import ( "go.opentelemetry.io/collector/receiver" appsv1 "k8s.io/api/apps/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" batchv1 "k8s.io/api/batch/v1" - batchv1beta1 "k8s.io/api/batch/v1beta1" corev1 "k8s.io/api/core/v1" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/clusterresourcequota" @@ -99,15 +97,9 @@ func (dc *DataCollector) CollectMetricData(currentTime time.Time) pmetric.Metric dc.metadataStore.ForEach(gvk.CronJob, func(o any) { cronjob.RecordMetrics(dc.metricsBuilder, o.(*batchv1.CronJob), ts) }) - dc.metadataStore.ForEach(gvk.CronJobBeta, func(o any) { - cronjob.RecordMetricsBeta(dc.metricsBuilder, o.(*batchv1beta1.CronJob), ts) - }) dc.metadataStore.ForEach(gvk.HorizontalPodAutoscaler, func(o any) { hpa.RecordMetrics(dc.metricsBuilder, o.(*autoscalingv2.HorizontalPodAutoscaler), ts) }) - dc.metadataStore.ForEach(gvk.HorizontalPodAutoscalerBeta, func(o any) { - hpa.RecordMetricsBeta(dc.metricsBuilder, o.(*autoscalingv2beta2.HorizontalPodAutoscaler), ts) - }) dc.metadataStore.ForEach(gvk.ClusterResourceQuota, func(o any) { clusterresourcequota.RecordMetrics(dc.metricsBuilder, o.(*quotav1.ClusterResourceQuota), ts) }) diff --git a/receiver/k8sclusterreceiver/internal/cronjob/cronjobs.go b/receiver/k8sclusterreceiver/internal/cronjob/cronjobs.go index e7a49e6c15da..f514192d65cf 100644 --- a/receiver/k8sclusterreceiver/internal/cronjob/cronjobs.go +++ b/receiver/k8sclusterreceiver/internal/cronjob/cronjobs.go @@ -6,7 +6,6 @@ package cronjob // import "github.com/open-telemetry/opentelemetry-collector-con import ( "go.opentelemetry.io/collector/pdata/pcommon" batchv1 "k8s.io/api/batch/v1" - batchv1beta1 "k8s.io/api/batch/v1beta1" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/constants" @@ -30,26 +29,9 @@ func RecordMetrics(mb *metadata.MetricsBuilder, cj *batchv1.CronJob, ts pcommon. mb.EmitForResource(metadata.WithResource(rb.Emit())) } -func RecordMetricsBeta(mb *metadata.MetricsBuilder, cj *batchv1beta1.CronJob, ts pcommon.Timestamp) { - mb.RecordK8sCronjobActiveJobsDataPoint(ts, int64(len(cj.Status.Active))) - rb := mb.NewResourceBuilder() - rb.SetK8sNamespaceName(cj.Namespace) - rb.SetK8sCronjobUID(string(cj.UID)) - rb.SetK8sCronjobName(cj.Name) - rb.SetOpencensusResourcetype("k8s") - mb.EmitForResource(metadata.WithResource(rb.Emit())) -} - func GetMetadata(cj *batchv1.CronJob) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { rm := metadata.GetGenericMetadata(&cj.ObjectMeta, constants.K8sKindCronJob) rm.Metadata[cronJobKeySchedule] = cj.Spec.Schedule rm.Metadata[cronJobKeyConcurrencyPolicy] = string(cj.Spec.ConcurrencyPolicy) return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{experimentalmetricmetadata.ResourceID(cj.UID): rm} } - -func GetMetadataBeta(cj *batchv1beta1.CronJob) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { - rm := metadata.GetGenericMetadata(&cj.ObjectMeta, constants.K8sKindCronJob) - rm.Metadata[cronJobKeySchedule] = cj.Spec.Schedule - rm.Metadata[cronJobKeyConcurrencyPolicy] = string(cj.Spec.ConcurrencyPolicy) - return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{experimentalmetricmetadata.ResourceID(cj.UID): rm} -} diff --git a/receiver/k8sclusterreceiver/internal/gvk/gvk.go b/receiver/k8sclusterreceiver/internal/gvk/gvk.go index 2424d0c71ec6..58e540821077 100644 --- a/receiver/k8sclusterreceiver/internal/gvk/gvk.go +++ b/receiver/k8sclusterreceiver/internal/gvk/gvk.go @@ -7,20 +7,18 @@ import "k8s.io/apimachinery/pkg/runtime/schema" // Kubernetes group version kinds var ( - Pod = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"} - Node = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"} - Namespace = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"} - ReplicationController = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ReplicationController"} - ResourceQuota = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ResourceQuota"} - Service = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"} - DaemonSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"} - Deployment = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} - ReplicaSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"} - StatefulSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"} - Job = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"} - CronJob = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "CronJob"} - CronJobBeta = schema.GroupVersionKind{Group: "batch", Version: "v1beta1", Kind: "CronJob"} - HorizontalPodAutoscaler = schema.GroupVersionKind{Group: "autoscaling", Version: "v2", Kind: "HorizontalPodAutoscaler"} - HorizontalPodAutoscalerBeta = schema.GroupVersionKind{Group: "autoscaling", Version: "v2beta2", Kind: "HorizontalPodAutoscaler"} - ClusterResourceQuota = schema.GroupVersionKind{Group: "quota", Version: "v1", Kind: "ClusterResourceQuota"} + Pod = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"} + Node = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"} + Namespace = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"} + ReplicationController = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ReplicationController"} + ResourceQuota = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ResourceQuota"} + Service = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"} + DaemonSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"} + Deployment = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} + ReplicaSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"} + StatefulSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"} + Job = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"} + CronJob = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "CronJob"} + HorizontalPodAutoscaler = schema.GroupVersionKind{Group: "autoscaling", Version: "v2", Kind: "HorizontalPodAutoscaler"} + ClusterResourceQuota = schema.GroupVersionKind{Group: "quota", Version: "v1", Kind: "ClusterResourceQuota"} ) diff --git a/receiver/k8sclusterreceiver/internal/hpa/hpa.go b/receiver/k8sclusterreceiver/internal/hpa/hpa.go index 380f1fac87a7..15d437e9863e 100644 --- a/receiver/k8sclusterreceiver/internal/hpa/hpa.go +++ b/receiver/k8sclusterreceiver/internal/hpa/hpa.go @@ -6,24 +6,11 @@ package hpa // import "github.com/open-telemetry/opentelemetry-collector-contrib import ( "go.opentelemetry.io/collector/pdata/pcommon" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/metadata" ) -func RecordMetricsBeta(mb *metadata.MetricsBuilder, hpa *autoscalingv2beta2.HorizontalPodAutoscaler, ts pcommon.Timestamp) { - mb.RecordK8sHpaMaxReplicasDataPoint(ts, int64(hpa.Spec.MaxReplicas)) - mb.RecordK8sHpaMinReplicasDataPoint(ts, int64(*hpa.Spec.MinReplicas)) - mb.RecordK8sHpaCurrentReplicasDataPoint(ts, int64(hpa.Status.CurrentReplicas)) - mb.RecordK8sHpaDesiredReplicasDataPoint(ts, int64(hpa.Status.DesiredReplicas)) - rb := mb.NewResourceBuilder() - rb.SetK8sHpaUID(string(hpa.UID)) - rb.SetK8sHpaName(hpa.Name) - rb.SetK8sNamespaceName(hpa.Namespace) - mb.EmitForResource(metadata.WithResource(rb.Emit())) -} - func RecordMetrics(mb *metadata.MetricsBuilder, hpa *autoscalingv2.HorizontalPodAutoscaler, ts pcommon.Timestamp) { mb.RecordK8sHpaMaxReplicasDataPoint(ts, int64(hpa.Spec.MaxReplicas)) mb.RecordK8sHpaMinReplicasDataPoint(ts, int64(*hpa.Spec.MinReplicas)) @@ -41,9 +28,3 @@ func GetMetadata(hpa *autoscalingv2.HorizontalPodAutoscaler) map[experimentalmet experimentalmetricmetadata.ResourceID(hpa.UID): metadata.GetGenericMetadata(&hpa.ObjectMeta, "HPA"), } } - -func GetMetadataBeta(hpa *autoscalingv2beta2.HorizontalPodAutoscaler) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { - return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{ - experimentalmetricmetadata.ResourceID(hpa.UID): metadata.GetGenericMetadata(&hpa.ObjectMeta, "HPA"), - } -} diff --git a/receiver/k8sclusterreceiver/internal/testutils/objects.go b/receiver/k8sclusterreceiver/internal/testutils/objects.go index 97d72021e6a2..5432e2351e58 100644 --- a/receiver/k8sclusterreceiver/internal/testutils/objects.go +++ b/receiver/k8sclusterreceiver/internal/testutils/objects.go @@ -7,7 +7,6 @@ import ( quotav1 "github.com/openshift/api/quota/v1" appsv1 "k8s.io/api/apps/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -34,25 +33,6 @@ func NewHPA(id string) *autoscalingv2.HorizontalPodAutoscaler { } } -func NewHPABeta(id string) *autoscalingv2beta2.HorizontalPodAutoscaler { - minReplicas := int32(2) - return &autoscalingv2beta2.HorizontalPodAutoscaler{ - ObjectMeta: v1.ObjectMeta{ - Name: "test-hpa-" + id, - Namespace: "test-namespace", - UID: types.UID("test-hpa-" + id + "-uid"), - }, - Status: autoscalingv2beta2.HorizontalPodAutoscalerStatus{ - CurrentReplicas: 5, - DesiredReplicas: 7, - }, - Spec: autoscalingv2beta2.HorizontalPodAutoscalerSpec{ - MinReplicas: &minReplicas, - MaxReplicas: 10, - }, - } -} - func NewJob(id string) *batchv1.Job { p := int32(2) c := int32(10) diff --git a/receiver/k8sclusterreceiver/receiver_test.go b/receiver/k8sclusterreceiver/receiver_test.go index 86e6f2f76cb6..6b8fba583fb7 100644 --- a/receiver/k8sclusterreceiver/receiver_test.go +++ b/receiver/k8sclusterreceiver/receiver_test.go @@ -275,12 +275,6 @@ func newFakeClientWithAllResources() *fake.Clientset { gvkToAPIResource(gvk.HorizontalPodAutoscaler), }, }, - { - GroupVersion: "autoscaling/v2beta2", - APIResources: []v1.APIResource{ - gvkToAPIResource(gvk.HorizontalPodAutoscalerBeta), - }, - }, } return client } diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index 88bb262ced44..5cf39b07c584 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -20,9 +20,7 @@ import ( "go.uber.org/zap/zapcore" appsv1 "k8s.io/api/apps/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" batchv1 "k8s.io/api/batch/v1" - batchv1beta1 "k8s.io/api/batch/v1beta1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" @@ -127,25 +125,19 @@ func (rw *resourceWatcher) prepareSharedInformerFactory() error { // informer for that kind won't be set and a warning message is thrown. // This map should be kept in sync with what can be provided by the supported k8s server versions. supportedKinds := map[string][]schema.GroupVersionKind{ - "Pod": {gvk.Pod}, - "Node": {gvk.Node}, - "Namespace": {gvk.Namespace}, - "ReplicationController": {gvk.ReplicationController}, - "ResourceQuota": {gvk.ResourceQuota}, - "Service": {gvk.Service}, - "DaemonSet": {gvk.DaemonSet}, - "Deployment": {gvk.Deployment}, - "ReplicaSet": {gvk.ReplicaSet}, - "StatefulSet": {gvk.StatefulSet}, - "Job": {gvk.Job}, - } - - if !rw.config.IgnoreDeprecatedResources { - supportedKinds["CronJob"] = []schema.GroupVersionKind{gvk.CronJob, gvk.CronJobBeta} - supportedKinds["HorizontalPodAutoscaler"] = []schema.GroupVersionKind{gvk.HorizontalPodAutoscaler, gvk.HorizontalPodAutoscalerBeta} - } else { - supportedKinds["CronJob"] = []schema.GroupVersionKind{gvk.CronJob} - supportedKinds["HorizontalPodAutoscaler"] = []schema.GroupVersionKind{gvk.HorizontalPodAutoscaler} + "Pod": {gvk.Pod}, + "Node": {gvk.Node}, + "Namespace": {gvk.Namespace}, + "ReplicationController": {gvk.ReplicationController}, + "ResourceQuota": {gvk.ResourceQuota}, + "Service": {gvk.Service}, + "DaemonSet": {gvk.DaemonSet}, + "Deployment": {gvk.Deployment}, + "ReplicaSet": {gvk.ReplicaSet}, + "StatefulSet": {gvk.StatefulSet}, + "Job": {gvk.Job}, + "CronJob": {gvk.CronJob}, + "HorizontalPodAutoscaler": {gvk.HorizontalPodAutoscaler}, } for kind, gvks := range supportedKinds { @@ -220,12 +212,8 @@ func (rw *resourceWatcher) setupInformerForKind(kind schema.GroupVersionKind, fa rw.setupInformer(kind, factory.Batch().V1().Jobs().Informer()) case gvk.CronJob: rw.setupInformer(kind, factory.Batch().V1().CronJobs().Informer()) - case gvk.CronJobBeta: - rw.setupInformer(kind, factory.Batch().V1beta1().CronJobs().Informer()) case gvk.HorizontalPodAutoscaler: rw.setupInformer(kind, factory.Autoscaling().V2().HorizontalPodAutoscalers().Informer()) - case gvk.HorizontalPodAutoscalerBeta: - rw.setupInformer(kind, factory.Autoscaling().V2beta2().HorizontalPodAutoscalers().Informer()) default: rw.logger.Error("Could not setup an informer for provided group version kind", zap.String("group version kind", kind.String())) @@ -314,12 +302,8 @@ func (rw *resourceWatcher) objMetadata(obj interface{}) map[experimentalmetricme return jobs.GetMetadata(o) case *batchv1.CronJob: return cronjob.GetMetadata(o) - case *batchv1beta1.CronJob: - return cronjob.GetMetadataBeta(o) case *autoscalingv2.HorizontalPodAutoscaler: return hpa.GetMetadata(o) - case *autoscalingv2beta2.HorizontalPodAutoscaler: - return hpa.GetMetadataBeta(o) } return nil } diff --git a/receiver/k8sclusterreceiver/watcher_test.go b/receiver/k8sclusterreceiver/watcher_test.go index f4bbbb72e9dd..c6c7ee62988a 100644 --- a/receiver/k8sclusterreceiver/watcher_test.go +++ b/receiver/k8sclusterreceiver/watcher_test.go @@ -118,12 +118,6 @@ func TestIsKindSupported(t *testing.T) { gvk: gvk.Pod, expected: true, }, - { - name: "unsupported_kind", - client: fake.NewSimpleClientset(), - gvk: gvk.CronJobBeta, - expected: false, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -178,24 +172,12 @@ func TestPrepareSharedInformerFactory(t *testing.T) { gvkToAPIResource(gvk.Job), }, }, - { - GroupVersion: "batch/v1beta1", - APIResources: []metav1.APIResource{ - gvkToAPIResource(gvk.CronJobBeta), - }, - }, { GroupVersion: "autoscaling/v2", APIResources: []metav1.APIResource{ gvkToAPIResource(gvk.HorizontalPodAutoscaler), }, }, - { - GroupVersion: "autoscaling/v2beta2", - APIResources: []metav1.APIResource{ - gvkToAPIResource(gvk.HorizontalPodAutoscalerBeta), - }, - }, } return client }(), From 97e1d40dd73dd4294f66c6b98ea1ec599ef9dc11 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Sat, 9 Sep 2023 14:41:12 +0530 Subject: [PATCH 06/11] =?UTF-8?q?docs(k8sclusterreceiver):=20=F0=9F=93=9D?= =?UTF-8?q?=20update=20readme=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Prashant Shahi --- receiver/k8sclusterreceiver/README.md | 4 ---- receiver/k8sclusterreceiver/testdata/config.yaml | 1 - 2 files changed, 5 deletions(-) diff --git a/receiver/k8sclusterreceiver/README.md b/receiver/k8sclusterreceiver/README.md index 1bb79c3dd513..dfea42f5a03c 100644 --- a/receiver/k8sclusterreceiver/README.md +++ b/receiver/k8sclusterreceiver/README.md @@ -67,9 +67,6 @@ The following allocatable resource types are available. - storage - `metrics`: Allows to enable/disable metrics. - `resource_attributes`: Allows to enable/disable resource attributes. -- `ignore_deprecated_resources` (default = `false`): Whether to ignore deprecated Kubernetes API resources. If set to true, - the receiver will not collect metrics for deprecated resources. This setting is useful for clusters that have deprecated - resources that are not used anymore and are causing errors or warnings in the logs. Example: @@ -84,7 +81,6 @@ Example: resource_attributes: container.id: enabled: false - ignore_deprecated_resources: true ``` The full list of settings exposed for this receiver are documented [here](./config.go) diff --git a/receiver/k8sclusterreceiver/testdata/config.yaml b/receiver/k8sclusterreceiver/testdata/config.yaml index 1acd1da6c82d..b7d2737c4e79 100644 --- a/receiver/k8sclusterreceiver/testdata/config.yaml +++ b/receiver/k8sclusterreceiver/testdata/config.yaml @@ -5,7 +5,6 @@ k8s_cluster/all_settings: allocatable_types_to_report: [ "cpu","memory" ] metadata_exporters: [ nop ] metadata_collection_interval: 30m - ignore_deprecated_resources: false k8s_cluster/partial_settings: collection_interval: 30s distribution: openshift From a6622b2cf43cc3a4f9239be92ab8e72a2b8631e1 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Sat, 9 Sep 2023 14:41:22 +0530 Subject: [PATCH 07/11] =?UTF-8?q?docs(k8scluster):=20=F0=9F=93=9D=20update?= =?UTF-8?q?=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Prashant Shahi --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fceb02f926d..5094cb181f1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,7 +55,7 @@ If you are looking for developer-facing changes, check out [CHANGELOG-API.md](./ - `snmpreceiver`: Timeout for SNMP requests can now be configured. (#25885) - `telemetrygen`: The telemetrygen now supports setting the log's body (#26031) - `awsxrayexporter`: add `exporter.awsxray.skiptimestampvalidation` Alpha feature gate to remove xray timestamp restriction on first 32 bits of trace id (#26041) -- `k8sclusterreceiver`: Add `ignore_deprecated_resources` option to ignore deprecated Kubernetes API resources (#26516) +- `k8sclusterreceiver`: Remove deprecated Kubernetes API resources (#26516) ### 🧰 Bug fixes 🧰 From ee9e5d76b0710800f9b76e67aeafd86fca34cd63 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Mon, 11 Sep 2023 23:45:03 +0530 Subject: [PATCH 08/11] =?UTF-8?q?docs(k8scluster):=20=F0=9F=93=9D=20update?= =?UTF-8?q?=20changelog=20generator=20config=20instead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Prashant Shahi --- ...rreceiver-remove-deprecated-resources.yaml | 20 +++++++++++++++++++ CHANGELOG.md | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml diff --git a/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml b/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml new file mode 100644 index 000000000000..478826a5eda5 --- /dev/null +++ b/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml @@ -0,0 +1,20 @@ +# Use this changelog template to create an entry for release notes. +# If your change doesn't affect end users, such as a test fix or a tooling change, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'deprecation' + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: k8sclusterreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Remove deprecated Kubernetes API resources" + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [23612,26551] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/CHANGELOG.md b/CHANGELOG.md index 5094cb181f1b..48e91e2fc43e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,7 +55,6 @@ If you are looking for developer-facing changes, check out [CHANGELOG-API.md](./ - `snmpreceiver`: Timeout for SNMP requests can now be configured. (#25885) - `telemetrygen`: The telemetrygen now supports setting the log's body (#26031) - `awsxrayexporter`: add `exporter.awsxray.skiptimestampvalidation` Alpha feature gate to remove xray timestamp restriction on first 32 bits of trace id (#26041) -- `k8sclusterreceiver`: Remove deprecated Kubernetes API resources (#26516) ### 🧰 Bug fixes 🧰 From 7a9bea31ac9398ac22590fae2161cf61d5bee1f7 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Mon, 11 Sep 2023 23:48:25 +0530 Subject: [PATCH 09/11] =?UTF-8?q?docs(k8scluster):=20=F0=9F=93=9D=20update?= =?UTF-8?q?=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Prashant Shahi --- ...clusterreceiver-remove-deprecated-resources.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml b/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml index 478826a5eda5..1cd1126fb04c 100644 --- a/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml +++ b/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml @@ -1,9 +1,7 @@ # Use this changelog template to create an entry for release notes. -# If your change doesn't affect end users, such as a test fix or a tooling change, -# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' -change_type: 'deprecation' +change_type: "deprecation" # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) component: k8sclusterreceiver @@ -18,3 +16,12 @@ issues: [23612,26551] # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] From fb9a09153052cbab2db7de4860bcd7785eb854bf Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Tue, 12 Sep 2023 00:28:05 +0530 Subject: [PATCH 10/11] chore: update .chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml Co-authored-by: Dmitrii Anoshin --- .chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml b/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml index 1cd1126fb04c..78b25bde46bb 100644 --- a/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml +++ b/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml @@ -15,7 +15,9 @@ issues: [23612,26551] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. -subtext: +subtext: | + Drop support of HorizontalPodAutoscaler v2beta2 version and CronJob v1beta1 version. + Note that metrics for those resources will not be emitted anymore on Kubernetes 1.22 and older. # If your change doesn't affect end users or the exported elements of any package, # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. From b8e0fbb138daa1975beb3a04a01c3723703aead9 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Tue, 12 Sep 2023 00:28:14 +0530 Subject: [PATCH 11/11] chore: update .chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml Co-authored-by: Dmitrii Anoshin --- .chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml b/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml index 78b25bde46bb..3a3737ff36b1 100644 --- a/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml +++ b/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml @@ -1,7 +1,7 @@ # Use this changelog template to create an entry for release notes. # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' -change_type: "deprecation" +change_type: "breaking" # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) component: k8sclusterreceiver