diff --git a/receiver/k8sclusterreceiver/documentation.md b/receiver/k8sclusterreceiver/documentation.md index 7f93cbc2c5c4..1d5eac04254a 100644 --- a/receiver/k8sclusterreceiver/documentation.md +++ b/receiver/k8sclusterreceiver/documentation.md @@ -236,6 +236,22 @@ The capacity of persistent volume. | ---- | ----------- | ---------- | | By | Gauge | Int | +### k8s.persistentvolumeclaim.allocated + +The allocated capacity of persistent volume. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| By | Gauge | Int | + +### k8s.persistentvolumeclaim.capacity + +The capacity of persistent volume claim. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| By | Gauge | Int | + ### k8s.pod.phase Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) @@ -462,8 +478,20 @@ Current status reason of the pod (1 - Evicted, 2 - NodeAffinity, 3 - NodeLost, 4 | k8s.persistentvolume.type | The type of the Persistent Volume. | Any Str | true | | k8s.persistentvolume.uid | The UID of the Persistent Volume | Any Str | true | | k8s.persistentvolume.volume_mode | The volume mode of the Persistent Volume. | Any Str | true | +| k8s.persistentvolumeclaim.access_modes | Access modes of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.annotations | The annotations of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.finalizers | Finalizers of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.labels | Labels of the Persistent Volume Claim. | Any Str | true | | k8s.persistentvolumeclaim.name | The Name of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.namespace | The namespace of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.phase | The phase of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.selector | The selector of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.start_time | The start time of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.storage_class | The storage class of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.type | The type of the Persistent Volume Claim. | Any Str | true | | k8s.persistentvolumeclaim.uid | The UID of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.volume_mode | The volume mode of the Persistent Volume Claim. | Any Str | true | +| k8s.persistentvolumeclaim.volume_name | The volume name of the Persistent Volume Claim. | Any Str | true | | k8s.pod.name | The k8s pod name. | Any Str | true | | k8s.pod.start_time | The start time of the Pod. | Any Str | true | | k8s.pod.uid | The k8s pod uid. | Any Str | true | diff --git a/receiver/k8sclusterreceiver/internal/collection/collector.go b/receiver/k8sclusterreceiver/internal/collection/collector.go index d19ca86f82c1..00860a1cc155 100644 --- a/receiver/k8sclusterreceiver/internal/collection/collector.go +++ b/receiver/k8sclusterreceiver/internal/collection/collector.go @@ -30,6 +30,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/namespace" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/node" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/persistentvolume" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/persistentvolumeclaim" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/pod" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/replicaset" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/replicationcontroller" @@ -81,6 +82,9 @@ func (dc *DataCollector) CollectMetricData(currentTime time.Time) pmetric.Metric dc.metadataStore.ForEach(gvk.PersistentVolume, func(o any) { persistentvolume.RecordMetrics(dc.metricsBuilder, o.(*corev1.PersistentVolume), ts) }) + dc.metadataStore.ForEach(gvk.PersistentVolumeClaim, func(o any) { + persistentvolumeclaim.RecordMetrics(dc.metricsBuilder, o.(*corev1.PersistentVolumeClaim), ts) + }) dc.metadataStore.ForEach(gvk.Namespace, func(o any) { namespace.RecordMetrics(dc.metricsBuilder, o.(*corev1.Namespace), ts) }) diff --git a/receiver/k8sclusterreceiver/internal/gvk/gvk.go b/receiver/k8sclusterreceiver/internal/gvk/gvk.go index b6545eb5738a..9753596a12b0 100644 --- a/receiver/k8sclusterreceiver/internal/gvk/gvk.go +++ b/receiver/k8sclusterreceiver/internal/gvk/gvk.go @@ -10,6 +10,7 @@ var ( Pod = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"} Node = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"} PersistentVolume = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolume"} + PersistentVolumeClaim = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolumeClaim"} Namespace = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"} ReplicationController = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ReplicationController"} ResourceQuota = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ResourceQuota"} diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_config.go b/receiver/k8sclusterreceiver/internal/metadata/generated_config.go index edff613ca389..feb80ea7e7aa 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_config.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_config.go @@ -53,6 +53,8 @@ type MetricsConfig struct { K8sJobSuccessfulPods MetricConfig `mapstructure:"k8s.job.successful_pods"` K8sNamespacePhase MetricConfig `mapstructure:"k8s.namespace.phase"` K8sPersistentvolumeCapacity MetricConfig `mapstructure:"k8s.persistentvolume.capacity"` + K8sPersistentvolumeclaimAllocated MetricConfig `mapstructure:"k8s.persistentvolumeclaim.allocated"` + K8sPersistentvolumeclaimCapacity MetricConfig `mapstructure:"k8s.persistentvolumeclaim.capacity"` K8sPodPhase MetricConfig `mapstructure:"k8s.pod.phase"` K8sPodStatusReason MetricConfig `mapstructure:"k8s.pod.status_reason"` K8sReplicasetAvailable MetricConfig `mapstructure:"k8s.replicaset.available"` @@ -158,6 +160,12 @@ func DefaultMetricsConfig() MetricsConfig { K8sPersistentvolumeCapacity: MetricConfig{ Enabled: true, }, + K8sPersistentvolumeclaimAllocated: MetricConfig{ + Enabled: true, + }, + K8sPersistentvolumeclaimCapacity: MetricConfig{ + Enabled: true, + }, K8sPodPhase: MetricConfig{ Enabled: true, }, @@ -215,86 +223,84 @@ func DefaultMetricsConfig() MetricsConfig { // ResourceAttributeConfig provides common config for a particular resource attribute. type ResourceAttributeConfig struct { Enabled bool `mapstructure:"enabled"` - - enabledSetByUser bool -} - -func (rac *ResourceAttributeConfig) Unmarshal(parser *confmap.Conf) error { - if parser == nil { - return nil - } - err := parser.Unmarshal(rac, confmap.WithErrorUnused()) - if err != nil { - return err - } - rac.enabledSetByUser = parser.IsSet("enabled") - return nil } // ResourceAttributesConfig provides config for k8s_cluster resource attributes. type ResourceAttributesConfig struct { - ContainerID ResourceAttributeConfig `mapstructure:"container.id"` - ContainerImageName ResourceAttributeConfig `mapstructure:"container.image.name"` - ContainerImageTag ResourceAttributeConfig `mapstructure:"container.image.tag"` - K8sClusterName ResourceAttributeConfig `mapstructure:"k8s.cluster.name"` - K8sContainerName ResourceAttributeConfig `mapstructure:"k8s.container.name"` - K8sCronjobName ResourceAttributeConfig `mapstructure:"k8s.cronjob.name"` - K8sCronjobStartTime ResourceAttributeConfig `mapstructure:"k8s.cronjob.start_time"` - K8sCronjobUID ResourceAttributeConfig `mapstructure:"k8s.cronjob.uid"` - K8sDaemonsetName ResourceAttributeConfig `mapstructure:"k8s.daemonset.name"` - K8sDaemonsetStartTime ResourceAttributeConfig `mapstructure:"k8s.daemonset.start_time"` - K8sDaemonsetUID ResourceAttributeConfig `mapstructure:"k8s.daemonset.uid"` - K8sDeploymentName ResourceAttributeConfig `mapstructure:"k8s.deployment.name"` - K8sDeploymentStartTime ResourceAttributeConfig `mapstructure:"k8s.deployment.start_time"` - K8sDeploymentUID ResourceAttributeConfig `mapstructure:"k8s.deployment.uid"` - K8sHpaName ResourceAttributeConfig `mapstructure:"k8s.hpa.name"` - K8sHpaUID ResourceAttributeConfig `mapstructure:"k8s.hpa.uid"` - K8sJobName ResourceAttributeConfig `mapstructure:"k8s.job.name"` - K8sJobStartTime ResourceAttributeConfig `mapstructure:"k8s.job.start_time"` - K8sJobUID ResourceAttributeConfig `mapstructure:"k8s.job.uid"` - K8sNamespaceName ResourceAttributeConfig `mapstructure:"k8s.namespace.name"` - K8sNamespaceStartTime ResourceAttributeConfig `mapstructure:"k8s.namespace.start_time"` - K8sNamespaceUID ResourceAttributeConfig `mapstructure:"k8s.namespace.uid"` - K8sNodeName ResourceAttributeConfig `mapstructure:"k8s.node.name"` - K8sNodeStartTime ResourceAttributeConfig `mapstructure:"k8s.node.start_time"` - K8sNodeUID ResourceAttributeConfig `mapstructure:"k8s.node.uid"` - K8sPersistentvolumeAccessModes ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.access_modes"` - K8sPersistentvolumeAnnotations ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.annotations"` - K8sPersistentvolumeFinalizers ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.finalizers"` - K8sPersistentvolumeLabels ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.labels"` - K8sPersistentvolumeName ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.name"` - K8sPersistentvolumeNamespace ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.namespace"` - K8sPersistentvolumePhase ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.phase"` - K8sPersistentvolumeReclaimPolicy ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.reclaim_policy"` - K8sPersistentvolumeStartTime ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.start_time"` - K8sPersistentvolumeStorageClass ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.storage_class"` - K8sPersistentvolumeType ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.type"` - K8sPersistentvolumeUID ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.uid"` - K8sPersistentvolumeVolumeMode ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.volume_mode"` - K8sPersistentvolumeclaimName ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.name"` - K8sPersistentvolumeclaimUID ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.uid"` - K8sPodName ResourceAttributeConfig `mapstructure:"k8s.pod.name"` - K8sPodStartTime ResourceAttributeConfig `mapstructure:"k8s.pod.start_time"` - K8sPodUID ResourceAttributeConfig `mapstructure:"k8s.pod.uid"` - K8sReplicasetName ResourceAttributeConfig `mapstructure:"k8s.replicaset.name"` - K8sReplicasetStartTime ResourceAttributeConfig `mapstructure:"k8s.replicaset.start_time"` - K8sReplicasetUID ResourceAttributeConfig `mapstructure:"k8s.replicaset.uid"` - K8sReplicationcontrollerName ResourceAttributeConfig `mapstructure:"k8s.replicationcontroller.name"` - K8sReplicationcontrollerUID ResourceAttributeConfig `mapstructure:"k8s.replicationcontroller.uid"` - K8sResourcequotaName ResourceAttributeConfig `mapstructure:"k8s.resourcequota.name"` - K8sResourcequotaUID ResourceAttributeConfig `mapstructure:"k8s.resourcequota.uid"` - K8sServiceClusterIP ResourceAttributeConfig `mapstructure:"k8s.service.cluster_ip"` - K8sServiceName ResourceAttributeConfig `mapstructure:"k8s.service.name"` - K8sServiceNamespace ResourceAttributeConfig `mapstructure:"k8s.service.namespace"` - K8sServiceType ResourceAttributeConfig `mapstructure:"k8s.service.type"` - K8sServiceUID ResourceAttributeConfig `mapstructure:"k8s.service.uid"` - K8sServiceAccountName ResourceAttributeConfig `mapstructure:"k8s.service_account.name"` - K8sStatefulsetName ResourceAttributeConfig `mapstructure:"k8s.statefulset.name"` - K8sStatefulsetStartTime ResourceAttributeConfig `mapstructure:"k8s.statefulset.start_time"` - K8sStatefulsetUID ResourceAttributeConfig `mapstructure:"k8s.statefulset.uid"` - OpencensusResourcetype ResourceAttributeConfig `mapstructure:"opencensus.resourcetype"` - OpenshiftClusterquotaName ResourceAttributeConfig `mapstructure:"openshift.clusterquota.name"` - OpenshiftClusterquotaUID ResourceAttributeConfig `mapstructure:"openshift.clusterquota.uid"` + ContainerID ResourceAttributeConfig `mapstructure:"container.id"` + ContainerImageName ResourceAttributeConfig `mapstructure:"container.image.name"` + ContainerImageTag ResourceAttributeConfig `mapstructure:"container.image.tag"` + K8sClusterName ResourceAttributeConfig `mapstructure:"k8s.cluster.name"` + K8sContainerName ResourceAttributeConfig `mapstructure:"k8s.container.name"` + K8sCronjobName ResourceAttributeConfig `mapstructure:"k8s.cronjob.name"` + K8sCronjobStartTime ResourceAttributeConfig `mapstructure:"k8s.cronjob.start_time"` + K8sCronjobUID ResourceAttributeConfig `mapstructure:"k8s.cronjob.uid"` + K8sDaemonsetName ResourceAttributeConfig `mapstructure:"k8s.daemonset.name"` + K8sDaemonsetStartTime ResourceAttributeConfig `mapstructure:"k8s.daemonset.start_time"` + K8sDaemonsetUID ResourceAttributeConfig `mapstructure:"k8s.daemonset.uid"` + K8sDeploymentName ResourceAttributeConfig `mapstructure:"k8s.deployment.name"` + K8sDeploymentStartTime ResourceAttributeConfig `mapstructure:"k8s.deployment.start_time"` + K8sDeploymentUID ResourceAttributeConfig `mapstructure:"k8s.deployment.uid"` + K8sHpaName ResourceAttributeConfig `mapstructure:"k8s.hpa.name"` + K8sHpaUID ResourceAttributeConfig `mapstructure:"k8s.hpa.uid"` + K8sJobName ResourceAttributeConfig `mapstructure:"k8s.job.name"` + K8sJobStartTime ResourceAttributeConfig `mapstructure:"k8s.job.start_time"` + K8sJobUID ResourceAttributeConfig `mapstructure:"k8s.job.uid"` + K8sNamespaceName ResourceAttributeConfig `mapstructure:"k8s.namespace.name"` + K8sNamespaceStartTime ResourceAttributeConfig `mapstructure:"k8s.namespace.start_time"` + K8sNamespaceUID ResourceAttributeConfig `mapstructure:"k8s.namespace.uid"` + K8sNodeName ResourceAttributeConfig `mapstructure:"k8s.node.name"` + K8sNodeStartTime ResourceAttributeConfig `mapstructure:"k8s.node.start_time"` + K8sNodeUID ResourceAttributeConfig `mapstructure:"k8s.node.uid"` + K8sPersistentvolumeAccessModes ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.access_modes"` + K8sPersistentvolumeAnnotations ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.annotations"` + K8sPersistentvolumeFinalizers ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.finalizers"` + K8sPersistentvolumeLabels ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.labels"` + K8sPersistentvolumeName ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.name"` + K8sPersistentvolumeNamespace ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.namespace"` + K8sPersistentvolumePhase ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.phase"` + K8sPersistentvolumeReclaimPolicy ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.reclaim_policy"` + K8sPersistentvolumeStartTime ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.start_time"` + K8sPersistentvolumeStorageClass ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.storage_class"` + K8sPersistentvolumeType ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.type"` + K8sPersistentvolumeUID ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.uid"` + K8sPersistentvolumeVolumeMode ResourceAttributeConfig `mapstructure:"k8s.persistentvolume.volume_mode"` + K8sPersistentvolumeclaimAccessModes ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.access_modes"` + K8sPersistentvolumeclaimAnnotations ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.annotations"` + K8sPersistentvolumeclaimFinalizers ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.finalizers"` + K8sPersistentvolumeclaimLabels ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.labels"` + K8sPersistentvolumeclaimName ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.name"` + K8sPersistentvolumeclaimNamespace ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.namespace"` + K8sPersistentvolumeclaimPhase ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.phase"` + K8sPersistentvolumeclaimSelector ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.selector"` + K8sPersistentvolumeclaimStartTime ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.start_time"` + K8sPersistentvolumeclaimStorageClass ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.storage_class"` + K8sPersistentvolumeclaimType ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.type"` + K8sPersistentvolumeclaimUID ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.uid"` + K8sPersistentvolumeclaimVolumeMode ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.volume_mode"` + K8sPersistentvolumeclaimVolumeName ResourceAttributeConfig `mapstructure:"k8s.persistentvolumeclaim.volume_name"` + K8sPodName ResourceAttributeConfig `mapstructure:"k8s.pod.name"` + K8sPodStartTime ResourceAttributeConfig `mapstructure:"k8s.pod.start_time"` + K8sPodUID ResourceAttributeConfig `mapstructure:"k8s.pod.uid"` + K8sReplicasetName ResourceAttributeConfig `mapstructure:"k8s.replicaset.name"` + K8sReplicasetStartTime ResourceAttributeConfig `mapstructure:"k8s.replicaset.start_time"` + K8sReplicasetUID ResourceAttributeConfig `mapstructure:"k8s.replicaset.uid"` + K8sReplicationcontrollerName ResourceAttributeConfig `mapstructure:"k8s.replicationcontroller.name"` + K8sReplicationcontrollerUID ResourceAttributeConfig `mapstructure:"k8s.replicationcontroller.uid"` + K8sResourcequotaName ResourceAttributeConfig `mapstructure:"k8s.resourcequota.name"` + K8sResourcequotaUID ResourceAttributeConfig `mapstructure:"k8s.resourcequota.uid"` + K8sServiceClusterIP ResourceAttributeConfig `mapstructure:"k8s.service.cluster_ip"` + K8sServiceName ResourceAttributeConfig `mapstructure:"k8s.service.name"` + K8sServiceNamespace ResourceAttributeConfig `mapstructure:"k8s.service.namespace"` + K8sServiceType ResourceAttributeConfig `mapstructure:"k8s.service.type"` + K8sServiceUID ResourceAttributeConfig `mapstructure:"k8s.service.uid"` + K8sServiceAccountName ResourceAttributeConfig `mapstructure:"k8s.service_account.name"` + K8sStatefulsetName ResourceAttributeConfig `mapstructure:"k8s.statefulset.name"` + K8sStatefulsetStartTime ResourceAttributeConfig `mapstructure:"k8s.statefulset.start_time"` + K8sStatefulsetUID ResourceAttributeConfig `mapstructure:"k8s.statefulset.uid"` + OpencensusResourcetype ResourceAttributeConfig `mapstructure:"opencensus.resourcetype"` + OpenshiftClusterquotaName ResourceAttributeConfig `mapstructure:"openshift.clusterquota.name"` + OpenshiftClusterquotaUID ResourceAttributeConfig `mapstructure:"openshift.clusterquota.uid"` } func DefaultResourceAttributesConfig() ResourceAttributesConfig { @@ -413,12 +419,48 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { K8sPersistentvolumeVolumeMode: ResourceAttributeConfig{ Enabled: true, }, + K8sPersistentvolumeclaimAccessModes: ResourceAttributeConfig{ + Enabled: true, + }, + K8sPersistentvolumeclaimAnnotations: ResourceAttributeConfig{ + Enabled: true, + }, + K8sPersistentvolumeclaimFinalizers: ResourceAttributeConfig{ + Enabled: true, + }, + K8sPersistentvolumeclaimLabels: ResourceAttributeConfig{ + Enabled: true, + }, K8sPersistentvolumeclaimName: ResourceAttributeConfig{ Enabled: true, }, + K8sPersistentvolumeclaimNamespace: ResourceAttributeConfig{ + Enabled: true, + }, + K8sPersistentvolumeclaimPhase: ResourceAttributeConfig{ + Enabled: true, + }, + K8sPersistentvolumeclaimSelector: ResourceAttributeConfig{ + Enabled: true, + }, + K8sPersistentvolumeclaimStartTime: ResourceAttributeConfig{ + Enabled: true, + }, + K8sPersistentvolumeclaimStorageClass: ResourceAttributeConfig{ + Enabled: true, + }, + K8sPersistentvolumeclaimType: ResourceAttributeConfig{ + Enabled: true, + }, K8sPersistentvolumeclaimUID: ResourceAttributeConfig{ Enabled: true, }, + K8sPersistentvolumeclaimVolumeMode: ResourceAttributeConfig{ + Enabled: true, + }, + K8sPersistentvolumeclaimVolumeName: ResourceAttributeConfig{ + Enabled: true, + }, K8sPodName: ResourceAttributeConfig{ Enabled: true, }, diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go b/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go index 479cfd894730..36259d96c319 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go @@ -54,6 +54,8 @@ func TestMetricsBuilderConfig(t *testing.T) { K8sJobSuccessfulPods: MetricConfig{Enabled: true}, K8sNamespacePhase: MetricConfig{Enabled: true}, K8sPersistentvolumeCapacity: MetricConfig{Enabled: true}, + K8sPersistentvolumeclaimAllocated: MetricConfig{Enabled: true}, + K8sPersistentvolumeclaimCapacity: MetricConfig{Enabled: true}, K8sPodPhase: MetricConfig{Enabled: true}, K8sPodStatusReason: MetricConfig{Enabled: true}, K8sReplicasetAvailable: MetricConfig{Enabled: true}, @@ -73,68 +75,80 @@ func TestMetricsBuilderConfig(t *testing.T) { OpenshiftClusterquotaUsed: MetricConfig{Enabled: true}, }, ResourceAttributes: ResourceAttributesConfig{ - ContainerID: ResourceAttributeConfig{Enabled: true}, - ContainerImageName: ResourceAttributeConfig{Enabled: true}, - ContainerImageTag: ResourceAttributeConfig{Enabled: true}, - K8sClusterName: ResourceAttributeConfig{Enabled: true}, - K8sContainerName: ResourceAttributeConfig{Enabled: true}, - K8sCronjobName: ResourceAttributeConfig{Enabled: true}, - K8sCronjobStartTime: ResourceAttributeConfig{Enabled: true}, - K8sCronjobUID: ResourceAttributeConfig{Enabled: true}, - K8sDaemonsetName: ResourceAttributeConfig{Enabled: true}, - K8sDaemonsetStartTime: ResourceAttributeConfig{Enabled: true}, - K8sDaemonsetUID: ResourceAttributeConfig{Enabled: true}, - K8sDeploymentName: ResourceAttributeConfig{Enabled: true}, - K8sDeploymentStartTime: ResourceAttributeConfig{Enabled: true}, - K8sDeploymentUID: ResourceAttributeConfig{Enabled: true}, - K8sHpaName: ResourceAttributeConfig{Enabled: true}, - K8sHpaUID: ResourceAttributeConfig{Enabled: true}, - K8sJobName: ResourceAttributeConfig{Enabled: true}, - K8sJobStartTime: ResourceAttributeConfig{Enabled: true}, - K8sJobUID: ResourceAttributeConfig{Enabled: true}, - K8sNamespaceName: ResourceAttributeConfig{Enabled: true}, - K8sNamespaceStartTime: ResourceAttributeConfig{Enabled: true}, - K8sNamespaceUID: ResourceAttributeConfig{Enabled: true}, - K8sNodeName: ResourceAttributeConfig{Enabled: true}, - K8sNodeStartTime: ResourceAttributeConfig{Enabled: true}, - K8sNodeUID: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeAccessModes: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeAnnotations: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeFinalizers: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeLabels: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeName: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeNamespace: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumePhase: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeReclaimPolicy: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeStartTime: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeStorageClass: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeType: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeUID: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeVolumeMode: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeclaimUID: ResourceAttributeConfig{Enabled: true}, - K8sPodName: ResourceAttributeConfig{Enabled: true}, - K8sPodStartTime: ResourceAttributeConfig{Enabled: true}, - K8sPodUID: ResourceAttributeConfig{Enabled: true}, - K8sReplicasetName: ResourceAttributeConfig{Enabled: true}, - K8sReplicasetStartTime: ResourceAttributeConfig{Enabled: true}, - K8sReplicasetUID: ResourceAttributeConfig{Enabled: true}, - K8sReplicationcontrollerName: ResourceAttributeConfig{Enabled: true}, - K8sReplicationcontrollerUID: ResourceAttributeConfig{Enabled: true}, - K8sResourcequotaName: ResourceAttributeConfig{Enabled: true}, - K8sResourcequotaUID: ResourceAttributeConfig{Enabled: true}, - K8sServiceClusterIP: ResourceAttributeConfig{Enabled: true}, - K8sServiceName: ResourceAttributeConfig{Enabled: true}, - K8sServiceNamespace: ResourceAttributeConfig{Enabled: true}, - K8sServiceType: ResourceAttributeConfig{Enabled: true}, - K8sServiceUID: ResourceAttributeConfig{Enabled: true}, - K8sServiceAccountName: ResourceAttributeConfig{Enabled: true}, - K8sStatefulsetName: ResourceAttributeConfig{Enabled: true}, - K8sStatefulsetStartTime: ResourceAttributeConfig{Enabled: true}, - K8sStatefulsetUID: ResourceAttributeConfig{Enabled: true}, - OpencensusResourcetype: ResourceAttributeConfig{Enabled: true}, - OpenshiftClusterquotaName: ResourceAttributeConfig{Enabled: true}, - OpenshiftClusterquotaUID: ResourceAttributeConfig{Enabled: true}, + ContainerID: ResourceAttributeConfig{Enabled: true}, + ContainerImageName: ResourceAttributeConfig{Enabled: true}, + ContainerImageTag: ResourceAttributeConfig{Enabled: true}, + K8sClusterName: ResourceAttributeConfig{Enabled: true}, + K8sContainerName: ResourceAttributeConfig{Enabled: true}, + K8sCronjobName: ResourceAttributeConfig{Enabled: true}, + K8sCronjobStartTime: ResourceAttributeConfig{Enabled: true}, + K8sCronjobUID: ResourceAttributeConfig{Enabled: true}, + K8sDaemonsetName: ResourceAttributeConfig{Enabled: true}, + K8sDaemonsetStartTime: ResourceAttributeConfig{Enabled: true}, + K8sDaemonsetUID: ResourceAttributeConfig{Enabled: true}, + K8sDeploymentName: ResourceAttributeConfig{Enabled: true}, + K8sDeploymentStartTime: ResourceAttributeConfig{Enabled: true}, + K8sDeploymentUID: ResourceAttributeConfig{Enabled: true}, + K8sHpaName: ResourceAttributeConfig{Enabled: true}, + K8sHpaUID: ResourceAttributeConfig{Enabled: true}, + K8sJobName: ResourceAttributeConfig{Enabled: true}, + K8sJobStartTime: ResourceAttributeConfig{Enabled: true}, + K8sJobUID: ResourceAttributeConfig{Enabled: true}, + K8sNamespaceName: ResourceAttributeConfig{Enabled: true}, + K8sNamespaceStartTime: ResourceAttributeConfig{Enabled: true}, + K8sNamespaceUID: ResourceAttributeConfig{Enabled: true}, + K8sNodeName: ResourceAttributeConfig{Enabled: true}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: true}, + K8sNodeUID: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeAccessModes: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeFinalizers: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeLabels: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeName: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeNamespace: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumePhase: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeReclaimPolicy: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeStartTime: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeStorageClass: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeType: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeUID: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeVolumeMode: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimAccessModes: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimFinalizers: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimLabels: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimNamespace: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimPhase: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimSelector: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimStartTime: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimStorageClass: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimType: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimUID: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimVolumeMode: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimVolumeName: ResourceAttributeConfig{Enabled: true}, + K8sPodName: ResourceAttributeConfig{Enabled: true}, + K8sPodStartTime: ResourceAttributeConfig{Enabled: true}, + K8sPodUID: ResourceAttributeConfig{Enabled: true}, + K8sReplicasetName: ResourceAttributeConfig{Enabled: true}, + K8sReplicasetStartTime: ResourceAttributeConfig{Enabled: true}, + K8sReplicasetUID: ResourceAttributeConfig{Enabled: true}, + K8sReplicationcontrollerName: ResourceAttributeConfig{Enabled: true}, + K8sReplicationcontrollerUID: ResourceAttributeConfig{Enabled: true}, + K8sResourcequotaName: ResourceAttributeConfig{Enabled: true}, + K8sResourcequotaUID: ResourceAttributeConfig{Enabled: true}, + K8sServiceClusterIP: ResourceAttributeConfig{Enabled: true}, + K8sServiceName: ResourceAttributeConfig{Enabled: true}, + K8sServiceNamespace: ResourceAttributeConfig{Enabled: true}, + K8sServiceType: ResourceAttributeConfig{Enabled: true}, + K8sServiceUID: ResourceAttributeConfig{Enabled: true}, + K8sServiceAccountName: ResourceAttributeConfig{Enabled: true}, + K8sStatefulsetName: ResourceAttributeConfig{Enabled: true}, + K8sStatefulsetStartTime: ResourceAttributeConfig{Enabled: true}, + K8sStatefulsetUID: ResourceAttributeConfig{Enabled: true}, + OpencensusResourcetype: ResourceAttributeConfig{Enabled: true}, + OpenshiftClusterquotaName: ResourceAttributeConfig{Enabled: true}, + OpenshiftClusterquotaUID: ResourceAttributeConfig{Enabled: true}, }, }, }, @@ -170,6 +184,8 @@ func TestMetricsBuilderConfig(t *testing.T) { K8sJobSuccessfulPods: MetricConfig{Enabled: false}, K8sNamespacePhase: MetricConfig{Enabled: false}, K8sPersistentvolumeCapacity: MetricConfig{Enabled: false}, + K8sPersistentvolumeclaimAllocated: MetricConfig{Enabled: false}, + K8sPersistentvolumeclaimCapacity: MetricConfig{Enabled: false}, K8sPodPhase: MetricConfig{Enabled: false}, K8sPodStatusReason: MetricConfig{Enabled: false}, K8sReplicasetAvailable: MetricConfig{Enabled: false}, @@ -189,68 +205,80 @@ func TestMetricsBuilderConfig(t *testing.T) { OpenshiftClusterquotaUsed: MetricConfig{Enabled: false}, }, ResourceAttributes: ResourceAttributesConfig{ - ContainerID: ResourceAttributeConfig{Enabled: false}, - ContainerImageName: ResourceAttributeConfig{Enabled: false}, - ContainerImageTag: ResourceAttributeConfig{Enabled: false}, - K8sClusterName: ResourceAttributeConfig{Enabled: false}, - K8sContainerName: ResourceAttributeConfig{Enabled: false}, - K8sCronjobName: ResourceAttributeConfig{Enabled: false}, - K8sCronjobStartTime: ResourceAttributeConfig{Enabled: false}, - K8sCronjobUID: ResourceAttributeConfig{Enabled: false}, - K8sDaemonsetName: ResourceAttributeConfig{Enabled: false}, - K8sDaemonsetStartTime: ResourceAttributeConfig{Enabled: false}, - K8sDaemonsetUID: ResourceAttributeConfig{Enabled: false}, - K8sDeploymentName: ResourceAttributeConfig{Enabled: false}, - K8sDeploymentStartTime: ResourceAttributeConfig{Enabled: false}, - K8sDeploymentUID: ResourceAttributeConfig{Enabled: false}, - K8sHpaName: ResourceAttributeConfig{Enabled: false}, - K8sHpaUID: ResourceAttributeConfig{Enabled: false}, - K8sJobName: ResourceAttributeConfig{Enabled: false}, - K8sJobStartTime: ResourceAttributeConfig{Enabled: false}, - K8sJobUID: ResourceAttributeConfig{Enabled: false}, - K8sNamespaceName: ResourceAttributeConfig{Enabled: false}, - K8sNamespaceStartTime: ResourceAttributeConfig{Enabled: false}, - K8sNamespaceUID: ResourceAttributeConfig{Enabled: false}, - K8sNodeName: ResourceAttributeConfig{Enabled: false}, - K8sNodeStartTime: ResourceAttributeConfig{Enabled: false}, - K8sNodeUID: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeAccessModes: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeAnnotations: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeFinalizers: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeLabels: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeName: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeNamespace: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumePhase: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeReclaimPolicy: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeStartTime: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeStorageClass: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeType: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeUID: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeVolumeMode: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: false}, - K8sPersistentvolumeclaimUID: ResourceAttributeConfig{Enabled: false}, - K8sPodName: ResourceAttributeConfig{Enabled: false}, - K8sPodStartTime: ResourceAttributeConfig{Enabled: false}, - K8sPodUID: ResourceAttributeConfig{Enabled: false}, - K8sReplicasetName: ResourceAttributeConfig{Enabled: false}, - K8sReplicasetStartTime: ResourceAttributeConfig{Enabled: false}, - K8sReplicasetUID: ResourceAttributeConfig{Enabled: false}, - K8sReplicationcontrollerName: ResourceAttributeConfig{Enabled: false}, - K8sReplicationcontrollerUID: ResourceAttributeConfig{Enabled: false}, - K8sResourcequotaName: ResourceAttributeConfig{Enabled: false}, - K8sResourcequotaUID: ResourceAttributeConfig{Enabled: false}, - K8sServiceClusterIP: ResourceAttributeConfig{Enabled: false}, - K8sServiceName: ResourceAttributeConfig{Enabled: false}, - K8sServiceNamespace: ResourceAttributeConfig{Enabled: false}, - K8sServiceType: ResourceAttributeConfig{Enabled: false}, - K8sServiceUID: ResourceAttributeConfig{Enabled: false}, - K8sServiceAccountName: ResourceAttributeConfig{Enabled: false}, - K8sStatefulsetName: ResourceAttributeConfig{Enabled: false}, - K8sStatefulsetStartTime: ResourceAttributeConfig{Enabled: false}, - K8sStatefulsetUID: ResourceAttributeConfig{Enabled: false}, - OpencensusResourcetype: ResourceAttributeConfig{Enabled: false}, - OpenshiftClusterquotaName: ResourceAttributeConfig{Enabled: false}, - OpenshiftClusterquotaUID: ResourceAttributeConfig{Enabled: false}, + ContainerID: ResourceAttributeConfig{Enabled: false}, + ContainerImageName: ResourceAttributeConfig{Enabled: false}, + ContainerImageTag: ResourceAttributeConfig{Enabled: false}, + K8sClusterName: ResourceAttributeConfig{Enabled: false}, + K8sContainerName: ResourceAttributeConfig{Enabled: false}, + K8sCronjobName: ResourceAttributeConfig{Enabled: false}, + K8sCronjobStartTime: ResourceAttributeConfig{Enabled: false}, + K8sCronjobUID: ResourceAttributeConfig{Enabled: false}, + K8sDaemonsetName: ResourceAttributeConfig{Enabled: false}, + K8sDaemonsetStartTime: ResourceAttributeConfig{Enabled: false}, + K8sDaemonsetUID: ResourceAttributeConfig{Enabled: false}, + K8sDeploymentName: ResourceAttributeConfig{Enabled: false}, + K8sDeploymentStartTime: ResourceAttributeConfig{Enabled: false}, + K8sDeploymentUID: ResourceAttributeConfig{Enabled: false}, + K8sHpaName: ResourceAttributeConfig{Enabled: false}, + K8sHpaUID: ResourceAttributeConfig{Enabled: false}, + K8sJobName: ResourceAttributeConfig{Enabled: false}, + K8sJobStartTime: ResourceAttributeConfig{Enabled: false}, + K8sJobUID: ResourceAttributeConfig{Enabled: false}, + K8sNamespaceName: ResourceAttributeConfig{Enabled: false}, + K8sNamespaceStartTime: ResourceAttributeConfig{Enabled: false}, + K8sNamespaceUID: ResourceAttributeConfig{Enabled: false}, + K8sNodeName: ResourceAttributeConfig{Enabled: false}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: false}, + K8sNodeUID: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeAccessModes: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeFinalizers: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeLabels: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeName: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeNamespace: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumePhase: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeReclaimPolicy: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeStartTime: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeStorageClass: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeType: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeUID: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeVolumeMode: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimAccessModes: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimFinalizers: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimLabels: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimNamespace: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimPhase: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimSelector: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimStartTime: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimStorageClass: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimType: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimUID: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimVolumeMode: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimVolumeName: ResourceAttributeConfig{Enabled: false}, + K8sPodName: ResourceAttributeConfig{Enabled: false}, + K8sPodStartTime: ResourceAttributeConfig{Enabled: false}, + K8sPodUID: ResourceAttributeConfig{Enabled: false}, + K8sReplicasetName: ResourceAttributeConfig{Enabled: false}, + K8sReplicasetStartTime: ResourceAttributeConfig{Enabled: false}, + K8sReplicasetUID: ResourceAttributeConfig{Enabled: false}, + K8sReplicationcontrollerName: ResourceAttributeConfig{Enabled: false}, + K8sReplicationcontrollerUID: ResourceAttributeConfig{Enabled: false}, + K8sResourcequotaName: ResourceAttributeConfig{Enabled: false}, + K8sResourcequotaUID: ResourceAttributeConfig{Enabled: false}, + K8sServiceClusterIP: ResourceAttributeConfig{Enabled: false}, + K8sServiceName: ResourceAttributeConfig{Enabled: false}, + K8sServiceNamespace: ResourceAttributeConfig{Enabled: false}, + K8sServiceType: ResourceAttributeConfig{Enabled: false}, + K8sServiceUID: ResourceAttributeConfig{Enabled: false}, + K8sServiceAccountName: ResourceAttributeConfig{Enabled: false}, + K8sStatefulsetName: ResourceAttributeConfig{Enabled: false}, + K8sStatefulsetStartTime: ResourceAttributeConfig{Enabled: false}, + K8sStatefulsetUID: ResourceAttributeConfig{Enabled: false}, + OpencensusResourcetype: ResourceAttributeConfig{Enabled: false}, + OpenshiftClusterquotaName: ResourceAttributeConfig{Enabled: false}, + OpenshiftClusterquotaUID: ResourceAttributeConfig{Enabled: false}, }, }, }, @@ -287,120 +315,159 @@ func TestResourceAttributesConfig(t *testing.T) { { name: "all_set", want: ResourceAttributesConfig{ - ContainerID: ResourceAttributeConfig{Enabled: true}, - ContainerImageName: ResourceAttributeConfig{Enabled: true}, - ContainerImageTag: ResourceAttributeConfig{Enabled: true}, - K8sClusterName: ResourceAttributeConfig{Enabled: true}, - K8sContainerName: ResourceAttributeConfig{Enabled: true}, - K8sCronjobName: ResourceAttributeConfig{Enabled: true}, - K8sCronjobStartTime: ResourceAttributeConfig{Enabled: true}, - K8sCronjobUID: ResourceAttributeConfig{Enabled: true}, - K8sDaemonsetName: ResourceAttributeConfig{Enabled: true}, - K8sDaemonsetStartTime: ResourceAttributeConfig{Enabled: true}, - K8sDaemonsetUID: ResourceAttributeConfig{Enabled: true}, - K8sDeploymentName: ResourceAttributeConfig{Enabled: true}, - K8sDeploymentStartTime: ResourceAttributeConfig{Enabled: true}, - K8sDeploymentUID: ResourceAttributeConfig{Enabled: true}, - K8sHpaName: ResourceAttributeConfig{Enabled: true}, - K8sHpaUID: ResourceAttributeConfig{Enabled: true}, - K8sJobName: ResourceAttributeConfig{Enabled: true}, - K8sJobStartTime: ResourceAttributeConfig{Enabled: true}, - K8sJobUID: ResourceAttributeConfig{Enabled: true}, - K8sNamespaceName: ResourceAttributeConfig{Enabled: true}, - K8sNamespaceStartTime: ResourceAttributeConfig{Enabled: true}, - K8sNamespaceUID: ResourceAttributeConfig{Enabled: true}, - K8sNodeName: ResourceAttributeConfig{Enabled: true}, - K8sNodeStartTime: ResourceAttributeConfig{Enabled: true}, - K8sNodeUID: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeAccessModes: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeAnnotations: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeFinalizers: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeLabels: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeName: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeNamespace: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumePhase: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeReclaimPolicy: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeStartTime: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeStorageClass: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeType: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeUID: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeVolumeMode: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: true}, - K8sPersistentvolumeclaimUID: ResourceAttributeConfig{Enabled: true}, - K8sPodName: ResourceAttributeConfig{Enabled: true}, - K8sPodStartTime: ResourceAttributeConfig{Enabled: true}, - K8sPodUID: ResourceAttributeConfig{Enabled: true}, - K8sReplicasetName: ResourceAttributeConfig{Enabled: true}, - K8sReplicasetStartTime: ResourceAttributeConfig{Enabled: true}, - K8sReplicasetUID: ResourceAttributeConfig{Enabled: true}, - K8sReplicationcontrollerName: ResourceAttributeConfig{Enabled: true}, - K8sReplicationcontrollerUID: ResourceAttributeConfig{Enabled: true}, - K8sResourcequotaName: ResourceAttributeConfig{Enabled: true}, - K8sResourcequotaUID: ResourceAttributeConfig{Enabled: true}, - K8sServiceClusterIP: ResourceAttributeConfig{Enabled: true}, - K8sServiceName: ResourceAttributeConfig{Enabled: true}, - K8sServiceNamespace: ResourceAttributeConfig{Enabled: true}, - K8sServiceType: ResourceAttributeConfig{Enabled: true}, - K8sServiceUID: ResourceAttributeConfig{Enabled: true}, - K8sServiceAccountName: ResourceAttributeConfig{Enabled: true}, - K8sStatefulsetName: ResourceAttributeConfig{Enabled: true}, - K8sStatefulsetStartTime: ResourceAttributeConfig{Enabled: true}, - K8sStatefulsetUID: ResourceAttributeConfig{Enabled: true}, - OpencensusResourcetype: ResourceAttributeConfig{Enabled: true}, - OpenshiftClusterquotaName: ResourceAttributeConfig{Enabled: true}, - OpenshiftClusterquotaUID: ResourceAttributeConfig{Enabled: true}, + ContainerID: ResourceAttributeConfig{Enabled: true}, + ContainerImageName: ResourceAttributeConfig{Enabled: true}, + ContainerImageTag: ResourceAttributeConfig{Enabled: true}, + K8sClusterName: ResourceAttributeConfig{Enabled: true}, + K8sContainerName: ResourceAttributeConfig{Enabled: true}, + K8sCronjobName: ResourceAttributeConfig{Enabled: true}, + K8sCronjobStartTime: ResourceAttributeConfig{Enabled: true}, + K8sCronjobUID: ResourceAttributeConfig{Enabled: true}, + K8sDaemonsetName: ResourceAttributeConfig{Enabled: true}, + K8sDaemonsetStartTime: ResourceAttributeConfig{Enabled: true}, + K8sDaemonsetUID: ResourceAttributeConfig{Enabled: true}, + K8sDeploymentName: ResourceAttributeConfig{Enabled: true}, + K8sDeploymentStartTime: ResourceAttributeConfig{Enabled: true}, + K8sDeploymentUID: ResourceAttributeConfig{Enabled: true}, + K8sHpaName: ResourceAttributeConfig{Enabled: true}, + K8sHpaUID: ResourceAttributeConfig{Enabled: true}, + K8sJobName: ResourceAttributeConfig{Enabled: true}, + K8sJobStartTime: ResourceAttributeConfig{Enabled: true}, + K8sJobUID: ResourceAttributeConfig{Enabled: true}, + K8sNamespaceName: ResourceAttributeConfig{Enabled: true}, + K8sNamespaceStartTime: ResourceAttributeConfig{Enabled: true}, + K8sNamespaceUID: ResourceAttributeConfig{Enabled: true}, + K8sNodeName: ResourceAttributeConfig{Enabled: true}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: true}, + K8sNodeUID: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeAccessModes: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeFinalizers: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeLabels: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeName: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeNamespace: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumePhase: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeReclaimPolicy: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeStartTime: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeStorageClass: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeType: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeUID: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeVolumeMode: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimAccessModes: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimFinalizers: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimLabels: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimNamespace: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimPhase: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimSelector: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimStartTime: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimStorageClass: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimType: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimUID: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimVolumeMode: ResourceAttributeConfig{Enabled: true}, + K8sPersistentvolumeclaimVolumeName: ResourceAttributeConfig{Enabled: true}, + K8sPodName: ResourceAttributeConfig{Enabled: true}, + K8sPodStartTime: ResourceAttributeConfig{Enabled: true}, + K8sPodUID: ResourceAttributeConfig{Enabled: true}, + K8sReplicasetName: ResourceAttributeConfig{Enabled: true}, + K8sReplicasetStartTime: ResourceAttributeConfig{Enabled: true}, + K8sReplicasetUID: ResourceAttributeConfig{Enabled: true}, + K8sReplicationcontrollerName: ResourceAttributeConfig{Enabled: true}, + K8sReplicationcontrollerUID: ResourceAttributeConfig{Enabled: true}, + K8sResourcequotaName: ResourceAttributeConfig{Enabled: true}, + K8sResourcequotaUID: ResourceAttributeConfig{Enabled: true}, + K8sServiceClusterIP: ResourceAttributeConfig{Enabled: true}, + K8sServiceName: ResourceAttributeConfig{Enabled: true}, + K8sServiceNamespace: ResourceAttributeConfig{Enabled: true}, + K8sServiceType: ResourceAttributeConfig{Enabled: true}, + K8sServiceUID: ResourceAttributeConfig{Enabled: true}, + K8sServiceAccountName: ResourceAttributeConfig{Enabled: true}, + K8sStatefulsetName: ResourceAttributeConfig{Enabled: true}, + K8sStatefulsetStartTime: ResourceAttributeConfig{Enabled: true}, + K8sStatefulsetUID: ResourceAttributeConfig{Enabled: true}, + OpencensusResourcetype: ResourceAttributeConfig{Enabled: true}, + OpenshiftClusterquotaName: ResourceAttributeConfig{Enabled: true}, + OpenshiftClusterquotaUID: ResourceAttributeConfig{Enabled: true}, }, }, { name: "none_set", want: ResourceAttributesConfig{ - ContainerID: ResourceAttributeConfig{Enabled: false}, - ContainerImageName: ResourceAttributeConfig{Enabled: false}, - ContainerImageTag: ResourceAttributeConfig{Enabled: false}, - K8sClusterName: ResourceAttributeConfig{Enabled: false}, - K8sContainerName: ResourceAttributeConfig{Enabled: false}, - K8sCronjobName: ResourceAttributeConfig{Enabled: false}, - K8sCronjobStartTime: ResourceAttributeConfig{Enabled: false}, - K8sCronjobUID: ResourceAttributeConfig{Enabled: false}, - K8sDaemonsetName: ResourceAttributeConfig{Enabled: false}, - K8sDaemonsetStartTime: ResourceAttributeConfig{Enabled: false}, - K8sDaemonsetUID: ResourceAttributeConfig{Enabled: false}, - K8sDeploymentName: ResourceAttributeConfig{Enabled: false}, - K8sDeploymentStartTime: ResourceAttributeConfig{Enabled: false}, - K8sDeploymentUID: ResourceAttributeConfig{Enabled: false}, - K8sHpaName: ResourceAttributeConfig{Enabled: false}, - K8sHpaUID: ResourceAttributeConfig{Enabled: false}, - K8sJobName: ResourceAttributeConfig{Enabled: false}, - K8sJobStartTime: ResourceAttributeConfig{Enabled: false}, - K8sJobUID: ResourceAttributeConfig{Enabled: false}, - K8sNamespaceName: ResourceAttributeConfig{Enabled: false}, - K8sNamespaceStartTime: ResourceAttributeConfig{Enabled: false}, - K8sNamespaceUID: ResourceAttributeConfig{Enabled: false}, - K8sNodeName: ResourceAttributeConfig{Enabled: false}, - K8sNodeStartTime: ResourceAttributeConfig{Enabled: false}, - K8sNodeUID: ResourceAttributeConfig{Enabled: false}, - K8sPodName: ResourceAttributeConfig{Enabled: false}, - K8sPodStartTime: ResourceAttributeConfig{Enabled: false}, - K8sPodUID: ResourceAttributeConfig{Enabled: false}, - K8sReplicasetName: ResourceAttributeConfig{Enabled: false}, - K8sReplicasetStartTime: ResourceAttributeConfig{Enabled: false}, - K8sReplicasetUID: ResourceAttributeConfig{Enabled: false}, - K8sReplicationcontrollerName: ResourceAttributeConfig{Enabled: false}, - K8sReplicationcontrollerUID: ResourceAttributeConfig{Enabled: false}, - K8sResourcequotaName: ResourceAttributeConfig{Enabled: false}, - K8sResourcequotaUID: ResourceAttributeConfig{Enabled: false}, - K8sServiceClusterIP: ResourceAttributeConfig{Enabled: false}, - K8sServiceName: ResourceAttributeConfig{Enabled: false}, - K8sServiceNamespace: ResourceAttributeConfig{Enabled: false}, - K8sServiceType: ResourceAttributeConfig{Enabled: false}, - K8sServiceUID: ResourceAttributeConfig{Enabled: false}, - K8sServiceAccountName: ResourceAttributeConfig{Enabled: false}, - K8sStatefulsetName: ResourceAttributeConfig{Enabled: false}, - K8sStatefulsetStartTime: ResourceAttributeConfig{Enabled: false}, - K8sStatefulsetUID: ResourceAttributeConfig{Enabled: false}, - OpencensusResourcetype: ResourceAttributeConfig{Enabled: false}, - OpenshiftClusterquotaName: ResourceAttributeConfig{Enabled: false}, - OpenshiftClusterquotaUID: ResourceAttributeConfig{Enabled: false}, + ContainerID: ResourceAttributeConfig{Enabled: false}, + ContainerImageName: ResourceAttributeConfig{Enabled: false}, + ContainerImageTag: ResourceAttributeConfig{Enabled: false}, + K8sClusterName: ResourceAttributeConfig{Enabled: false}, + K8sContainerName: ResourceAttributeConfig{Enabled: false}, + K8sCronjobName: ResourceAttributeConfig{Enabled: false}, + K8sCronjobStartTime: ResourceAttributeConfig{Enabled: false}, + K8sCronjobUID: ResourceAttributeConfig{Enabled: false}, + K8sDaemonsetName: ResourceAttributeConfig{Enabled: false}, + K8sDaemonsetStartTime: ResourceAttributeConfig{Enabled: false}, + K8sDaemonsetUID: ResourceAttributeConfig{Enabled: false}, + K8sDeploymentName: ResourceAttributeConfig{Enabled: false}, + K8sDeploymentStartTime: ResourceAttributeConfig{Enabled: false}, + K8sDeploymentUID: ResourceAttributeConfig{Enabled: false}, + K8sHpaName: ResourceAttributeConfig{Enabled: false}, + K8sHpaUID: ResourceAttributeConfig{Enabled: false}, + K8sJobName: ResourceAttributeConfig{Enabled: false}, + K8sJobStartTime: ResourceAttributeConfig{Enabled: false}, + K8sJobUID: ResourceAttributeConfig{Enabled: false}, + K8sNamespaceName: ResourceAttributeConfig{Enabled: false}, + K8sNamespaceStartTime: ResourceAttributeConfig{Enabled: false}, + K8sNamespaceUID: ResourceAttributeConfig{Enabled: false}, + K8sNodeName: ResourceAttributeConfig{Enabled: false}, + K8sNodeStartTime: ResourceAttributeConfig{Enabled: false}, + K8sNodeUID: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeAccessModes: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeFinalizers: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeLabels: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeName: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeNamespace: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumePhase: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeReclaimPolicy: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeStartTime: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeStorageClass: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeType: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeUID: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeVolumeMode: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimAccessModes: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimFinalizers: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimLabels: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimName: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimNamespace: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimPhase: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimSelector: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimStartTime: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimStorageClass: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimType: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimUID: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimVolumeMode: ResourceAttributeConfig{Enabled: false}, + K8sPersistentvolumeclaimVolumeName: ResourceAttributeConfig{Enabled: false}, + K8sPodName: ResourceAttributeConfig{Enabled: false}, + K8sPodStartTime: ResourceAttributeConfig{Enabled: false}, + K8sPodUID: ResourceAttributeConfig{Enabled: false}, + K8sReplicasetName: ResourceAttributeConfig{Enabled: false}, + K8sReplicasetStartTime: ResourceAttributeConfig{Enabled: false}, + K8sReplicasetUID: ResourceAttributeConfig{Enabled: false}, + K8sReplicationcontrollerName: ResourceAttributeConfig{Enabled: false}, + K8sReplicationcontrollerUID: ResourceAttributeConfig{Enabled: false}, + K8sResourcequotaName: ResourceAttributeConfig{Enabled: false}, + K8sResourcequotaUID: ResourceAttributeConfig{Enabled: false}, + K8sServiceClusterIP: ResourceAttributeConfig{Enabled: false}, + K8sServiceName: ResourceAttributeConfig{Enabled: false}, + K8sServiceNamespace: ResourceAttributeConfig{Enabled: false}, + K8sServiceType: ResourceAttributeConfig{Enabled: false}, + K8sServiceUID: ResourceAttributeConfig{Enabled: false}, + K8sServiceAccountName: ResourceAttributeConfig{Enabled: false}, + K8sStatefulsetName: ResourceAttributeConfig{Enabled: false}, + K8sStatefulsetStartTime: ResourceAttributeConfig{Enabled: false}, + K8sStatefulsetUID: ResourceAttributeConfig{Enabled: false}, + OpencensusResourcetype: ResourceAttributeConfig{Enabled: false}, + OpenshiftClusterquotaName: ResourceAttributeConfig{Enabled: false}, + OpenshiftClusterquotaUID: ResourceAttributeConfig{Enabled: false}, }, }, } diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_metrics.go b/receiver/k8sclusterreceiver/internal/metadata/generated_metrics.go index 2090c68d8fdf..6cd8af8be642 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_metrics.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_metrics.go @@ -1384,6 +1384,104 @@ func newMetricK8sPersistentvolumeCapacity(cfg MetricConfig) metricK8sPersistentv return m } +type metricK8sPersistentvolumeclaimAllocated struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills k8s.persistentvolumeclaim.allocated metric with initial data. +func (m *metricK8sPersistentvolumeclaimAllocated) init() { + m.data.SetName("k8s.persistentvolumeclaim.allocated") + m.data.SetDescription("The allocated capacity of persistent volume.") + m.data.SetUnit("By") + m.data.SetEmptyGauge() +} + +func (m *metricK8sPersistentvolumeclaimAllocated) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricK8sPersistentvolumeclaimAllocated) updateCapacity() { + if m.data.Gauge().DataPoints().Len() > m.capacity { + m.capacity = m.data.Gauge().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricK8sPersistentvolumeclaimAllocated) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricK8sPersistentvolumeclaimAllocated(cfg MetricConfig) metricK8sPersistentvolumeclaimAllocated { + m := metricK8sPersistentvolumeclaimAllocated{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricK8sPersistentvolumeclaimCapacity struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills k8s.persistentvolumeclaim.capacity metric with initial data. +func (m *metricK8sPersistentvolumeclaimCapacity) init() { + m.data.SetName("k8s.persistentvolumeclaim.capacity") + m.data.SetDescription("The capacity of persistent volume claim.") + m.data.SetUnit("By") + m.data.SetEmptyGauge() +} + +func (m *metricK8sPersistentvolumeclaimCapacity) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricK8sPersistentvolumeclaimCapacity) updateCapacity() { + if m.data.Gauge().DataPoints().Len() > m.capacity { + m.capacity = m.data.Gauge().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricK8sPersistentvolumeclaimCapacity) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricK8sPersistentvolumeclaimCapacity(cfg MetricConfig) metricK8sPersistentvolumeclaimCapacity { + m := metricK8sPersistentvolumeclaimCapacity{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricK8sPodPhase struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -2267,6 +2365,8 @@ type MetricsBuilder struct { metricK8sJobSuccessfulPods metricK8sJobSuccessfulPods metricK8sNamespacePhase metricK8sNamespacePhase metricK8sPersistentvolumeCapacity metricK8sPersistentvolumeCapacity + metricK8sPersistentvolumeclaimAllocated metricK8sPersistentvolumeclaimAllocated + metricK8sPersistentvolumeclaimCapacity metricK8sPersistentvolumeclaimCapacity metricK8sPodPhase metricK8sPodPhase metricK8sPodStatusReason metricK8sPodStatusReason metricK8sReplicasetAvailable metricK8sReplicasetAvailable @@ -2330,6 +2430,8 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting metricK8sJobSuccessfulPods: newMetricK8sJobSuccessfulPods(mbc.Metrics.K8sJobSuccessfulPods), metricK8sNamespacePhase: newMetricK8sNamespacePhase(mbc.Metrics.K8sNamespacePhase), metricK8sPersistentvolumeCapacity: newMetricK8sPersistentvolumeCapacity(mbc.Metrics.K8sPersistentvolumeCapacity), + metricK8sPersistentvolumeclaimAllocated: newMetricK8sPersistentvolumeclaimAllocated(mbc.Metrics.K8sPersistentvolumeclaimAllocated), + metricK8sPersistentvolumeclaimCapacity: newMetricK8sPersistentvolumeclaimCapacity(mbc.Metrics.K8sPersistentvolumeclaimCapacity), metricK8sPodPhase: newMetricK8sPodPhase(mbc.Metrics.K8sPodPhase), metricK8sPodStatusReason: newMetricK8sPodStatusReason(mbc.Metrics.K8sPodStatusReason), metricK8sReplicasetAvailable: newMetricK8sReplicasetAvailable(mbc.Metrics.K8sReplicasetAvailable), @@ -2437,6 +2539,8 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricK8sJobSuccessfulPods.emit(ils.Metrics()) mb.metricK8sNamespacePhase.emit(ils.Metrics()) mb.metricK8sPersistentvolumeCapacity.emit(ils.Metrics()) + mb.metricK8sPersistentvolumeclaimAllocated.emit(ils.Metrics()) + mb.metricK8sPersistentvolumeclaimCapacity.emit(ils.Metrics()) mb.metricK8sPodPhase.emit(ils.Metrics()) mb.metricK8sPodStatusReason.emit(ils.Metrics()) mb.metricK8sReplicasetAvailable.emit(ils.Metrics()) @@ -2614,6 +2718,16 @@ func (mb *MetricsBuilder) RecordK8sPersistentvolumeCapacityDataPoint(ts pcommon. mb.metricK8sPersistentvolumeCapacity.recordDataPoint(mb.startTime, ts, val) } +// RecordK8sPersistentvolumeclaimAllocatedDataPoint adds a data point to k8s.persistentvolumeclaim.allocated metric. +func (mb *MetricsBuilder) RecordK8sPersistentvolumeclaimAllocatedDataPoint(ts pcommon.Timestamp, val int64) { + mb.metricK8sPersistentvolumeclaimAllocated.recordDataPoint(mb.startTime, ts, val) +} + +// RecordK8sPersistentvolumeclaimCapacityDataPoint adds a data point to k8s.persistentvolumeclaim.capacity metric. +func (mb *MetricsBuilder) RecordK8sPersistentvolumeclaimCapacityDataPoint(ts pcommon.Timestamp, val int64) { + mb.metricK8sPersistentvolumeclaimCapacity.recordDataPoint(mb.startTime, ts, val) +} + // RecordK8sPodPhaseDataPoint adds a data point to k8s.pod.phase metric. func (mb *MetricsBuilder) RecordK8sPodPhaseDataPoint(ts pcommon.Timestamp, val int64) { mb.metricK8sPodPhase.recordDataPoint(mb.startTime, ts, val) diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_metrics_test.go b/receiver/k8sclusterreceiver/internal/metadata/generated_metrics_test.go index 135b91cbb477..e32382c487a2 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_metrics_test.go @@ -49,7 +49,6 @@ func TestMetricsBuilder(t *testing.T) { mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, test.name), settings, WithStartTime(start)) expectedWarnings := 0 - assert.Equal(t, expectedWarnings, observedLogs.Len()) defaultMetricsCount := 0 @@ -167,6 +166,14 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordK8sPersistentvolumeCapacityDataPoint(ts, 1) + defaultMetricsCount++ + allMetricsCount++ + mb.RecordK8sPersistentvolumeclaimAllocatedDataPoint(ts, 1) + + defaultMetricsCount++ + allMetricsCount++ + mb.RecordK8sPersistentvolumeclaimCapacityDataPoint(ts, 1) + defaultMetricsCount++ allMetricsCount++ mb.RecordK8sPodPhaseDataPoint(ts, 1) @@ -273,8 +280,20 @@ func TestMetricsBuilder(t *testing.T) { rb.SetK8sPersistentvolumeType("k8s.persistentvolume.type-val") rb.SetK8sPersistentvolumeUID("k8s.persistentvolume.uid-val") rb.SetK8sPersistentvolumeVolumeMode("k8s.persistentvolume.volume_mode-val") + rb.SetK8sPersistentvolumeclaimAccessModes("k8s.persistentvolumeclaim.access_modes-val") + rb.SetK8sPersistentvolumeclaimAnnotations("k8s.persistentvolumeclaim.annotations-val") + rb.SetK8sPersistentvolumeclaimFinalizers("k8s.persistentvolumeclaim.finalizers-val") + rb.SetK8sPersistentvolumeclaimLabels("k8s.persistentvolumeclaim.labels-val") rb.SetK8sPersistentvolumeclaimName("k8s.persistentvolumeclaim.name-val") + rb.SetK8sPersistentvolumeclaimNamespace("k8s.persistentvolumeclaim.namespace-val") + rb.SetK8sPersistentvolumeclaimPhase("k8s.persistentvolumeclaim.phase-val") + rb.SetK8sPersistentvolumeclaimSelector("k8s.persistentvolumeclaim.selector-val") + rb.SetK8sPersistentvolumeclaimStartTime("k8s.persistentvolumeclaim.start_time-val") + rb.SetK8sPersistentvolumeclaimStorageClass("k8s.persistentvolumeclaim.storage_class-val") + rb.SetK8sPersistentvolumeclaimType("k8s.persistentvolumeclaim.type-val") rb.SetK8sPersistentvolumeclaimUID("k8s.persistentvolumeclaim.uid-val") + rb.SetK8sPersistentvolumeclaimVolumeMode("k8s.persistentvolumeclaim.volume_mode-val") + rb.SetK8sPersistentvolumeclaimVolumeName("k8s.persistentvolumeclaim.volume_name-val") rb.SetK8sPodName("k8s.pod.name-val") rb.SetK8sPodStartTime("k8s.pod.start_time-val") rb.SetK8sPodUID("k8s.pod.uid-val") @@ -655,6 +674,30 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) assert.Equal(t, int64(1), dp.IntValue()) + case "k8s.persistentvolumeclaim.allocated": + assert.False(t, validatedMetrics["k8s.persistentvolumeclaim.allocated"], "Found a duplicate in the metrics slice: k8s.persistentvolumeclaim.allocated") + validatedMetrics["k8s.persistentvolumeclaim.allocated"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "The allocated capacity of persistent volume.", ms.At(i).Description()) + assert.Equal(t, "By", ms.At(i).Unit()) + dp := ms.At(i).Gauge().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) + case "k8s.persistentvolumeclaim.capacity": + assert.False(t, validatedMetrics["k8s.persistentvolumeclaim.capacity"], "Found a duplicate in the metrics slice: k8s.persistentvolumeclaim.capacity") + validatedMetrics["k8s.persistentvolumeclaim.capacity"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "The capacity of persistent volume claim.", ms.At(i).Description()) + assert.Equal(t, "By", ms.At(i).Unit()) + dp := ms.At(i).Gauge().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) case "k8s.pod.phase": assert.False(t, validatedMetrics["k8s.pod.phase"], "Found a duplicate in the metrics slice: k8s.pod.phase") validatedMetrics["k8s.pod.phase"] = true diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go b/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go index 356acab2e603..864012e31720 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go @@ -287,6 +287,34 @@ func (rb *ResourceBuilder) SetK8sPersistentvolumeVolumeMode(val string) { } } +// SetK8sPersistentvolumeclaimAccessModes sets provided value as "k8s.persistentvolumeclaim.access_modes" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimAccessModes(val string) { + if rb.config.K8sPersistentvolumeclaimAccessModes.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.access_modes", val) + } +} + +// SetK8sPersistentvolumeclaimAnnotations sets provided value as "k8s.persistentvolumeclaim.annotations" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimAnnotations(val string) { + if rb.config.K8sPersistentvolumeclaimAnnotations.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.annotations", val) + } +} + +// SetK8sPersistentvolumeclaimFinalizers sets provided value as "k8s.persistentvolumeclaim.finalizers" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimFinalizers(val string) { + if rb.config.K8sPersistentvolumeclaimFinalizers.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.finalizers", val) + } +} + +// SetK8sPersistentvolumeclaimLabels sets provided value as "k8s.persistentvolumeclaim.labels" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimLabels(val string) { + if rb.config.K8sPersistentvolumeclaimLabels.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.labels", val) + } +} + // SetK8sPersistentvolumeclaimName sets provided value as "k8s.persistentvolumeclaim.name" attribute. func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimName(val string) { if rb.config.K8sPersistentvolumeclaimName.Enabled { @@ -294,6 +322,48 @@ func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimName(val string) { } } +// SetK8sPersistentvolumeclaimNamespace sets provided value as "k8s.persistentvolumeclaim.namespace" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimNamespace(val string) { + if rb.config.K8sPersistentvolumeclaimNamespace.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.namespace", val) + } +} + +// SetK8sPersistentvolumeclaimPhase sets provided value as "k8s.persistentvolumeclaim.phase" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimPhase(val string) { + if rb.config.K8sPersistentvolumeclaimPhase.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.phase", val) + } +} + +// SetK8sPersistentvolumeclaimSelector sets provided value as "k8s.persistentvolumeclaim.selector" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimSelector(val string) { + if rb.config.K8sPersistentvolumeclaimSelector.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.selector", val) + } +} + +// SetK8sPersistentvolumeclaimStartTime sets provided value as "k8s.persistentvolumeclaim.start_time" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimStartTime(val string) { + if rb.config.K8sPersistentvolumeclaimStartTime.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.start_time", val) + } +} + +// SetK8sPersistentvolumeclaimStorageClass sets provided value as "k8s.persistentvolumeclaim.storage_class" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimStorageClass(val string) { + if rb.config.K8sPersistentvolumeclaimStorageClass.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.storage_class", val) + } +} + +// SetK8sPersistentvolumeclaimType sets provided value as "k8s.persistentvolumeclaim.type" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimType(val string) { + if rb.config.K8sPersistentvolumeclaimType.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.type", val) + } +} + // SetK8sPersistentvolumeclaimUID sets provided value as "k8s.persistentvolumeclaim.uid" attribute. func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimUID(val string) { if rb.config.K8sPersistentvolumeclaimUID.Enabled { @@ -301,6 +371,20 @@ func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimUID(val string) { } } +// SetK8sPersistentvolumeclaimVolumeMode sets provided value as "k8s.persistentvolumeclaim.volume_mode" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimVolumeMode(val string) { + if rb.config.K8sPersistentvolumeclaimVolumeMode.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.volume_mode", val) + } +} + +// SetK8sPersistentvolumeclaimVolumeName sets provided value as "k8s.persistentvolumeclaim.volume_name" attribute. +func (rb *ResourceBuilder) SetK8sPersistentvolumeclaimVolumeName(val string) { + if rb.config.K8sPersistentvolumeclaimVolumeName.Enabled { + rb.res.Attributes().PutStr("k8s.persistentvolumeclaim.volume_name", val) + } +} + // SetK8sPodName sets provided value as "k8s.pod.name" attribute. func (rb *ResourceBuilder) SetK8sPodName(val string) { if rb.config.K8sPodName.Enabled { diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go b/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go index 31caf0da0893..e49a50fbd469 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go @@ -51,8 +51,20 @@ func TestResourceBuilder(t *testing.T) { rb.SetK8sPersistentvolumeType("k8s.persistentvolume.type-val") rb.SetK8sPersistentvolumeUID("k8s.persistentvolume.uid-val") rb.SetK8sPersistentvolumeVolumeMode("k8s.persistentvolume.volume_mode-val") + rb.SetK8sPersistentvolumeclaimAccessModes("k8s.persistentvolumeclaim.access_modes-val") + rb.SetK8sPersistentvolumeclaimAnnotations("k8s.persistentvolumeclaim.annotations-val") + rb.SetK8sPersistentvolumeclaimFinalizers("k8s.persistentvolumeclaim.finalizers-val") + rb.SetK8sPersistentvolumeclaimLabels("k8s.persistentvolumeclaim.labels-val") rb.SetK8sPersistentvolumeclaimName("k8s.persistentvolumeclaim.name-val") + rb.SetK8sPersistentvolumeclaimNamespace("k8s.persistentvolumeclaim.namespace-val") + rb.SetK8sPersistentvolumeclaimPhase("k8s.persistentvolumeclaim.phase-val") + rb.SetK8sPersistentvolumeclaimSelector("k8s.persistentvolumeclaim.selector-val") + rb.SetK8sPersistentvolumeclaimStartTime("k8s.persistentvolumeclaim.start_time-val") + rb.SetK8sPersistentvolumeclaimStorageClass("k8s.persistentvolumeclaim.storage_class-val") + rb.SetK8sPersistentvolumeclaimType("k8s.persistentvolumeclaim.type-val") rb.SetK8sPersistentvolumeclaimUID("k8s.persistentvolumeclaim.uid-val") + rb.SetK8sPersistentvolumeclaimVolumeMode("k8s.persistentvolumeclaim.volume_mode-val") + rb.SetK8sPersistentvolumeclaimVolumeName("k8s.persistentvolumeclaim.volume_name-val") rb.SetK8sPodName("k8s.pod.name-val") rb.SetK8sPodStartTime("k8s.pod.start_time-val") rb.SetK8sPodUID("k8s.pod.uid-val") @@ -81,9 +93,9 @@ func TestResourceBuilder(t *testing.T) { switch test { case "default": - assert.Equal(t, 47, res.Attributes().Len()) + assert.Equal(t, 74, res.Attributes().Len()) case "all_set": - assert.Equal(t, 47, res.Attributes().Len()) + assert.Equal(t, 74, res.Attributes().Len()) case "none_set": assert.Equal(t, 0, res.Attributes().Len()) return @@ -281,16 +293,76 @@ func TestResourceBuilder(t *testing.T) { if ok { assert.EqualValues(t, "k8s.persistentvolume.volume_mode-val", val.Str()) } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.access_modes") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.access_modes-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.annotations") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.annotations-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.finalizers") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.finalizers-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.labels") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.labels-val", val.Str()) + } val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.name") assert.True(t, ok) if ok { assert.EqualValues(t, "k8s.persistentvolumeclaim.name-val", val.Str()) } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.namespace") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.namespace-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.phase") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.phase-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.selector") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.selector-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.start_time") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.start_time-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.storage_class") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.storage_class-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.type") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.type-val", val.Str()) + } val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.uid") assert.True(t, ok) if ok { assert.EqualValues(t, "k8s.persistentvolumeclaim.uid-val", val.Str()) } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.volume_mode") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.volume_mode-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.persistentvolumeclaim.volume_name") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.persistentvolumeclaim.volume_name-val", val.Str()) + } val, ok = res.Attributes().Get("k8s.pod.name") assert.True(t, ok) if ok { diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_status.go b/receiver/k8sclusterreceiver/internal/metadata/generated_status.go index 784c87d59c29..1eaeb822b837 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_status.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_status.go @@ -4,8 +4,6 @@ package metadata import ( "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/trace" ) const ( @@ -13,11 +11,3 @@ const ( MetricsStability = component.StabilityLevelBeta LogsStability = component.StabilityLevelDevelopment ) - -func Meter(settings component.TelemetrySettings) metric.Meter { - return settings.MeterProvider.Meter("otelcol/k8sclusterreceiver") -} - -func Tracer(settings component.TelemetrySettings) trace.Tracer { - return settings.TracerProvider.Tracer("otelcol/k8sclusterreceiver") -} diff --git a/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml b/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml index f62de9c0c462..5fb4af711282 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml @@ -57,6 +57,10 @@ all_set: enabled: true k8s.persistentvolume.capacity: enabled: true + k8s.persistentvolumeclaim.allocated: + enabled: true + k8s.persistentvolumeclaim.capacity: + enabled: true k8s.pod.phase: enabled: true k8s.pod.status_reason: @@ -168,10 +172,34 @@ all_set: enabled: true k8s.persistentvolume.volume_mode: enabled: true + k8s.persistentvolumeclaim.access_modes: + enabled: true + k8s.persistentvolumeclaim.annotations: + enabled: true + k8s.persistentvolumeclaim.finalizers: + enabled: true + k8s.persistentvolumeclaim.labels: + enabled: true k8s.persistentvolumeclaim.name: enabled: true + k8s.persistentvolumeclaim.namespace: + enabled: true + k8s.persistentvolumeclaim.phase: + enabled: true + k8s.persistentvolumeclaim.selector: + enabled: true + k8s.persistentvolumeclaim.start_time: + enabled: true + k8s.persistentvolumeclaim.storage_class: + enabled: true + k8s.persistentvolumeclaim.type: + enabled: true k8s.persistentvolumeclaim.uid: enabled: true + k8s.persistentvolumeclaim.volume_mode: + enabled: true + k8s.persistentvolumeclaim.volume_name: + enabled: true k8s.pod.name: enabled: true k8s.pod.start_time: @@ -274,6 +302,10 @@ none_set: enabled: false k8s.persistentvolume.capacity: enabled: false + k8s.persistentvolumeclaim.allocated: + enabled: false + k8s.persistentvolumeclaim.capacity: + enabled: false k8s.pod.phase: enabled: false k8s.pod.status_reason: @@ -385,10 +417,34 @@ none_set: enabled: false k8s.persistentvolume.volume_mode: enabled: false + k8s.persistentvolumeclaim.access_modes: + enabled: false + k8s.persistentvolumeclaim.annotations: + enabled: false + k8s.persistentvolumeclaim.finalizers: + enabled: false + k8s.persistentvolumeclaim.labels: + enabled: false k8s.persistentvolumeclaim.name: enabled: false + k8s.persistentvolumeclaim.namespace: + enabled: false + k8s.persistentvolumeclaim.phase: + enabled: false + k8s.persistentvolumeclaim.selector: + enabled: false + k8s.persistentvolumeclaim.start_time: + enabled: false + k8s.persistentvolumeclaim.storage_class: + enabled: false + k8s.persistentvolumeclaim.type: + enabled: false k8s.persistentvolumeclaim.uid: enabled: false + k8s.persistentvolumeclaim.volume_mode: + enabled: false + k8s.persistentvolumeclaim.volume_name: + enabled: false k8s.pod.name: enabled: false k8s.pod.start_time: diff --git a/receiver/k8sclusterreceiver/internal/persistentvolume/persistentvolume.go b/receiver/k8sclusterreceiver/internal/persistentvolume/persistentvolume.go index 8bd78e16d424..969280db9099 100644 --- a/receiver/k8sclusterreceiver/internal/persistentvolume/persistentvolume.go +++ b/receiver/k8sclusterreceiver/internal/persistentvolume/persistentvolume.go @@ -20,8 +20,8 @@ const ( persistentvolumeCreationTime = "persistentvolume.creation_timestamp" ) -// Transform transforms the node to remove the fields that we don't use to reduce RAM utilization. -// IMPORTANT: Make sure to update this function before using new node fields. +// Transform transforms the persistent-volume to remove the fields that we don't use to reduce RAM utilization. +// IMPORTANT: Make sure to update this function before using new persistent-volume fields. func Transform(pv *corev1.PersistentVolume) *corev1.PersistentVolume { newPv := &corev1.PersistentVolume{ ObjectMeta: metadata.TransformObjectMeta(pv.ObjectMeta), @@ -55,7 +55,7 @@ func RecordMetrics(mb *imetadata.MetricsBuilder, pv *corev1.PersistentVolume, ts rb.SetK8sPersistentvolumeReclaimPolicy(string(pv.Spec.PersistentVolumeReclaimPolicy)) rb.SetK8sPersistentvolumeStartTime(pv.GetCreationTimestamp().String()) rb.SetK8sPersistentvolumeStorageClass(pv.Spec.StorageClassName) - rb.SetK8sPersistentvolumeType(pv.Kind) + rb.SetK8sPersistentvolumeType("PersistentVolume") rb.SetK8sPersistentvolumeVolumeMode(string(*pv.Spec.VolumeMode)) rb.SetK8sPersistentvolumeclaimUID(string((*pv.Spec.ClaimRef).UID)) rb.SetK8sPersistentvolumeclaimName((pv.Spec.ClaimRef).Name) diff --git a/receiver/k8sclusterreceiver/internal/persistentvolumeclaim/persistentvolumeclaim.go b/receiver/k8sclusterreceiver/internal/persistentvolumeclaim/persistentvolumeclaim.go new file mode 100644 index 000000000000..044f793f6637 --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/persistentvolumeclaim/persistentvolumeclaim.go @@ -0,0 +1,104 @@ +package persistentvolumeclaim + +import ( + "fmt" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/maps" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata" + "go.opentelemetry.io/collector/pdata/pcommon" + corev1 "k8s.io/api/core/v1" + "strings" + "time" + + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/metadata" + imetadata "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/metadata" +) + +const ( + // Keys for persistentvolumeclaim metadata. + AttributeK8SPersistentvolumeclaimUID = "k8s.persistentvolumeclaim.uid" + AttributeK8SPersistentvolumeclaimName = "k8s.persistentvolumeclaim.name" + persistentvolumeclaimCreationTime = "persistentvolumeclaim.creation_timestamp" +) + +// Transform transforms the persistent-volume-claim to remove the fields that we don't use to reduce RAM utilization. +// IMPORTANT: Make sure to update this function before using new persistent-volume-claim fields. +func Transform(pvc *corev1.PersistentVolumeClaim) *corev1.PersistentVolumeClaim { + newPvc := &corev1.PersistentVolumeClaim{ + ObjectMeta: metadata.TransformObjectMeta(pvc.ObjectMeta), + Status: corev1.PersistentVolumeClaimStatus{ + Phase: pvc.Status.Phase, + }, + } + newPvc.Status.Capacity = pvc.Status.Capacity + newPvc.Spec.VolumeName = pvc.Spec.VolumeName + for _, c := range pvc.Spec.AccessModes { + newPvc.Spec.AccessModes = append(newPvc.Spec.AccessModes, c) + } + return newPvc +} + +func RecordMetrics(mb *imetadata.MetricsBuilder, pvc *corev1.PersistentVolumeClaim, ts pcommon.Timestamp) { + var capacity int64 + var allocated int64 + + for _, quantity := range pvc.Status.Capacity { + capacity += quantity.Value() + } + for _, quantity := range pvc.Status.AllocatedResources { + allocated += quantity.Value() + } + + mb.RecordK8sPersistentvolumeclaimCapacityDataPoint(ts, capacity) + mb.RecordK8sPersistentvolumeclaimAllocatedDataPoint(ts, allocated) + + rb := mb.NewResourceBuilder() + rb.SetK8sPersistentvolumeclaimUID(string(pvc.GetUID())) + rb.SetK8sPersistentvolumeclaimName(pvc.GetName()) + rb.SetK8sClusterName("unknown") + rb.SetK8sPersistentvolumeclaimNamespace(pvc.GetNamespace()) + rb.SetK8sPersistentvolumeclaimLabels(mapToString(pvc.GetLabels(), "&")) + rb.SetK8sPersistentvolumeclaimPhase(string(pvc.Status.Phase)) + rb.SetK8sPersistentvolumeclaimSelector("") + rb.SetK8sPersistentvolumeclaimStorageClass(*pvc.Spec.StorageClassName) + rb.SetK8sPersistentvolumeclaimVolumeMode(string(*pvc.Spec.VolumeMode)) + rb.SetK8sPersistentvolumeclaimAccessModes(sliceToString(pvc.Spec.AccessModes, ",")) + rb.SetK8sPersistentvolumeclaimFinalizers(strings.Join(pvc.Finalizers, ",")) + rb.SetK8sPersistentvolumeclaimStartTime(pvc.GetCreationTimestamp().String()) + rb.SetK8sPersistentvolumeclaimAnnotations(mapToString(pvc.GetAnnotations(), "&")) + rb.SetK8sPersistentvolumeclaimVolumeName(pvc.Spec.VolumeName) + rb.SetK8sPersistentvolumeclaimType("PersistentVolumeClaim") + mb.EmitForResource(metadata.WithResource(rb.Emit())) +} + +func mapToString(m map[string]string, seperator string) string { + var res []string + for k, v := range m { + res = append(res, fmt.Sprintf("%s=%s", k, v)) + } + return strings.Join(res, seperator) +} + +func sliceToString(s []corev1.PersistentVolumeAccessMode, seperator string) string { + var res []string + for _, mode := range s { + res = append(res, string(mode)) + } + return strings.Join(res, seperator) +} + +func GetMetadata(pvc *corev1.PersistentVolumeClaim) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { + meta := maps.MergeStringMaps(map[string]string{}, pvc.Labels) + + meta[AttributeK8SPersistentvolumeclaimName] = pvc.Name + meta[persistentvolumeclaimCreationTime] = pvc.GetCreationTimestamp().Format(time.RFC3339) + + pvcID := experimentalmetricmetadata.ResourceID(pvc.UID) + return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{ + pvcID: { + EntityType: "k8s.persistentvolumeclaim", + ResourceIDKey: AttributeK8SPersistentvolumeclaimUID, + ResourceID: pvcID, + Metadata: meta, + }, + } +} diff --git a/receiver/k8sclusterreceiver/internal/persistentvolumeclaim/persistentvolumeclaim_test.go b/receiver/k8sclusterreceiver/internal/persistentvolumeclaim/persistentvolumeclaim_test.go new file mode 100644 index 000000000000..4dc5d24a22e1 --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/persistentvolumeclaim/persistentvolumeclaim_test.go @@ -0,0 +1,51 @@ +package persistentvolumeclaim + +import ( + "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "testing" +) + +func TestTransform(t *testing.T) { + originalPVC := &corev1.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-pvc", + UID: "my-pvc-uid", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + VolumeName: "my-pv", + AccessModes: []corev1.PersistentVolumeAccessMode{ + corev1.ReadWriteOnce, + corev1.ReadOnlyMany, + }, + }, + Status: corev1.PersistentVolumeClaimStatus{ + Phase: corev1.ClaimBound, + Capacity: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("10Gi"), + }, + }, + } + wantPVC := &corev1.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-pvc", + UID: "my-pvc-uid", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + VolumeName: "my-pv", + AccessModes: []corev1.PersistentVolumeAccessMode{ + corev1.ReadWriteOnce, + corev1.ReadOnlyMany, + }, + }, + Status: corev1.PersistentVolumeClaimStatus{ + Phase: corev1.ClaimBound, + Capacity: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("10Gi"), + }, + }, + } + assert.Equal(t, wantPVC, Transform(originalPVC)) +} diff --git a/receiver/k8sclusterreceiver/metadata.yaml b/receiver/k8sclusterreceiver/metadata.yaml index 777649ac9fc7..26258287f4d5 100644 --- a/receiver/k8sclusterreceiver/metadata.yaml +++ b/receiver/k8sclusterreceiver/metadata.yaml @@ -148,6 +148,66 @@ resource_attributes: type: string enabled: true + k8s.persistentvolumeclaim.namespace: + description: The namespace of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.labels: + description: Labels of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.phase: + description: The phase of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.selector: + description: The selector of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.storage_class: + description: The storage class of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.volume_mode: + description: The volume mode of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.access_modes: + description: Access modes of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.finalizers: + description: Finalizers of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.start_time: + description: The start time of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.annotations: + description: The annotations of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.volume_name: + description: The volume name of the Persistent Volume Claim. + type: string + enabled: true + + k8s.persistentvolumeclaim.type: + description: The type of the Persistent Volume Claim. + type: string + enabled: true + container.id: description: The container id. type: string @@ -178,11 +238,6 @@ resource_attributes: type: string enabled: true - k8s.pod.start_time: - description: "The start time of the Pod." - enabled: true - type: string - k8s.replicaset.name: description: The k8s replicaset name type: string @@ -420,6 +475,20 @@ metrics: gauge: value_type: int + k8s.persistentvolumeclaim.capacity: + enabled: true + description: The capacity of persistent volume claim. + unit: "By" + gauge: + value_type: int + + k8s.persistentvolumeclaim.allocated: + enabled: true + description: The allocated capacity of persistent volume. + unit: "By" + gauge: + value_type: int + k8s.deployment.desired: enabled: true description: Number of desired pods in this deployment diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index 75591e48ba16..38dc452e6506 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -41,6 +41,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/node" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/persistentvolume" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/persistentvolumeclaim" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/pod" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/replicaset" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/replicationcontroller" @@ -131,6 +132,7 @@ func (rw *resourceWatcher) prepareSharedInformerFactory() error { "Pod": {gvk.Pod}, "Node": {gvk.Node}, "PersistentVolume": {gvk.PersistentVolume}, + "PersistentVolumeClaim": {gvk.PersistentVolumeClaim}, "Namespace": {gvk.Namespace}, "ReplicationController": {gvk.ReplicationController}, "ResourceQuota": {gvk.ResourceQuota}, @@ -198,6 +200,8 @@ func (rw *resourceWatcher) setupInformerForKind(kind schema.GroupVersionKind, fa rw.setupInformer(kind, factory.Core().V1().Nodes().Informer()) case gvk.PersistentVolume: rw.setupInformer(kind, factory.Core().V1().PersistentVolumes().Informer()) + case gvk.PersistentVolumeClaim: + rw.setupInformer(kind, factory.Core().V1().PersistentVolumeClaims().Informer()) case gvk.Namespace: rw.setupInformer(kind, factory.Core().V1().Namespaces().Informer()) case gvk.ReplicationController: @@ -300,6 +304,8 @@ func (rw *resourceWatcher) objMetadata(obj interface{}) map[experimentalmetricme return node.GetMetadata(o) case *corev1.PersistentVolume: return persistentvolume.GetMetadata(o) + case *corev1.PersistentVolumeClaim: + return persistentvolumeclaim.GetMetadata(o) case *corev1.ReplicationController: return replicationcontroller.GetMetadata(o) case *appsv1.Deployment: