From 9d719b2f060ff792f34bff55540124869968de3c Mon Sep 17 00:00:00 2001 From: Sanjay Suthar <21999586+sanjoyment@users.noreply.github.com> Date: Wed, 21 Feb 2024 10:58:06 +0530 Subject: [PATCH] Added Role, RoleBinding, ClusterRole, ClusterRoleBinding and ServiceAccount modules (#45) * ENG-947 & ENG-1241: Removed Persistent-Volume from transformObject flow * ENG-947: Added Persistent-Volume-Claim flow * ENG-1948, ENG-1949 & ENG-1955: Added Role, RoleBinding, ClusterRole, ClusterRoleBinding and ServiceAccount modules * ENG-1948, ENG-1949 & ENG-1955: Added Role, RoleBinding, ClusterRole, ClusterRoleBinding and ServiceAccount modules --- receiver/k8sclusterreceiver/documentation.md | 82 ++ .../internal/clusterrole/clusterrole.go | 98 +++ .../internal/clusterrole/clusterrole_test.go | 24 + .../clusterrolebinding/clusterrolebinding.go | 95 +++ .../clusterrolebinding_test.go | 24 + .../internal/collection/collector.go | 24 +- .../k8sclusterreceiver/internal/gvk/gvk.go | 5 + .../internal/metadata/generated_config.go | 336 ++++++-- .../metadata/generated_config_test.go | 770 +++++++++++------- .../internal/metadata/generated_metrics.go | 299 ++++++- .../metadata/generated_metrics_test.go | 122 +++ .../internal/metadata/generated_resource.go | 294 +++++++ .../metadata/generated_resource_test.go | 256 +++++- .../internal/metadata/testdata/config.yaml | 188 +++++ .../k8sclusterreceiver/internal/role/role.go | 99 +++ .../internal/role/role_test.go | 24 + .../internal/rolebinding/rolebinding.go | 96 +++ .../internal/rolebinding/rolebinding_test.go | 24 + .../internal/serviceaccount/serviceaccount.go | 109 +++ .../serviceaccount/serviceaccount_test.go | 24 + receiver/k8sclusterreceiver/metadata.yaml | 245 ++++++ receiver/k8sclusterreceiver/watcher.go | 31 + 22 files changed, 2888 insertions(+), 381 deletions(-) create mode 100644 receiver/k8sclusterreceiver/internal/clusterrole/clusterrole.go create mode 100644 receiver/k8sclusterreceiver/internal/clusterrole/clusterrole_test.go create mode 100644 receiver/k8sclusterreceiver/internal/clusterrolebinding/clusterrolebinding.go create mode 100644 receiver/k8sclusterreceiver/internal/clusterrolebinding/clusterrolebinding_test.go create mode 100644 receiver/k8sclusterreceiver/internal/role/role.go create mode 100644 receiver/k8sclusterreceiver/internal/role/role_test.go create mode 100644 receiver/k8sclusterreceiver/internal/rolebinding/rolebinding.go create mode 100644 receiver/k8sclusterreceiver/internal/rolebinding/rolebinding_test.go create mode 100644 receiver/k8sclusterreceiver/internal/serviceaccount/serviceaccount.go create mode 100644 receiver/k8sclusterreceiver/internal/serviceaccount/serviceaccount_test.go diff --git a/receiver/k8sclusterreceiver/documentation.md b/receiver/k8sclusterreceiver/documentation.md index 1d5eac04254a..91c6acb9e363 100644 --- a/receiver/k8sclusterreceiver/documentation.md +++ b/receiver/k8sclusterreceiver/documentation.md @@ -12,6 +12,22 @@ metrics: enabled: false ``` +### k8s.clusterrole.rule_count + +The count of cluster roles. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| 1 | Gauge | Int | + +### k8s.clusterrolebinding.subject_count + +The subject count of cluster role bindings. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| 1 | Gauge | Int | + ### k8s.container.cpu_limit Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details @@ -320,6 +336,22 @@ The usage for a particular resource in a specific namespace. Will only be sent i | ---- | ----------- | ------ | | resource | the name of the resource on which the quota is applied | Any Str | +### k8s.role.rule_count + +The count of roles. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| 1 | Gauge | Int | + +### k8s.rolebinding.subject_count + +The subject count of role bindings. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| 1 | Gauge | Int | + ### k8s.service.port_count The number of ports in the service @@ -328,6 +360,14 @@ The number of ports in the service | ---- | ----------- | ---------- | | 1 | Gauge | Int | +### k8s.serviceaccount.secret_count + +The count of secrets in Service Account. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| 1 | Gauge | Int | + ### k8s.statefulset.current_pods The number of pods created by the StatefulSet controller from the StatefulSet version @@ -444,6 +484,21 @@ Current status reason of the pod (1 - Evicted, 2 - NodeAffinity, 3 - NodeLost, 4 | container.image.name | The container image name | Any Str | true | | container.image.tag | The container image tag | Any Str | true | | k8s.cluster.name | The k8s cluster name. | Any Str | true | +| k8s.clusterrole.annotations | Annotations of the Cluster Role. | Any Str | true | +| k8s.clusterrole.labels | Labels of the Cluster Role. | Any Str | true | +| k8s.clusterrole.name | The name of the Cluster Role. | Any Str | true | +| k8s.clusterrole.rules | Rules of the Cluster Role. | Any Str | true | +| k8s.clusterrole.start_time | The start time of the Cluster Role. | Any Str | true | +| k8s.clusterrole.type | The type of the Cluster Role. | Any Str | true | +| k8s.clusterrole.uid | The UID of the Role. | Any Str | true | +| k8s.clusterrolebinding.annotations | Annotations of the Cluster Role Binding. | Any Str | true | +| k8s.clusterrolebinding.labels | Labels of the Cluster Role Binding. | Any Str | true | +| k8s.clusterrolebinding.name | The name of the Cluster Role Binding. | Any Str | true | +| k8s.clusterrolebinding.role_ref | RoleRef can reference a Cluster Role. | Any Str | true | +| k8s.clusterrolebinding.start_time | The start time of the Cluster Role Binding. | Any Str | true | +| k8s.clusterrolebinding.subjects | Subjects holds references to the objects, the cluster role applies to. | Any Str | true | +| k8s.clusterrolebinding.type | The type of the Cluster Role Binding. | Any Str | true | +| k8s.clusterrolebinding.uid | The UID of the Cluster Role Binding. | Any Str | true | | k8s.container.name | The k8s container name | Any Str | true | | k8s.cronjob.name | The k8s CronJob name | Any Str | true | | k8s.cronjob.start_time | The start time of the Cronjob. | Any Str | true | @@ -502,12 +557,39 @@ Current status reason of the pod (1 - Evicted, 2 - NodeAffinity, 3 - NodeLost, 4 | k8s.replicationcontroller.uid | The k8s replicationcontroller uid. | Any Str | true | | k8s.resourcequota.name | The k8s resourcequota name. | Any Str | true | | k8s.resourcequota.uid | The k8s resourcequota uid. | Any Str | true | +| k8s.role.annotations | Annotations of the Role. | Any Str | true | +| k8s.role.labels | Labels of the Role. | Any Str | true | +| k8s.role.name | The name of the Role. | Any Str | true | +| k8s.role.namespace | The namespace of the Role. | Any Str | true | +| k8s.role.rules | Rules of the Role. | Any Str | true | +| k8s.role.start_time | The start time of the Role. | Any Str | true | +| k8s.role.type | The type of the Role. | Any Str | true | +| k8s.role.uid | The UID of the Role. | Any Str | true | +| k8s.rolebinding.annotations | Annotations of the Role Binding. | Any Str | true | +| k8s.rolebinding.labels | Labels of the Role Binding. | Any Str | true | +| k8s.rolebinding.name | The name of the Role Binding. | Any Str | true | +| k8s.rolebinding.namespace | The namespace of the Role Binding. | Any Str | true | +| k8s.rolebinding.role_ref | RoleRef can reference a Role in the current namespace. | Any Str | true | +| k8s.rolebinding.start_time | The start time of the Role Binding. | Any Str | true | +| k8s.rolebinding.subjects | Subjects holds references to the objects, the role applies to. | Any Str | true | +| k8s.rolebinding.type | The type of the Role Binding. | Any Str | true | +| k8s.rolebinding.uid | The UID of the Role Binding. | Any Str | true | | k8s.service.cluster_ip | The cluster IP of the service | Any Str | true | | k8s.service.name | The name of the service | Any Str | true | | k8s.service.namespace | The namespace of the service | Any Str | true | | k8s.service.type | The type of the service | Any Str | true | | k8s.service.uid | The UID of the service | Any Str | true | | k8s.service_account.name | The name of the Service-account | Any Str | true | +| k8s.serviceaccount.annotations | Annotations of the Service Account. | Any Str | true | +| k8s.serviceaccount.automount_serviceaccount_token | Automount service account token of the Service Account. | Any Str | true | +| k8s.serviceaccount.image_pull_secrets | Image pull secrets of the Service Account. | Any Str | true | +| k8s.serviceaccount.labels | Labels of the Service Account. | Any Str | true | +| k8s.serviceaccount.name | The name of the Service Account. | Any Str | true | +| k8s.serviceaccount.namespace | The namespace of the Service Account. | Any Str | true | +| k8s.serviceaccount.secrets | Secrets of the Service Account. | Any Str | true | +| k8s.serviceaccount.start_time | The start time of the Service Account. | Any Str | true | +| k8s.serviceaccount.type | The type of the Service Account. | Any Str | true | +| k8s.serviceaccount.uid | The UID of the Service Account. | Any Str | true | | k8s.statefulset.name | The k8s statefulset name. | Any Str | true | | k8s.statefulset.start_time | The start time of the Statefulset. | Any Str | true | | k8s.statefulset.uid | The k8s statefulset uid. | Any Str | true | diff --git a/receiver/k8sclusterreceiver/internal/clusterrole/clusterrole.go b/receiver/k8sclusterreceiver/internal/clusterrole/clusterrole.go new file mode 100644 index 000000000000..fdb743a5422d --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/clusterrole/clusterrole.go @@ -0,0 +1,98 @@ +package clusterrole + +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" + rbacv1 "k8s.io/api/rbac/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 clusterrole metadata. + AttributeK8SClusterRoleUID = "k8s.clusterrole.uid" + AttributeK8SClusterRoleName = "k8s.clusterrole.name" + ClusterRoleCreationTime = "clusterrole.creation_timestamp" +) + +// Transform transforms the clusterrole to remove the fields. +// IMPORTANT: Make sure to update this function before using new clusterrole fields. +func Transform(r *rbacv1.ClusterRole) *rbacv1.ClusterRole { + newCR := &rbacv1.ClusterRole{ + ObjectMeta: metadata.TransformObjectMeta(r.ObjectMeta), + } + return newCR +} + +func RecordMetrics(mb *imetadata.MetricsBuilder, cr *rbacv1.ClusterRole, ts pcommon.Timestamp) { + mb.RecordK8sClusterroleRuleCountDataPoint(ts, int64(len(cr.Rules))) + + rb := mb.NewResourceBuilder() + rb.SetK8sClusterroleUID(string(cr.GetUID())) + rb.SetK8sClusterroleName(cr.GetName()) + rb.SetK8sClusterName("unknown") + rb.SetK8sClusterroleType("ClusterRole") + rb.SetK8sClusterroleStartTime(cr.GetCreationTimestamp().String()) + rb.SetK8sClusterroleLabels(mapToString(cr.GetLabels(), "&")) + rb.SetK8sClusterroleAnnotations(mapToString(cr.GetAnnotations(), "&")) + rb.SetK8sClusterroleRules(convertRulesToString(cr.Rules)) + 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 convertRulesToString(rules []rbacv1.PolicyRule) string { + var result strings.Builder + + for i, rule := range rules { + if i > 0 { + result.WriteString(";") + } + + result.WriteString("verbs=") + result.WriteString(strings.Join(rule.Verbs, ",")) + + result.WriteString("&apiGroups=") + result.WriteString(strings.Join(rule.APIGroups, ",")) + + result.WriteString("&resources=") + result.WriteString(strings.Join(rule.Resources, ",")) + + result.WriteString("&resourceNames=") + result.WriteString(strings.Join(rule.ResourceNames, ",")) + + result.WriteString("&nonResourceURLs=") + result.WriteString(strings.Join(rule.NonResourceURLs, ",")) + + } + + return result.String() +} + +func GetMetadata(r *rbacv1.ClusterRole) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { + meta := maps.MergeStringMaps(map[string]string{}, r.Labels) + + meta[AttributeK8SClusterRoleName] = r.Name + meta[ClusterRoleCreationTime] = r.GetCreationTimestamp().Format(time.RFC3339) + + rID := experimentalmetricmetadata.ResourceID(r.UID) + return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{ + rID: { + EntityType: "k8s.clusterrole", + ResourceIDKey: AttributeK8SClusterRoleUID, + ResourceID: rID, + Metadata: meta, + }, + } +} diff --git a/receiver/k8sclusterreceiver/internal/clusterrole/clusterrole_test.go b/receiver/k8sclusterreceiver/internal/clusterrole/clusterrole_test.go new file mode 100644 index 000000000000..e5b395374e3a --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/clusterrole/clusterrole_test.go @@ -0,0 +1,24 @@ +package clusterrole + +import ( + "github.com/stretchr/testify/assert" + rbacv1 "k8s.io/api/rbac/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "testing" +) + +func TestTransform(t *testing.T) { + originalCR := &rbacv1.ClusterRole{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-cr", + UID: "my-cr-uid", + }, + } + wantCR := &rbacv1.ClusterRole{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-cr", + UID: "my-cr-uid", + }, + } + assert.Equal(t, wantCR, Transform(originalCR)) +} diff --git a/receiver/k8sclusterreceiver/internal/clusterrolebinding/clusterrolebinding.go b/receiver/k8sclusterreceiver/internal/clusterrolebinding/clusterrolebinding.go new file mode 100644 index 000000000000..07aa640967f6 --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/clusterrolebinding/clusterrolebinding.go @@ -0,0 +1,95 @@ +package clusterrolebinding + +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" + rbacv1 "k8s.io/api/rbac/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 clusterrolebinding metadata. + AttributeK8SClusterRoleBindingUID = "k8s.clusterrolebinding.uid" + AttributeK8SClusterRoleBindingName = "k8s.clusterrolebinding.name" + ClusterRoleBindingCreationTime = "clusterrolebinding.creation_timestamp" +) + +// Transform transforms the clusterrolebinding to remove the fields. +// IMPORTANT: Make sure to update this function before using new clusterrolebinding fields. +func Transform(rb *rbacv1.ClusterRoleBinding) *rbacv1.ClusterRoleBinding { + newCRB := &rbacv1.ClusterRoleBinding{ + ObjectMeta: metadata.TransformObjectMeta(rb.ObjectMeta), + } + return newCRB +} + +func RecordMetrics(mb *imetadata.MetricsBuilder, crbind *rbacv1.ClusterRoleBinding, ts pcommon.Timestamp) { + mb.RecordK8sClusterrolebindingSubjectCountDataPoint(ts, int64(len(crbind.Subjects))) + + rb := mb.NewResourceBuilder() + rb.SetK8sClusterrolebindingUID(string(crbind.GetUID())) + rb.SetK8sClusterrolebindingName(crbind.GetName()) + rb.SetK8sClusterName("unknown") + rb.SetK8sClusterrolebindingLabels(mapToString(crbind.GetLabels(), "&")) + rb.SetK8sClusterrolebindingAnnotations(mapToString(crbind.GetAnnotations(), "&")) + rb.SetK8sClusterrolebindingStartTime(crbind.GetCreationTimestamp().String()) + rb.SetK8sClusterrolebindingType("ClusterRoleBinding") + rb.SetK8sClusterrolebindingSubjects(convertSubjectsToString(crbind.Subjects)) + rb.SetK8sClusterrolebindingRoleRef(fmt.Sprintf("apiGroup=%s&kind=%s&name=%s", + crbind.RoleRef.APIGroup, + crbind.RoleRef.Kind, + crbind.RoleRef.Name)) + 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 convertSubjectsToString(subjects []rbacv1.Subject) string { + var result strings.Builder + + for i, subject := range subjects { + if i > 0 { + result.WriteString(";") + } + + result.WriteString("kind=") + result.WriteString(subject.Kind) + + result.WriteString("&name=") + result.WriteString(subject.Name) + + result.WriteString("&namespace=") + result.WriteString(subject.Namespace) + } + + return result.String() +} + +func GetMetadata(crb *rbacv1.ClusterRoleBinding) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { + meta := maps.MergeStringMaps(map[string]string{}, crb.Labels) + + meta[AttributeK8SClusterRoleBindingName] = crb.Name + meta[ClusterRoleBindingCreationTime] = crb.GetCreationTimestamp().Format(time.RFC3339) + + crbID := experimentalmetricmetadata.ResourceID(crb.UID) + return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{ + crbID: { + EntityType: "k8s.clusterrolebinding", + ResourceIDKey: AttributeK8SClusterRoleBindingUID, + ResourceID: crbID, + Metadata: meta, + }, + } +} diff --git a/receiver/k8sclusterreceiver/internal/clusterrolebinding/clusterrolebinding_test.go b/receiver/k8sclusterreceiver/internal/clusterrolebinding/clusterrolebinding_test.go new file mode 100644 index 000000000000..f72eb6e1de58 --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/clusterrolebinding/clusterrolebinding_test.go @@ -0,0 +1,24 @@ +package clusterrolebinding + +import ( + "github.com/stretchr/testify/assert" + rbacv1 "k8s.io/api/rbac/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "testing" +) + +func TestTransform(t *testing.T) { + originalCRB := &rbacv1.ClusterRoleBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-crb", + UID: "my-crb-uid", + }, + } + wantCRB := &rbacv1.ClusterRoleBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-crb", + UID: "my-crb-uid", + }, + } + assert.Equal(t, wantCRB, Transform(originalCRB)) +} diff --git a/receiver/k8sclusterreceiver/internal/collection/collector.go b/receiver/k8sclusterreceiver/internal/collection/collector.go index 00860a1cc155..85d17e7bc9c2 100644 --- a/receiver/k8sclusterreceiver/internal/collection/collector.go +++ b/receiver/k8sclusterreceiver/internal/collection/collector.go @@ -6,8 +6,6 @@ package collection // import "github.com/open-telemetry/opentelemetry-collector- import ( "time" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/service" - quotav1 "github.com/openshift/api/quota/v1" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" @@ -18,8 +16,11 @@ import ( batchv1 "k8s.io/api/batch/v1" batchv1beta1 "k8s.io/api/batch/v1beta1" corev1 "k8s.io/api/core/v1" + rbacv1 "k8s.io/api/rbac/v1" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/clusterresourcequota" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/clusterrole" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/clusterrolebinding" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/cronjob" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/demonset" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/deployment" @@ -35,6 +36,10 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/replicaset" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/replicationcontroller" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/resourcequota" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/role" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/rolebinding" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/service" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/serviceaccount" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/statefulset" ) @@ -85,6 +90,18 @@ func (dc *DataCollector) CollectMetricData(currentTime time.Time) pmetric.Metric dc.metadataStore.ForEach(gvk.PersistentVolumeClaim, func(o any) { persistentvolumeclaim.RecordMetrics(dc.metricsBuilder, o.(*corev1.PersistentVolumeClaim), ts) }) + dc.metadataStore.ForEach(gvk.Role, func(o any) { + role.RecordMetrics(dc.metricsBuilder, o.(*rbacv1.Role), ts) + }) + dc.metadataStore.ForEach(gvk.RoleBinding, func(o any) { + rolebinding.RecordMetrics(dc.metricsBuilder, o.(*rbacv1.RoleBinding), ts) + }) + dc.metadataStore.ForEach(gvk.ClusterRole, func(o any) { + clusterrole.RecordMetrics(dc.metricsBuilder, o.(*rbacv1.ClusterRole), ts) + }) + dc.metadataStore.ForEach(gvk.ClusterRoleBinding, func(o any) { + clusterrolebinding.RecordMetrics(dc.metricsBuilder, o.(*rbacv1.ClusterRoleBinding), ts) + }) dc.metadataStore.ForEach(gvk.Namespace, func(o any) { namespace.RecordMetrics(dc.metricsBuilder, o.(*corev1.Namespace), ts) }) @@ -97,6 +114,9 @@ func (dc *DataCollector) CollectMetricData(currentTime time.Time) pmetric.Metric dc.metadataStore.ForEach(gvk.Service, func(o any) { service.RecordMetrics(dc.metricsBuilder, o.(*corev1.Service), ts) }) + dc.metadataStore.ForEach(gvk.ServiceAccount, func(o any) { + serviceaccount.RecordMetrics(dc.metricsBuilder, o.(*corev1.ServiceAccount), ts) + }) dc.metadataStore.ForEach(gvk.Deployment, func(o any) { deployment.RecordMetrics(dc.metricsBuilder, o.(*appsv1.Deployment), ts) }) diff --git a/receiver/k8sclusterreceiver/internal/gvk/gvk.go b/receiver/k8sclusterreceiver/internal/gvk/gvk.go index 9753596a12b0..d908019ec93b 100644 --- a/receiver/k8sclusterreceiver/internal/gvk/gvk.go +++ b/receiver/k8sclusterreceiver/internal/gvk/gvk.go @@ -15,6 +15,7 @@ var ( ReplicationController = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ReplicationController"} ResourceQuota = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ResourceQuota"} Service = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"} + ServiceAccount = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ServiceAccount"} DaemonSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"} Deployment = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} ReplicaSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"} @@ -25,4 +26,8 @@ var ( HorizontalPodAutoscaler = schema.GroupVersionKind{Group: "autoscaling", Version: "v2", Kind: "HorizontalPodAutoscaler"} HorizontalPodAutoscalerBeta = schema.GroupVersionKind{Group: "autoscaling", Version: "v2beta2", Kind: "HorizontalPodAutoscaler"} ClusterResourceQuota = schema.GroupVersionKind{Group: "quota", Version: "v1", Kind: "ClusterResourceQuota"} + Role = schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Role"} + RoleBinding = schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding"} + ClusterRole = schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"} + ClusterRoleBinding = schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"} ) diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_config.go b/receiver/k8sclusterreceiver/internal/metadata/generated_config.go index feb80ea7e7aa..17bfd4d80507 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_config.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_config.go @@ -25,6 +25,8 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { // MetricsConfig provides config for k8s_cluster metrics. type MetricsConfig struct { + K8sClusterroleRuleCount MetricConfig `mapstructure:"k8s.clusterrole.rule_count"` + K8sClusterrolebindingSubjectCount MetricConfig `mapstructure:"k8s.clusterrolebinding.subject_count"` K8sContainerCPULimit MetricConfig `mapstructure:"k8s.container.cpu_limit"` K8sContainerCPURequest MetricConfig `mapstructure:"k8s.container.cpu_request"` K8sContainerEphemeralstorageLimit MetricConfig `mapstructure:"k8s.container.ephemeralstorage_limit"` @@ -63,7 +65,10 @@ type MetricsConfig struct { K8sReplicationControllerDesired MetricConfig `mapstructure:"k8s.replication_controller.desired"` K8sResourceQuotaHardLimit MetricConfig `mapstructure:"k8s.resource_quota.hard_limit"` K8sResourceQuotaUsed MetricConfig `mapstructure:"k8s.resource_quota.used"` + K8sRoleRuleCount MetricConfig `mapstructure:"k8s.role.rule_count"` + K8sRolebindingSubjectCount MetricConfig `mapstructure:"k8s.rolebinding.subject_count"` K8sServicePortCount MetricConfig `mapstructure:"k8s.service.port_count"` + K8sServiceaccountSecretCount MetricConfig `mapstructure:"k8s.serviceaccount.secret_count"` K8sStatefulsetCurrentPods MetricConfig `mapstructure:"k8s.statefulset.current_pods"` K8sStatefulsetDesiredPods MetricConfig `mapstructure:"k8s.statefulset.desired_pods"` K8sStatefulsetReadyPods MetricConfig `mapstructure:"k8s.statefulset.ready_pods"` @@ -76,6 +81,12 @@ type MetricsConfig struct { func DefaultMetricsConfig() MetricsConfig { return MetricsConfig{ + K8sClusterroleRuleCount: MetricConfig{ + Enabled: true, + }, + K8sClusterrolebindingSubjectCount: MetricConfig{ + Enabled: true, + }, K8sContainerCPULimit: MetricConfig{ Enabled: true, }, @@ -190,9 +201,18 @@ func DefaultMetricsConfig() MetricsConfig { K8sResourceQuotaUsed: MetricConfig{ Enabled: true, }, + K8sRoleRuleCount: MetricConfig{ + Enabled: true, + }, + K8sRolebindingSubjectCount: MetricConfig{ + Enabled: true, + }, K8sServicePortCount: MetricConfig{ Enabled: true, }, + K8sServiceaccountSecretCount: MetricConfig{ + Enabled: true, + }, K8sStatefulsetCurrentPods: MetricConfig{ Enabled: true, }, @@ -227,80 +247,122 @@ type ResourceAttributeConfig struct { // 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"` - 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"` + ContainerID ResourceAttributeConfig `mapstructure:"container.id"` + ContainerImageName ResourceAttributeConfig `mapstructure:"container.image.name"` + ContainerImageTag ResourceAttributeConfig `mapstructure:"container.image.tag"` + K8sClusterName ResourceAttributeConfig `mapstructure:"k8s.cluster.name"` + K8sClusterroleAnnotations ResourceAttributeConfig `mapstructure:"k8s.clusterrole.annotations"` + K8sClusterroleLabels ResourceAttributeConfig `mapstructure:"k8s.clusterrole.labels"` + K8sClusterroleName ResourceAttributeConfig `mapstructure:"k8s.clusterrole.name"` + K8sClusterroleRules ResourceAttributeConfig `mapstructure:"k8s.clusterrole.rules"` + K8sClusterroleStartTime ResourceAttributeConfig `mapstructure:"k8s.clusterrole.start_time"` + K8sClusterroleType ResourceAttributeConfig `mapstructure:"k8s.clusterrole.type"` + K8sClusterroleUID ResourceAttributeConfig `mapstructure:"k8s.clusterrole.uid"` + K8sClusterrolebindingAnnotations ResourceAttributeConfig `mapstructure:"k8s.clusterrolebinding.annotations"` + K8sClusterrolebindingLabels ResourceAttributeConfig `mapstructure:"k8s.clusterrolebinding.labels"` + K8sClusterrolebindingName ResourceAttributeConfig `mapstructure:"k8s.clusterrolebinding.name"` + K8sClusterrolebindingRoleRef ResourceAttributeConfig `mapstructure:"k8s.clusterrolebinding.role_ref"` + K8sClusterrolebindingStartTime ResourceAttributeConfig `mapstructure:"k8s.clusterrolebinding.start_time"` + K8sClusterrolebindingSubjects ResourceAttributeConfig `mapstructure:"k8s.clusterrolebinding.subjects"` + K8sClusterrolebindingType ResourceAttributeConfig `mapstructure:"k8s.clusterrolebinding.type"` + K8sClusterrolebindingUID ResourceAttributeConfig `mapstructure:"k8s.clusterrolebinding.uid"` + 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"` + K8sRoleAnnotations ResourceAttributeConfig `mapstructure:"k8s.role.annotations"` + K8sRoleLabels ResourceAttributeConfig `mapstructure:"k8s.role.labels"` + K8sRoleName ResourceAttributeConfig `mapstructure:"k8s.role.name"` + K8sRoleNamespace ResourceAttributeConfig `mapstructure:"k8s.role.namespace"` + K8sRoleRules ResourceAttributeConfig `mapstructure:"k8s.role.rules"` + K8sRoleStartTime ResourceAttributeConfig `mapstructure:"k8s.role.start_time"` + K8sRoleType ResourceAttributeConfig `mapstructure:"k8s.role.type"` + K8sRoleUID ResourceAttributeConfig `mapstructure:"k8s.role.uid"` + K8sRolebindingAnnotations ResourceAttributeConfig `mapstructure:"k8s.rolebinding.annotations"` + K8sRolebindingLabels ResourceAttributeConfig `mapstructure:"k8s.rolebinding.labels"` + K8sRolebindingName ResourceAttributeConfig `mapstructure:"k8s.rolebinding.name"` + K8sRolebindingNamespace ResourceAttributeConfig `mapstructure:"k8s.rolebinding.namespace"` + K8sRolebindingRoleRef ResourceAttributeConfig `mapstructure:"k8s.rolebinding.role_ref"` + K8sRolebindingStartTime ResourceAttributeConfig `mapstructure:"k8s.rolebinding.start_time"` + K8sRolebindingSubjects ResourceAttributeConfig `mapstructure:"k8s.rolebinding.subjects"` + K8sRolebindingType ResourceAttributeConfig `mapstructure:"k8s.rolebinding.type"` + K8sRolebindingUID ResourceAttributeConfig `mapstructure:"k8s.rolebinding.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"` + K8sServiceaccountAnnotations ResourceAttributeConfig `mapstructure:"k8s.serviceaccount.annotations"` + K8sServiceaccountAutomountServiceaccountToken ResourceAttributeConfig `mapstructure:"k8s.serviceaccount.automount_serviceaccount_token"` + K8sServiceaccountImagePullSecrets ResourceAttributeConfig `mapstructure:"k8s.serviceaccount.image_pull_secrets"` + K8sServiceaccountLabels ResourceAttributeConfig `mapstructure:"k8s.serviceaccount.labels"` + K8sServiceaccountName ResourceAttributeConfig `mapstructure:"k8s.serviceaccount.name"` + K8sServiceaccountNamespace ResourceAttributeConfig `mapstructure:"k8s.serviceaccount.namespace"` + K8sServiceaccountSecrets ResourceAttributeConfig `mapstructure:"k8s.serviceaccount.secrets"` + K8sServiceaccountStartTime ResourceAttributeConfig `mapstructure:"k8s.serviceaccount.start_time"` + K8sServiceaccountType ResourceAttributeConfig `mapstructure:"k8s.serviceaccount.type"` + K8sServiceaccountUID ResourceAttributeConfig `mapstructure:"k8s.serviceaccount.uid"` + 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 { @@ -317,6 +379,51 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { K8sClusterName: ResourceAttributeConfig{ Enabled: true, }, + K8sClusterroleAnnotations: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterroleLabels: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterroleName: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterroleRules: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterroleStartTime: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterroleType: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterroleUID: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterrolebindingAnnotations: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterrolebindingLabels: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterrolebindingName: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterrolebindingRoleRef: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterrolebindingStartTime: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterrolebindingSubjects: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterrolebindingType: ResourceAttributeConfig{ + Enabled: true, + }, + K8sClusterrolebindingUID: ResourceAttributeConfig{ + Enabled: true, + }, K8sContainerName: ResourceAttributeConfig{ Enabled: true, }, @@ -491,6 +598,57 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { K8sResourcequotaUID: ResourceAttributeConfig{ Enabled: true, }, + K8sRoleAnnotations: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRoleLabels: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRoleName: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRoleNamespace: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRoleRules: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRoleStartTime: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRoleType: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRoleUID: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRolebindingAnnotations: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRolebindingLabels: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRolebindingName: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRolebindingNamespace: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRolebindingRoleRef: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRolebindingStartTime: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRolebindingSubjects: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRolebindingType: ResourceAttributeConfig{ + Enabled: true, + }, + K8sRolebindingUID: ResourceAttributeConfig{ + Enabled: true, + }, K8sServiceClusterIP: ResourceAttributeConfig{ Enabled: true, }, @@ -509,6 +667,36 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { K8sServiceAccountName: ResourceAttributeConfig{ Enabled: true, }, + K8sServiceaccountAnnotations: ResourceAttributeConfig{ + Enabled: true, + }, + K8sServiceaccountAutomountServiceaccountToken: ResourceAttributeConfig{ + Enabled: true, + }, + K8sServiceaccountImagePullSecrets: ResourceAttributeConfig{ + Enabled: true, + }, + K8sServiceaccountLabels: ResourceAttributeConfig{ + Enabled: true, + }, + K8sServiceaccountName: ResourceAttributeConfig{ + Enabled: true, + }, + K8sServiceaccountNamespace: ResourceAttributeConfig{ + Enabled: true, + }, + K8sServiceaccountSecrets: ResourceAttributeConfig{ + Enabled: true, + }, + K8sServiceaccountStartTime: ResourceAttributeConfig{ + Enabled: true, + }, + K8sServiceaccountType: ResourceAttributeConfig{ + Enabled: true, + }, + K8sServiceaccountUID: ResourceAttributeConfig{ + Enabled: true, + }, K8sStatefulsetName: ResourceAttributeConfig{ Enabled: true, }, diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go b/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go index 36259d96c319..6a38139fe5c2 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_config_test.go @@ -26,6 +26,8 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "all_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ + K8sClusterroleRuleCount: MetricConfig{Enabled: true}, + K8sClusterrolebindingSubjectCount: MetricConfig{Enabled: true}, K8sContainerCPULimit: MetricConfig{Enabled: true}, K8sContainerCPURequest: MetricConfig{Enabled: true}, K8sContainerEphemeralstorageLimit: MetricConfig{Enabled: true}, @@ -64,7 +66,10 @@ func TestMetricsBuilderConfig(t *testing.T) { K8sReplicationControllerDesired: MetricConfig{Enabled: true}, K8sResourceQuotaHardLimit: MetricConfig{Enabled: true}, K8sResourceQuotaUsed: MetricConfig{Enabled: true}, + K8sRoleRuleCount: MetricConfig{Enabled: true}, + K8sRolebindingSubjectCount: MetricConfig{Enabled: true}, K8sServicePortCount: MetricConfig{Enabled: true}, + K8sServiceaccountSecretCount: MetricConfig{Enabled: true}, K8sStatefulsetCurrentPods: MetricConfig{Enabled: true}, K8sStatefulsetDesiredPods: MetricConfig{Enabled: true}, K8sStatefulsetReadyPods: MetricConfig{Enabled: true}, @@ -75,80 +80,122 @@ 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}, - 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}, + ContainerID: ResourceAttributeConfig{Enabled: true}, + ContainerImageName: ResourceAttributeConfig{Enabled: true}, + ContainerImageTag: ResourceAttributeConfig{Enabled: true}, + K8sClusterName: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleLabels: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleName: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleRules: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleStartTime: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleType: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleUID: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingLabels: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingName: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingRoleRef: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingStartTime: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingSubjects: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingType: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingUID: 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}, + K8sRoleAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sRoleLabels: ResourceAttributeConfig{Enabled: true}, + K8sRoleName: ResourceAttributeConfig{Enabled: true}, + K8sRoleNamespace: ResourceAttributeConfig{Enabled: true}, + K8sRoleRules: ResourceAttributeConfig{Enabled: true}, + K8sRoleStartTime: ResourceAttributeConfig{Enabled: true}, + K8sRoleType: ResourceAttributeConfig{Enabled: true}, + K8sRoleUID: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingLabels: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingName: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingNamespace: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingRoleRef: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingStartTime: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingSubjects: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingType: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingUID: 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}, + K8sServiceaccountAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountAutomountServiceaccountToken: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountImagePullSecrets: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountLabels: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountName: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountNamespace: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountSecrets: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountStartTime: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountType: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountUID: 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}, }, }, }, @@ -156,6 +203,8 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "none_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ + K8sClusterroleRuleCount: MetricConfig{Enabled: false}, + K8sClusterrolebindingSubjectCount: MetricConfig{Enabled: false}, K8sContainerCPULimit: MetricConfig{Enabled: false}, K8sContainerCPURequest: MetricConfig{Enabled: false}, K8sContainerEphemeralstorageLimit: MetricConfig{Enabled: false}, @@ -194,7 +243,10 @@ func TestMetricsBuilderConfig(t *testing.T) { K8sReplicationControllerDesired: MetricConfig{Enabled: false}, K8sResourceQuotaHardLimit: MetricConfig{Enabled: false}, K8sResourceQuotaUsed: MetricConfig{Enabled: false}, + K8sRoleRuleCount: MetricConfig{Enabled: false}, + K8sRolebindingSubjectCount: MetricConfig{Enabled: false}, K8sServicePortCount: MetricConfig{Enabled: false}, + K8sServiceaccountSecretCount: MetricConfig{Enabled: false}, K8sStatefulsetCurrentPods: MetricConfig{Enabled: false}, K8sStatefulsetDesiredPods: MetricConfig{Enabled: false}, K8sStatefulsetReadyPods: MetricConfig{Enabled: false}, @@ -205,80 +257,122 @@ 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}, - 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}, + ContainerID: ResourceAttributeConfig{Enabled: false}, + ContainerImageName: ResourceAttributeConfig{Enabled: false}, + ContainerImageTag: ResourceAttributeConfig{Enabled: false}, + K8sClusterName: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleLabels: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleName: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleRules: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleStartTime: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleType: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleUID: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingLabels: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingName: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingRoleRef: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingStartTime: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingSubjects: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingType: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingUID: 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}, + K8sRoleAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sRoleLabels: ResourceAttributeConfig{Enabled: false}, + K8sRoleName: ResourceAttributeConfig{Enabled: false}, + K8sRoleNamespace: ResourceAttributeConfig{Enabled: false}, + K8sRoleRules: ResourceAttributeConfig{Enabled: false}, + K8sRoleStartTime: ResourceAttributeConfig{Enabled: false}, + K8sRoleType: ResourceAttributeConfig{Enabled: false}, + K8sRoleUID: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingLabels: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingName: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingNamespace: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingRoleRef: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingStartTime: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingSubjects: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingType: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingUID: 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}, + K8sServiceaccountAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountAutomountServiceaccountToken: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountImagePullSecrets: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountLabels: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountName: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountNamespace: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountSecrets: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountStartTime: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountType: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountUID: 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}, }, }, }, @@ -315,159 +409,243 @@ 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}, - 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}, + ContainerID: ResourceAttributeConfig{Enabled: true}, + ContainerImageName: ResourceAttributeConfig{Enabled: true}, + ContainerImageTag: ResourceAttributeConfig{Enabled: true}, + K8sClusterName: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleLabels: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleName: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleRules: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleStartTime: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleType: ResourceAttributeConfig{Enabled: true}, + K8sClusterroleUID: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingLabels: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingName: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingRoleRef: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingStartTime: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingSubjects: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingType: ResourceAttributeConfig{Enabled: true}, + K8sClusterrolebindingUID: 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}, + K8sRoleAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sRoleLabels: ResourceAttributeConfig{Enabled: true}, + K8sRoleName: ResourceAttributeConfig{Enabled: true}, + K8sRoleNamespace: ResourceAttributeConfig{Enabled: true}, + K8sRoleRules: ResourceAttributeConfig{Enabled: true}, + K8sRoleStartTime: ResourceAttributeConfig{Enabled: true}, + K8sRoleType: ResourceAttributeConfig{Enabled: true}, + K8sRoleUID: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingLabels: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingName: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingNamespace: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingRoleRef: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingStartTime: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingSubjects: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingType: ResourceAttributeConfig{Enabled: true}, + K8sRolebindingUID: 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}, + K8sServiceaccountAnnotations: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountAutomountServiceaccountToken: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountImagePullSecrets: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountLabels: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountName: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountNamespace: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountSecrets: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountStartTime: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountType: ResourceAttributeConfig{Enabled: true}, + K8sServiceaccountUID: 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}, - 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}, + ContainerID: ResourceAttributeConfig{Enabled: false}, + ContainerImageName: ResourceAttributeConfig{Enabled: false}, + ContainerImageTag: ResourceAttributeConfig{Enabled: false}, + K8sClusterName: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleLabels: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleName: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleRules: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleStartTime: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleType: ResourceAttributeConfig{Enabled: false}, + K8sClusterroleUID: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingLabels: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingName: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingRoleRef: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingStartTime: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingSubjects: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingType: ResourceAttributeConfig{Enabled: false}, + K8sClusterrolebindingUID: 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}, + K8sRoleAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sRoleLabels: ResourceAttributeConfig{Enabled: false}, + K8sRoleName: ResourceAttributeConfig{Enabled: false}, + K8sRoleNamespace: ResourceAttributeConfig{Enabled: false}, + K8sRoleRules: ResourceAttributeConfig{Enabled: false}, + K8sRoleStartTime: ResourceAttributeConfig{Enabled: false}, + K8sRoleType: ResourceAttributeConfig{Enabled: false}, + K8sRoleUID: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingLabels: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingName: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingNamespace: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingRoleRef: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingStartTime: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingSubjects: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingType: ResourceAttributeConfig{Enabled: false}, + K8sRolebindingUID: 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}, + K8sServiceaccountAnnotations: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountAutomountServiceaccountToken: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountImagePullSecrets: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountLabels: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountName: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountNamespace: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountSecrets: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountStartTime: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountType: ResourceAttributeConfig{Enabled: false}, + K8sServiceaccountUID: 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 6cd8af8be642..6fbaa91dbb16 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_metrics.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_metrics.go @@ -12,6 +12,104 @@ import ( conventions "go.opentelemetry.io/collector/semconv/v1.18.0" ) +type metricK8sClusterroleRuleCount 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.clusterrole.rule_count metric with initial data. +func (m *metricK8sClusterroleRuleCount) init() { + m.data.SetName("k8s.clusterrole.rule_count") + m.data.SetDescription("The count of cluster roles.") + m.data.SetUnit("1") + m.data.SetEmptyGauge() +} + +func (m *metricK8sClusterroleRuleCount) 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 *metricK8sClusterroleRuleCount) 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 *metricK8sClusterroleRuleCount) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricK8sClusterroleRuleCount(cfg MetricConfig) metricK8sClusterroleRuleCount { + m := metricK8sClusterroleRuleCount{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricK8sClusterrolebindingSubjectCount 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.clusterrolebinding.subject_count metric with initial data. +func (m *metricK8sClusterrolebindingSubjectCount) init() { + m.data.SetName("k8s.clusterrolebinding.subject_count") + m.data.SetDescription("The subject count of cluster role bindings.") + m.data.SetUnit("1") + m.data.SetEmptyGauge() +} + +func (m *metricK8sClusterrolebindingSubjectCount) 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 *metricK8sClusterrolebindingSubjectCount) 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 *metricK8sClusterrolebindingSubjectCount) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricK8sClusterrolebindingSubjectCount(cfg MetricConfig) metricK8sClusterrolebindingSubjectCount { + m := metricK8sClusterrolebindingSubjectCount{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricK8sContainerCPULimit struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -1878,6 +1976,104 @@ func newMetricK8sResourceQuotaUsed(cfg MetricConfig) metricK8sResourceQuotaUsed return m } +type metricK8sRoleRuleCount 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.role.rule_count metric with initial data. +func (m *metricK8sRoleRuleCount) init() { + m.data.SetName("k8s.role.rule_count") + m.data.SetDescription("The count of roles.") + m.data.SetUnit("1") + m.data.SetEmptyGauge() +} + +func (m *metricK8sRoleRuleCount) 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 *metricK8sRoleRuleCount) 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 *metricK8sRoleRuleCount) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricK8sRoleRuleCount(cfg MetricConfig) metricK8sRoleRuleCount { + m := metricK8sRoleRuleCount{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricK8sRolebindingSubjectCount 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.rolebinding.subject_count metric with initial data. +func (m *metricK8sRolebindingSubjectCount) init() { + m.data.SetName("k8s.rolebinding.subject_count") + m.data.SetDescription("The subject count of role bindings.") + m.data.SetUnit("1") + m.data.SetEmptyGauge() +} + +func (m *metricK8sRolebindingSubjectCount) 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 *metricK8sRolebindingSubjectCount) 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 *metricK8sRolebindingSubjectCount) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricK8sRolebindingSubjectCount(cfg MetricConfig) metricK8sRolebindingSubjectCount { + m := metricK8sRolebindingSubjectCount{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricK8sServicePortCount struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -1927,6 +2123,55 @@ func newMetricK8sServicePortCount(cfg MetricConfig) metricK8sServicePortCount { return m } +type metricK8sServiceaccountSecretCount 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.serviceaccount.secret_count metric with initial data. +func (m *metricK8sServiceaccountSecretCount) init() { + m.data.SetName("k8s.serviceaccount.secret_count") + m.data.SetDescription("The count of secrets in Service Account.") + m.data.SetUnit("1") + m.data.SetEmptyGauge() +} + +func (m *metricK8sServiceaccountSecretCount) 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 *metricK8sServiceaccountSecretCount) 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 *metricK8sServiceaccountSecretCount) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricK8sServiceaccountSecretCount(cfg MetricConfig) metricK8sServiceaccountSecretCount { + m := metricK8sServiceaccountSecretCount{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricK8sStatefulsetCurrentPods struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -2337,6 +2582,8 @@ type MetricsBuilder struct { metricsCapacity int // maximum observed number of metrics per resource. metricsBuffer pmetric.Metrics // accumulates metrics data before emitting. buildInfo component.BuildInfo // contains version information. + metricK8sClusterroleRuleCount metricK8sClusterroleRuleCount + metricK8sClusterrolebindingSubjectCount metricK8sClusterrolebindingSubjectCount metricK8sContainerCPULimit metricK8sContainerCPULimit metricK8sContainerCPURequest metricK8sContainerCPURequest metricK8sContainerEphemeralstorageLimit metricK8sContainerEphemeralstorageLimit @@ -2375,7 +2622,10 @@ type MetricsBuilder struct { metricK8sReplicationControllerDesired metricK8sReplicationControllerDesired metricK8sResourceQuotaHardLimit metricK8sResourceQuotaHardLimit metricK8sResourceQuotaUsed metricK8sResourceQuotaUsed + metricK8sRoleRuleCount metricK8sRoleRuleCount + metricK8sRolebindingSubjectCount metricK8sRolebindingSubjectCount metricK8sServicePortCount metricK8sServicePortCount + metricK8sServiceaccountSecretCount metricK8sServiceaccountSecretCount metricK8sStatefulsetCurrentPods metricK8sStatefulsetCurrentPods metricK8sStatefulsetDesiredPods metricK8sStatefulsetDesiredPods metricK8sStatefulsetReadyPods metricK8sStatefulsetReadyPods @@ -2398,13 +2648,15 @@ func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption { func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSettings, options ...metricBuilderOption) *MetricsBuilder { mb := &MetricsBuilder{ - config: mbc, - startTime: pcommon.NewTimestampFromTime(time.Now()), - metricsBuffer: pmetric.NewMetrics(), - buildInfo: settings.BuildInfo, - metricK8sContainerCPULimit: newMetricK8sContainerCPULimit(mbc.Metrics.K8sContainerCPULimit), - metricK8sContainerCPURequest: newMetricK8sContainerCPURequest(mbc.Metrics.K8sContainerCPURequest), - metricK8sContainerEphemeralstorageLimit: newMetricK8sContainerEphemeralstorageLimit(mbc.Metrics.K8sContainerEphemeralstorageLimit), + config: mbc, + startTime: pcommon.NewTimestampFromTime(time.Now()), + metricsBuffer: pmetric.NewMetrics(), + buildInfo: settings.BuildInfo, + metricK8sClusterroleRuleCount: newMetricK8sClusterroleRuleCount(mbc.Metrics.K8sClusterroleRuleCount), + metricK8sClusterrolebindingSubjectCount: newMetricK8sClusterrolebindingSubjectCount(mbc.Metrics.K8sClusterrolebindingSubjectCount), + metricK8sContainerCPULimit: newMetricK8sContainerCPULimit(mbc.Metrics.K8sContainerCPULimit), + metricK8sContainerCPURequest: newMetricK8sContainerCPURequest(mbc.Metrics.K8sContainerCPURequest), + metricK8sContainerEphemeralstorageLimit: newMetricK8sContainerEphemeralstorageLimit(mbc.Metrics.K8sContainerEphemeralstorageLimit), metricK8sContainerEphemeralstorageRequest: newMetricK8sContainerEphemeralstorageRequest(mbc.Metrics.K8sContainerEphemeralstorageRequest), metricK8sContainerMemoryLimit: newMetricK8sContainerMemoryLimit(mbc.Metrics.K8sContainerMemoryLimit), metricK8sContainerMemoryRequest: newMetricK8sContainerMemoryRequest(mbc.Metrics.K8sContainerMemoryRequest), @@ -2440,7 +2692,10 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting metricK8sReplicationControllerDesired: newMetricK8sReplicationControllerDesired(mbc.Metrics.K8sReplicationControllerDesired), metricK8sResourceQuotaHardLimit: newMetricK8sResourceQuotaHardLimit(mbc.Metrics.K8sResourceQuotaHardLimit), metricK8sResourceQuotaUsed: newMetricK8sResourceQuotaUsed(mbc.Metrics.K8sResourceQuotaUsed), + metricK8sRoleRuleCount: newMetricK8sRoleRuleCount(mbc.Metrics.K8sRoleRuleCount), + metricK8sRolebindingSubjectCount: newMetricK8sRolebindingSubjectCount(mbc.Metrics.K8sRolebindingSubjectCount), metricK8sServicePortCount: newMetricK8sServicePortCount(mbc.Metrics.K8sServicePortCount), + metricK8sServiceaccountSecretCount: newMetricK8sServiceaccountSecretCount(mbc.Metrics.K8sServiceaccountSecretCount), metricK8sStatefulsetCurrentPods: newMetricK8sStatefulsetCurrentPods(mbc.Metrics.K8sStatefulsetCurrentPods), metricK8sStatefulsetDesiredPods: newMetricK8sStatefulsetDesiredPods(mbc.Metrics.K8sStatefulsetDesiredPods), metricK8sStatefulsetReadyPods: newMetricK8sStatefulsetReadyPods(mbc.Metrics.K8sStatefulsetReadyPods), @@ -2511,6 +2766,8 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { ils.Scope().SetName("otelcol/k8sclusterreceiver") ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) + mb.metricK8sClusterroleRuleCount.emit(ils.Metrics()) + mb.metricK8sClusterrolebindingSubjectCount.emit(ils.Metrics()) mb.metricK8sContainerCPULimit.emit(ils.Metrics()) mb.metricK8sContainerCPURequest.emit(ils.Metrics()) mb.metricK8sContainerEphemeralstorageLimit.emit(ils.Metrics()) @@ -2549,7 +2806,10 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricK8sReplicationControllerDesired.emit(ils.Metrics()) mb.metricK8sResourceQuotaHardLimit.emit(ils.Metrics()) mb.metricK8sResourceQuotaUsed.emit(ils.Metrics()) + mb.metricK8sRoleRuleCount.emit(ils.Metrics()) + mb.metricK8sRolebindingSubjectCount.emit(ils.Metrics()) mb.metricK8sServicePortCount.emit(ils.Metrics()) + mb.metricK8sServiceaccountSecretCount.emit(ils.Metrics()) mb.metricK8sStatefulsetCurrentPods.emit(ils.Metrics()) mb.metricK8sStatefulsetDesiredPods.emit(ils.Metrics()) mb.metricK8sStatefulsetReadyPods.emit(ils.Metrics()) @@ -2578,6 +2838,16 @@ func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { return metrics } +// RecordK8sClusterroleRuleCountDataPoint adds a data point to k8s.clusterrole.rule_count metric. +func (mb *MetricsBuilder) RecordK8sClusterroleRuleCountDataPoint(ts pcommon.Timestamp, val int64) { + mb.metricK8sClusterroleRuleCount.recordDataPoint(mb.startTime, ts, val) +} + +// RecordK8sClusterrolebindingSubjectCountDataPoint adds a data point to k8s.clusterrolebinding.subject_count metric. +func (mb *MetricsBuilder) RecordK8sClusterrolebindingSubjectCountDataPoint(ts pcommon.Timestamp, val int64) { + mb.metricK8sClusterrolebindingSubjectCount.recordDataPoint(mb.startTime, ts, val) +} + // RecordK8sContainerCPULimitDataPoint adds a data point to k8s.container.cpu_limit metric. func (mb *MetricsBuilder) RecordK8sContainerCPULimitDataPoint(ts pcommon.Timestamp, val float64) { mb.metricK8sContainerCPULimit.recordDataPoint(mb.startTime, ts, val) @@ -2768,11 +3038,26 @@ func (mb *MetricsBuilder) RecordK8sResourceQuotaUsedDataPoint(ts pcommon.Timesta mb.metricK8sResourceQuotaUsed.recordDataPoint(mb.startTime, ts, val, resourceAttributeValue) } +// RecordK8sRoleRuleCountDataPoint adds a data point to k8s.role.rule_count metric. +func (mb *MetricsBuilder) RecordK8sRoleRuleCountDataPoint(ts pcommon.Timestamp, val int64) { + mb.metricK8sRoleRuleCount.recordDataPoint(mb.startTime, ts, val) +} + +// RecordK8sRolebindingSubjectCountDataPoint adds a data point to k8s.rolebinding.subject_count metric. +func (mb *MetricsBuilder) RecordK8sRolebindingSubjectCountDataPoint(ts pcommon.Timestamp, val int64) { + mb.metricK8sRolebindingSubjectCount.recordDataPoint(mb.startTime, ts, val) +} + // RecordK8sServicePortCountDataPoint adds a data point to k8s.service.port_count metric. func (mb *MetricsBuilder) RecordK8sServicePortCountDataPoint(ts pcommon.Timestamp, val int64) { mb.metricK8sServicePortCount.recordDataPoint(mb.startTime, ts, val) } +// RecordK8sServiceaccountSecretCountDataPoint adds a data point to k8s.serviceaccount.secret_count metric. +func (mb *MetricsBuilder) RecordK8sServiceaccountSecretCountDataPoint(ts pcommon.Timestamp, val int64) { + mb.metricK8sServiceaccountSecretCount.recordDataPoint(mb.startTime, ts, val) +} + // RecordK8sStatefulsetCurrentPodsDataPoint adds a data point to k8s.statefulset.current_pods metric. func (mb *MetricsBuilder) RecordK8sStatefulsetCurrentPodsDataPoint(ts pcommon.Timestamp, val int64) { mb.metricK8sStatefulsetCurrentPods.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 e32382c487a2..28dbbf20209d 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_metrics_test.go @@ -54,6 +54,14 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount := 0 allMetricsCount := 0 + defaultMetricsCount++ + allMetricsCount++ + mb.RecordK8sClusterroleRuleCountDataPoint(ts, 1) + + defaultMetricsCount++ + allMetricsCount++ + mb.RecordK8sClusterrolebindingSubjectCountDataPoint(ts, 1) + defaultMetricsCount++ allMetricsCount++ mb.RecordK8sContainerCPULimitDataPoint(ts, 1) @@ -205,10 +213,22 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordK8sResourceQuotaUsedDataPoint(ts, 1, "resource-val") + defaultMetricsCount++ + allMetricsCount++ + mb.RecordK8sRoleRuleCountDataPoint(ts, 1) + + defaultMetricsCount++ + allMetricsCount++ + mb.RecordK8sRolebindingSubjectCountDataPoint(ts, 1) + defaultMetricsCount++ allMetricsCount++ mb.RecordK8sServicePortCountDataPoint(ts, 1) + defaultMetricsCount++ + allMetricsCount++ + mb.RecordK8sServiceaccountSecretCountDataPoint(ts, 1) + defaultMetricsCount++ allMetricsCount++ mb.RecordK8sStatefulsetCurrentPodsDataPoint(ts, 1) @@ -246,6 +266,21 @@ func TestMetricsBuilder(t *testing.T) { rb.SetContainerImageName("container.image.name-val") rb.SetContainerImageTag("container.image.tag-val") rb.SetK8sClusterName("k8s.cluster.name-val") + rb.SetK8sClusterroleAnnotations("k8s.clusterrole.annotations-val") + rb.SetK8sClusterroleLabels("k8s.clusterrole.labels-val") + rb.SetK8sClusterroleName("k8s.clusterrole.name-val") + rb.SetK8sClusterroleRules("k8s.clusterrole.rules-val") + rb.SetK8sClusterroleStartTime("k8s.clusterrole.start_time-val") + rb.SetK8sClusterroleType("k8s.clusterrole.type-val") + rb.SetK8sClusterroleUID("k8s.clusterrole.uid-val") + rb.SetK8sClusterrolebindingAnnotations("k8s.clusterrolebinding.annotations-val") + rb.SetK8sClusterrolebindingLabels("k8s.clusterrolebinding.labels-val") + rb.SetK8sClusterrolebindingName("k8s.clusterrolebinding.name-val") + rb.SetK8sClusterrolebindingRoleRef("k8s.clusterrolebinding.role_ref-val") + rb.SetK8sClusterrolebindingStartTime("k8s.clusterrolebinding.start_time-val") + rb.SetK8sClusterrolebindingSubjects("k8s.clusterrolebinding.subjects-val") + rb.SetK8sClusterrolebindingType("k8s.clusterrolebinding.type-val") + rb.SetK8sClusterrolebindingUID("k8s.clusterrolebinding.uid-val") rb.SetK8sContainerName("k8s.container.name-val") rb.SetK8sCronjobName("k8s.cronjob.name-val") rb.SetK8sCronjobStartTime("k8s.cronjob.start_time-val") @@ -304,12 +339,39 @@ func TestMetricsBuilder(t *testing.T) { rb.SetK8sReplicationcontrollerUID("k8s.replicationcontroller.uid-val") rb.SetK8sResourcequotaName("k8s.resourcequota.name-val") rb.SetK8sResourcequotaUID("k8s.resourcequota.uid-val") + rb.SetK8sRoleAnnotations("k8s.role.annotations-val") + rb.SetK8sRoleLabels("k8s.role.labels-val") + rb.SetK8sRoleName("k8s.role.name-val") + rb.SetK8sRoleNamespace("k8s.role.namespace-val") + rb.SetK8sRoleRules("k8s.role.rules-val") + rb.SetK8sRoleStartTime("k8s.role.start_time-val") + rb.SetK8sRoleType("k8s.role.type-val") + rb.SetK8sRoleUID("k8s.role.uid-val") + rb.SetK8sRolebindingAnnotations("k8s.rolebinding.annotations-val") + rb.SetK8sRolebindingLabels("k8s.rolebinding.labels-val") + rb.SetK8sRolebindingName("k8s.rolebinding.name-val") + rb.SetK8sRolebindingNamespace("k8s.rolebinding.namespace-val") + rb.SetK8sRolebindingRoleRef("k8s.rolebinding.role_ref-val") + rb.SetK8sRolebindingStartTime("k8s.rolebinding.start_time-val") + rb.SetK8sRolebindingSubjects("k8s.rolebinding.subjects-val") + rb.SetK8sRolebindingType("k8s.rolebinding.type-val") + rb.SetK8sRolebindingUID("k8s.rolebinding.uid-val") rb.SetK8sServiceClusterIP("k8s.service.cluster_ip-val") rb.SetK8sServiceName("k8s.service.name-val") rb.SetK8sServiceNamespace("k8s.service.namespace-val") rb.SetK8sServiceType("k8s.service.type-val") rb.SetK8sServiceUID("k8s.service.uid-val") rb.SetK8sServiceAccountName("k8s.service_account.name-val") + rb.SetK8sServiceaccountAnnotations("k8s.serviceaccount.annotations-val") + rb.SetK8sServiceaccountAutomountServiceaccountToken("k8s.serviceaccount.automount_serviceaccount_token-val") + rb.SetK8sServiceaccountImagePullSecrets("k8s.serviceaccount.image_pull_secrets-val") + rb.SetK8sServiceaccountLabels("k8s.serviceaccount.labels-val") + rb.SetK8sServiceaccountName("k8s.serviceaccount.name-val") + rb.SetK8sServiceaccountNamespace("k8s.serviceaccount.namespace-val") + rb.SetK8sServiceaccountSecrets("k8s.serviceaccount.secrets-val") + rb.SetK8sServiceaccountStartTime("k8s.serviceaccount.start_time-val") + rb.SetK8sServiceaccountType("k8s.serviceaccount.type-val") + rb.SetK8sServiceaccountUID("k8s.serviceaccount.uid-val") rb.SetK8sStatefulsetName("k8s.statefulset.name-val") rb.SetK8sStatefulsetStartTime("k8s.statefulset.start_time-val") rb.SetK8sStatefulsetUID("k8s.statefulset.uid-val") @@ -338,6 +400,30 @@ func TestMetricsBuilder(t *testing.T) { validatedMetrics := make(map[string]bool) for i := 0; i < ms.Len(); i++ { switch ms.At(i).Name() { + case "k8s.clusterrole.rule_count": + assert.False(t, validatedMetrics["k8s.clusterrole.rule_count"], "Found a duplicate in the metrics slice: k8s.clusterrole.rule_count") + validatedMetrics["k8s.clusterrole.rule_count"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "The count of cluster roles.", ms.At(i).Description()) + assert.Equal(t, "1", 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.clusterrolebinding.subject_count": + assert.False(t, validatedMetrics["k8s.clusterrolebinding.subject_count"], "Found a duplicate in the metrics slice: k8s.clusterrolebinding.subject_count") + validatedMetrics["k8s.clusterrolebinding.subject_count"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "The subject count of cluster role bindings.", ms.At(i).Description()) + assert.Equal(t, "1", 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.container.cpu_limit": assert.False(t, validatedMetrics["k8s.container.cpu_limit"], "Found a duplicate in the metrics slice: k8s.container.cpu_limit") validatedMetrics["k8s.container.cpu_limit"] = true @@ -800,6 +886,30 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("resource") assert.True(t, ok) assert.EqualValues(t, "resource-val", attrVal.Str()) + case "k8s.role.rule_count": + assert.False(t, validatedMetrics["k8s.role.rule_count"], "Found a duplicate in the metrics slice: k8s.role.rule_count") + validatedMetrics["k8s.role.rule_count"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "The count of roles.", ms.At(i).Description()) + assert.Equal(t, "1", 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.rolebinding.subject_count": + assert.False(t, validatedMetrics["k8s.rolebinding.subject_count"], "Found a duplicate in the metrics slice: k8s.rolebinding.subject_count") + validatedMetrics["k8s.rolebinding.subject_count"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "The subject count of role bindings.", ms.At(i).Description()) + assert.Equal(t, "1", 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.service.port_count": assert.False(t, validatedMetrics["k8s.service.port_count"], "Found a duplicate in the metrics slice: k8s.service.port_count") validatedMetrics["k8s.service.port_count"] = true @@ -812,6 +922,18 @@ 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.serviceaccount.secret_count": + assert.False(t, validatedMetrics["k8s.serviceaccount.secret_count"], "Found a duplicate in the metrics slice: k8s.serviceaccount.secret_count") + validatedMetrics["k8s.serviceaccount.secret_count"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "The count of secrets in Service Account.", ms.At(i).Description()) + assert.Equal(t, "1", 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.statefulset.current_pods": assert.False(t, validatedMetrics["k8s.statefulset.current_pods"], "Found a duplicate in the metrics slice: k8s.statefulset.current_pods") validatedMetrics["k8s.statefulset.current_pods"] = true diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go b/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go index 864012e31720..e3a6121b031d 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_resource.go @@ -49,6 +49,111 @@ func (rb *ResourceBuilder) SetK8sClusterName(val string) { } } +// SetK8sClusterroleAnnotations sets provided value as "k8s.clusterrole.annotations" attribute. +func (rb *ResourceBuilder) SetK8sClusterroleAnnotations(val string) { + if rb.config.K8sClusterroleAnnotations.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrole.annotations", val) + } +} + +// SetK8sClusterroleLabels sets provided value as "k8s.clusterrole.labels" attribute. +func (rb *ResourceBuilder) SetK8sClusterroleLabels(val string) { + if rb.config.K8sClusterroleLabels.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrole.labels", val) + } +} + +// SetK8sClusterroleName sets provided value as "k8s.clusterrole.name" attribute. +func (rb *ResourceBuilder) SetK8sClusterroleName(val string) { + if rb.config.K8sClusterroleName.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrole.name", val) + } +} + +// SetK8sClusterroleRules sets provided value as "k8s.clusterrole.rules" attribute. +func (rb *ResourceBuilder) SetK8sClusterroleRules(val string) { + if rb.config.K8sClusterroleRules.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrole.rules", val) + } +} + +// SetK8sClusterroleStartTime sets provided value as "k8s.clusterrole.start_time" attribute. +func (rb *ResourceBuilder) SetK8sClusterroleStartTime(val string) { + if rb.config.K8sClusterroleStartTime.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrole.start_time", val) + } +} + +// SetK8sClusterroleType sets provided value as "k8s.clusterrole.type" attribute. +func (rb *ResourceBuilder) SetK8sClusterroleType(val string) { + if rb.config.K8sClusterroleType.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrole.type", val) + } +} + +// SetK8sClusterroleUID sets provided value as "k8s.clusterrole.uid" attribute. +func (rb *ResourceBuilder) SetK8sClusterroleUID(val string) { + if rb.config.K8sClusterroleUID.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrole.uid", val) + } +} + +// SetK8sClusterrolebindingAnnotations sets provided value as "k8s.clusterrolebinding.annotations" attribute. +func (rb *ResourceBuilder) SetK8sClusterrolebindingAnnotations(val string) { + if rb.config.K8sClusterrolebindingAnnotations.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrolebinding.annotations", val) + } +} + +// SetK8sClusterrolebindingLabels sets provided value as "k8s.clusterrolebinding.labels" attribute. +func (rb *ResourceBuilder) SetK8sClusterrolebindingLabels(val string) { + if rb.config.K8sClusterrolebindingLabels.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrolebinding.labels", val) + } +} + +// SetK8sClusterrolebindingName sets provided value as "k8s.clusterrolebinding.name" attribute. +func (rb *ResourceBuilder) SetK8sClusterrolebindingName(val string) { + if rb.config.K8sClusterrolebindingName.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrolebinding.name", val) + } +} + +// SetK8sClusterrolebindingRoleRef sets provided value as "k8s.clusterrolebinding.role_ref" attribute. +func (rb *ResourceBuilder) SetK8sClusterrolebindingRoleRef(val string) { + if rb.config.K8sClusterrolebindingRoleRef.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrolebinding.role_ref", val) + } +} + +// SetK8sClusterrolebindingStartTime sets provided value as "k8s.clusterrolebinding.start_time" attribute. +func (rb *ResourceBuilder) SetK8sClusterrolebindingStartTime(val string) { + if rb.config.K8sClusterrolebindingStartTime.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrolebinding.start_time", val) + } +} + +// SetK8sClusterrolebindingSubjects sets provided value as "k8s.clusterrolebinding.subjects" attribute. +func (rb *ResourceBuilder) SetK8sClusterrolebindingSubjects(val string) { + if rb.config.K8sClusterrolebindingSubjects.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrolebinding.subjects", val) + } +} + +// SetK8sClusterrolebindingType sets provided value as "k8s.clusterrolebinding.type" attribute. +func (rb *ResourceBuilder) SetK8sClusterrolebindingType(val string) { + if rb.config.K8sClusterrolebindingType.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrolebinding.type", val) + } +} + +// SetK8sClusterrolebindingUID sets provided value as "k8s.clusterrolebinding.uid" attribute. +func (rb *ResourceBuilder) SetK8sClusterrolebindingUID(val string) { + if rb.config.K8sClusterrolebindingUID.Enabled { + rb.res.Attributes().PutStr("k8s.clusterrolebinding.uid", val) + } +} + // SetK8sContainerName sets provided value as "k8s.container.name" attribute. func (rb *ResourceBuilder) SetK8sContainerName(val string) { if rb.config.K8sContainerName.Enabled { @@ -455,6 +560,125 @@ func (rb *ResourceBuilder) SetK8sResourcequotaUID(val string) { } } +// SetK8sRoleAnnotations sets provided value as "k8s.role.annotations" attribute. +func (rb *ResourceBuilder) SetK8sRoleAnnotations(val string) { + if rb.config.K8sRoleAnnotations.Enabled { + rb.res.Attributes().PutStr("k8s.role.annotations", val) + } +} + +// SetK8sRoleLabels sets provided value as "k8s.role.labels" attribute. +func (rb *ResourceBuilder) SetK8sRoleLabels(val string) { + if rb.config.K8sRoleLabels.Enabled { + rb.res.Attributes().PutStr("k8s.role.labels", val) + } +} + +// SetK8sRoleName sets provided value as "k8s.role.name" attribute. +func (rb *ResourceBuilder) SetK8sRoleName(val string) { + if rb.config.K8sRoleName.Enabled { + rb.res.Attributes().PutStr("k8s.role.name", val) + } +} + +// SetK8sRoleNamespace sets provided value as "k8s.role.namespace" attribute. +func (rb *ResourceBuilder) SetK8sRoleNamespace(val string) { + if rb.config.K8sRoleNamespace.Enabled { + rb.res.Attributes().PutStr("k8s.role.namespace", val) + } +} + +// SetK8sRoleRules sets provided value as "k8s.role.rules" attribute. +func (rb *ResourceBuilder) SetK8sRoleRules(val string) { + if rb.config.K8sRoleRules.Enabled { + rb.res.Attributes().PutStr("k8s.role.rules", val) + } +} + +// SetK8sRoleStartTime sets provided value as "k8s.role.start_time" attribute. +func (rb *ResourceBuilder) SetK8sRoleStartTime(val string) { + if rb.config.K8sRoleStartTime.Enabled { + rb.res.Attributes().PutStr("k8s.role.start_time", val) + } +} + +// SetK8sRoleType sets provided value as "k8s.role.type" attribute. +func (rb *ResourceBuilder) SetK8sRoleType(val string) { + if rb.config.K8sRoleType.Enabled { + rb.res.Attributes().PutStr("k8s.role.type", val) + } +} + +// SetK8sRoleUID sets provided value as "k8s.role.uid" attribute. +func (rb *ResourceBuilder) SetK8sRoleUID(val string) { + if rb.config.K8sRoleUID.Enabled { + rb.res.Attributes().PutStr("k8s.role.uid", val) + } +} + +// SetK8sRolebindingAnnotations sets provided value as "k8s.rolebinding.annotations" attribute. +func (rb *ResourceBuilder) SetK8sRolebindingAnnotations(val string) { + if rb.config.K8sRolebindingAnnotations.Enabled { + rb.res.Attributes().PutStr("k8s.rolebinding.annotations", val) + } +} + +// SetK8sRolebindingLabels sets provided value as "k8s.rolebinding.labels" attribute. +func (rb *ResourceBuilder) SetK8sRolebindingLabels(val string) { + if rb.config.K8sRolebindingLabels.Enabled { + rb.res.Attributes().PutStr("k8s.rolebinding.labels", val) + } +} + +// SetK8sRolebindingName sets provided value as "k8s.rolebinding.name" attribute. +func (rb *ResourceBuilder) SetK8sRolebindingName(val string) { + if rb.config.K8sRolebindingName.Enabled { + rb.res.Attributes().PutStr("k8s.rolebinding.name", val) + } +} + +// SetK8sRolebindingNamespace sets provided value as "k8s.rolebinding.namespace" attribute. +func (rb *ResourceBuilder) SetK8sRolebindingNamespace(val string) { + if rb.config.K8sRolebindingNamespace.Enabled { + rb.res.Attributes().PutStr("k8s.rolebinding.namespace", val) + } +} + +// SetK8sRolebindingRoleRef sets provided value as "k8s.rolebinding.role_ref" attribute. +func (rb *ResourceBuilder) SetK8sRolebindingRoleRef(val string) { + if rb.config.K8sRolebindingRoleRef.Enabled { + rb.res.Attributes().PutStr("k8s.rolebinding.role_ref", val) + } +} + +// SetK8sRolebindingStartTime sets provided value as "k8s.rolebinding.start_time" attribute. +func (rb *ResourceBuilder) SetK8sRolebindingStartTime(val string) { + if rb.config.K8sRolebindingStartTime.Enabled { + rb.res.Attributes().PutStr("k8s.rolebinding.start_time", val) + } +} + +// SetK8sRolebindingSubjects sets provided value as "k8s.rolebinding.subjects" attribute. +func (rb *ResourceBuilder) SetK8sRolebindingSubjects(val string) { + if rb.config.K8sRolebindingSubjects.Enabled { + rb.res.Attributes().PutStr("k8s.rolebinding.subjects", val) + } +} + +// SetK8sRolebindingType sets provided value as "k8s.rolebinding.type" attribute. +func (rb *ResourceBuilder) SetK8sRolebindingType(val string) { + if rb.config.K8sRolebindingType.Enabled { + rb.res.Attributes().PutStr("k8s.rolebinding.type", val) + } +} + +// SetK8sRolebindingUID sets provided value as "k8s.rolebinding.uid" attribute. +func (rb *ResourceBuilder) SetK8sRolebindingUID(val string) { + if rb.config.K8sRolebindingUID.Enabled { + rb.res.Attributes().PutStr("k8s.rolebinding.uid", val) + } +} + // SetK8sServiceClusterIP sets provided value as "k8s.service.cluster_ip" attribute. func (rb *ResourceBuilder) SetK8sServiceClusterIP(val string) { if rb.config.K8sServiceClusterIP.Enabled { @@ -497,6 +721,76 @@ func (rb *ResourceBuilder) SetK8sServiceAccountName(val string) { } } +// SetK8sServiceaccountAnnotations sets provided value as "k8s.serviceaccount.annotations" attribute. +func (rb *ResourceBuilder) SetK8sServiceaccountAnnotations(val string) { + if rb.config.K8sServiceaccountAnnotations.Enabled { + rb.res.Attributes().PutStr("k8s.serviceaccount.annotations", val) + } +} + +// SetK8sServiceaccountAutomountServiceaccountToken sets provided value as "k8s.serviceaccount.automount_serviceaccount_token" attribute. +func (rb *ResourceBuilder) SetK8sServiceaccountAutomountServiceaccountToken(val string) { + if rb.config.K8sServiceaccountAutomountServiceaccountToken.Enabled { + rb.res.Attributes().PutStr("k8s.serviceaccount.automount_serviceaccount_token", val) + } +} + +// SetK8sServiceaccountImagePullSecrets sets provided value as "k8s.serviceaccount.image_pull_secrets" attribute. +func (rb *ResourceBuilder) SetK8sServiceaccountImagePullSecrets(val string) { + if rb.config.K8sServiceaccountImagePullSecrets.Enabled { + rb.res.Attributes().PutStr("k8s.serviceaccount.image_pull_secrets", val) + } +} + +// SetK8sServiceaccountLabels sets provided value as "k8s.serviceaccount.labels" attribute. +func (rb *ResourceBuilder) SetK8sServiceaccountLabels(val string) { + if rb.config.K8sServiceaccountLabels.Enabled { + rb.res.Attributes().PutStr("k8s.serviceaccount.labels", val) + } +} + +// SetK8sServiceaccountName sets provided value as "k8s.serviceaccount.name" attribute. +func (rb *ResourceBuilder) SetK8sServiceaccountName(val string) { + if rb.config.K8sServiceaccountName.Enabled { + rb.res.Attributes().PutStr("k8s.serviceaccount.name", val) + } +} + +// SetK8sServiceaccountNamespace sets provided value as "k8s.serviceaccount.namespace" attribute. +func (rb *ResourceBuilder) SetK8sServiceaccountNamespace(val string) { + if rb.config.K8sServiceaccountNamespace.Enabled { + rb.res.Attributes().PutStr("k8s.serviceaccount.namespace", val) + } +} + +// SetK8sServiceaccountSecrets sets provided value as "k8s.serviceaccount.secrets" attribute. +func (rb *ResourceBuilder) SetK8sServiceaccountSecrets(val string) { + if rb.config.K8sServiceaccountSecrets.Enabled { + rb.res.Attributes().PutStr("k8s.serviceaccount.secrets", val) + } +} + +// SetK8sServiceaccountStartTime sets provided value as "k8s.serviceaccount.start_time" attribute. +func (rb *ResourceBuilder) SetK8sServiceaccountStartTime(val string) { + if rb.config.K8sServiceaccountStartTime.Enabled { + rb.res.Attributes().PutStr("k8s.serviceaccount.start_time", val) + } +} + +// SetK8sServiceaccountType sets provided value as "k8s.serviceaccount.type" attribute. +func (rb *ResourceBuilder) SetK8sServiceaccountType(val string) { + if rb.config.K8sServiceaccountType.Enabled { + rb.res.Attributes().PutStr("k8s.serviceaccount.type", val) + } +} + +// SetK8sServiceaccountUID sets provided value as "k8s.serviceaccount.uid" attribute. +func (rb *ResourceBuilder) SetK8sServiceaccountUID(val string) { + if rb.config.K8sServiceaccountUID.Enabled { + rb.res.Attributes().PutStr("k8s.serviceaccount.uid", val) + } +} + // SetK8sStatefulsetName sets provided value as "k8s.statefulset.name" attribute. func (rb *ResourceBuilder) SetK8sStatefulsetName(val string) { if rb.config.K8sStatefulsetName.Enabled { diff --git a/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go b/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go index e49a50fbd469..eeb01454e530 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go +++ b/receiver/k8sclusterreceiver/internal/metadata/generated_resource_test.go @@ -17,6 +17,21 @@ func TestResourceBuilder(t *testing.T) { rb.SetContainerImageName("container.image.name-val") rb.SetContainerImageTag("container.image.tag-val") rb.SetK8sClusterName("k8s.cluster.name-val") + rb.SetK8sClusterroleAnnotations("k8s.clusterrole.annotations-val") + rb.SetK8sClusterroleLabels("k8s.clusterrole.labels-val") + rb.SetK8sClusterroleName("k8s.clusterrole.name-val") + rb.SetK8sClusterroleRules("k8s.clusterrole.rules-val") + rb.SetK8sClusterroleStartTime("k8s.clusterrole.start_time-val") + rb.SetK8sClusterroleType("k8s.clusterrole.type-val") + rb.SetK8sClusterroleUID("k8s.clusterrole.uid-val") + rb.SetK8sClusterrolebindingAnnotations("k8s.clusterrolebinding.annotations-val") + rb.SetK8sClusterrolebindingLabels("k8s.clusterrolebinding.labels-val") + rb.SetK8sClusterrolebindingName("k8s.clusterrolebinding.name-val") + rb.SetK8sClusterrolebindingRoleRef("k8s.clusterrolebinding.role_ref-val") + rb.SetK8sClusterrolebindingStartTime("k8s.clusterrolebinding.start_time-val") + rb.SetK8sClusterrolebindingSubjects("k8s.clusterrolebinding.subjects-val") + rb.SetK8sClusterrolebindingType("k8s.clusterrolebinding.type-val") + rb.SetK8sClusterrolebindingUID("k8s.clusterrolebinding.uid-val") rb.SetK8sContainerName("k8s.container.name-val") rb.SetK8sCronjobName("k8s.cronjob.name-val") rb.SetK8sCronjobStartTime("k8s.cronjob.start_time-val") @@ -75,12 +90,39 @@ func TestResourceBuilder(t *testing.T) { rb.SetK8sReplicationcontrollerUID("k8s.replicationcontroller.uid-val") rb.SetK8sResourcequotaName("k8s.resourcequota.name-val") rb.SetK8sResourcequotaUID("k8s.resourcequota.uid-val") + rb.SetK8sRoleAnnotations("k8s.role.annotations-val") + rb.SetK8sRoleLabels("k8s.role.labels-val") + rb.SetK8sRoleName("k8s.role.name-val") + rb.SetK8sRoleNamespace("k8s.role.namespace-val") + rb.SetK8sRoleRules("k8s.role.rules-val") + rb.SetK8sRoleStartTime("k8s.role.start_time-val") + rb.SetK8sRoleType("k8s.role.type-val") + rb.SetK8sRoleUID("k8s.role.uid-val") + rb.SetK8sRolebindingAnnotations("k8s.rolebinding.annotations-val") + rb.SetK8sRolebindingLabels("k8s.rolebinding.labels-val") + rb.SetK8sRolebindingName("k8s.rolebinding.name-val") + rb.SetK8sRolebindingNamespace("k8s.rolebinding.namespace-val") + rb.SetK8sRolebindingRoleRef("k8s.rolebinding.role_ref-val") + rb.SetK8sRolebindingStartTime("k8s.rolebinding.start_time-val") + rb.SetK8sRolebindingSubjects("k8s.rolebinding.subjects-val") + rb.SetK8sRolebindingType("k8s.rolebinding.type-val") + rb.SetK8sRolebindingUID("k8s.rolebinding.uid-val") rb.SetK8sServiceClusterIP("k8s.service.cluster_ip-val") rb.SetK8sServiceName("k8s.service.name-val") rb.SetK8sServiceNamespace("k8s.service.namespace-val") rb.SetK8sServiceType("k8s.service.type-val") rb.SetK8sServiceUID("k8s.service.uid-val") rb.SetK8sServiceAccountName("k8s.service_account.name-val") + rb.SetK8sServiceaccountAnnotations("k8s.serviceaccount.annotations-val") + rb.SetK8sServiceaccountAutomountServiceaccountToken("k8s.serviceaccount.automount_serviceaccount_token-val") + rb.SetK8sServiceaccountImagePullSecrets("k8s.serviceaccount.image_pull_secrets-val") + rb.SetK8sServiceaccountLabels("k8s.serviceaccount.labels-val") + rb.SetK8sServiceaccountName("k8s.serviceaccount.name-val") + rb.SetK8sServiceaccountNamespace("k8s.serviceaccount.namespace-val") + rb.SetK8sServiceaccountSecrets("k8s.serviceaccount.secrets-val") + rb.SetK8sServiceaccountStartTime("k8s.serviceaccount.start_time-val") + rb.SetK8sServiceaccountType("k8s.serviceaccount.type-val") + rb.SetK8sServiceaccountUID("k8s.serviceaccount.uid-val") rb.SetK8sStatefulsetName("k8s.statefulset.name-val") rb.SetK8sStatefulsetStartTime("k8s.statefulset.start_time-val") rb.SetK8sStatefulsetUID("k8s.statefulset.uid-val") @@ -93,9 +135,9 @@ func TestResourceBuilder(t *testing.T) { switch test { case "default": - assert.Equal(t, 74, res.Attributes().Len()) + assert.Equal(t, 116, res.Attributes().Len()) case "all_set": - assert.Equal(t, 74, res.Attributes().Len()) + assert.Equal(t, 116, res.Attributes().Len()) case "none_set": assert.Equal(t, 0, res.Attributes().Len()) return @@ -123,6 +165,81 @@ func TestResourceBuilder(t *testing.T) { if ok { assert.EqualValues(t, "k8s.cluster.name-val", val.Str()) } + val, ok = res.Attributes().Get("k8s.clusterrole.annotations") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrole.annotations-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrole.labels") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrole.labels-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrole.name") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrole.name-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrole.rules") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrole.rules-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrole.start_time") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrole.start_time-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrole.type") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrole.type-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrole.uid") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrole.uid-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrolebinding.annotations") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrolebinding.annotations-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrolebinding.labels") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrolebinding.labels-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrolebinding.name") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrolebinding.name-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrolebinding.role_ref") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrolebinding.role_ref-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrolebinding.start_time") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrolebinding.start_time-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrolebinding.subjects") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrolebinding.subjects-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrolebinding.type") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrolebinding.type-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.clusterrolebinding.uid") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.clusterrolebinding.uid-val", val.Str()) + } val, ok = res.Attributes().Get("k8s.container.name") assert.True(t, ok) if ok { @@ -413,6 +530,91 @@ func TestResourceBuilder(t *testing.T) { if ok { assert.EqualValues(t, "k8s.resourcequota.uid-val", val.Str()) } + val, ok = res.Attributes().Get("k8s.role.annotations") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.role.annotations-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.role.labels") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.role.labels-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.role.name") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.role.name-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.role.namespace") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.role.namespace-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.role.rules") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.role.rules-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.role.start_time") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.role.start_time-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.role.type") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.role.type-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.role.uid") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.role.uid-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.rolebinding.annotations") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.rolebinding.annotations-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.rolebinding.labels") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.rolebinding.labels-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.rolebinding.name") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.rolebinding.name-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.rolebinding.namespace") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.rolebinding.namespace-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.rolebinding.role_ref") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.rolebinding.role_ref-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.rolebinding.start_time") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.rolebinding.start_time-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.rolebinding.subjects") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.rolebinding.subjects-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.rolebinding.type") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.rolebinding.type-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.rolebinding.uid") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.rolebinding.uid-val", val.Str()) + } val, ok = res.Attributes().Get("k8s.service.cluster_ip") assert.True(t, ok) if ok { @@ -443,6 +645,56 @@ func TestResourceBuilder(t *testing.T) { if ok { assert.EqualValues(t, "k8s.service_account.name-val", val.Str()) } + val, ok = res.Attributes().Get("k8s.serviceaccount.annotations") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.serviceaccount.annotations-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.serviceaccount.automount_serviceaccount_token") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.serviceaccount.automount_serviceaccount_token-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.serviceaccount.image_pull_secrets") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.serviceaccount.image_pull_secrets-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.serviceaccount.labels") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.serviceaccount.labels-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.serviceaccount.name") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.serviceaccount.name-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.serviceaccount.namespace") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.serviceaccount.namespace-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.serviceaccount.secrets") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.serviceaccount.secrets-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.serviceaccount.start_time") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.serviceaccount.start_time-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.serviceaccount.type") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.serviceaccount.type-val", val.Str()) + } + val, ok = res.Attributes().Get("k8s.serviceaccount.uid") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "k8s.serviceaccount.uid-val", val.Str()) + } val, ok = res.Attributes().Get("k8s.statefulset.name") assert.True(t, ok) if ok { diff --git a/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml b/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml index 5fb4af711282..8fa5edbdb746 100644 --- a/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/k8sclusterreceiver/internal/metadata/testdata/config.yaml @@ -1,6 +1,10 @@ default: all_set: metrics: + k8s.clusterrole.rule_count: + enabled: true + k8s.clusterrolebinding.subject_count: + enabled: true k8s.container.cpu_limit: enabled: true k8s.container.cpu_request: @@ -77,8 +81,14 @@ all_set: enabled: true k8s.resource_quota.used: enabled: true + k8s.role.rule_count: + enabled: true + k8s.rolebinding.subject_count: + enabled: true k8s.service.port_count: enabled: true + k8s.serviceaccount.secret_count: + enabled: true k8s.statefulset.current_pods: enabled: true k8s.statefulset.desired_pods: @@ -104,6 +114,36 @@ all_set: enabled: true k8s.cluster.name: enabled: true + k8s.clusterrole.annotations: + enabled: true + k8s.clusterrole.labels: + enabled: true + k8s.clusterrole.name: + enabled: true + k8s.clusterrole.rules: + enabled: true + k8s.clusterrole.start_time: + enabled: true + k8s.clusterrole.type: + enabled: true + k8s.clusterrole.uid: + enabled: true + k8s.clusterrolebinding.annotations: + enabled: true + k8s.clusterrolebinding.labels: + enabled: true + k8s.clusterrolebinding.name: + enabled: true + k8s.clusterrolebinding.role_ref: + enabled: true + k8s.clusterrolebinding.start_time: + enabled: true + k8s.clusterrolebinding.subjects: + enabled: true + k8s.clusterrolebinding.type: + enabled: true + k8s.clusterrolebinding.uid: + enabled: true k8s.container.name: enabled: true k8s.cronjob.name: @@ -220,6 +260,40 @@ all_set: enabled: true k8s.resourcequota.uid: enabled: true + k8s.role.annotations: + enabled: true + k8s.role.labels: + enabled: true + k8s.role.name: + enabled: true + k8s.role.namespace: + enabled: true + k8s.role.rules: + enabled: true + k8s.role.start_time: + enabled: true + k8s.role.type: + enabled: true + k8s.role.uid: + enabled: true + k8s.rolebinding.annotations: + enabled: true + k8s.rolebinding.labels: + enabled: true + k8s.rolebinding.name: + enabled: true + k8s.rolebinding.namespace: + enabled: true + k8s.rolebinding.role_ref: + enabled: true + k8s.rolebinding.start_time: + enabled: true + k8s.rolebinding.subjects: + enabled: true + k8s.rolebinding.type: + enabled: true + k8s.rolebinding.uid: + enabled: true k8s.service.cluster_ip: enabled: true k8s.service.name: @@ -232,6 +306,26 @@ all_set: enabled: true k8s.service_account.name: enabled: true + k8s.serviceaccount.annotations: + enabled: true + k8s.serviceaccount.automount_serviceaccount_token: + enabled: true + k8s.serviceaccount.image_pull_secrets: + enabled: true + k8s.serviceaccount.labels: + enabled: true + k8s.serviceaccount.name: + enabled: true + k8s.serviceaccount.namespace: + enabled: true + k8s.serviceaccount.secrets: + enabled: true + k8s.serviceaccount.start_time: + enabled: true + k8s.serviceaccount.type: + enabled: true + k8s.serviceaccount.uid: + enabled: true k8s.statefulset.name: enabled: true k8s.statefulset.start_time: @@ -246,6 +340,10 @@ all_set: enabled: true none_set: metrics: + k8s.clusterrole.rule_count: + enabled: false + k8s.clusterrolebinding.subject_count: + enabled: false k8s.container.cpu_limit: enabled: false k8s.container.cpu_request: @@ -322,8 +420,14 @@ none_set: enabled: false k8s.resource_quota.used: enabled: false + k8s.role.rule_count: + enabled: false + k8s.rolebinding.subject_count: + enabled: false k8s.service.port_count: enabled: false + k8s.serviceaccount.secret_count: + enabled: false k8s.statefulset.current_pods: enabled: false k8s.statefulset.desired_pods: @@ -349,6 +453,36 @@ none_set: enabled: false k8s.cluster.name: enabled: false + k8s.clusterrole.annotations: + enabled: false + k8s.clusterrole.labels: + enabled: false + k8s.clusterrole.name: + enabled: false + k8s.clusterrole.rules: + enabled: false + k8s.clusterrole.start_time: + enabled: false + k8s.clusterrole.type: + enabled: false + k8s.clusterrole.uid: + enabled: false + k8s.clusterrolebinding.annotations: + enabled: false + k8s.clusterrolebinding.labels: + enabled: false + k8s.clusterrolebinding.name: + enabled: false + k8s.clusterrolebinding.role_ref: + enabled: false + k8s.clusterrolebinding.start_time: + enabled: false + k8s.clusterrolebinding.subjects: + enabled: false + k8s.clusterrolebinding.type: + enabled: false + k8s.clusterrolebinding.uid: + enabled: false k8s.container.name: enabled: false k8s.cronjob.name: @@ -465,6 +599,40 @@ none_set: enabled: false k8s.resourcequota.uid: enabled: false + k8s.role.annotations: + enabled: false + k8s.role.labels: + enabled: false + k8s.role.name: + enabled: false + k8s.role.namespace: + enabled: false + k8s.role.rules: + enabled: false + k8s.role.start_time: + enabled: false + k8s.role.type: + enabled: false + k8s.role.uid: + enabled: false + k8s.rolebinding.annotations: + enabled: false + k8s.rolebinding.labels: + enabled: false + k8s.rolebinding.name: + enabled: false + k8s.rolebinding.namespace: + enabled: false + k8s.rolebinding.role_ref: + enabled: false + k8s.rolebinding.start_time: + enabled: false + k8s.rolebinding.subjects: + enabled: false + k8s.rolebinding.type: + enabled: false + k8s.rolebinding.uid: + enabled: false k8s.service.cluster_ip: enabled: false k8s.service.name: @@ -477,6 +645,26 @@ none_set: enabled: false k8s.service_account.name: enabled: false + k8s.serviceaccount.annotations: + enabled: false + k8s.serviceaccount.automount_serviceaccount_token: + enabled: false + k8s.serviceaccount.image_pull_secrets: + enabled: false + k8s.serviceaccount.labels: + enabled: false + k8s.serviceaccount.name: + enabled: false + k8s.serviceaccount.namespace: + enabled: false + k8s.serviceaccount.secrets: + enabled: false + k8s.serviceaccount.start_time: + enabled: false + k8s.serviceaccount.type: + enabled: false + k8s.serviceaccount.uid: + enabled: false k8s.statefulset.name: enabled: false k8s.statefulset.start_time: diff --git a/receiver/k8sclusterreceiver/internal/role/role.go b/receiver/k8sclusterreceiver/internal/role/role.go new file mode 100644 index 000000000000..9bdeebe64bb2 --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/role/role.go @@ -0,0 +1,99 @@ +package role + +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" + rbacv1 "k8s.io/api/rbac/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 role metadata. + AttributeK8SRoleUID = "k8s.role.uid" + AttributeK8SRoleName = "k8s.role.name" + RoleCreationTime = "role.creation_timestamp" +) + +// Transform transforms the role to remove the fields. +// IMPORTANT: Make sure to update this function before using new role fields. +func Transform(r *rbacv1.Role) *rbacv1.Role { + newR := &rbacv1.Role{ + ObjectMeta: metadata.TransformObjectMeta(r.ObjectMeta), + } + return newR +} + +func RecordMetrics(mb *imetadata.MetricsBuilder, r *rbacv1.Role, ts pcommon.Timestamp) { + mb.RecordK8sRoleRuleCountDataPoint(ts, int64(len(r.Rules))) + + rb := mb.NewResourceBuilder() + rb.SetK8sRoleUID(string(r.GetUID())) + rb.SetK8sRoleName(r.GetName()) + rb.SetK8sClusterName("unknown") + rb.SetK8sRoleNamespace(r.GetNamespace()) + rb.SetK8sRoleLabels(mapToString(r.GetLabels(), "&")) + rb.SetK8sRoleAnnotations(mapToString(r.GetAnnotations(), "&")) + rb.SetK8sRoleStartTime(r.GetCreationTimestamp().String()) + rb.SetK8sRoleType("Role") + rb.SetK8sRoleRules(convertRulesToString(r.Rules)) + 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 convertRulesToString(rules []rbacv1.PolicyRule) string { + var result strings.Builder + + for i, rule := range rules { + if i > 0 { + result.WriteString(";") + } + + result.WriteString("verbs=") + result.WriteString(strings.Join(rule.Verbs, ",")) + + result.WriteString("&apiGroups=") + result.WriteString(strings.Join(rule.APIGroups, ",")) + + result.WriteString("&resources=") + result.WriteString(strings.Join(rule.Resources, ",")) + + result.WriteString("&resourceNames=") + result.WriteString(strings.Join(rule.ResourceNames, ",")) + + result.WriteString("&nonResourceURLs=") + result.WriteString(strings.Join(rule.NonResourceURLs, ",")) + + } + + return result.String() +} + +func GetMetadata(r *rbacv1.Role) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { + meta := maps.MergeStringMaps(map[string]string{}, r.Labels) + + meta[AttributeK8SRoleName] = r.Name + meta[RoleCreationTime] = r.GetCreationTimestamp().Format(time.RFC3339) + + rID := experimentalmetricmetadata.ResourceID(r.UID) + return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{ + rID: { + EntityType: "k8s.role", + ResourceIDKey: AttributeK8SRoleUID, + ResourceID: rID, + Metadata: meta, + }, + } +} diff --git a/receiver/k8sclusterreceiver/internal/role/role_test.go b/receiver/k8sclusterreceiver/internal/role/role_test.go new file mode 100644 index 000000000000..f0a61684eaed --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/role/role_test.go @@ -0,0 +1,24 @@ +package role + +import ( + "github.com/stretchr/testify/assert" + rbacv1 "k8s.io/api/rbac/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "testing" +) + +func TestTransform(t *testing.T) { + originalR := &rbacv1.Role{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-role", + UID: "my-role-uid", + }, + } + wantR := &rbacv1.Role{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-role", + UID: "my-role-uid", + }, + } + assert.Equal(t, wantR, Transform(originalR)) +} diff --git a/receiver/k8sclusterreceiver/internal/rolebinding/rolebinding.go b/receiver/k8sclusterreceiver/internal/rolebinding/rolebinding.go new file mode 100644 index 000000000000..ca65bb2a2bb5 --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/rolebinding/rolebinding.go @@ -0,0 +1,96 @@ +package rolebinding + +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" + rbacv1 "k8s.io/api/rbac/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 rolebinding metadata. + AttributeK8SRoleBindingUID = "k8s.rolebinding.uid" + AttributeK8SRoleBindingName = "k8s.rolebinding.name" + RoleBindingCreationTime = "rolebinding.creation_timestamp" +) + +// Transform transforms the rolebinding to remove the fields. +// IMPORTANT: Make sure to update this function before using new rolebinding fields. +func Transform(rb *rbacv1.RoleBinding) *rbacv1.RoleBinding { + newRB := &rbacv1.RoleBinding{ + ObjectMeta: metadata.TransformObjectMeta(rb.ObjectMeta), + } + return newRB +} + +func RecordMetrics(mb *imetadata.MetricsBuilder, rbind *rbacv1.RoleBinding, ts pcommon.Timestamp) { + mb.RecordK8sRolebindingSubjectCountDataPoint(ts, int64(len(rbind.Subjects))) + + rb := mb.NewResourceBuilder() + rb.SetK8sRolebindingUID(string(rbind.GetUID())) + rb.SetK8sRolebindingName(rbind.GetName()) + rb.SetK8sClusterName("unknown") + rb.SetK8sRolebindingNamespace(rbind.GetNamespace()) + rb.SetK8sRolebindingLabels(mapToString(rbind.GetLabels(), "&")) + rb.SetK8sRolebindingAnnotations(mapToString(rbind.GetAnnotations(), "&")) + rb.SetK8sRolebindingStartTime(rbind.GetCreationTimestamp().String()) + rb.SetK8sRolebindingType("RoleBinding") + rb.SetK8sRolebindingSubjects(convertSubjectsToString(rbind.Subjects)) + rb.SetK8sRolebindingRoleRef(fmt.Sprintf("apiGroup=%s&kind=%s&name=%s", + rbind.RoleRef.APIGroup, + rbind.RoleRef.Kind, + rbind.RoleRef.Name)) + 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 convertSubjectsToString(subjects []rbacv1.Subject) string { + var result strings.Builder + + for i, subject := range subjects { + if i > 0 { + result.WriteString(";") + } + + result.WriteString("kind=") + result.WriteString(subject.Kind) + + result.WriteString("&name=") + result.WriteString(subject.Name) + + result.WriteString("&namespace=") + result.WriteString(subject.Namespace) + } + + return result.String() +} + +func GetMetadata(rb *rbacv1.RoleBinding) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { + meta := maps.MergeStringMaps(map[string]string{}, rb.Labels) + + meta[AttributeK8SRoleBindingName] = rb.Name + meta[RoleBindingCreationTime] = rb.GetCreationTimestamp().Format(time.RFC3339) + + rbID := experimentalmetricmetadata.ResourceID(rb.UID) + return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{ + rbID: { + EntityType: "k8s.rolebinding", + ResourceIDKey: AttributeK8SRoleBindingUID, + ResourceID: rbID, + Metadata: meta, + }, + } +} diff --git a/receiver/k8sclusterreceiver/internal/rolebinding/rolebinding_test.go b/receiver/k8sclusterreceiver/internal/rolebinding/rolebinding_test.go new file mode 100644 index 000000000000..44c81329bf72 --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/rolebinding/rolebinding_test.go @@ -0,0 +1,24 @@ +package rolebinding + +import ( + "github.com/stretchr/testify/assert" + rbacv1 "k8s.io/api/rbac/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "testing" +) + +func TestTransform(t *testing.T) { + originalRB := &rbacv1.RoleBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-rb", + UID: "my-rb-uid", + }, + } + wantRB := &rbacv1.RoleBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-rb", + UID: "my-rb-uid", + }, + } + assert.Equal(t, wantRB, Transform(originalRB)) +} diff --git a/receiver/k8sclusterreceiver/internal/serviceaccount/serviceaccount.go b/receiver/k8sclusterreceiver/internal/serviceaccount/serviceaccount.go new file mode 100644 index 000000000000..aa32c56df40b --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/serviceaccount/serviceaccount.go @@ -0,0 +1,109 @@ +package serviceaccount + +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" + "strconv" + "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 serviceaccount metadata. + AttributeK8SServiceAccountUID = "k8s.serviceaccount.uid" + AttributeK8SServiceAccountName = "k8s.serviceaccount.name" + ServiceAccountCreationTime = "serviceaccount.creation_timestamp" +) + +// Transform transforms the service account to remove the fields. +// IMPORTANT: Make sure to update this function before using new service account fields. +func Transform(sa *corev1.ServiceAccount) *corev1.ServiceAccount { + newSA := &corev1.ServiceAccount{ + ObjectMeta: metadata.TransformObjectMeta(sa.ObjectMeta), + } + return newSA +} + +func RecordMetrics(mb *imetadata.MetricsBuilder, sa *corev1.ServiceAccount, ts pcommon.Timestamp) { + mb.RecordK8sServiceaccountSecretCountDataPoint(ts, int64(len(sa.Secrets))) + + var automountFlag string + if sa.AutomountServiceAccountToken != nil { + automountFlag = strconv.FormatBool(*sa.AutomountServiceAccountToken) + } + + rb := mb.NewResourceBuilder() + rb.SetK8sServiceaccountUID(string(sa.GetUID())) + rb.SetK8sServiceaccountName(sa.GetName()) + rb.SetK8sClusterName("unknown") + rb.SetK8sServiceaccountNamespace(sa.GetNamespace()) + rb.SetK8sServiceaccountLabels(mapToString(sa.GetLabels(), "&")) + rb.SetK8sServiceaccountAnnotations(mapToString(sa.GetAnnotations(), "&")) + rb.SetK8sServiceaccountStartTime(sa.GetCreationTimestamp().String()) + rb.SetK8sServiceaccountType("ServiceAccount") + rb.SetK8sServiceaccountSecrets(convertSecretsToString(sa.Secrets)) + rb.SetK8sServiceaccountImagePullSecrets(sliceToString(sa.ImagePullSecrets, ",")) + rb.SetK8sServiceaccountAutomountServiceaccountToken(automountFlag) + 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.LocalObjectReference, seperator string) string { + var res []string + for _, secret := range s { + res = append(res, string(secret.Name)) + } + return strings.Join(res, seperator) +} + +func convertSecretsToString(secrets []corev1.ObjectReference) string { + var result strings.Builder + + for i, secret := range secrets { + if i > 0 { + result.WriteString(";") + } + + result.WriteString("kind=") + result.WriteString(secret.Kind) + + result.WriteString("&name=") + result.WriteString(secret.Name) + + result.WriteString("&namespace=") + result.WriteString(secret.Namespace) + + } + + return result.String() +} + +func GetMetadata(sa *corev1.ServiceAccount) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { + meta := maps.MergeStringMaps(map[string]string{}, sa.Labels) + + meta[AttributeK8SServiceAccountName] = sa.Name + meta[ServiceAccountCreationTime] = sa.GetCreationTimestamp().Format(time.RFC3339) + + saID := experimentalmetricmetadata.ResourceID(sa.UID) + return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{ + saID: { + EntityType: "k8s.serviceaccount", + ResourceIDKey: AttributeK8SServiceAccountUID, + ResourceID: saID, + Metadata: meta, + }, + } +} diff --git a/receiver/k8sclusterreceiver/internal/serviceaccount/serviceaccount_test.go b/receiver/k8sclusterreceiver/internal/serviceaccount/serviceaccount_test.go new file mode 100644 index 000000000000..96bcbeae395d --- /dev/null +++ b/receiver/k8sclusterreceiver/internal/serviceaccount/serviceaccount_test.go @@ -0,0 +1,24 @@ +package serviceaccount + +import ( + "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "testing" +) + +func TestTransform(t *testing.T) { + originalSA := &corev1.ServiceAccount{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-sa", + UID: "my-sa-uid", + }, + } + wantSA := &corev1.ServiceAccount{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-sa", + UID: "my-sa-uid", + }, + } + assert.Equal(t, wantSA, Transform(originalSA)) +} diff --git a/receiver/k8sclusterreceiver/metadata.yaml b/receiver/k8sclusterreceiver/metadata.yaml index 26258287f4d5..1a5abd59c5da 100644 --- a/receiver/k8sclusterreceiver/metadata.yaml +++ b/receiver/k8sclusterreceiver/metadata.yaml @@ -208,6 +208,216 @@ resource_attributes: type: string enabled: true + k8s.serviceaccount.uid: + description: The UID of the Service Account. + type: string + enabled: true + + k8s.serviceaccount.name: + description: The name of the Service Account. + type: string + enabled: true + + k8s.serviceaccount.namespace: + description: The namespace of the Service Account. + type: string + enabled: true + + k8s.serviceaccount.labels: + description: Labels of the Service Account. + type: string + enabled: true + + k8s.serviceaccount.annotations: + description: Annotations of the Service Account. + type: string + enabled: true + + k8s.serviceaccount.start_time: + description: The start time of the Service Account. + type: string + enabled: true + + k8s.serviceaccount.secrets: + description: Secrets of the Service Account. + type: string + enabled: true + + k8s.serviceaccount.image_pull_secrets: + description: Image pull secrets of the Service Account. + type: string + enabled: true + + k8s.serviceaccount.automount_serviceaccount_token: + description: Automount service account token of the Service Account. + type: string + enabled: true + + k8s.serviceaccount.type: + description: The type of the Service Account. + type: string + enabled: true + + k8s.role.uid: + description: The UID of the Role. + type: string + enabled: true + + k8s.role.name: + description: The name of the Role. + type: string + enabled: true + + k8s.role.namespace: + description: The namespace of the Role. + type: string + enabled: true + + k8s.role.labels: + description: Labels of the Role. + type: string + enabled: true + + k8s.role.annotations: + description: Annotations of the Role. + type: string + enabled: true + + k8s.role.start_time: + description: The start time of the Role. + type: string + enabled: true + + k8s.role.rules: + description: Rules of the Role. + type: string + enabled: true + + k8s.role.type: + description: The type of the Role. + type: string + enabled: true + + k8s.rolebinding.uid: + description: The UID of the Role Binding. + type: string + enabled: true + + k8s.rolebinding.name: + description: The name of the Role Binding. + type: string + enabled: true + + k8s.rolebinding.namespace: + description: The namespace of the Role Binding. + type: string + enabled: true + + k8s.rolebinding.labels: + description: Labels of the Role Binding. + type: string + enabled: true + + k8s.rolebinding.annotations: + description: Annotations of the Role Binding. + type: string + enabled: true + + k8s.rolebinding.start_time: + description: The start time of the Role Binding. + type: string + enabled: true + + k8s.rolebinding.type: + description: The type of the Role Binding. + type: string + enabled: true + + k8s.rolebinding.subjects: + description: Subjects holds references to the objects, the role applies to. + type: string + enabled: true + + k8s.rolebinding.role_ref: + description: RoleRef can reference a Role in the current namespace. + type: string + enabled: true + + k8s.clusterrole.uid: + description: The UID of the Role. + type: string + enabled: true + + k8s.clusterrole.name: + description: The name of the Cluster Role. + type: string + enabled: true + + k8s.clusterrole.labels: + description: Labels of the Cluster Role. + type: string + enabled: true + + k8s.clusterrole.annotations: + description: Annotations of the Cluster Role. + type: string + enabled: true + + k8s.clusterrole.start_time: + description: The start time of the Cluster Role. + type: string + enabled: true + + k8s.clusterrole.rules: + description: Rules of the Cluster Role. + type: string + enabled: true + + k8s.clusterrole.type: + description: The type of the Cluster Role. + type: string + enabled: true + + k8s.clusterrolebinding.uid: + description: The UID of the Cluster Role Binding. + type: string + enabled: true + + k8s.clusterrolebinding.name: + description: The name of the Cluster Role Binding. + type: string + enabled: true + + k8s.clusterrolebinding.labels: + description: Labels of the Cluster Role Binding. + type: string + enabled: true + + k8s.clusterrolebinding.annotations: + description: Annotations of the Cluster Role Binding. + type: string + enabled: true + + k8s.clusterrolebinding.start_time: + description: The start time of the Cluster Role Binding. + type: string + enabled: true + + k8s.clusterrolebinding.type: + description: The type of the Cluster Role Binding. + type: string + enabled: true + + k8s.clusterrolebinding.subjects: + description: Subjects holds references to the objects, the cluster role applies to. + type: string + enabled: true + + k8s.clusterrolebinding.role_ref: + description: RoleRef can reference a Cluster Role. + type: string + enabled: true + container.id: description: The container id. type: string @@ -489,6 +699,41 @@ metrics: gauge: value_type: int + k8s.serviceaccount.secret_count: + enabled: true + description: The count of secrets in Service Account. + unit: "1" + gauge: + value_type: int + + k8s.role.rule_count: + enabled: true + description: The count of roles. + unit: "1" + gauge: + value_type: int + + k8s.rolebinding.subject_count: + enabled: true + description: The subject count of role bindings. + unit: "1" + gauge: + value_type: int + + k8s.clusterrole.rule_count: + enabled: true + description: The count of cluster roles. + unit: "1" + gauge: + value_type: int + + k8s.clusterrolebinding.subject_count: + enabled: true + description: The subject count of cluster role bindings. + unit: "1" + 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 38dc452e6506..d6a49f6c775d 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -24,6 +24,7 @@ import ( batchv1 "k8s.io/api/batch/v1" batchv1beta1 "k8s.io/api/batch/v1beta1" corev1 "k8s.io/api/core/v1" + rbacv1 "k8s.io/api/rbac/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/informers" @@ -32,6 +33,8 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/clusterrole" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/clusterrolebinding" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/cronjob" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/demonset" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/deployment" @@ -45,6 +48,9 @@ import ( "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" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/role" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/rolebinding" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/serviceaccount" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/statefulset" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/utils" ) @@ -133,10 +139,15 @@ func (rw *resourceWatcher) prepareSharedInformerFactory() error { "Node": {gvk.Node}, "PersistentVolume": {gvk.PersistentVolume}, "PersistentVolumeClaim": {gvk.PersistentVolumeClaim}, + "role": {gvk.Role}, + "rolebinding": {gvk.RoleBinding}, + "clusterrole": {gvk.ClusterRole}, + "clusterrolebinding": {gvk.ClusterRoleBinding}, "Namespace": {gvk.Namespace}, "ReplicationController": {gvk.ReplicationController}, "ResourceQuota": {gvk.ResourceQuota}, "Service": {gvk.Service}, + "ServiceAccount": {gvk.ServiceAccount}, "DaemonSet": {gvk.DaemonSet}, "Deployment": {gvk.Deployment}, "ReplicaSet": {gvk.ReplicaSet}, @@ -202,6 +213,14 @@ func (rw *resourceWatcher) setupInformerForKind(kind schema.GroupVersionKind, fa rw.setupInformer(kind, factory.Core().V1().PersistentVolumes().Informer()) case gvk.PersistentVolumeClaim: rw.setupInformer(kind, factory.Core().V1().PersistentVolumeClaims().Informer()) + case gvk.Role: + rw.setupInformer(kind, factory.Rbac().V1().Roles().Informer()) + case gvk.RoleBinding: + rw.setupInformer(kind, factory.Rbac().V1().RoleBindings().Informer()) + case gvk.ClusterRole: + rw.setupInformer(kind, factory.Rbac().V1().ClusterRoles().Informer()) + case gvk.ClusterRoleBinding: + rw.setupInformer(kind, factory.Rbac().V1().ClusterRoleBindings().Informer()) case gvk.Namespace: rw.setupInformer(kind, factory.Core().V1().Namespaces().Informer()) case gvk.ReplicationController: @@ -210,6 +229,8 @@ func (rw *resourceWatcher) setupInformerForKind(kind schema.GroupVersionKind, fa rw.setupInformer(kind, factory.Core().V1().ResourceQuotas().Informer()) case gvk.Service: rw.setupInformer(kind, factory.Core().V1().Services().Informer()) + case gvk.ServiceAccount: + rw.setupInformer(kind, factory.Core().V1().ServiceAccounts().Informer()) case gvk.DaemonSet: rw.setupInformer(kind, factory.Apps().V1().DaemonSets().Informer()) case gvk.Deployment: @@ -306,6 +327,16 @@ func (rw *resourceWatcher) objMetadata(obj interface{}) map[experimentalmetricme return persistentvolume.GetMetadata(o) case *corev1.PersistentVolumeClaim: return persistentvolumeclaim.GetMetadata(o) + case *corev1.ServiceAccount: + return serviceaccount.GetMetadata(o) + case *rbacv1.Role: + return role.GetMetadata(o) + case *rbacv1.RoleBinding: + return rolebinding.GetMetadata(o) + case *rbacv1.ClusterRole: + return clusterrole.GetMetadata(o) + case *rbacv1.ClusterRoleBinding: + return clusterrolebinding.GetMetadata(o) case *corev1.ReplicationController: return replicationcontroller.GetMetadata(o) case *appsv1.Deployment: