From f259d1d9c9136f482b194debd8c092b6862ee02d Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 9 Oct 2024 11:12:45 +0200 Subject: [PATCH 01/39] replace deprecated fake client initialisation Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/config.go | 5 +++++ receiver/k8sclusterreceiver/receiver_test.go | 2 +- receiver/k8sclusterreceiver/watcher.go | 19 ++++++++++++++++++- receiver/k8sclusterreceiver/watcher_test.go | 4 ++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/receiver/k8sclusterreceiver/config.go b/receiver/k8sclusterreceiver/config.go index 40731a808da8..ede021bde6c6 100644 --- a/receiver/k8sclusterreceiver/config.go +++ b/receiver/k8sclusterreceiver/config.go @@ -39,6 +39,11 @@ type Config struct { // MetricsBuilderConfig allows customizing scraped metrics/attributes representation. metadata.MetricsBuilderConfig `mapstructure:",squash"` + + // Namespace to fetch resources from. If this is set, certain cluster-wide resources such as Nodes or Namespaces + // will not be able to be observed. Setting this option is recommended for sidecar deployment patterns where the collector runs + // as a sidecar for a pod, or in environments where due to security restrictions the collector can not be granted cluster-wide permissions. + Namespace string `mapstructure:"namespace"` } func (cfg *Config) Validate() error { diff --git a/receiver/k8sclusterreceiver/receiver_test.go b/receiver/k8sclusterreceiver/receiver_test.go index 406f9107701b..0a6561c9962b 100644 --- a/receiver/k8sclusterreceiver/receiver_test.go +++ b/receiver/k8sclusterreceiver/receiver_test.go @@ -255,7 +255,7 @@ func setupReceiver( } func newFakeClientWithAllResources() *fake.Clientset { - client := fake.NewSimpleClientset() + client := fake.NewClientset() client.Resources = []*v1.APIResourceList{ { GroupVersion: "v1", diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index 63bc5ac09e9e..c90e870f3c4f 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -106,7 +106,7 @@ func (rw *resourceWatcher) initialize() error { } func (rw *resourceWatcher) prepareSharedInformerFactory() error { - factory := informers.NewSharedInformerFactoryWithOptions(rw.client, rw.config.MetadataCollectionInterval) + factory := rw.getInformerFactory() // Map of supported group version kinds by name of a kind. // If none of the group versions are supported by k8s server for a specific kind, @@ -156,6 +156,23 @@ func (rw *resourceWatcher) prepareSharedInformerFactory() error { return nil } +func (rw *resourceWatcher) getInformerFactory() informers.SharedInformerFactory { + var factory informers.SharedInformerFactory + if rw.config.Namespace != "" { + factory = informers.NewSharedInformerFactoryWithOptions( + rw.client, + rw.config.MetadataCollectionInterval, + informers.WithNamespace(rw.config.Namespace), + ) + } else { + factory = informers.NewSharedInformerFactoryWithOptions( + rw.client, + rw.config.MetadataCollectionInterval, + ) + } + return factory +} + func (rw *resourceWatcher) isKindSupported(gvk schema.GroupVersionKind) (bool, error) { resources, err := rw.client.Discovery().ServerResourcesForGroupVersion(gvk.GroupVersion().String()) if err != nil { diff --git a/receiver/k8sclusterreceiver/watcher_test.go b/receiver/k8sclusterreceiver/watcher_test.go index 29b5d2901ea9..c5dc8fe4742f 100644 --- a/receiver/k8sclusterreceiver/watcher_test.go +++ b/receiver/k8sclusterreceiver/watcher_test.go @@ -108,7 +108,7 @@ func TestIsKindSupported(t *testing.T) { }{ { name: "nothing_supported", - client: fake.NewSimpleClientset(), + client: fake.NewClientset(), gvk: gvk.Pod, expected: false, }, @@ -144,7 +144,7 @@ func TestPrepareSharedInformerFactory(t *testing.T) { { name: "old_server_version", // With no batch/v1.CronJob support. client: func() *fake.Clientset { - client := fake.NewSimpleClientset() + client := fake.NewClientset() client.Resources = []*metav1.APIResourceList{ { GroupVersion: "v1", From 981f1c2a6f577e3b28e5c256f4b74aef54110f52 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 10 Oct 2024 11:28:03 +0200 Subject: [PATCH 02/39] add e2e test scenario for namespaced k8s cluster receiver Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 88 +- receiver/k8sclusterreceiver/receiver_test.go | 12 +- .../collector/clusterrole.yaml | 0 .../collector/clusterrolebinding.yaml | 0 .../collector/configmap.yaml | 0 .../collector/deployment.yaml | 0 .../collector/service.yaml | 0 .../collector/serviceaccount.yaml | 0 .../e2e/{ => cluster-scoped}/expected.yaml | 0 .../namespace-scoped/collector/configmap.yaml | 32 + .../collector/deployment.yaml | 59 + .../e2e/namespace-scoped/collector/role.yaml | 64 + .../collector/rolebinding.yaml | 12 + .../namespace-scoped/collector/service.yaml | 16 + .../collector/serviceaccount.yaml | 5 + .../e2e/namespace-scoped/expected.yaml | 1266 +++++++++++++++++ 16 files changed, 1545 insertions(+), 9 deletions(-) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/collector/clusterrole.yaml (100%) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/collector/clusterrolebinding.yaml (100%) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/collector/configmap.yaml (100%) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/collector/deployment.yaml (100%) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/collector/service.yaml (100%) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/collector/serviceaccount.yaml (100%) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/expected.yaml (100%) create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/service.yaml create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/serviceaccount.yaml create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 8f685047816f..42614dfc3de6 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -28,17 +28,17 @@ import ( const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" -// TestE2E tests the k8s cluster receiver with a real k8s cluster. +// TestE2EClusterScoped tests the k8s cluster receiver with a real k8s cluster. // The test requires a prebuilt otelcontribcol image uploaded to a kind k8s cluster defined in // `/tmp/kube-config-otelcol-e2e-testing`. Run the following command prior to running the test locally: // // kind create cluster --kubeconfig=/tmp/kube-config-otelcol-e2e-testing // make docker-otelcontribcol // KUBECONFIG=/tmp/kube-config-otelcol-e2e-testing kind load docker-image otelcontribcol:latest -func TestE2E(t *testing.T) { +func TestE2EClusterScoped(t *testing.T) { var expected pmetric.Metrics - expectedFile := filepath.Join("testdata", "e2e", "expected.yaml") + expectedFile := filepath.Join("testdata", "e2e", "cluster-scoped", "expected.yaml") expected, err := golden.ReadMetrics(expectedFile) require.NoError(t, err) @@ -50,7 +50,87 @@ func TestE2E(t *testing.T) { defer shutdownSink() testID := uuid.NewString()[:8] - collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, "") + collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "cluster-scoped", "collector")) + + defer func() { + for _, obj := range append(collectorObjs) { + require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName()) + } + }() + + wantEntries := 10 // Minimal number of metrics to wait for. + waitForData(t, wantEntries, metricsConsumer) + + replaceWithStar := func(string) string { return "*" } + shortenNames := func(value string) string { + if strings.HasPrefix(value, "kube-proxy") { + return "kube-proxy" + } + if strings.HasPrefix(value, "local-path-provisioner") { + return "local-path-provisioner" + } + if strings.HasPrefix(value, "kindnet") { + return "kindnet" + } + if strings.HasPrefix(value, "coredns") { + return "coredns" + } + if strings.HasPrefix(value, "otelcol") { + return "otelcol" + } + return value + } + containerImageShorten := func(value string) string { + return value[(strings.LastIndex(value, "/") + 1):] + } + require.NoError(t, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1], + pmetrictest.IgnoreTimestamp(), + pmetrictest.IgnoreStartTimestamp(), + pmetrictest.IgnoreMetricValues("k8s.deployment.desired", "k8s.deployment.available", "k8s.container.restarts", "k8s.container.cpu_request", "k8s.container.memory_request", "k8s.container.memory_limit"), + pmetrictest.ChangeResourceAttributeValue("k8s.deployment.name", shortenNames), + pmetrictest.ChangeResourceAttributeValue("k8s.pod.name", shortenNames), + pmetrictest.ChangeResourceAttributeValue("k8s.replicaset.name", shortenNames), + pmetrictest.ChangeResourceAttributeValue("k8s.deployment.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.pod.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.replicaset.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("container.id", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("container.image.tag", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.node.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.namespace.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.daemonset.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("container.image.name", containerImageShorten), + pmetrictest.IgnoreScopeVersion(), + pmetrictest.IgnoreResourceMetricsOrder(), + pmetrictest.IgnoreMetricsOrder(), + pmetrictest.IgnoreScopeMetricsOrder(), + pmetrictest.IgnoreMetricDataPointsOrder(), + ), + ) +} + +// TestE2ENamespaceScoped tests the k8s cluster receiver with a real k8s cluster. +// The test requires a prebuilt otelcontribcol image uploaded to a kind k8s cluster defined in +// `/tmp/kube-config-otelcol-e2e-testing`. Run the following command prior to running the test locally: +// +// kind create cluster --kubeconfig=/tmp/kube-config-otelcol-e2e-testing +// make docker-otelcontribcol +// KUBECONFIG=/tmp/kube-config-otelcol-e2e-testing kind load docker-image otelcontribcol:latest +func TestE2ENamespaceScoped(t *testing.T) { + + var expected pmetric.Metrics + expectedFile := filepath.Join("testdata", "e2e", "namespace-scoped", "expected.yaml") + expected, err := golden.ReadMetrics(expectedFile) + require.NoError(t, err) + + k8sClient, err := k8stest.NewK8sClient(testKubeConfig) + require.NoError(t, err) + + metricsConsumer := new(consumertest.MetricsSink) + shutdownSink := startUpSink(t, metricsConsumer) + defer shutdownSink() + + testID := uuid.NewString()[:8] + collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "namespace-scoped", "collector")) defer func() { for _, obj := range append(collectorObjs) { diff --git a/receiver/k8sclusterreceiver/receiver_test.go b/receiver/k8sclusterreceiver/receiver_test.go index 0a6561c9962b..b8beb9991211 100644 --- a/receiver/k8sclusterreceiver/receiver_test.go +++ b/receiver/k8sclusterreceiver/receiver_test.go @@ -54,7 +54,7 @@ func TestReceiver(t *testing.T) { osQuotaClient := fakeQuota.NewSimpleClientset() sink := new(consumertest.MetricsSink) - r := setupReceiver(client, osQuotaClient, sink, nil, 10*time.Second, tt) + r := setupReceiver(client, osQuotaClient, sink, nil, 10*time.Second, tt, "") // Setup k8s resources. numPods := 2 @@ -102,7 +102,7 @@ func TestReceiverTimesOutAfterStartup(t *testing.T) { client := newFakeClientWithAllResources() // Mock initial cache sync timing out, using a small timeout. - r := setupReceiver(client, nil, consumertest.NewNop(), nil, 1*time.Millisecond, tt) + r := setupReceiver(client, nil, consumertest.NewNop(), nil, 1*time.Millisecond, tt, "") createPods(t, client, 1) @@ -125,7 +125,7 @@ func TestReceiverWithManyResources(t *testing.T) { osQuotaClient := fakeQuota.NewSimpleClientset() sink := new(consumertest.MetricsSink) - r := setupReceiver(client, osQuotaClient, sink, nil, 10*time.Second, tt) + r := setupReceiver(client, osQuotaClient, sink, nil, 10*time.Second, tt, "") numPods := 1000 numQuotas := 2 @@ -165,7 +165,7 @@ func TestReceiverWithMetadata(t *testing.T) { logsConsumer := new(consumertest.LogsSink) - r := setupReceiver(client, nil, metricsConsumer, logsConsumer, 10*time.Second, tt) + r := setupReceiver(client, nil, metricsConsumer, logsConsumer, 10*time.Second, tt, "") r.config.MetadataExporters = []string{"nop/withmetadata"} // Setup k8s resources. @@ -225,7 +225,8 @@ func setupReceiver( metricsConsumer consumer.Metrics, logsConsumer consumer.Logs, initialSyncTimeout time.Duration, - tt componenttest.TestTelemetry) *kubernetesReceiver { + tt componenttest.TestTelemetry, + namespace string) *kubernetesReceiver { distribution := distributionKubernetes if osQuotaClient != nil { @@ -238,6 +239,7 @@ func setupReceiver( AllocatableTypesToReport: []string{"cpu", "memory"}, Distribution: distribution, MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), + Namespace: namespace, } r, _ := newReceiver(context.Background(), receiver.Settings{ID: component.NewID(metadata.Type), TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, config) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/collector/clusterrole.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/clusterrole.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/collector/clusterrole.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/clusterrole.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/collector/clusterrolebinding.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/clusterrolebinding.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/collector/clusterrolebinding.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/clusterrolebinding.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/collector/configmap.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/configmap.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/collector/configmap.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/configmap.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/collector/deployment.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/deployment.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/collector/deployment.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/deployment.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/collector/service.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/service.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/collector/service.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/service.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/collector/serviceaccount.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/serviceaccount.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/collector/serviceaccount.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/serviceaccount.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/expected.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/expected.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/expected.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml new file mode 100644 index 000000000000..3354e435f289 --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml @@ -0,0 +1,32 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Name }}-config + namespace: default +data: + relay: | + exporters: + otlp: + endpoint: {{ .HostEndpoint }}:4317 + tls: + insecure: true + extensions: + health_check: + endpoint: 0.0.0.0:13133 + processors: + receivers: + k8s_cluster: + namespace: default + + service: + telemetry: + logs: + level: "debug" + extensions: + - health_check + pipelines: + metrics: + exporters: + - otlp + receivers: + - k8s_cluster diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml new file mode 100644 index 000000000000..841c472b04f4 --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml @@ -0,0 +1,59 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Name }} + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: opentelemetry-collector + app.kubernetes.io/instance: {{ .Name }} + template: + metadata: + labels: + app.kubernetes.io/name: opentelemetry-collector + app.kubernetes.io/instance: {{ .Name }} + spec: + serviceAccountName: {{ .Name }} + containers: + - name: opentelemetry-collector + command: + - /otelcontribcol + - --config=/conf/relay.yaml + image: "otelcontribcol:latest" + imagePullPolicy: Never + ports: + - name: otlp + containerPort: 4317 + protocol: TCP + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: status.podIP + livenessProbe: + httpGet: + path: / + port: 13133 + initialDelaySeconds: 3 + readinessProbe: + httpGet: + path: / + port: 13133 + initialDelaySeconds: 3 + resources: + limits: + cpu: 128m + memory: 256Mi + volumeMounts: + - mountPath: /conf + name: opentelemetry-collector-configmap + volumes: + - name: opentelemetry-collector-configmap + configMap: + name: {{ .Name }}-config + items: + - key: relay + path: relay.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml new file mode 100644 index 000000000000..2e8228b51cfc --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml @@ -0,0 +1,64 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ .Name }} + labels: + app: {{ .Name }} + namespace: default +rules: + - apiGroups: + - "" + resources: + - events + - namespaces + - namespaces/status + - nodes + - nodes/spec + - pods + - pods/status + - replicationcontrollers + - replicationcontrollers/status + - resourcequotas + - services + verbs: + - get + - list + - watch + - apiGroups: + - apps + resources: + - daemonsets + - deployments + - replicasets + - statefulsets + verbs: + - get + - list + - watch + - apiGroups: + - extensions + resources: + - daemonsets + - deployments + - replicasets + verbs: + - get + - list + - watch + - apiGroups: + - batch + resources: + - jobs + - cronjobs + verbs: + - get + - list + - watch + - apiGroups: + - autoscaling + resources: + - horizontalpodautoscalers + verbs: + - get + - list + - watch \ No newline at end of file diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml new file mode 100644 index 000000000000..9c8223f1a9f7 --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ .Name }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ .Name }} +subjects: + - kind: ServiceAccount + name: {{ .Name }} + namespace: default diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/service.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/service.yaml new file mode 100644 index 000000000000..1bbfffb99197 --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Name }} + namespace: default +spec: + type: ClusterIP + ports: + - name: otlp + port: 4317 + targetPort: 4317 + protocol: TCP + appProtocol: grpc + selector: + app.kubernetes.io/name: opentelemetry-collector + app.kubernetes.io/instance: {{ .Name }} diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/serviceaccount.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/serviceaccount.yaml new file mode 100644 index 000000000000..bdb3a8dd1b8f --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/serviceaccount.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ .Name }} + namespace: default diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml new file mode 100644 index 000000000000..bbd6a95685b9 --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml @@ -0,0 +1,1266 @@ +resourceMetrics: + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.namespace.uid + value: + stringValue: 3604b135-20f2-404b-9c1a-175ef649793e + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: The current phase of namespaces (1 for active and 0 for terminating) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.namespace.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: local-path-storage + - key: k8s.namespace.uid + value: + stringValue: 414da07d-33d0-4043-ae7c-d6b264d134e5 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: The current phase of namespaces (1 for active and 0 for terminating) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.namespace.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-public + - key: k8s.namespace.uid + value: + stringValue: 7516afba-1597-49e3-8569-9732b7b94865 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: The current phase of namespaces (1 for active and 0 for terminating) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.namespace.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-node-lease + - key: k8s.namespace.uid + value: + stringValue: 8dd32894-d0ff-4cff-bd75-b818c20fc72b + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: The current phase of namespaces (1 for active and 0 for terminating) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.namespace.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.namespace.uid + value: + stringValue: caa467a2-d3e8-4e66-8b76-a155464bac79 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: The current phase of namespaces (1 for active and 0 for terminating) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.namespace.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.node.uid + value: + stringValue: afd51338-8dbe-4234-aed3-0d1a9b3ee38e + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Ready condition status of the node (true=1, false=0, unknown=-1) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.node.condition_ready + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.daemonset.name + value: + stringValue: kindnet + - key: k8s.daemonset.uid + value: + stringValue: e7f2def1-dc2a-42f1-800e-187a4d408359 + - key: k8s.namespace.name + value: + stringValue: kube-system + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Number of nodes that are running at least 1 daemon pod and are supposed to run the daemon pod + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.daemonset.current_scheduled_nodes + unit: "{node}" + - description: Number of nodes that should be running the daemon pod (including nodes currently running the daemon pod) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.daemonset.desired_scheduled_nodes + unit: "{node}" + - description: Number of nodes that are running the daemon pod, but are not supposed to run the daemon pod + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.daemonset.misscheduled_nodes + unit: "{node}" + - description: Number of nodes that should be running the daemon pod and have one or more of the daemon pod running and ready + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.daemonset.ready_nodes + unit: "{node}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.daemonset.name + value: + stringValue: kube-proxy + - key: k8s.daemonset.uid + value: + stringValue: d84cd585-d6bb-44af-b070-a9cb363fa903 + - key: k8s.namespace.name + value: + stringValue: kube-system + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Number of nodes that are running at least 1 daemon pod and are supposed to run the daemon pod + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.daemonset.current_scheduled_nodes + unit: "{node}" + - description: Number of nodes that should be running the daemon pod (including nodes currently running the daemon pod) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.daemonset.desired_scheduled_nodes + unit: "{node}" + - description: Number of nodes that are running the daemon pod, but are not supposed to run the daemon pod + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.daemonset.misscheduled_nodes + unit: "{node}" + - description: Number of nodes that should be running the daemon pod and have one or more of the daemon pod running and ready + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.daemonset.ready_nodes + unit: "{node}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.deployment.name + value: + stringValue: coredns + - key: k8s.deployment.uid + value: + stringValue: 2c83cf0c-8b3d-4106-a54c-4c84f9b6e755 + - key: k8s.namespace.name + value: + stringValue: kube-system + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Number of desired pods in this deployment + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.deployment.desired + unit: "{pod}" + - description: Total number of available pods (ready for at least minReadySeconds) targeted by this deployment + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.deployment.available + unit: "{pod}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.deployment.name + value: + stringValue: local-path-provisioner + - key: k8s.deployment.uid + value: + stringValue: 998d752c-e947-4784-95a8-373e587ae6be + - key: k8s.namespace.name + value: + stringValue: local-path-storage + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Number of desired pods in this deployment + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.deployment.desired + unit: "{pod}" + - description: Total number of available pods (ready for at least minReadySeconds) targeted by this deployment + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.deployment.available + unit: "{pod}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.deployment.name + value: + stringValue: otelcol-5ffb893c + - key: k8s.deployment.uid + value: + stringValue: ed2f7c36-acb7-4348-9eaa-6e86d17b3e70 + - key: k8s.namespace.name + value: + stringValue: default + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Number of desired pods in this deployment + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.deployment.desired + unit: "{pod}" + - description: Total number of available pods (ready for at least minReadySeconds) targeted by this deployment + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.deployment.available + unit: "{pod}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.replicaset.name + value: + stringValue: otelcol-5ffb893c-5459b589fd + - key: k8s.replicaset.uid + value: + stringValue: fafc728a-82c7-49d6-a816-6bff81a191b4 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Number of desired pods in this replicaset + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.replicaset.desired + unit: "{pod}" + - description: Total number of available pods (ready for at least minReadySeconds) targeted by this replicaset + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.replicaset.available + unit: "{pod}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.replicaset.name + value: + stringValue: coredns-565d847f94 + - key: k8s.replicaset.uid + value: + stringValue: 8477bceb-33de-4072-9bb1-fbc762defdda + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Number of desired pods in this replicaset + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.replicaset.desired + unit: "{pod}" + - description: Total number of available pods (ready for at least minReadySeconds) targeted by this replicaset + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.replicaset.available + unit: "{pod}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: local-path-storage + - key: k8s.replicaset.name + value: + stringValue: local-path-provisioner-684f458cdd + - key: k8s.replicaset.uid + value: + stringValue: 59e21dbf-09e1-4053-851d-90aad70bfb01 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Number of desired pods in this replicaset + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.replicaset.desired + unit: "{pod}" + - description: Total number of available pods (ready for at least minReadySeconds) targeted by this replicaset + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.replicaset.available + unit: "{pod}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: otelcol-5ffb893c-5459b589fd-lrbpq + - key: k8s.pod.uid + value: + stringValue: 5e4d1b29-35e5-4ff6-9779-b02921adcace + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.pod.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: coredns-565d847f94-kt4s4 + - key: k8s.pod.uid + value: + stringValue: ebd4da01-4a19-4ed8-bb2b-a75fa9c66160 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.pod.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: coredns-565d847f94-v6kmv + - key: k8s.pod.uid + value: + stringValue: 2c672907-5d69-4f91-85e0-f1792164cadc + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.pod.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: etcd-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: 16463557-8966-458d-b356-54f16895a1dd + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.pod.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kindnet-kjb8z + - key: k8s.pod.uid + value: + stringValue: 9405ca8b-7b7d-4271-80d1-41901f84c9e8 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.pod.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-apiserver-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: 4ce29152-4749-43a7-89b4-b8265bf35b09 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.pod.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-controller-manager-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: 5ebe0d65-e661-4e6b-a053-a3a22adec893 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.pod.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-proxy-twxhf + - key: k8s.pod.uid + value: + stringValue: 38e3c8d5-0c3e-465f-8a79-4117dbcd7607 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.pod.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-scheduler-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: d966df8b-e9d3-41d5-9b25-6c1a5ec9d3dc + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.pod.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: local-path-storage + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: local-path-provisioner-684f458cdd-v726j + - key: k8s.pod.uid + value: + stringValue: 22a22d93-0ec2-4c90-91b1-29a0b3ea9173 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + timeUnixNano: "1686772769034865545" + name: k8s.pod.phase + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 065c7c8b8e35d285df3e05ada86520ab9a55dd5cb25331c1fb0e39739ae7fdfa + - key: container.image.name + value: + stringValue: registry.k8s.io/etcd + - key: container.image.tag + value: + stringValue: 3.5.4-0 + - key: k8s.container.name + value: + stringValue: etcd + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: etcd-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: 16463557-8966-458d-b356-54f16895a1dd + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.container.restarts + unit: "{restart}" + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.container.ready + unit: "" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + timeUnixNano: "1686772769034865545" + name: k8s.container.cpu_request + unit: "{cpu}" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "104857600" + timeUnixNano: "1686772769034865545" + name: k8s.container.memory_request + unit: "By" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 077787bc155f57b4bc991cbc069732fbe95c67df5e30b15d97144b0897828f4b + - key: container.image.name + value: + stringValue: docker.io/kindest/kindnetd + - key: container.image.tag + value: + stringValue: v20221004-44d545d1 + - key: k8s.container.name + value: + stringValue: kindnet-cni + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kindnet-kjb8z + - key: k8s.pod.uid + value: + stringValue: 9405ca8b-7b7d-4271-80d1-41901f84c9e8 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.container.restarts + unit: "{restart}" + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.container.ready + unit: "" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + timeUnixNano: "1686772769034865545" + name: k8s.container.cpu_request + unit: "{cpu}" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "52428800" + timeUnixNano: "1686772769034865545" + name: k8s.container.memory_request + unit: "By" + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + timeUnixNano: "1686772769034865545" + name: k8s.container.cpu_limit + unit: "{cpu}" + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "52428800" + timeUnixNano: "1686772769034865545" + name: k8s.container.memory_limit + unit: "By" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 1a5b9c371c8a7c5d8b0e56a82395aeee88523b1e2d96f17b4a6ae22bf11936bb + - key: container.image.name + value: + stringValue: registry.k8s.io/kube-apiserver-amd64 + - key: container.image.tag + value: + stringValue: v1.25.3 + - key: k8s.container.name + value: + stringValue: kube-apiserver + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-apiserver-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: 4ce29152-4749-43a7-89b4-b8265bf35b09 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.container.restarts + unit: "{restart}" + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.container.ready + unit: "" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.25 + timeUnixNano: "1686772769034865545" + name: k8s.container.cpu_request + unit: "{cpu}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 2e506922310bbf1ffb8dbbf56c04e540306f272b794d89ffbe776fe5e2fc148e + - key: container.image.name + value: + stringValue: registry.k8s.io/kube-scheduler-amd64 + - key: container.image.tag + value: + stringValue: v1.25.3 + - key: k8s.container.name + value: + stringValue: kube-scheduler + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-scheduler-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: d966df8b-e9d3-41d5-9b25-6c1a5ec9d3dc + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.container.restarts + unit: "{restart}" + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.container.ready + unit: "" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + timeUnixNano: "1686772769034865545" + name: k8s.container.cpu_request + unit: "{cpu}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 3baa03c525095d74e7ee24a5c4c42a4680b131f9b8a68f5e2e853ae569d97e4c + - key: container.image.name + value: + stringValue: registry.k8s.io/kube-controller-manager-amd64 + - key: container.image.tag + value: + stringValue: v1.25.3 + - key: k8s.container.name + value: + stringValue: kube-controller-manager + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-controller-manager-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: 5ebe0d65-e661-4e6b-a053-a3a22adec893 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.container.restarts + unit: "{restart}" + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.container.ready + unit: "" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.2 + timeUnixNano: "1686772769034865545" + name: k8s.container.cpu_request + unit: "{cpu}" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 5cfead143bc88798f93fae8e05586b1191771477030fe89ed7bca288bb82c0aa + - key: container.image.name + value: + stringValue: registry.k8s.io/kube-proxy-amd64 + - key: container.image.tag + value: + stringValue: v1.25.3 + - key: k8s.container.name + value: + stringValue: kube-proxy + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-proxy-twxhf + - key: k8s.pod.uid + value: + stringValue: 38e3c8d5-0c3e-465f-8a79-4117dbcd7607 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.container.restarts + unit: "{restart}" + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.container.ready + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 6963960c145745e079a94ccf5d9775339ac8b3ba42209d452597c145c5ddb4d4 + - key: container.image.name + value: + stringValue: registry.k8s.io/coredns/coredns + - key: container.image.tag + value: + stringValue: v1.9.3 + - key: k8s.container.name + value: + stringValue: coredns + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: coredns-565d847f94-kt4s4 + - key: k8s.pod.uid + value: + stringValue: ebd4da01-4a19-4ed8-bb2b-a75fa9c66160 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.container.restarts + unit: "{restart}" + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.container.ready + unit: "" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + timeUnixNano: "1686772769034865545" + name: k8s.container.cpu_request + unit: "{cpu}" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "73400320" + timeUnixNano: "1686772769034865545" + name: k8s.container.memory_request + unit: "By" + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "178257920" + timeUnixNano: "1686772769034865545" + name: k8s.container.memory_limit + unit: "By" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 7c34e046e14a5c952a3fdc5ba539fbb65b1f56192d6c320f69e28563afede0fd + - key: container.image.name + value: + stringValue: docker.io/library/otelcontribcol + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: opentelemetry-collector + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: otelcol-5ffb893c-5459b589fd-lrbpq + - key: k8s.pod.uid + value: + stringValue: 5e4d1b29-35e5-4ff6-9779-b02921adcace + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.container.restarts + unit: "{restart}" + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.container.ready + unit: "" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "268435456" + timeUnixNano: "1686772769034865545" + name: k8s.container.memory_request + unit: "By" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.128 + timeUnixNano: "1686772769034865545" + name: k8s.container.cpu_request + unit: "{cpu}" + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.128 + timeUnixNano: "1686772769034865545" + name: k8s.container.cpu_limit + unit: "{cpu}" + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "268435456" + timeUnixNano: "1686772769034865545" + name: k8s.container.memory_limit + unit: "By" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: cadc2e45454bec4fbe1bec28ab5ba391be414e20dbd927745e4350b728409c50 + - key: container.image.name + value: + stringValue: docker.io/kindest/local-path-provisioner + - key: container.image.tag + value: + stringValue: v0.0.22-kind.0 + - key: k8s.container.name + value: + stringValue: local-path-provisioner + - key: k8s.namespace.name + value: + stringValue: local-path-storage + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: local-path-provisioner-684f458cdd-v726j + - key: k8s.pod.uid + value: + stringValue: 22a22d93-0ec2-4c90-91b1-29a0b3ea9173 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.container.restarts + unit: "{restart}" + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.container.ready + unit: "" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: d174ef52b51e0896b08fb5128589c747f4fbe112bcd6aaced727783fe79d8d2f + - key: container.image.name + value: + stringValue: registry.k8s.io/coredns/coredns + - key: container.image.tag + value: + stringValue: v1.9.3 + - key: k8s.container.name + value: + stringValue: coredns + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: coredns-565d847f94-v6kmv + - key: k8s.pod.uid + value: + stringValue: 2c672907-5d69-4f91-85e0-f1792164cadc + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + timeUnixNano: "1686772769034865545" + name: k8s.container.restarts + unit: "{restart}" + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + timeUnixNano: "1686772769034865545" + name: k8s.container.ready + unit: "" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + timeUnixNano: "1686772769034865545" + name: k8s.container.cpu_request + unit: "{cpu}" + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "73400320" + timeUnixNano: "1686772769034865545" + name: k8s.container.memory_request + unit: "By" + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "178257920" + timeUnixNano: "1686772769034865545" + name: k8s.container.memory_limit + unit: "By" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest From bfc23d8b4b349e1af50033b31b5f5f052aa8598c Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 10 Oct 2024 11:32:16 +0200 Subject: [PATCH 03/39] remove non-fitting resources from namespaced e2e test Signed-off-by: Florian Bacher --- .../e2e/namespace-scoped/expected.yaml | 1146 +---------------- 1 file changed, 43 insertions(+), 1103 deletions(-) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml index bbd6a95685b9..1ed672939950 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml @@ -3,1077 +3,130 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: kube-system - - key: k8s.namespace.uid - value: - stringValue: 3604b135-20f2-404b-9c1a-175ef649793e - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: The current phase of namespaces (1 for active and 0 for terminating) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.namespace.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: local-path-storage - - key: k8s.namespace.uid - value: - stringValue: 414da07d-33d0-4043-ae7c-d6b264d134e5 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: The current phase of namespaces (1 for active and 0 for terminating) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.namespace.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-public - - key: k8s.namespace.uid - value: - stringValue: 7516afba-1597-49e3-8569-9732b7b94865 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: The current phase of namespaces (1 for active and 0 for terminating) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.namespace.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-node-lease - - key: k8s.namespace.uid - value: - stringValue: 8dd32894-d0ff-4cff-bd75-b818c20fc72b - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: The current phase of namespaces (1 for active and 0 for terminating) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.namespace.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: default - - key: k8s.namespace.uid - value: - stringValue: caa467a2-d3e8-4e66-8b76-a155464bac79 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: The current phase of namespaces (1 for active and 0 for terminating) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.namespace.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.node.uid - value: - stringValue: afd51338-8dbe-4234-aed3-0d1a9b3ee38e - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Ready condition status of the node (true=1, false=0, unknown=-1) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.node.condition_ready - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.daemonset.name - value: - stringValue: kindnet - - key: k8s.daemonset.uid - value: - stringValue: e7f2def1-dc2a-42f1-800e-187a4d408359 - - key: k8s.namespace.name - value: - stringValue: kube-system - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Number of nodes that are running at least 1 daemon pod and are supposed to run the daemon pod - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.daemonset.current_scheduled_nodes - unit: "{node}" - - description: Number of nodes that should be running the daemon pod (including nodes currently running the daemon pod) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.daemonset.desired_scheduled_nodes - unit: "{node}" - - description: Number of nodes that are running the daemon pod, but are not supposed to run the daemon pod - gauge: - dataPoints: - - asInt: "0" - timeUnixNano: "1686772769034865545" - name: k8s.daemonset.misscheduled_nodes - unit: "{node}" - - description: Number of nodes that should be running the daemon pod and have one or more of the daemon pod running and ready - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.daemonset.ready_nodes - unit: "{node}" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.daemonset.name - value: - stringValue: kube-proxy - - key: k8s.daemonset.uid - value: - stringValue: d84cd585-d6bb-44af-b070-a9cb363fa903 - - key: k8s.namespace.name - value: - stringValue: kube-system - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Number of nodes that are running at least 1 daemon pod and are supposed to run the daemon pod - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.daemonset.current_scheduled_nodes - unit: "{node}" - - description: Number of nodes that should be running the daemon pod (including nodes currently running the daemon pod) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.daemonset.desired_scheduled_nodes - unit: "{node}" - - description: Number of nodes that are running the daemon pod, but are not supposed to run the daemon pod - gauge: - dataPoints: - - asInt: "0" - timeUnixNano: "1686772769034865545" - name: k8s.daemonset.misscheduled_nodes - unit: "{node}" - - description: Number of nodes that should be running the daemon pod and have one or more of the daemon pod running and ready - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.daemonset.ready_nodes - unit: "{node}" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.deployment.name - value: - stringValue: coredns - - key: k8s.deployment.uid - value: - stringValue: 2c83cf0c-8b3d-4106-a54c-4c84f9b6e755 - - key: k8s.namespace.name - value: - stringValue: kube-system - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Number of desired pods in this deployment - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.deployment.desired - unit: "{pod}" - - description: Total number of available pods (ready for at least minReadySeconds) targeted by this deployment - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.deployment.available - unit: "{pod}" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.deployment.name - value: - stringValue: local-path-provisioner - - key: k8s.deployment.uid - value: - stringValue: 998d752c-e947-4784-95a8-373e587ae6be - - key: k8s.namespace.name - value: - stringValue: local-path-storage - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Number of desired pods in this deployment - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.deployment.desired - unit: "{pod}" - - description: Total number of available pods (ready for at least minReadySeconds) targeted by this deployment - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.deployment.available - unit: "{pod}" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.deployment.name - value: - stringValue: otelcol-5ffb893c - - key: k8s.deployment.uid - value: - stringValue: ed2f7c36-acb7-4348-9eaa-6e86d17b3e70 - - key: k8s.namespace.name - value: - stringValue: default - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Number of desired pods in this deployment - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.deployment.desired - unit: "{pod}" - - description: Total number of available pods (ready for at least minReadySeconds) targeted by this deployment - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.deployment.available - unit: "{pod}" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: default - - key: k8s.replicaset.name - value: - stringValue: otelcol-5ffb893c-5459b589fd - - key: k8s.replicaset.uid - value: - stringValue: fafc728a-82c7-49d6-a816-6bff81a191b4 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Number of desired pods in this replicaset - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.replicaset.desired - unit: "{pod}" - - description: Total number of available pods (ready for at least minReadySeconds) targeted by this replicaset - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.replicaset.available - unit: "{pod}" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.replicaset.name - value: - stringValue: coredns-565d847f94 - - key: k8s.replicaset.uid - value: - stringValue: 8477bceb-33de-4072-9bb1-fbc762defdda - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Number of desired pods in this replicaset - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.replicaset.desired - unit: "{pod}" - - description: Total number of available pods (ready for at least minReadySeconds) targeted by this replicaset - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.replicaset.available - unit: "{pod}" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: local-path-storage - - key: k8s.replicaset.name - value: - stringValue: local-path-provisioner-684f458cdd - - key: k8s.replicaset.uid - value: - stringValue: 59e21dbf-09e1-4053-851d-90aad70bfb01 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Number of desired pods in this replicaset - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.replicaset.desired - unit: "{pod}" - - description: Total number of available pods (ready for at least minReadySeconds) targeted by this replicaset - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.replicaset.available - unit: "{pod}" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: default - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: otelcol-5ffb893c-5459b589fd-lrbpq - - key: k8s.pod.uid - value: - stringValue: 5e4d1b29-35e5-4ff6-9779-b02921adcace - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.pod.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: coredns-565d847f94-kt4s4 - - key: k8s.pod.uid - value: - stringValue: ebd4da01-4a19-4ed8-bb2b-a75fa9c66160 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.pod.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: coredns-565d847f94-v6kmv - - key: k8s.pod.uid - value: - stringValue: 2c672907-5d69-4f91-85e0-f1792164cadc - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.pod.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: etcd-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: 16463557-8966-458d-b356-54f16895a1dd - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.pod.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kindnet-kjb8z - - key: k8s.pod.uid - value: - stringValue: 9405ca8b-7b7d-4271-80d1-41901f84c9e8 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.pod.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kube-apiserver-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: 4ce29152-4749-43a7-89b4-b8265bf35b09 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.pod.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kube-controller-manager-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: 5ebe0d65-e661-4e6b-a053-a3a22adec893 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.pod.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kube-proxy-twxhf - - key: k8s.pod.uid - value: - stringValue: 38e3c8d5-0c3e-465f-8a79-4117dbcd7607 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.pod.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kube-scheduler-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: d966df8b-e9d3-41d5-9b25-6c1a5ec9d3dc - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.pod.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: local-path-storage - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: local-path-provisioner-684f458cdd-v726j - - key: k8s.pod.uid - value: - stringValue: 22a22d93-0ec2-4c90-91b1-29a0b3ea9173 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - timeUnixNano: "1686772769034865545" - name: k8s.pod.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 065c7c8b8e35d285df3e05ada86520ab9a55dd5cb25331c1fb0e39739ae7fdfa - - key: container.image.name - value: - stringValue: registry.k8s.io/etcd - - key: container.image.tag - value: - stringValue: 3.5.4-0 - - key: k8s.container.name - value: - stringValue: etcd - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: etcd-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: 16463557-8966-458d-b356-54f16895a1dd - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - timeUnixNano: "1686772769034865545" - name: k8s.container.restarts - unit: "{restart}" - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.container.ready - unit: "" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - timeUnixNano: "1686772769034865545" - name: k8s.container.cpu_request - unit: "{cpu}" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "104857600" - timeUnixNano: "1686772769034865545" - name: k8s.container.memory_request - unit: "By" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 077787bc155f57b4bc991cbc069732fbe95c67df5e30b15d97144b0897828f4b - - key: container.image.name - value: - stringValue: docker.io/kindest/kindnetd - - key: container.image.tag - value: - stringValue: v20221004-44d545d1 - - key: k8s.container.name - value: - stringValue: kindnet-cni - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kindnet-kjb8z - - key: k8s.pod.uid - value: - stringValue: 9405ca8b-7b7d-4271-80d1-41901f84c9e8 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - timeUnixNano: "1686772769034865545" - name: k8s.container.restarts - unit: "{restart}" - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.container.ready - unit: "" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - timeUnixNano: "1686772769034865545" - name: k8s.container.cpu_request - unit: "{cpu}" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "52428800" - timeUnixNano: "1686772769034865545" - name: k8s.container.memory_request - unit: "By" - - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - timeUnixNano: "1686772769034865545" - name: k8s.container.cpu_limit - unit: "{cpu}" - - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "52428800" - timeUnixNano: "1686772769034865545" - name: k8s.container.memory_limit - unit: "By" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 1a5b9c371c8a7c5d8b0e56a82395aeee88523b1e2d96f17b4a6ae22bf11936bb - - key: container.image.name - value: - stringValue: registry.k8s.io/kube-apiserver-amd64 - - key: container.image.tag - value: - stringValue: v1.25.3 - - key: k8s.container.name - value: - stringValue: kube-apiserver - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kube-apiserver-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: 4ce29152-4749-43a7-89b4-b8265bf35b09 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - timeUnixNano: "1686772769034865545" - name: k8s.container.restarts - unit: "{restart}" - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + stringValue: default + - key: k8s.namespace.uid + value: + stringValue: caa467a2-d3e8-4e66-8b76-a155464bac79 + schemaUrl: "https://opentelemetry.io/schemas/1.18.0" + scopeMetrics: + - metrics: + - description: The current phase of namespaces (1 for active and 0 for terminating) gauge: dataPoints: - asInt: "1" timeUnixNano: "1686772769034865545" - name: k8s.container.ready + name: k8s.namespace.phase unit: "" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.25 - timeUnixNano: "1686772769034865545" - name: k8s.container.cpu_request - unit: "{cpu}" scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest - resource: attributes: - - key: container.id - value: - stringValue: 2e506922310bbf1ffb8dbbf56c04e540306f272b794d89ffbe776fe5e2fc148e - - key: container.image.name - value: - stringValue: registry.k8s.io/kube-scheduler-amd64 - - key: container.image.tag - value: - stringValue: v1.25.3 - - key: k8s.container.name - value: - stringValue: kube-scheduler - - key: k8s.namespace.name - value: - stringValue: kube-system - key: k8s.node.name value: stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kube-scheduler-kind-control-plane - - key: k8s.pod.uid + - key: k8s.node.uid value: - stringValue: d966df8b-e9d3-41d5-9b25-6c1a5ec9d3dc + stringValue: afd51338-8dbe-4234-aed3-0d1a9b3ee38e schemaUrl: "https://opentelemetry.io/schemas/1.18.0" scopeMetrics: - metrics: - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - timeUnixNano: "1686772769034865545" - name: k8s.container.restarts - unit: "{restart}" - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + - description: Ready condition status of the node (true=1, false=0, unknown=-1) gauge: dataPoints: - asInt: "1" timeUnixNano: "1686772769034865545" - name: k8s.container.ready + name: k8s.node.condition_ready unit: "" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - timeUnixNano: "1686772769034865545" - name: k8s.container.cpu_request - unit: "{cpu}" scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest - resource: attributes: - - key: container.id - value: - stringValue: 3baa03c525095d74e7ee24a5c4c42a4680b131f9b8a68f5e2e853ae569d97e4c - - key: container.image.name - value: - stringValue: registry.k8s.io/kube-controller-manager-amd64 - - key: container.image.tag + - key: k8s.deployment.name value: - stringValue: v1.25.3 - - key: k8s.container.name + stringValue: otelcol-5ffb893c + - key: k8s.deployment.uid value: - stringValue: kube-controller-manager + stringValue: ed2f7c36-acb7-4348-9eaa-6e86d17b3e70 - key: k8s.namespace.name value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kube-controller-manager-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: 5ebe0d65-e661-4e6b-a053-a3a22adec893 + stringValue: default schemaUrl: "https://opentelemetry.io/schemas/1.18.0" scopeMetrics: - metrics: - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - timeUnixNano: "1686772769034865545" - name: k8s.container.restarts - unit: "{restart}" - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + - description: Number of desired pods in this deployment gauge: dataPoints: - asInt: "1" timeUnixNano: "1686772769034865545" - name: k8s.container.ready - unit: "" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + name: k8s.deployment.desired + unit: "{pod}" + - description: Total number of available pods (ready for at least minReadySeconds) targeted by this deployment gauge: dataPoints: - - asDouble: 0.2 + - asInt: "1" timeUnixNano: "1686772769034865545" - name: k8s.container.cpu_request - unit: "{cpu}" + name: k8s.deployment.available + unit: "{pod}" scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest - resource: attributes: - - key: container.id - value: - stringValue: 5cfead143bc88798f93fae8e05586b1191771477030fe89ed7bca288bb82c0aa - - key: container.image.name - value: - stringValue: registry.k8s.io/kube-proxy-amd64 - - key: container.image.tag - value: - stringValue: v1.25.3 - - key: k8s.container.name - value: - stringValue: kube-proxy - key: k8s.namespace.name value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name + stringValue: default + - key: k8s.replicaset.name value: - stringValue: kube-proxy-twxhf - - key: k8s.pod.uid + stringValue: otelcol-5ffb893c-5459b589fd + - key: k8s.replicaset.uid value: - stringValue: 38e3c8d5-0c3e-465f-8a79-4117dbcd7607 + stringValue: fafc728a-82c7-49d6-a816-6bff81a191b4 schemaUrl: "https://opentelemetry.io/schemas/1.18.0" scopeMetrics: - metrics: - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + - description: Number of desired pods in this replicaset gauge: dataPoints: - - asInt: "0" + - asInt: "1" timeUnixNano: "1686772769034865545" - name: k8s.container.restarts - unit: "{restart}" - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + name: k8s.replicaset.desired + unit: "{pod}" + - description: Total number of available pods (ready for at least minReadySeconds) targeted by this replicaset gauge: dataPoints: - asInt: "1" timeUnixNano: "1686772769034865545" - name: k8s.container.ready - unit: "" + name: k8s.replicaset.available + unit: "{pod}" scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest - resource: attributes: - - key: container.id - value: - stringValue: 6963960c145745e079a94ccf5d9775339ac8b3ba42209d452597c145c5ddb4d4 - - key: container.image.name - value: - stringValue: registry.k8s.io/coredns/coredns - - key: container.image.tag - value: - stringValue: v1.9.3 - - key: k8s.container.name - value: - stringValue: coredns - key: k8s.namespace.name value: - stringValue: kube-system + stringValue: default - key: k8s.node.name value: stringValue: kind-control-plane - key: k8s.pod.name value: - stringValue: coredns-565d847f94-kt4s4 + stringValue: otelcol-5ffb893c-5459b589fd-lrbpq - key: k8s.pod.uid value: - stringValue: ebd4da01-4a19-4ed8-bb2b-a75fa9c66160 + stringValue: 5e4d1b29-35e5-4ff6-9779-b02921adcace schemaUrl: "https://opentelemetry.io/schemas/1.18.0" scopeMetrics: - metrics: - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - timeUnixNano: "1686772769034865545" - name: k8s.container.restarts - unit: "{restart}" - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) gauge: dataPoints: - - asInt: "1" + - asInt: "2" timeUnixNano: "1686772769034865545" - name: k8s.container.ready + name: k8s.pod.phase unit: "" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - timeUnixNano: "1686772769034865545" - name: k8s.container.cpu_request - unit: "{cpu}" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "73400320" - timeUnixNano: "1686772769034865545" - name: k8s.container.memory_request - unit: "By" - - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "178257920" - timeUnixNano: "1686772769034865545" - name: k8s.container.memory_limit - unit: "By" scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest @@ -1151,116 +204,3 @@ resourceMetrics: scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: cadc2e45454bec4fbe1bec28ab5ba391be414e20dbd927745e4350b728409c50 - - key: container.image.name - value: - stringValue: docker.io/kindest/local-path-provisioner - - key: container.image.tag - value: - stringValue: v0.0.22-kind.0 - - key: k8s.container.name - value: - stringValue: local-path-provisioner - - key: k8s.namespace.name - value: - stringValue: local-path-storage - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: local-path-provisioner-684f458cdd-v726j - - key: k8s.pod.uid - value: - stringValue: 22a22d93-0ec2-4c90-91b1-29a0b3ea9173 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - timeUnixNano: "1686772769034865545" - name: k8s.container.restarts - unit: "{restart}" - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.container.ready - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: d174ef52b51e0896b08fb5128589c747f4fbe112bcd6aaced727783fe79d8d2f - - key: container.image.name - value: - stringValue: registry.k8s.io/coredns/coredns - - key: container.image.tag - value: - stringValue: v1.9.3 - - key: k8s.container.name - value: - stringValue: coredns - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: coredns-565d847f94-v6kmv - - key: k8s.pod.uid - value: - stringValue: 2c672907-5d69-4f91-85e0-f1792164cadc - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - timeUnixNano: "1686772769034865545" - name: k8s.container.restarts - unit: "{restart}" - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.container.ready - unit: "" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - timeUnixNano: "1686772769034865545" - name: k8s.container.cpu_request - unit: "{cpu}" - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "73400320" - timeUnixNano: "1686772769034865545" - name: k8s.container.memory_request - unit: "By" - - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "178257920" - timeUnixNano: "1686772769034865545" - name: k8s.container.memory_limit - unit: "By" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest From 5b9c6acca87ba33006b2d94eec2505d4d7357747 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 10 Oct 2024 13:45:38 +0200 Subject: [PATCH 04/39] add namespace to role binding Signed-off-by: Florian Bacher --- .../testdata/e2e/namespace-scoped/collector/rolebinding.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml index 9c8223f1a9f7..c5b4c0953188 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml @@ -2,6 +2,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: {{ .Name }} + namespace: default roleRef: apiGroup: rbac.authorization.k8s.io kind: Role From 46d11fd7e5f73bdf8de483cd7f25e22c21074f16 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 10 Oct 2024 14:06:19 +0200 Subject: [PATCH 05/39] adapt test expectations Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 42614dfc3de6..3f01bbfa434d 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -26,7 +26,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" ) -const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" +const testKubeConfig = "/Users/florian.bacher/.kube/config" // TestE2EClusterScoped tests the k8s cluster receiver with a real k8s cluster. // The test requires a prebuilt otelcontribcol image uploaded to a kind k8s cluster defined in @@ -138,23 +138,11 @@ func TestE2ENamespaceScoped(t *testing.T) { } }() - wantEntries := 10 // Minimal number of metrics to wait for. + wantEntries := 6 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) replaceWithStar := func(string) string { return "*" } shortenNames := func(value string) string { - if strings.HasPrefix(value, "kube-proxy") { - return "kube-proxy" - } - if strings.HasPrefix(value, "local-path-provisioner") { - return "local-path-provisioner" - } - if strings.HasPrefix(value, "kindnet") { - return "kindnet" - } - if strings.HasPrefix(value, "coredns") { - return "coredns" - } if strings.HasPrefix(value, "otelcol") { return "otelcol" } From dc3b2f3fc5518a6d21ef10e740b1d2ee58e42159 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 10 Oct 2024 14:19:15 +0200 Subject: [PATCH 06/39] revert accidental change Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 3f01bbfa434d..4dd5d291bd5d 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -26,7 +26,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" ) -const testKubeConfig = "/Users/florian.bacher/.kube/config" +const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" // TestE2EClusterScoped tests the k8s cluster receiver with a real k8s cluster. // The test requires a prebuilt otelcontribcol image uploaded to a kind k8s cluster defined in From 1b53fa046cc9dd29f699481f778db123136dd756 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 10 Oct 2024 14:57:40 +0200 Subject: [PATCH 07/39] omit cluster scoped observers if namespace filter is set Signed-off-by: Florian Bacher --- .../testdata/e2e/namespace-scoped/collector/role.yaml | 4 ---- receiver/k8sclusterreceiver/watcher.go | 8 ++++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml index 2e8228b51cfc..842a153f38f1 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml @@ -10,10 +10,6 @@ rules: - "" resources: - events - - namespaces - - namespaces/status - - nodes - - nodes/spec - pods - pods/status - replicationcontrollers diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index c90e870f3c4f..926c979cc471 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -196,9 +196,13 @@ func (rw *resourceWatcher) setupInformerForKind(kind schema.GroupVersionKind, fa case gvk.Pod: rw.setupInformer(kind, factory.Core().V1().Pods().Informer()) case gvk.Node: - rw.setupInformer(kind, factory.Core().V1().Nodes().Informer()) + if rw.config.Namespace != "" { + rw.setupInformer(kind, factory.Core().V1().Nodes().Informer()) + } case gvk.Namespace: - rw.setupInformer(kind, factory.Core().V1().Namespaces().Informer()) + if rw.config.Namespace != "" { + rw.setupInformer(kind, factory.Core().V1().Namespaces().Informer()) + } case gvk.ReplicationController: rw.setupInformer(kind, factory.Core().V1().ReplicationControllers().Informer()) case gvk.ResourceQuota: From e18f4e555c1d0dce5b90462700fc0cb0fc194b1c Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 16 Oct 2024 07:10:11 +0200 Subject: [PATCH 08/39] [revert when done] - adapt test setup to run locally Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 2 +- .../testdata/e2e/cluster-scoped/collector/deployment.yaml | 4 ++-- .../testdata/e2e/namespace-scoped/collector/deployment.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 4dd5d291bd5d..3f01bbfa434d 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -26,7 +26,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" ) -const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" +const testKubeConfig = "/Users/florian.bacher/.kube/config" // TestE2EClusterScoped tests the k8s cluster receiver with a real k8s cluster. // The test requires a prebuilt otelcontribcol image uploaded to a kind k8s cluster defined in diff --git a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/deployment.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/deployment.yaml index 841c472b04f4..c129253f5bf8 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/deployment.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/deployment.yaml @@ -21,8 +21,8 @@ spec: command: - /otelcontribcol - --config=/conf/relay.yaml - image: "otelcontribcol:latest" - imagePullPolicy: Never + image: "localhost/otelcontribcol:latest" + imagePullPolicy: Always ports: - name: otlp containerPort: 4317 diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml index 841c472b04f4..3a9357ed34e2 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml @@ -21,7 +21,7 @@ spec: command: - /otelcontribcol - --config=/conf/relay.yaml - image: "otelcontribcol:latest" + image: "localhost/otelcontribcol:latest" imagePullPolicy: Never ports: - name: otlp From a2990f3dc9c10bc38bfa71d6db13d2d579f0e20a Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 17 Oct 2024 10:32:01 +0200 Subject: [PATCH 09/39] fix informer setup Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 2 +- .../testdata/e2e/cluster-scoped/collector/deployment.yaml | 4 ++-- .../testdata/e2e/namespace-scoped/collector/deployment.yaml | 2 +- receiver/k8sclusterreceiver/watcher.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 3f01bbfa434d..4dd5d291bd5d 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -26,7 +26,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" ) -const testKubeConfig = "/Users/florian.bacher/.kube/config" +const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" // TestE2EClusterScoped tests the k8s cluster receiver with a real k8s cluster. // The test requires a prebuilt otelcontribcol image uploaded to a kind k8s cluster defined in diff --git a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/deployment.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/deployment.yaml index c129253f5bf8..841c472b04f4 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/deployment.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/collector/deployment.yaml @@ -21,8 +21,8 @@ spec: command: - /otelcontribcol - --config=/conf/relay.yaml - image: "localhost/otelcontribcol:latest" - imagePullPolicy: Always + image: "otelcontribcol:latest" + imagePullPolicy: Never ports: - name: otlp containerPort: 4317 diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml index 3a9357ed34e2..841c472b04f4 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml @@ -21,7 +21,7 @@ spec: command: - /otelcontribcol - --config=/conf/relay.yaml - image: "localhost/otelcontribcol:latest" + image: "otelcontribcol:latest" imagePullPolicy: Never ports: - name: otlp diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index 926c979cc471..23912945d886 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -196,11 +196,11 @@ func (rw *resourceWatcher) setupInformerForKind(kind schema.GroupVersionKind, fa case gvk.Pod: rw.setupInformer(kind, factory.Core().V1().Pods().Informer()) case gvk.Node: - if rw.config.Namespace != "" { + if rw.config.Namespace == "" { rw.setupInformer(kind, factory.Core().V1().Nodes().Informer()) } case gvk.Namespace: - if rw.config.Namespace != "" { + if rw.config.Namespace == "" { rw.setupInformer(kind, factory.Core().V1().Namespaces().Informer()) } case gvk.ReplicationController: From c8b1f29b0cafaa48f1c4dd5534bb883733f53a1d Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 17 Oct 2024 11:03:38 +0200 Subject: [PATCH 10/39] update expected metrics Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 2 +- .../e2e/namespace-scoped/expected.yaml | 42 ------------------- 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 4dd5d291bd5d..e260d20122b6 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -138,7 +138,7 @@ func TestE2ENamespaceScoped(t *testing.T) { } }() - wantEntries := 6 // Minimal number of metrics to wait for. + wantEntries := 4 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) replaceWithStar := func(string) string { return "*" } diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml index 1ed672939950..d6df777f3561 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml @@ -1,46 +1,4 @@ resourceMetrics: - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: default - - key: k8s.namespace.uid - value: - stringValue: caa467a2-d3e8-4e66-8b76-a155464bac79 - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: The current phase of namespaces (1 for active and 0 for terminating) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.namespace.phase - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.node.uid - value: - stringValue: afd51338-8dbe-4234-aed3-0d1a9b3ee38e - schemaUrl: "https://opentelemetry.io/schemas/1.18.0" - scopeMetrics: - - metrics: - - description: Ready condition status of the node (true=1, false=0, unknown=-1) - gauge: - dataPoints: - - asInt: "1" - timeUnixNano: "1686772769034865545" - name: k8s.node.condition_ready - unit: "" - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - resource: attributes: - key: k8s.deployment.name From f94b07512e7797ae3b4978655f10473abcffbae2 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 17 Oct 2024 12:53:28 +0200 Subject: [PATCH 11/39] do not try to observe cluster resource quotas when namespace limit has been specified Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/receiver_test.go | 51 +++++++++++++++++++ .../e2e/namespace-scoped/collector/role.yaml | 1 - receiver/k8sclusterreceiver/watcher.go | 2 +- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/receiver/k8sclusterreceiver/receiver_test.go b/receiver/k8sclusterreceiver/receiver_test.go index 75cfe989edff..ee8582a71f9e 100644 --- a/receiver/k8sclusterreceiver/receiver_test.go +++ b/receiver/k8sclusterreceiver/receiver_test.go @@ -93,6 +93,57 @@ func TestReceiver(t *testing.T) { require.NoError(t, r.Shutdown(ctx)) } +func TestNamespacedReceiver(t *testing.T) { + tt, err := componenttest.SetupTelemetry(component.NewID(metadata.Type)) + require.NoError(t, err) + defer func() { + require.NoError(t, tt.Shutdown(context.Background())) + }() + + client := newFakeClientWithAllResources() + osQuotaClient := fakeQuota.NewSimpleClientset() + sink := new(consumertest.MetricsSink) + + r := setupReceiver(client, osQuotaClient, sink, nil, 10*time.Second, tt, "test") + + // Setup k8s resources. + numPods := 2 + numNodes := 1 + numQuotas := 2 + + createPods(t, client, numPods) + createNodes(t, client, numNodes) + createClusterQuota(t, osQuotaClient, numQuotas) + + ctx := context.Background() + require.NoError(t, r.Start(ctx, newNopHost())) + + // Expects metric data from pods only, where each metric data + // struct corresponds to one resource. + // Nodes and ClusterResourceQuotas should not be observed as these are non-namespaced resources + expectedNumMetrics := numPods + var initialDataPointCount int + require.Eventually(t, func() bool { + initialDataPointCount = sink.DataPointCount() + return initialDataPointCount == expectedNumMetrics + }, 10*time.Second, 100*time.Millisecond, + "metrics not collected") + + numPodsToDelete := 1 + deletePods(t, client, numPodsToDelete) + + // Expects metric data from a node, since other resources were deleted. + expectedNumMetrics = numPods - numPodsToDelete + var metricsCountDelta int + require.Eventually(t, func() bool { + metricsCountDelta = sink.DataPointCount() - initialDataPointCount + return metricsCountDelta == expectedNumMetrics + }, 10*time.Second, 100*time.Millisecond, + "updated metrics not collected") + + require.NoError(t, r.Shutdown(ctx)) +} + func TestReceiverTimesOutAfterStartup(t *testing.T) { tt, err := componenttest.SetupTelemetry(component.NewID(metadata.Type)) require.NoError(t, err) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml index 842a153f38f1..21a01c7dbf55 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml @@ -14,7 +14,6 @@ rules: - pods/status - replicationcontrollers - replicationcontrollers/status - - resourcequotas - services verbs: - get diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index 23912945d886..b826b7b4ccb9 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -90,7 +90,7 @@ func (rw *resourceWatcher) initialize() error { } rw.client = client - if rw.config.Distribution == distributionOpenShift { + if rw.config.Distribution == distributionOpenShift && rw.config.Namespace == "" { rw.osQuotaClient, err = rw.makeOpenShiftQuotaClient(rw.config.APIConfig) if err != nil { return fmt.Errorf("Failed to create OpenShift quota API client: %w", err) From b0710fb6d7431e7a5e67f6a3ee996c3306a3e28e Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 17 Oct 2024 13:14:04 +0200 Subject: [PATCH 12/39] extend readme and add changelog entry Signed-off-by: Florian Bacher --- .chloggen/k8sclusterreceiver-namespaced.yaml | 27 ++++++ receiver/k8sclusterreceiver/README.md | 92 ++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 .chloggen/k8sclusterreceiver-namespaced.yaml diff --git a/.chloggen/k8sclusterreceiver-namespaced.yaml b/.chloggen/k8sclusterreceiver-namespaced.yaml new file mode 100644 index 000000000000..3eb2ec73fd7d --- /dev/null +++ b/.chloggen/k8sclusterreceiver-namespaced.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: k8sclusterreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add support for limiting observed resources to a specific namespace. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [9401] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: This change allows to make use of this receiver with `Roles`/`RoleBindings`, as opposed to giving the collector cluster-wide read access. + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/receiver/k8sclusterreceiver/README.md b/receiver/k8sclusterreceiver/README.md index d14e4e09b59f..03916dc10d4b 100644 --- a/receiver/k8sclusterreceiver/README.md +++ b/receiver/k8sclusterreceiver/README.md @@ -64,6 +64,7 @@ The following allocatable resource types are available. - storage - `metrics`: Allows to enable/disable metrics. - `resource_attributes`: Allows to enable/disable resource attributes. +- `namespace`: Allows to observe resources for a particular namespace only. If this option is set to a non-empty string, `Nodes`, `Namespaces` and `ClusterResourceQuotas` will not be observed. Example: @@ -275,6 +276,97 @@ subjects: EOF ``` +As an alternative to setting up a `ClusterRole`/`ClusterRoleBinding`, it is also possible to limit the observed resources to a +particular namespace by setting the `namespace` option of the receiver. This allows the collector to only rely on `Roles`/`RoleBindings`, +instead of granting the collector cluster-wide read access to resources. +Note however, that in this case the following resources will not be observed by the `k8sclusterreceiver`: + +- `Nodes` +- `Namespaces` +- `ClusterResourceQuotas` + +To use this approach, use the commands below to create the required `Role` and `RoleBinding`: + +```bash +< Date: Thu, 17 Oct 2024 13:31:34 +0200 Subject: [PATCH 13/39] add resourcequota access to role Signed-off-by: Florian Bacher --- .../testdata/e2e/namespace-scoped/collector/role.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml index 21a01c7dbf55..842a153f38f1 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml @@ -14,6 +14,7 @@ rules: - pods/status - replicationcontrollers - replicationcontrollers/status + - resourcequotas - services verbs: - get From 6f751bcbe31e5a3838813a3f27208d1e04ce8862 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Mon, 21 Oct 2024 12:33:56 +0200 Subject: [PATCH 14/39] add check for mutually exclusive options in config validation Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/config.go | 5 +++++ receiver/k8sclusterreceiver/config_test.go | 24 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/receiver/k8sclusterreceiver/config.go b/receiver/k8sclusterreceiver/config.go index ede021bde6c6..70ec5e5d3915 100644 --- a/receiver/k8sclusterreceiver/config.go +++ b/receiver/k8sclusterreceiver/config.go @@ -53,5 +53,10 @@ func (cfg *Config) Validate() error { default: return fmt.Errorf("\"%s\" is not a supported distribution. Must be one of: \"openshift\", \"kubernetes\"", cfg.Distribution) } + + if cfg.Namespace != "" && (len(cfg.NodeConditionTypesToReport) > 0 || len(cfg.AllocatableTypesToReport) > 0) { + return fmt.Errorf("node specific options \"node_conditions_to_report\" and \"allocatable_types_to_report\" can not be used in combination with \"namespace\" filter") + } + return nil } diff --git a/receiver/k8sclusterreceiver/config_test.go b/receiver/k8sclusterreceiver/config_test.go index 7cfbb46c6f0e..3025b48f3229 100644 --- a/receiver/k8sclusterreceiver/config_test.go +++ b/receiver/k8sclusterreceiver/config_test.go @@ -96,4 +96,28 @@ func TestInvalidConfig(t *testing.T) { err = component.ValidateConfig(cfg) assert.Error(t, err) assert.Equal(t, "\"wrong\" is not a supported distribution. Must be one of: \"openshift\", \"kubernetes\"", err.Error()) + + // namespace filter together with node specific options (allocatable_types_to_report) + cfg = &Config{ + APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}, + Distribution: "kubernetes", + CollectionInterval: 30 * time.Second, + Namespace: "test-namespace", + AllocatableTypesToReport: []string{"cpu"}, + } + err = component.ValidateConfig(cfg) + assert.Error(t, err) + assert.Equal(t, "node specific options \"node_conditions_to_report\" and \"allocatable_types_to_report\" can not be used in combination with \"namespace\" filter", err.Error()) + + // namespace filter together with node specific options (node_conditions_to_report) + cfg = &Config{ + APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}, + Distribution: "kubernetes", + CollectionInterval: 30 * time.Second, + Namespace: "test-namespace", + NodeConditionTypesToReport: []string{"Ready"}, + } + err = component.ValidateConfig(cfg) + assert.Error(t, err) + assert.Equal(t, "node specific options \"node_conditions_to_report\" and \"allocatable_types_to_report\" can not be used in combination with \"namespace\" filter", err.Error()) } From aebbbc47d66ccb01ce49d701edbf46009992e9eb Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Tue, 22 Oct 2024 08:21:03 +0200 Subject: [PATCH 15/39] remove namespace check from validation and log hint about non-observable resources instead Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/config.go | 4 ---- receiver/k8sclusterreceiver/config_test.go | 24 ---------------------- receiver/k8sclusterreceiver/watcher.go | 1 + 3 files changed, 1 insertion(+), 28 deletions(-) diff --git a/receiver/k8sclusterreceiver/config.go b/receiver/k8sclusterreceiver/config.go index 70ec5e5d3915..b928ab872705 100644 --- a/receiver/k8sclusterreceiver/config.go +++ b/receiver/k8sclusterreceiver/config.go @@ -54,9 +54,5 @@ func (cfg *Config) Validate() error { return fmt.Errorf("\"%s\" is not a supported distribution. Must be one of: \"openshift\", \"kubernetes\"", cfg.Distribution) } - if cfg.Namespace != "" && (len(cfg.NodeConditionTypesToReport) > 0 || len(cfg.AllocatableTypesToReport) > 0) { - return fmt.Errorf("node specific options \"node_conditions_to_report\" and \"allocatable_types_to_report\" can not be used in combination with \"namespace\" filter") - } - return nil } diff --git a/receiver/k8sclusterreceiver/config_test.go b/receiver/k8sclusterreceiver/config_test.go index 3025b48f3229..7cfbb46c6f0e 100644 --- a/receiver/k8sclusterreceiver/config_test.go +++ b/receiver/k8sclusterreceiver/config_test.go @@ -96,28 +96,4 @@ func TestInvalidConfig(t *testing.T) { err = component.ValidateConfig(cfg) assert.Error(t, err) assert.Equal(t, "\"wrong\" is not a supported distribution. Must be one of: \"openshift\", \"kubernetes\"", err.Error()) - - // namespace filter together with node specific options (allocatable_types_to_report) - cfg = &Config{ - APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}, - Distribution: "kubernetes", - CollectionInterval: 30 * time.Second, - Namespace: "test-namespace", - AllocatableTypesToReport: []string{"cpu"}, - } - err = component.ValidateConfig(cfg) - assert.Error(t, err) - assert.Equal(t, "node specific options \"node_conditions_to_report\" and \"allocatable_types_to_report\" can not be used in combination with \"namespace\" filter", err.Error()) - - // namespace filter together with node specific options (node_conditions_to_report) - cfg = &Config{ - APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeNone}, - Distribution: "kubernetes", - CollectionInterval: 30 * time.Second, - Namespace: "test-namespace", - NodeConditionTypesToReport: []string{"Ready"}, - } - err = component.ValidateConfig(cfg) - assert.Error(t, err) - assert.Equal(t, "node specific options \"node_conditions_to_report\" and \"allocatable_types_to_report\" can not be used in combination with \"namespace\" filter", err.Error()) } diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index b826b7b4ccb9..240c4f9417b5 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -159,6 +159,7 @@ func (rw *resourceWatcher) prepareSharedInformerFactory() error { func (rw *resourceWatcher) getInformerFactory() informers.SharedInformerFactory { var factory informers.SharedInformerFactory if rw.config.Namespace != "" { + rw.logger.Info("Namespace filter has been enabled. Nodes and namespaces will not be observed.", zap.String("namespace", rw.config.Namespace)) factory = informers.NewSharedInformerFactoryWithOptions( rw.client, rw.config.MetadataCollectionInterval, From 7fecd06bf33fb9f24ce9387dc0c8dd00d5bd7f14 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Tue, 29 Oct 2024 10:08:40 +0100 Subject: [PATCH 16/39] remove sidecar deployment recommendation Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/receiver/k8sclusterreceiver/config.go b/receiver/k8sclusterreceiver/config.go index b928ab872705..73657b8504e6 100644 --- a/receiver/k8sclusterreceiver/config.go +++ b/receiver/k8sclusterreceiver/config.go @@ -41,8 +41,8 @@ type Config struct { metadata.MetricsBuilderConfig `mapstructure:",squash"` // Namespace to fetch resources from. If this is set, certain cluster-wide resources such as Nodes or Namespaces - // will not be able to be observed. Setting this option is recommended for sidecar deployment patterns where the collector runs - // as a sidecar for a pod, or in environments where due to security restrictions the collector can not be granted cluster-wide permissions. + // will not be able to be observed. Setting this option is recommended in environments where due to security restrictions + // the collector can not be granted cluster-wide permissions. Namespace string `mapstructure:"namespace"` } From 4ef2cad6d788eebcb05c83baff6120eeb665ff13 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 08:56:36 +0100 Subject: [PATCH 17/39] fix merge conflicts Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 29 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index ea3e79b67085..7ee1e97768e9 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -7,6 +7,7 @@ package k8sclusterreceiver import ( "context" + "path/filepath" "strings" "testing" "time" @@ -25,9 +26,11 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" ) -const expectedFile = "./testdata/e2e/expected.yaml" +const expectedFileClusterScoped = "./testdata/e2e/cluster-scoped/expected.yaml" +const expectedFileNamespaceScoped = "./testdata/e2e/namespace-scoped/expected.yaml" + +const testObjectsDirClusterScoped = "./testdata/e2e/cluster-scoped/testobjects/" const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" -const testObjectsDir = "./testdata/e2e/testobjects/" // TestE2EClusterScoped tests the k8s cluster receiver with a real k8s cluster. // The test requires a prebuilt otelcontribcol image uploaded to a kind k8s cluster defined in @@ -39,15 +42,14 @@ const testObjectsDir = "./testdata/e2e/testobjects/" func TestE2EClusterScoped(t *testing.T) { var expected pmetric.Metrics - expectedFile := filepath.Join("testdata", "e2e", "cluster-scoped", "expected.yaml") - expected, err := golden.ReadMetrics(expectedFile) + expected, err := golden.ReadMetrics(expectedFileClusterScoped) require.NoError(t, err) k8sClient, err := k8stest.NewK8sClient(testKubeConfig) require.NoError(t, err) // k8s test objs - testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDir) + testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDirClusterScoped) require.NoErrorf(t, err, "failed to create objects") t.Cleanup(func() { @@ -163,8 +165,7 @@ func TestE2EClusterScoped(t *testing.T) { func TestE2ENamespaceScoped(t *testing.T) { var expected pmetric.Metrics - expectedFile := filepath.Join("testdata", "e2e", "namespace-scoped", "expected.yaml") - expected, err := golden.ReadMetrics(expectedFile) + expected, err := golden.ReadMetrics(expectedFileNamespaceScoped) require.NoError(t, err) k8sClient, err := k8stest.NewK8sClient(testKubeConfig) @@ -199,7 +200,19 @@ func TestE2ENamespaceScoped(t *testing.T) { require.NoError(t, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1], pmetrictest.IgnoreTimestamp(), pmetrictest.IgnoreStartTimestamp(), - pmetrictest.IgnoreMetricValues("k8s.deployment.desired", "k8s.deployment.available", "k8s.container.restarts", "k8s.container.cpu_request", "k8s.container.memory_request", "k8s.container.memory_limit"), + pmetrictest.IgnoreMetricValues( + "k8s.container.cpu_request", + "k8s.container.memory_limit", + "k8s.container.memory_request", + "k8s.container.restarts", + "k8s.cronjob.active_jobs", + "k8s.deployment.available", + "k8s.deployment.desired", + "k8s.job.active_pods", + "k8s.job.desired_successful_pods", + "k8s.job.failed_pods", + "k8s.job.max_parallel_pods", + "k8s.job.successful_pods"), pmetrictest.ChangeResourceAttributeValue("k8s.deployment.name", shortenNames), pmetrictest.ChangeResourceAttributeValue("k8s.pod.name", shortenNames), pmetrictest.ChangeResourceAttributeValue("k8s.replicaset.name", shortenNames), From 28862e66aa3b104a21f2c13c4f243f577074ac77 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 09:10:53 +0100 Subject: [PATCH 18/39] fix path to testobjects directoy Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 7ee1e97768e9..5ba717f67e65 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -29,7 +29,7 @@ import ( const expectedFileClusterScoped = "./testdata/e2e/cluster-scoped/expected.yaml" const expectedFileNamespaceScoped = "./testdata/e2e/namespace-scoped/expected.yaml" -const testObjectsDirClusterScoped = "./testdata/e2e/cluster-scoped/testobjects/" +const testObjectsDir = "./testdata/e2e/testobjects/" const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" // TestE2EClusterScoped tests the k8s cluster receiver with a real k8s cluster. @@ -49,7 +49,7 @@ func TestE2EClusterScoped(t *testing.T) { require.NoError(t, err) // k8s test objs - testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDirClusterScoped) + testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDir) require.NoErrorf(t, err, "failed to create objects") t.Cleanup(func() { @@ -171,6 +171,14 @@ func TestE2ENamespaceScoped(t *testing.T) { k8sClient, err := k8stest.NewK8sClient(testKubeConfig) require.NoError(t, err) + // k8s test objs + testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDir) + require.NoErrorf(t, err, "failed to create objects") + + t.Cleanup(func() { + require.NoErrorf(t, k8stest.DeleteObjects(k8sClient, testObjs), "failed to delete objects") + }) + metricsConsumer := new(consumertest.MetricsSink) shutdownSink := startUpSink(t, metricsConsumer) defer shutdownSink() @@ -178,11 +186,11 @@ func TestE2ENamespaceScoped(t *testing.T) { testID := uuid.NewString()[:8] collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "namespace-scoped", "collector")) - defer func() { + t.Cleanup(func() { for _, obj := range append(collectorObjs) { require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName()) } - }() + }) wantEntries := 4 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) From 582f06c26b8416925a8e7f988dd60207bb914ecc Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 09:24:32 +0100 Subject: [PATCH 19/39] fix test cleanup Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 5ba717f67e65..6944a825a4a1 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -52,9 +52,9 @@ func TestE2EClusterScoped(t *testing.T) { testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDir) require.NoErrorf(t, err, "failed to create objects") - t.Cleanup(func() { + defer func() { require.NoErrorf(t, k8stest.DeleteObjects(k8sClient, testObjs), "failed to delete objects") - }) + }() metricsConsumer := new(consumertest.MetricsSink) shutdownSink := startUpSink(t, metricsConsumer) @@ -63,11 +63,11 @@ func TestE2EClusterScoped(t *testing.T) { testID := uuid.NewString()[:8] collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "cluster-scoped", "collector")) - t.Cleanup(func() { + defer func() { for _, obj := range append(collectorObjs) { require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName()) } - }) + }() wantEntries := 10 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) @@ -175,9 +175,9 @@ func TestE2ENamespaceScoped(t *testing.T) { testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDir) require.NoErrorf(t, err, "failed to create objects") - t.Cleanup(func() { + defer func() { require.NoErrorf(t, k8stest.DeleteObjects(k8sClient, testObjs), "failed to delete objects") - }) + }() metricsConsumer := new(consumertest.MetricsSink) shutdownSink := startUpSink(t, metricsConsumer) @@ -186,11 +186,11 @@ func TestE2ENamespaceScoped(t *testing.T) { testID := uuid.NewString()[:8] collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "namespace-scoped", "collector")) - t.Cleanup(func() { + defer func() { for _, obj := range append(collectorObjs) { require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName()) } - }) + }() wantEntries := 4 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) From 9916d6fe42becb6c6dcb44dd6ad48453c783c4d8 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 09:47:22 +0100 Subject: [PATCH 20/39] increase number of expected metrics before continuing with assertions Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 6944a825a4a1..3b62b005ee54 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -52,9 +52,9 @@ func TestE2EClusterScoped(t *testing.T) { testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDir) require.NoErrorf(t, err, "failed to create objects") - defer func() { + t.Cleanup(func() { require.NoErrorf(t, k8stest.DeleteObjects(k8sClient, testObjs), "failed to delete objects") - }() + }) metricsConsumer := new(consumertest.MetricsSink) shutdownSink := startUpSink(t, metricsConsumer) @@ -63,13 +63,13 @@ func TestE2EClusterScoped(t *testing.T) { testID := uuid.NewString()[:8] collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "cluster-scoped", "collector")) - defer func() { + t.Cleanup(func() { for _, obj := range append(collectorObjs) { require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName()) } - }() + }) - wantEntries := 10 // Minimal number of metrics to wait for. + wantEntries := 48 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) // golden.WriteMetrics(t, expectedFile, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1]) @@ -175,9 +175,9 @@ func TestE2ENamespaceScoped(t *testing.T) { testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDir) require.NoErrorf(t, err, "failed to create objects") - defer func() { + t.Cleanup(func() { require.NoErrorf(t, k8stest.DeleteObjects(k8sClient, testObjs), "failed to delete objects") - }() + }) metricsConsumer := new(consumertest.MetricsSink) shutdownSink := startUpSink(t, metricsConsumer) @@ -186,11 +186,11 @@ func TestE2ENamespaceScoped(t *testing.T) { testID := uuid.NewString()[:8] collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "namespace-scoped", "collector")) - defer func() { + t.Cleanup(func() { for _, obj := range append(collectorObjs) { require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName()) } - }() + }) wantEntries := 4 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) From 4251eecdb586460877968be96ceec69c68f77300 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 11:05:50 +0100 Subject: [PATCH 21/39] adapt expected.yaml to account for newly added k8s objects Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 21 +- .../e2e/namespace-scoped/expected.yaml | 1292 +++++++++++++++++ 2 files changed, 1306 insertions(+), 7 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 3b62b005ee54..4a8c2af5ed53 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -7,6 +7,7 @@ package k8sclusterreceiver import ( "context" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "path/filepath" "strings" "testing" @@ -40,7 +41,6 @@ const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" // make docker-otelcontribcol // KUBECONFIG=/tmp/kube-config-otelcol-e2e-testing kind load docker-image otelcontribcol:latest func TestE2EClusterScoped(t *testing.T) { - var expected pmetric.Metrics expected, err := golden.ReadMetrics(expectedFileClusterScoped) require.NoError(t, err) @@ -69,9 +69,7 @@ func TestE2EClusterScoped(t *testing.T) { } }) - wantEntries := 48 // Minimal number of metrics to wait for. - waitForData(t, wantEntries, metricsConsumer) - // golden.WriteMetrics(t, expectedFile, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1]) + waitForData(t, expected.ResourceMetrics().Len(), metricsConsumer) replaceWithStar := func(string) string { return "*" } shortenNames := func(value string) string { @@ -172,7 +170,17 @@ func TestE2ENamespaceScoped(t *testing.T) { require.NoError(t, err) // k8s test objs - testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDir) + + var testObjs []*unstructured.Unstructured + // the k8stest.Delete function does not wait for all objects to be fully deleted, therefore using Eventually here to retry in case + // one of the objects from the previous test is still being deleted + require.Eventually(t, func() bool { + testObjs, err = k8stest.CreateObjects(k8sClient, testObjectsDir) + if err != nil { + return false + } + return true + }, 30*time.Second, 5*time.Second) require.NoErrorf(t, err, "failed to create objects") t.Cleanup(func() { @@ -192,8 +200,7 @@ func TestE2ENamespaceScoped(t *testing.T) { } }) - wantEntries := 4 // Minimal number of metrics to wait for. - waitForData(t, wantEntries, metricsConsumer) + waitForData(t, expected.ResourceMetrics().Len(), metricsConsumer) replaceWithStar := func(string) string { return "*" } shortenNames := func(value string) string { diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml index d6df777f3561..a6b690a6949e 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml @@ -162,3 +162,1295 @@ resourceMetrics: scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest + - resource: + attributes: + - key: k8s.cronjob.name + value: + stringValue: test-k8scluster-receiver-cronjob + - key: k8s.cronjob.uid + value: + stringValue: 6a3c3e99-5db1-481f-9d5d-782ae9de9f58 + - key: k8s.namespace.name + value: + stringValue: default + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: The number of actively running jobs for a cronjob + gauge: + dataPoints: + - asInt: "2" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.cronjob.active_jobs + unit: '{job}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.hpa.name + value: + stringValue: test-k8scluster-receiver-hpa + - key: k8s.hpa.uid + value: + stringValue: 963572dc-4663-4fb2-930a-e143320a03c3 + - key: k8s.namespace.name + value: + stringValue: default + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Current number of pod replicas managed by this autoscaler. + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.hpa.current_replicas + unit: '{pod}' + - description: Desired number of pod replicas managed by this autoscaler. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.hpa.desired_replicas + unit: '{pod}' + - description: Maximum number of replicas to which the autoscaler can scale up. + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.hpa.max_replicas + unit: '{pod}' + - description: Minimum number of replicas to which the autoscaler can scale up. + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.hpa.min_replicas + unit: '{pod}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.job.name + value: + stringValue: test-k8scluster-receiver-cronjob-28839770 + - key: k8s.job.uid + value: + stringValue: a38da134-af71-4bc1-a585-c9e0342f9aab + - key: k8s.namespace.name + value: + stringValue: default + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: The number of actively running pods for a job + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.active_pods + unit: '{pod}' + - description: The desired number of successfully finished pods the job should be run with + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.desired_successful_pods + unit: '{pod}' + - description: The number of pods which reached phase Failed for a job + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.failed_pods + unit: '{pod}' + - description: The max desired number of pods the job should run at any given time + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.max_parallel_pods + unit: '{pod}' + - description: The number of pods which reached phase Succeeded for a job + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.successful_pods + unit: '{pod}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.job.name + value: + stringValue: test-k8scluster-receiver-cronjob-28839771 + - key: k8s.job.uid + value: + stringValue: 37a9e0cc-5315-4e89-bb2b-5221849ff483 + - key: k8s.namespace.name + value: + stringValue: default + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: The number of actively running pods for a job + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.active_pods + unit: '{pod}' + - description: The desired number of successfully finished pods the job should be run with + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.desired_successful_pods + unit: '{pod}' + - description: The number of pods which reached phase Failed for a job + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.failed_pods + unit: '{pod}' + - description: The max desired number of pods the job should run at any given time + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.max_parallel_pods + unit: '{pod}' + - description: The number of pods which reached phase Succeeded for a job + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.successful_pods + unit: '{pod}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.job.name + value: + stringValue: test-k8scluster-receiver-job + - key: k8s.job.uid + value: + stringValue: b7ecbf9e-8e1a-4d70-beda-aab183645382 + - key: k8s.namespace.name + value: + stringValue: default + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: The number of actively running pods for a job + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.active_pods + unit: '{pod}' + - description: The desired number of successfully finished pods the job should be run with + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.desired_successful_pods + unit: '{pod}' + - description: The number of pods which reached phase Failed for a job + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.failed_pods + unit: '{pod}' + - description: The max desired number of pods the job should run at any given time + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.max_parallel_pods + unit: '{pod}' + - description: The number of pods which reached phase Succeeded for a job + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.job.successful_pods + unit: '{pod}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.replicaset.name + value: + stringValue: otelcol-786b94f3-67cf69944f + - key: k8s.replicaset.uid + value: + stringValue: d532dd9c-0490-4f85-be78-fd21d8a1b56f + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Total number of available pods (ready for at least minReadySeconds) targeted by this replicaset + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.replicaset.available + unit: '{pod}' + - description: Number of desired pods in this replicaset + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.replicaset.desired + unit: '{pod}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.statefulset.name + value: + stringValue: test-k8scluster-receiver-statefulset + - key: k8s.statefulset.uid + value: + stringValue: 5ceb9f10-fc64-4d70-b6f8-228b4a0cfd3c + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: The number of pods created by the StatefulSet controller from the StatefulSet version + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.statefulset.current_pods + unit: '{pod}' + - description: Number of desired pods in the stateful set (the `spec.replicas` field) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.statefulset.desired_pods + unit: '{pod}' + - description: Number of pods created by the stateful set that have the `Ready` condition + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.statefulset.ready_pods + unit: '{pod}' + - description: Number of pods created by the StatefulSet controller from the StatefulSet version + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.statefulset.updated_pods + unit: '{pod}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-cronjob-28839770-9pp7g + - key: k8s.pod.uid + value: + stringValue: e388cfa8-06c3-47b6-a7a6-113d7cdda849 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.pod.phase + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-cronjob-28839771-llccr + - key: k8s.pod.uid + value: + stringValue: 0c2351b3-842c-4632-95c2-e7b061128a98 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.pod.phase + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-job-bzjrh + - key: k8s.pod.uid + value: + stringValue: 7e8bdace-4bce-4750-bd8c-d7359bb3e56b + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.pod.phase + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-statefulset-0 + - key: k8s.pod.uid + value: + stringValue: f1ea5486-77b7-41c6-a3be-d03650011801 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + gauge: + dataPoints: + - asInt: "2" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.pod.phase + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 10c9bec31ac94fc58e65ce5ed809455727eee9daae8ea80668990e848a7e7da0 + - key: container.image.name + value: + stringValue: docker.io/library/alpine + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: alpine + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-cronjob-28839771-llccr + - key: k8s.pod.uid + value: + stringValue: 0c2351b3-842c-4632-95c2-e7b061128a98 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 2cb1cb272a301a00f50020c3e4751bfa9a281496a6dc35f02a5546451e894e93 + - key: container.image.name + value: + stringValue: docker.io/library/nginx + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: nginx + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-statefulset-0 + - key: k8s.pod.uid + value: + stringValue: f1ea5486-77b7-41c6-a3be-d03650011801 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 567cd0ad83d68987dfb4dbffd056732b25bd2fc89e912605c16a5d1a4cd2b54c + - key: container.image.name + value: + stringValue: docker.io/library/alpine + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: alpine + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-job-bzjrh + - key: k8s.pod.uid + value: + stringValue: 7e8bdace-4bce-4750-bd8c-d7359bb3e56b + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 2cb1cb272a301a00f50020c3e4751bfa9a281496a6dc35f02a5546451e894e93 + - key: container.image.name + value: + stringValue: docker.io/library/nginx + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: nginx + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-statefulset-0 + - key: k8s.pod.uid + value: + stringValue: f1ea5486-77b7-41c6-a3be-d03650011801 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 567cd0ad83d68987dfb4dbffd056732b25bd2fc89e912605c16a5d1a4cd2b54c + - key: container.image.name + value: + stringValue: docker.io/library/alpine + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: alpine + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-job-bzjrh + - key: k8s.pod.uid + value: + stringValue: 7e8bdace-4bce-4750-bd8c-d7359bb3e56b + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 6af7be5c276ef225d046ad0de442ee450c39122a12991f9da82c9629f949967b + - key: container.image.name + value: + stringValue: registry.k8s.io/coredns/coredns + - key: container.image.tag + value: + stringValue: v1.11.1 + - key: k8s.container.name + value: + stringValue: coredns + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: coredns-7db6d8ff4d-5kh78 + - key: k8s.pod.uid + value: + stringValue: 2c5b60e0-a01e-4312-8818-d85f94ab841e + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.cpu_request + unit: '{cpu}' + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "178257920" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.memory_limit + unit: By + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "73400320" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.memory_request + unit: By + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 7349de0618283fb11a957febc6689a0fbbfd9b52af1106bb3608bc4278a27ecf + - key: container.image.name + value: + stringValue: registry.k8s.io/kube-scheduler-arm64 + - key: container.image.tag + value: + stringValue: v1.30.0 + - key: k8s.container.name + value: + stringValue: kube-scheduler + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-scheduler-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: 991bbf5d-d6b9-4e33-8954-2a5f3505ff2d + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.cpu_request + unit: '{cpu}' + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 9c70b20960c36ddb400607a354058cd7525ec491251379c5aa84c359c5d518d7 + - key: container.image.name + value: + stringValue: registry.k8s.io/etcd + - key: container.image.tag + value: + stringValue: 3.5.12-0 + - key: k8s.container.name + value: + stringValue: etcd + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: etcd-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: 40e8f13b-bec6-4dae-98d9-fd86939dfc4c + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.cpu_request + unit: '{cpu}' + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "104857600" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.memory_request + unit: By + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 9c9e2d8cc660d21018432215b93bd4b9f26fbb0b0dfe71dca8c7089997cce23e + - key: container.image.name + value: + stringValue: registry.k8s.io/coredns/coredns + - key: container.image.tag + value: + stringValue: v1.11.1 + - key: k8s.container.name + value: + stringValue: coredns + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: coredns-7db6d8ff4d-p89tc + - key: k8s.pod.uid + value: + stringValue: f3494708-493a-4f0f-965c-dcedfdca253f + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.cpu_request + unit: '{cpu}' + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "178257920" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.memory_limit + unit: By + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "73400320" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.memory_request + unit: By + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: acef2130e48fde6137e919c9eebc876435ff8a6a22031754fc1dde00cb6dae92 + - key: container.image.name + value: + stringValue: docker.io/kindest/local-path-provisioner + - key: container.image.tag + value: + stringValue: v20240202-8f1494ea + - key: k8s.container.name + value: + stringValue: local-path-provisioner + - key: k8s.namespace.name + value: + stringValue: local-path-storage + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: local-path-provisioner-988d74bc-c2wx7 + - key: k8s.pod.uid + value: + stringValue: 1169e7ae-031e-4535-bb94-aee23b0b7df3 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: bd25536854ec1e582f0bb3ac0f79ce761ae97317d9ba1f7b256f3e833bcba862 + - key: container.image.name + value: + stringValue: registry.k8s.io/kube-apiserver-arm64 + - key: container.image.tag + value: + stringValue: v1.30.0 + - key: k8s.container.name + value: + stringValue: kube-apiserver + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-apiserver-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: d2032a9e-8c7c-4d9c-bbcb-526bd1a7b4f7 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.25 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.cpu_request + unit: '{cpu}' + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: cc67e9bcb82cbeed83bc8dec9cf2b0c7915d921e793efb0d21da5225dfeb907d + - key: container.image.name + value: + stringValue: registry.k8s.io/kube-controller-manager-arm64 + - key: container.image.tag + value: + stringValue: v1.30.0 + - key: k8s.container.name + value: + stringValue: kube-controller-manager + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kube-controller-manager-kind-control-plane + - key: k8s.pod.uid + value: + stringValue: e3e6d44a-5bc6-4687-85f1-37eb42c42c05 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.2 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.cpu_request + unit: '{cpu}' + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: e14e6f08e774618b74202d19334266e4c65c1feb0b26ef7e8b7807644754f730 + - key: container.image.name + value: + stringValue: docker.io/library/otelcontribcol + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: opentelemetry-collector + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: otelcol-786b94f3-67cf69944f-6zv25 + - key: k8s.pod.uid + value: + stringValue: 1fb8be2b-ae32-41c2-a172-e6cb9beb7c37 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.128 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.cpu_limit + unit: '{cpu}' + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.128 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.cpu_request + unit: '{cpu}' + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "268435456" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.memory_limit + unit: By + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "268435456" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.memory_request + unit: By + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: ed3ab86077c3de40d6d9125bf4f25dbf1734c58c9c3a864e5ccc1ce3bcfc1d30 + - key: container.image.name + value: + stringValue: docker.io/kindest/kindnetd + - key: container.image.tag + value: + stringValue: v20240202-8f1494ea + - key: k8s.container.name + value: + stringValue: kindnet-cni + - key: k8s.namespace.name + value: + stringValue: kube-system + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: kindnet-qwzhw + - key: k8s.pod.uid + value: + stringValue: 955e1f8c-2fe3-4a1d-85e6-31ff7410dc00 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.cpu_limit + unit: '{cpu}' + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asDouble: 0.1 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.cpu_request + unit: '{cpu}' + - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "52428800" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.memory_limit + unit: By + - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details + gauge: + dataPoints: + - asInt: "52428800" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.memory_request + unit: By + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: f01b9f5343f9ba34db396889c75d6128dace385b8f0c7aed2d39866ddd0df826 + - key: container.image.name + value: + stringValue: docker.io/library/alpine + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: alpine + - key: k8s.namespace.name + value: + stringValue: default + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-cronjob-28839770-9pp7g + - key: k8s.pod.uid + value: + stringValue: e388cfa8-06c3-47b6-a7a6-113d7cdda849 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + gauge: + dataPoints: + - asInt: "1" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest \ No newline at end of file From db9746fc25ef712a86ad4d2aa3438b390dc15a38 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 11:45:08 +0100 Subject: [PATCH 22/39] adapt assertions Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 4a8c2af5ed53..de6ca5da5b4f 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -69,7 +69,8 @@ func TestE2EClusterScoped(t *testing.T) { } }) - waitForData(t, expected.ResourceMetrics().Len(), metricsConsumer) + wantEntries := 10 // Minimal number of metrics to wait for. + waitForData(t, wantEntries, metricsConsumer) replaceWithStar := func(string) string { return "*" } shortenNames := func(value string) string { @@ -200,7 +201,8 @@ func TestE2ENamespaceScoped(t *testing.T) { } }) - waitForData(t, expected.ResourceMetrics().Len(), metricsConsumer) + wantEntries := 10 // Minimal number of metrics to wait for. + waitForData(t, wantEntries, metricsConsumer) replaceWithStar := func(string) string { return "*" } shortenNames := func(value string) string { From 196809959560bd2dd18cf1d34fae915426b41870 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 12:53:03 +0100 Subject: [PATCH 23/39] use separate namespace for namespace-scoped test Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 27 ++++++---------- .../testobjects/cronjob.yaml | 0 .../{ => cluster-scoped}/testobjects/hpa.yaml | 0 .../{ => cluster-scoped}/testobjects/job.yaml | 0 .../testobjects/statefulset.yaml | 0 .../namespace-scoped/collector/configmap.yaml | 5 ++- .../collector/deployment.yaml | 2 +- .../e2e/namespace-scoped/collector/role.yaml | 2 +- .../collector/rolebinding.yaml | 4 +-- .../namespace-scoped/collector/service.yaml | 2 +- .../collector/serviceaccount.yaml | 2 +- .../e2e/namespace-scoped/expected.yaml | 32 +++++++++---------- .../namespace-scoped/testobjects/cronjob.yaml | 19 +++++++++++ .../e2e/namespace-scoped/testobjects/hpa.yaml | 13 ++++++++ .../e2e/namespace-scoped/testobjects/job.yaml | 17 ++++++++++ .../testobjects/namespace.yaml | 4 +++ .../testobjects/statefulset.yaml | 29 +++++++++++++++++ 17 files changed, 118 insertions(+), 40 deletions(-) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/testobjects/cronjob.yaml (100%) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/testobjects/hpa.yaml (100%) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/testobjects/job.yaml (100%) rename receiver/k8sclusterreceiver/testdata/e2e/{ => cluster-scoped}/testobjects/statefulset.yaml (100%) create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/cronjob.yaml create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/hpa.yaml create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/job.yaml create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/namespace.yaml create mode 100644 receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/statefulset.yaml diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index de6ca5da5b4f..7c31cce9a4ad 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -7,7 +7,6 @@ package k8sclusterreceiver import ( "context" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "path/filepath" "strings" "testing" @@ -30,7 +29,8 @@ import ( const expectedFileClusterScoped = "./testdata/e2e/cluster-scoped/expected.yaml" const expectedFileNamespaceScoped = "./testdata/e2e/namespace-scoped/expected.yaml" -const testObjectsDir = "./testdata/e2e/testobjects/" +const testObjectsDirClusterScoped = "./testdata/e2e/testobjects/cluster-scoped" +const testObjectsDirNamespaceScoped = "./testdata/e2e/testobjects/namespace-scoped" const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" // TestE2EClusterScoped tests the k8s cluster receiver with a real k8s cluster. @@ -49,7 +49,7 @@ func TestE2EClusterScoped(t *testing.T) { require.NoError(t, err) // k8s test objs - testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDir) + testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDirClusterScoped) require.NoErrorf(t, err, "failed to create objects") t.Cleanup(func() { @@ -69,7 +69,7 @@ func TestE2EClusterScoped(t *testing.T) { } }) - wantEntries := 10 // Minimal number of metrics to wait for. + wantEntries := expected.ResourceMetrics().Len() // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) replaceWithStar := func(string) string { return "*" } @@ -171,17 +171,7 @@ func TestE2ENamespaceScoped(t *testing.T) { require.NoError(t, err) // k8s test objs - - var testObjs []*unstructured.Unstructured - // the k8stest.Delete function does not wait for all objects to be fully deleted, therefore using Eventually here to retry in case - // one of the objects from the previous test is still being deleted - require.Eventually(t, func() bool { - testObjs, err = k8stest.CreateObjects(k8sClient, testObjectsDir) - if err != nil { - return false - } - return true - }, 30*time.Second, 5*time.Second) + testObjs, err := k8stest.CreateObjects(k8sClient, testObjectsDirNamespaceScoped) require.NoErrorf(t, err, "failed to create objects") t.Cleanup(func() { @@ -201,7 +191,7 @@ func TestE2ENamespaceScoped(t *testing.T) { } }) - wantEntries := 10 // Minimal number of metrics to wait for. + wantEntries := expected.ResourceMetrics().Len() // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) replaceWithStar := func(string) string { return "*" } @@ -268,7 +258,10 @@ func startUpSink(t *testing.T, mc *consumertest.MetricsSink) func() { func waitForData(t *testing.T, entriesNum int, mc *consumertest.MetricsSink) { timeoutMinutes := 3 require.Eventuallyf(t, func() bool { - return len(mc.AllMetrics()) > entriesNum + if len(mc.AllMetrics()) == 0 { + return false + } + return mc.AllMetrics()[len(mc.AllMetrics())-1].ResourceMetrics().Len() > entriesNum }, time.Duration(timeoutMinutes)*time.Minute, 1*time.Second, "failed to receive %d entries, received %d metrics in %d minutes", entriesNum, len(mc.AllMetrics()), timeoutMinutes) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/testobjects/cronjob.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/testobjects/cronjob.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/testobjects/hpa.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/hpa.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/testobjects/hpa.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/hpa.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/testobjects/job.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/job.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/testobjects/job.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/job.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/testobjects/statefulset.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/statefulset.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/testobjects/statefulset.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/statefulset.yaml diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml index 3354e435f289..3456a8e96eec 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: {{ .Name }}-config - namespace: default + namespace: my-namespace data: relay: | exporters: @@ -10,6 +10,8 @@ data: endpoint: {{ .HostEndpoint }}:4317 tls: insecure: true + debug: + verbosity: normal extensions: health_check: endpoint: 0.0.0.0:13133 @@ -28,5 +30,6 @@ data: metrics: exporters: - otlp + - debug receivers: - k8s_cluster diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml index 841c472b04f4..03c15792a9ec 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/deployment.yaml @@ -2,7 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Name }} - namespace: default + namespace: my-namespace spec: replicas: 1 selector: diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml index 842a153f38f1..9d56014df017 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/role.yaml @@ -4,7 +4,7 @@ metadata: name: {{ .Name }} labels: app: {{ .Name }} - namespace: default + namespace: my-namespace rules: - apiGroups: - "" diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml index c5b4c0953188..8f1bef259f45 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/rolebinding.yaml @@ -2,7 +2,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: {{ .Name }} - namespace: default + namespace: my-namespace roleRef: apiGroup: rbac.authorization.k8s.io kind: Role @@ -10,4 +10,4 @@ roleRef: subjects: - kind: ServiceAccount name: {{ .Name }} - namespace: default + namespace: my-namespace diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/service.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/service.yaml index 1bbfffb99197..560ce9f528c8 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/service.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/service.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Service metadata: name: {{ .Name }} - namespace: default + namespace: my-namespace spec: type: ClusterIP ports: diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/serviceaccount.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/serviceaccount.yaml index bdb3a8dd1b8f..52a523c42cc3 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/serviceaccount.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/serviceaccount.yaml @@ -2,4 +2,4 @@ apiVersion: v1 kind: ServiceAccount metadata: name: {{ .Name }} - namespace: default + namespace: my-namespace diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml index a6b690a6949e..011820c0106d 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml @@ -246,7 +246,7 @@ resourceMetrics: stringValue: a38da134-af71-4bc1-a585-c9e0342f9aab - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace schemaUrl: https://opentelemetry.io/schemas/1.18.0 scopeMetrics: - metrics: @@ -303,7 +303,7 @@ resourceMetrics: stringValue: 37a9e0cc-5315-4e89-bb2b-5221849ff483 - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace schemaUrl: https://opentelemetry.io/schemas/1.18.0 scopeMetrics: - metrics: @@ -360,7 +360,7 @@ resourceMetrics: stringValue: b7ecbf9e-8e1a-4d70-beda-aab183645382 - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace schemaUrl: https://opentelemetry.io/schemas/1.18.0 scopeMetrics: - metrics: @@ -411,7 +411,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.replicaset.name value: stringValue: otelcol-786b94f3-67cf69944f @@ -444,7 +444,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.statefulset.name value: stringValue: test-k8scluster-receiver-statefulset @@ -493,7 +493,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -520,7 +520,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -547,7 +547,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -574,7 +574,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -613,7 +613,7 @@ resourceMetrics: stringValue: alpine - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -660,7 +660,7 @@ resourceMetrics: stringValue: nginx - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -707,7 +707,7 @@ resourceMetrics: stringValue: alpine - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -754,7 +754,7 @@ resourceMetrics: stringValue: nginx - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -801,7 +801,7 @@ resourceMetrics: stringValue: alpine - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -1265,7 +1265,7 @@ resourceMetrics: stringValue: opentelemetry-collector - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -1423,7 +1423,7 @@ resourceMetrics: stringValue: alpine - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/cronjob.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/cronjob.yaml new file mode 100644 index 000000000000..5080e48a80d3 --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/cronjob.yaml @@ -0,0 +1,19 @@ +kind: CronJob +apiVersion: batch/v1 +metadata: + name: test-k8scluster-receiver-cronjob + namespace: my-namespace +spec: + schedule: "*/1 * * * *" + jobTemplate: + spec: + template: + spec: + containers: + - name: alpine + image: alpine + args: + - /bin/sh + - -c + - "echo Running; sleep 120" + restartPolicy: OnFailure diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/hpa.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/hpa.yaml new file mode 100644 index 000000000000..641832c5f954 --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/hpa.yaml @@ -0,0 +1,13 @@ +apiVersion: autoscaling/v1 +kind: HorizontalPodAutoscaler +metadata: + name: test-k8scluster-receiver-hpa + namespace: my-namespace +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: StatefulSet + name: test-k8scluster-receiver-statefulset + minReplicas: 1 + maxReplicas: 1 + targetCPUUtilizationPercentage: 50 diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/job.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/job.yaml new file mode 100644 index 000000000000..d449fef61582 --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/job.yaml @@ -0,0 +1,17 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: test-k8scluster-receiver-job + namespace: my-namespace +spec: + template: + spec: + containers: + - name: alpine + image: alpine + args: + - /bin/sh + - -c + - "echo Hello from Job; sleep 600" + restartPolicy: Never + backoffLimit: 3 diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/namespace.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/namespace.yaml new file mode 100644 index 000000000000..4cb279baf51a --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: my-namespace diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/statefulset.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/statefulset.yaml new file mode 100644 index 000000000000..50eb3f352361 --- /dev/null +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/statefulset.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-k8scluster-receiver-statefulset + namespace: my-namespace +spec: + serviceName: "test-k8scluster-receiver-statefulset-service" + replicas: 1 + selector: + matchLabels: + app: test-k8scluster-receiver-statefulset + template: + metadata: + labels: + app: test-k8scluster-receiver-statefulset + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 + volumeClaimTemplates: + - metadata: + name: test-k8scluster-receiver-statefulset-pvc + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 100Mi From fcbebe32064c8d875748d93a0873e49a87c5c58e Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 13:04:11 +0100 Subject: [PATCH 24/39] fix path to testobjects directory Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 7c31cce9a4ad..520e9a48cba1 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -29,8 +29,8 @@ import ( const expectedFileClusterScoped = "./testdata/e2e/cluster-scoped/expected.yaml" const expectedFileNamespaceScoped = "./testdata/e2e/namespace-scoped/expected.yaml" -const testObjectsDirClusterScoped = "./testdata/e2e/testobjects/cluster-scoped" -const testObjectsDirNamespaceScoped = "./testdata/e2e/testobjects/namespace-scoped" +const testObjectsDirClusterScoped = "./testdata/e2e/cluster-scoped/testobjects" +const testObjectsDirNamespaceScoped = "./testdata/e2e/namespace-scoped/testobjects" const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" // TestE2EClusterScoped tests the k8s cluster receiver with a real k8s cluster. From a4f913044827b51109b7fa2bc4ed93de3d68dc85 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 13:18:29 +0100 Subject: [PATCH 25/39] ensure namespace is created before applying other tests Signed-off-by: Florian Bacher --- .../testdata/e2e/cluster-scoped/testobjects/cronjob.yaml | 2 +- .../testobjects/{namespace.yaml => 1_namespace.yaml} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/{namespace.yaml => 1_namespace.yaml} (100%) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml index 706bc90f26df..3b67e5a5eb7b 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml @@ -15,5 +15,5 @@ spec: args: - /bin/sh - -c - - "echo Running; sleep 120" + - "echo Running; sleep 240" restartPolicy: OnFailure diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/namespace.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/1_namespace.yaml similarity index 100% rename from receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/namespace.yaml rename to receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/testobjects/1_namespace.yaml From 19f947f7a543f0ffde4a5db8d077cead657a65bf Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 13:39:55 +0100 Subject: [PATCH 26/39] fix namespace in confmap Signed-off-by: Florian Bacher --- .../testdata/e2e/namespace-scoped/collector/configmap.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml index 3456a8e96eec..b437e0cd7885 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/collector/configmap.yaml @@ -18,7 +18,7 @@ data: processors: receivers: k8s_cluster: - namespace: default + namespace: my-namespace service: telemetry: From dca10d1e7c8507016ffda44516f532cab3e3a40b Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 6 Nov 2024 13:44:48 +0100 Subject: [PATCH 27/39] adapt check for required number of metrics Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 520e9a48cba1..73ba98007ae2 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -261,7 +261,7 @@ func waitForData(t *testing.T, entriesNum int, mc *consumertest.MetricsSink) { if len(mc.AllMetrics()) == 0 { return false } - return mc.AllMetrics()[len(mc.AllMetrics())-1].ResourceMetrics().Len() > entriesNum + return mc.AllMetrics()[len(mc.AllMetrics())-1].ResourceMetrics().Len() == entriesNum }, time.Duration(timeoutMinutes)*time.Minute, 1*time.Second, "failed to receive %d entries, received %d metrics in %d minutes", entriesNum, len(mc.AllMetrics()), timeoutMinutes) From 742c6631ea5649bcc79f9a624465f6c8a06d0ecf Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 7 Nov 2024 09:13:04 +0100 Subject: [PATCH 28/39] fix test expectations Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 48 +- .../cluster-scoped/testobjects/cronjob.yaml | 4 +- .../e2e/namespace-scoped/expected.yaml | 1142 +++-------------- 3 files changed, 200 insertions(+), 994 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 73ba98007ae2..fe50eab0fd20 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -196,9 +196,36 @@ func TestE2ENamespaceScoped(t *testing.T) { replaceWithStar := func(string) string { return "*" } shortenNames := func(value string) string { + if strings.HasPrefix(value, "coredns") { + return "coredns" + } + if strings.HasPrefix(value, "kindnet") { + return "kindnet" + } + if strings.HasPrefix(value, "kube-apiserver") { + return "kube-apiserver" + } + if strings.HasPrefix(value, "kube-proxy") { + return "kube-proxy" + } + if strings.HasPrefix(value, "kube-scheduler") { + return "kube-scheduler" + } + if strings.HasPrefix(value, "kube-controller-manager") { + return "kube-controller-manager" + } + if strings.HasPrefix(value, "local-path-provisioner") { + return "local-path-provisioner" + } if strings.HasPrefix(value, "otelcol") { return "otelcol" } + if strings.HasPrefix(value, "test-k8scluster-receiver-cronjob") { + return "test-k8scluster-receiver-cronjob" + } + if strings.HasPrefix(value, "test-k8scluster-receiver-job") { + return "test-k8scluster-receiver-job" + } return value } containerImageShorten := func(value string) string { @@ -220,18 +247,23 @@ func TestE2ENamespaceScoped(t *testing.T) { "k8s.job.failed_pods", "k8s.job.max_parallel_pods", "k8s.job.successful_pods"), + pmetrictest.ChangeResourceAttributeValue("container.id", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("container.image.name", containerImageShorten), + pmetrictest.ChangeResourceAttributeValue("container.image.tag", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.cronjob.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.daemonset.uid", replaceWithStar), pmetrictest.ChangeResourceAttributeValue("k8s.deployment.name", shortenNames), - pmetrictest.ChangeResourceAttributeValue("k8s.pod.name", shortenNames), - pmetrictest.ChangeResourceAttributeValue("k8s.replicaset.name", shortenNames), pmetrictest.ChangeResourceAttributeValue("k8s.deployment.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.hpa.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.job.name", shortenNames), + pmetrictest.ChangeResourceAttributeValue("k8s.job.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.namespace.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.node.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.pod.name", shortenNames), pmetrictest.ChangeResourceAttributeValue("k8s.pod.uid", replaceWithStar), + pmetrictest.ChangeResourceAttributeValue("k8s.replicaset.name", shortenNames), pmetrictest.ChangeResourceAttributeValue("k8s.replicaset.uid", replaceWithStar), - pmetrictest.ChangeResourceAttributeValue("container.id", replaceWithStar), - pmetrictest.ChangeResourceAttributeValue("container.image.tag", replaceWithStar), - pmetrictest.ChangeResourceAttributeValue("k8s.node.uid", replaceWithStar), - pmetrictest.ChangeResourceAttributeValue("k8s.namespace.uid", replaceWithStar), - pmetrictest.ChangeResourceAttributeValue("k8s.daemonset.uid", replaceWithStar), - pmetrictest.ChangeResourceAttributeValue("container.image.name", containerImageShorten), + pmetrictest.ChangeResourceAttributeValue("k8s.statefulset.uid", replaceWithStar), pmetrictest.IgnoreScopeVersion(), pmetrictest.IgnoreResourceMetricsOrder(), pmetrictest.IgnoreMetricsOrder(), diff --git a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml index 3b67e5a5eb7b..ebc0e1f92507 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml @@ -4,6 +4,8 @@ metadata: name: test-k8scluster-receiver-cronjob namespace: default spec: + # ensure that only one job/pod is active for the lifetime of the test + concurrencyPolicy: Forbid schedule: "*/1 * * * *" jobTemplate: spec: @@ -15,5 +17,5 @@ spec: args: - /bin/sh - -c - - "echo Running; sleep 240" + - "echo Running; sleep 600" restartPolicy: OnFailure diff --git a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml index 011820c0106d..8c416ba833d8 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/namespace-scoped/expected.yaml @@ -9,7 +9,7 @@ resourceMetrics: stringValue: ed2f7c36-acb7-4348-9eaa-6e86d17b3e70 - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace schemaUrl: "https://opentelemetry.io/schemas/1.18.0" scopeMetrics: - metrics: @@ -34,7 +34,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.replicaset.name value: stringValue: otelcol-5ffb893c-5459b589fd @@ -65,7 +65,7 @@ resourceMetrics: attributes: - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -104,7 +104,7 @@ resourceMetrics: stringValue: opentelemetry-collector - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace - key: k8s.node.name value: stringValue: kind-control-plane @@ -172,7 +172,7 @@ resourceMetrics: stringValue: 6a3c3e99-5db1-481f-9d5d-782ae9de9f58 - key: k8s.namespace.name value: - stringValue: default + stringValue: my-namespace schemaUrl: https://opentelemetry.io/schemas/1.18.0 scopeMetrics: - metrics: @@ -187,55 +187,6 @@ resourceMetrics: scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest - - resource: - attributes: - - key: k8s.hpa.name - value: - stringValue: test-k8scluster-receiver-hpa - - key: k8s.hpa.uid - value: - stringValue: 963572dc-4663-4fb2-930a-e143320a03c3 - - key: k8s.namespace.name - value: - stringValue: default - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Current number of pod replicas managed by this autoscaler. - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.hpa.current_replicas - unit: '{pod}' - - description: Desired number of pod replicas managed by this autoscaler. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.hpa.desired_replicas - unit: '{pod}' - - description: Maximum number of replicas to which the autoscaler can scale up. - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.hpa.max_replicas - unit: '{pod}' - - description: Minimum number of replicas to which the autoscaler can scale up. - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.hpa.min_replicas - unit: '{pod}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - resource: attributes: - key: k8s.job.name @@ -295,58 +246,75 @@ resourceMetrics: version: latest - resource: attributes: - - key: k8s.job.name - value: - stringValue: test-k8scluster-receiver-cronjob-28839771 - - key: k8s.job.uid - value: - stringValue: 37a9e0cc-5315-4e89-bb2b-5221849ff483 - key: k8s.namespace.name value: stringValue: my-namespace + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-cronjob-28839770-9pp7g + - key: k8s.pod.uid + value: + stringValue: e388cfa8-06c3-47b6-a7a6-113d7cdda849 schemaUrl: https://opentelemetry.io/schemas/1.18.0 scopeMetrics: - metrics: - - description: The number of actively running pods for a job - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.job.active_pods - unit: '{pod}' - - description: The desired number of successfully finished pods the job should be run with - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.job.desired_successful_pods - unit: '{pod}' - - description: The number of pods which reached phase Failed for a job + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) gauge: dataPoints: - - asInt: "0" + - asInt: "2" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: k8s.job.failed_pods - unit: '{pod}' - - description: The max desired number of pods the job should run at any given time + name: k8s.pod.phase + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + - resource: + attributes: + - key: container.id + value: + stringValue: 10c9bec31ac94fc58e65ce5ed809455727eee9daae8ea80668990e848a7e7da0 + - key: container.image.name + value: + stringValue: docker.io/library/alpine + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: alpine + - key: k8s.namespace.name + value: + stringValue: my-namespace + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-cronjob-28839771-llccr + - key: k8s.pod.uid + value: + stringValue: 0c2351b3-842c-4632-95c2-e7b061128a98 + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) gauge: dataPoints: - asInt: "1" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: k8s.job.max_parallel_pods - unit: '{pod}' - - description: The number of pods which reached phase Succeeded for a job + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. gauge: dataPoints: - asInt: "0" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: k8s.job.successful_pods - unit: '{pod}' + name: k8s.container.restarts + unit: '{restart}' scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest @@ -407,39 +375,83 @@ resourceMetrics: scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest + - resource: attributes: - key: k8s.namespace.name value: stringValue: my-namespace - - key: k8s.replicaset.name + - key: k8s.node.name value: - stringValue: otelcol-786b94f3-67cf69944f - - key: k8s.replicaset.uid + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-job-bzjrh + - key: k8s.pod.uid value: - stringValue: d532dd9c-0490-4f85-be78-fd21d8a1b56f + stringValue: 7e8bdace-4bce-4750-bd8c-d7359bb3e56b schemaUrl: https://opentelemetry.io/schemas/1.18.0 scopeMetrics: - metrics: - - description: Total number of available pods (ready for at least minReadySeconds) targeted by this replicaset + - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) gauge: dataPoints: - - asInt: "1" + - asInt: "2" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: k8s.replicaset.available - unit: '{pod}' - - description: Number of desired pods in this replicaset + name: k8s.pod.phase + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver + version: latest + + - resource: + attributes: + - key: container.id + value: + stringValue: 567cd0ad83d68987dfb4dbffd056732b25bd2fc89e912605c16a5d1a4cd2b54c + - key: container.image.name + value: + stringValue: docker.io/library/alpine + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: alpine + - key: k8s.namespace.name + value: + stringValue: my-namespace + - key: k8s.node.name + value: + stringValue: kind-control-plane + - key: k8s.pod.name + value: + stringValue: test-k8scluster-receiver-job-bzjrh + - key: k8s.pod.uid + value: + stringValue: 7e8bdace-4bce-4750-bd8c-d7359bb3e56b + schemaUrl: https://opentelemetry.io/schemas/1.18.0 + scopeMetrics: + - metrics: + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) gauge: dataPoints: - asInt: "1" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: k8s.replicaset.desired - unit: '{pod}' + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest + - resource: attributes: - key: k8s.namespace.name @@ -489,6 +501,7 @@ resourceMetrics: scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest + - resource: attributes: - key: k8s.namespace.name @@ -499,10 +512,10 @@ resourceMetrics: stringValue: kind-control-plane - key: k8s.pod.name value: - stringValue: test-k8scluster-receiver-cronjob-28839770-9pp7g + stringValue: test-k8scluster-receiver-statefulset-0 - key: k8s.pod.uid value: - stringValue: e388cfa8-06c3-47b6-a7a6-113d7cdda849 + stringValue: f1ea5486-77b7-41c6-a3be-d03650011801 schemaUrl: https://opentelemetry.io/schemas/1.18.0 scopeMetrics: - metrics: @@ -518,6 +531,18 @@ resourceMetrics: version: latest - resource: attributes: + - key: container.id + value: + stringValue: 2cb1cb272a301a00f50020c3e4751bfa9a281496a6dc35f02a5546451e894e93 + - key: container.image.name + value: + stringValue: docker.io/library/nginx + - key: container.image.tag + value: + stringValue: latest + - key: k8s.container.name + value: + stringValue: nginx - key: k8s.namespace.name value: stringValue: my-namespace @@ -526,931 +551,78 @@ resourceMetrics: stringValue: kind-control-plane - key: k8s.pod.name value: - stringValue: test-k8scluster-receiver-cronjob-28839771-llccr + stringValue: test-k8scluster-receiver-statefulset-0 - key: k8s.pod.uid value: - stringValue: 0c2351b3-842c-4632-95c2-e7b061128a98 + stringValue: f1ea5486-77b7-41c6-a3be-d03650011801 schemaUrl: https://opentelemetry.io/schemas/1.18.0 scopeMetrics: - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) gauge: dataPoints: - - asInt: "2" + - asInt: "1" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: k8s.pod.phase + name: k8s.container.ready + - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + gauge: + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: k8s.container.restarts + unit: '{restart}' scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest + - resource: attributes: - - key: k8s.namespace.name - value: - stringValue: my-namespace - - key: k8s.node.name + - key: k8s.hpa.name value: - stringValue: kind-control-plane - - key: k8s.pod.name + stringValue: test-k8scluster-receiver-hpa + - key: k8s.hpa.uid value: - stringValue: test-k8scluster-receiver-job-bzjrh - - key: k8s.pod.uid + stringValue: 963572dc-4663-4fb2-930a-e143320a03c3 + - key: k8s.namespace.name value: - stringValue: 7e8bdace-4bce-4750-bd8c-d7359bb3e56b + stringValue: my-namespace schemaUrl: https://opentelemetry.io/schemas/1.18.0 scopeMetrics: - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) + - description: Current number of pod replicas managed by this autoscaler. gauge: dataPoints: - - asInt: "2" + - asInt: "1" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: k8s.pod.phase - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: my-namespace - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: test-k8scluster-receiver-statefulset-0 - - key: k8s.pod.uid - value: - stringValue: f1ea5486-77b7-41c6-a3be-d03650011801 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.pod.phase - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 10c9bec31ac94fc58e65ce5ed809455727eee9daae8ea80668990e848a7e7da0 - - key: container.image.name - value: - stringValue: docker.io/library/alpine - - key: container.image.tag - value: - stringValue: latest - - key: k8s.container.name - value: - stringValue: alpine - - key: k8s.namespace.name - value: - stringValue: my-namespace - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: test-k8scluster-receiver-cronjob-28839771-llccr - - key: k8s.pod.uid - value: - stringValue: 0c2351b3-842c-4632-95c2-e7b061128a98 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 2cb1cb272a301a00f50020c3e4751bfa9a281496a6dc35f02a5546451e894e93 - - key: container.image.name - value: - stringValue: docker.io/library/nginx - - key: container.image.tag - value: - stringValue: latest - - key: k8s.container.name - value: - stringValue: nginx - - key: k8s.namespace.name - value: - stringValue: my-namespace - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: test-k8scluster-receiver-statefulset-0 - - key: k8s.pod.uid - value: - stringValue: f1ea5486-77b7-41c6-a3be-d03650011801 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 567cd0ad83d68987dfb4dbffd056732b25bd2fc89e912605c16a5d1a4cd2b54c - - key: container.image.name - value: - stringValue: docker.io/library/alpine - - key: container.image.tag - value: - stringValue: latest - - key: k8s.container.name - value: - stringValue: alpine - - key: k8s.namespace.name - value: - stringValue: my-namespace - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: test-k8scluster-receiver-job-bzjrh - - key: k8s.pod.uid - value: - stringValue: 7e8bdace-4bce-4750-bd8c-d7359bb3e56b - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 2cb1cb272a301a00f50020c3e4751bfa9a281496a6dc35f02a5546451e894e93 - - key: container.image.name - value: - stringValue: docker.io/library/nginx - - key: container.image.tag - value: - stringValue: latest - - key: k8s.container.name - value: - stringValue: nginx - - key: k8s.namespace.name - value: - stringValue: my-namespace - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: test-k8scluster-receiver-statefulset-0 - - key: k8s.pod.uid - value: - stringValue: f1ea5486-77b7-41c6-a3be-d03650011801 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 567cd0ad83d68987dfb4dbffd056732b25bd2fc89e912605c16a5d1a4cd2b54c - - key: container.image.name - value: - stringValue: docker.io/library/alpine - - key: container.image.tag - value: - stringValue: latest - - key: k8s.container.name - value: - stringValue: alpine - - key: k8s.namespace.name - value: - stringValue: my-namespace - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: test-k8scluster-receiver-job-bzjrh - - key: k8s.pod.uid - value: - stringValue: 7e8bdace-4bce-4750-bd8c-d7359bb3e56b - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 6af7be5c276ef225d046ad0de442ee450c39122a12991f9da82c9629f949967b - - key: container.image.name - value: - stringValue: registry.k8s.io/coredns/coredns - - key: container.image.tag - value: - stringValue: v1.11.1 - - key: k8s.container.name - value: - stringValue: coredns - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: coredns-7db6d8ff4d-5kh78 - - key: k8s.pod.uid - value: - stringValue: 2c5b60e0-a01e-4312-8818-d85f94ab841e - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.cpu_request - unit: '{cpu}' - - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "178257920" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.memory_limit - unit: By - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "73400320" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.memory_request - unit: By - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 7349de0618283fb11a957febc6689a0fbbfd9b52af1106bb3608bc4278a27ecf - - key: container.image.name - value: - stringValue: registry.k8s.io/kube-scheduler-arm64 - - key: container.image.tag - value: - stringValue: v1.30.0 - - key: k8s.container.name - value: - stringValue: kube-scheduler - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kube-scheduler-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: 991bbf5d-d6b9-4e33-8954-2a5f3505ff2d - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.cpu_request - unit: '{cpu}' - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 9c70b20960c36ddb400607a354058cd7525ec491251379c5aa84c359c5d518d7 - - key: container.image.name - value: - stringValue: registry.k8s.io/etcd - - key: container.image.tag - value: - stringValue: 3.5.12-0 - - key: k8s.container.name - value: - stringValue: etcd - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: etcd-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: 40e8f13b-bec6-4dae-98d9-fd86939dfc4c - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.cpu_request - unit: '{cpu}' - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "104857600" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.memory_request - unit: By - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: 9c9e2d8cc660d21018432215b93bd4b9f26fbb0b0dfe71dca8c7089997cce23e - - key: container.image.name - value: - stringValue: registry.k8s.io/coredns/coredns - - key: container.image.tag - value: - stringValue: v1.11.1 - - key: k8s.container.name - value: - stringValue: coredns - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: coredns-7db6d8ff4d-p89tc - - key: k8s.pod.uid - value: - stringValue: f3494708-493a-4f0f-965c-dcedfdca253f - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.cpu_request - unit: '{cpu}' - - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "178257920" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.memory_limit - unit: By - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "73400320" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.memory_request - unit: By - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: acef2130e48fde6137e919c9eebc876435ff8a6a22031754fc1dde00cb6dae92 - - key: container.image.name - value: - stringValue: docker.io/kindest/local-path-provisioner - - key: container.image.tag - value: - stringValue: v20240202-8f1494ea - - key: k8s.container.name - value: - stringValue: local-path-provisioner - - key: k8s.namespace.name - value: - stringValue: local-path-storage - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: local-path-provisioner-988d74bc-c2wx7 - - key: k8s.pod.uid - value: - stringValue: 1169e7ae-031e-4535-bb94-aee23b0b7df3 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: bd25536854ec1e582f0bb3ac0f79ce761ae97317d9ba1f7b256f3e833bcba862 - - key: container.image.name - value: - stringValue: registry.k8s.io/kube-apiserver-arm64 - - key: container.image.tag - value: - stringValue: v1.30.0 - - key: k8s.container.name - value: - stringValue: kube-apiserver - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kube-apiserver-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: d2032a9e-8c7c-4d9c-bbcb-526bd1a7b4f7 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.25 - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.cpu_request - unit: '{cpu}' - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: cc67e9bcb82cbeed83bc8dec9cf2b0c7915d921e793efb0d21da5225dfeb907d - - key: container.image.name - value: - stringValue: registry.k8s.io/kube-controller-manager-arm64 - - key: container.image.tag - value: - stringValue: v1.30.0 - - key: k8s.container.name - value: - stringValue: kube-controller-manager - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kube-controller-manager-kind-control-plane - - key: k8s.pod.uid - value: - stringValue: e3e6d44a-5bc6-4687-85f1-37eb42c42c05 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.2 - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.cpu_request - unit: '{cpu}' - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: e14e6f08e774618b74202d19334266e4c65c1feb0b26ef7e8b7807644754f730 - - key: container.image.name - value: - stringValue: docker.io/library/otelcontribcol - - key: container.image.tag - value: - stringValue: latest - - key: k8s.container.name - value: - stringValue: opentelemetry-collector - - key: k8s.namespace.name - value: - stringValue: my-namespace - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: otelcol-786b94f3-67cf69944f-6zv25 - - key: k8s.pod.uid - value: - stringValue: 1fb8be2b-ae32-41c2-a172-e6cb9beb7c37 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.128 - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.cpu_limit - unit: '{cpu}' - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.128 - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.cpu_request - unit: '{cpu}' - - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "268435456" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.memory_limit - unit: By - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "268435456" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.memory_request - unit: By - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. + name: k8s.hpa.current_replicas + unit: '{pod}' + - description: Desired number of pod replicas managed by this autoscaler. gauge: dataPoints: - asInt: "0" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: ed3ab86077c3de40d6d9125bf4f25dbf1734c58c9c3a864e5ccc1ce3bcfc1d30 - - key: container.image.name - value: - stringValue: docker.io/kindest/kindnetd - - key: container.image.tag - value: - stringValue: v20240202-8f1494ea - - key: k8s.container.name - value: - stringValue: kindnet-cni - - key: k8s.namespace.name - value: - stringValue: kube-system - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: kindnet-qwzhw - - key: k8s.pod.uid - value: - stringValue: 955e1f8c-2fe3-4a1d-85e6-31ff7410dc00 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.cpu_limit - unit: '{cpu}' - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asDouble: 0.1 - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.cpu_request - unit: '{cpu}' - - description: Maximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "52428800" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.memory_limit - unit: By - - description: Resource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details - gauge: - dataPoints: - - asInt: "52428800" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.memory_request - unit: By - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + name: k8s.hpa.desired_replicas + unit: '{pod}' + - description: Maximum number of replicas to which the autoscaler can scale up. gauge: dataPoints: - asInt: "1" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: f01b9f5343f9ba34db396889c75d6128dace385b8f0c7aed2d39866ddd0df826 - - key: container.image.name - value: - stringValue: docker.io/library/alpine - - key: container.image.tag - value: - stringValue: latest - - key: k8s.container.name - value: - stringValue: alpine - - key: k8s.namespace.name - value: - stringValue: my-namespace - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: test-k8scluster-receiver-cronjob-28839770-9pp7g - - key: k8s.pod.uid - value: - stringValue: e388cfa8-06c3-47b6-a7a6-113d7cdda849 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) + name: k8s.hpa.max_replicas + unit: '{pod}' + - description: Minimum number of replicas to which the autoscaler can scale up. gauge: dataPoints: - asInt: "1" startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' + name: k8s.hpa.min_replicas + unit: '{pod}' scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest \ No newline at end of file From 75c8b0e988edb5f49efcda9f9ba07b01997b7582 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 7 Nov 2024 09:34:56 +0100 Subject: [PATCH 29/39] trigger CI Signed-off-by: Florian Bacher From bc00b770a5876bcc4aae1e3e9b2d4090f2c7aa79 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 7 Nov 2024 09:52:21 +0100 Subject: [PATCH 30/39] increase timeout and ignore k8s.hpa.current_replicas metric value Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index fe50eab0fd20..19890d5897dc 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -127,6 +127,7 @@ func TestE2EClusterScoped(t *testing.T) { "k8s.job.desired_successful_pods", "k8s.job.failed_pods", "k8s.job.max_parallel_pods", + "k8s.hpa.current_replicas", "k8s.job.successful_pods"), pmetrictest.ChangeResourceAttributeValue("container.id", replaceWithStar), pmetrictest.ChangeResourceAttributeValue("container.image.name", containerImageShorten), @@ -246,6 +247,7 @@ func TestE2ENamespaceScoped(t *testing.T) { "k8s.job.desired_successful_pods", "k8s.job.failed_pods", "k8s.job.max_parallel_pods", + "k8s.hpa.current_replicas", "k8s.job.successful_pods"), pmetrictest.ChangeResourceAttributeValue("container.id", replaceWithStar), pmetrictest.ChangeResourceAttributeValue("container.image.name", containerImageShorten), @@ -288,7 +290,7 @@ func startUpSink(t *testing.T, mc *consumertest.MetricsSink) func() { } func waitForData(t *testing.T, entriesNum int, mc *consumertest.MetricsSink) { - timeoutMinutes := 3 + timeoutMinutes := 6 require.Eventuallyf(t, func() bool { if len(mc.AllMetrics()) == 0 { return false From 1defed91c38976adc37cb41b248e54bda3d9d116 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 7 Nov 2024 10:23:48 +0100 Subject: [PATCH 31/39] add debug logs Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 19890d5897dc..b1dafcb2a3f8 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -295,6 +295,7 @@ func waitForData(t *testing.T, entriesNum int, mc *consumertest.MetricsSink) { if len(mc.AllMetrics()) == 0 { return false } + t.Logf("received %d metrics", mc.AllMetrics()[len(mc.AllMetrics())-1].ResourceMetrics().Len()) return mc.AllMetrics()[len(mc.AllMetrics())-1].ResourceMetrics().Len() == entriesNum }, time.Duration(timeoutMinutes)*time.Minute, 1*time.Second, "failed to receive %d entries, received %d metrics in %d minutes", entriesNum, From 4bb2346a97eb8e9d9b6a131a9d2de739588576b5 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 7 Nov 2024 10:50:11 +0100 Subject: [PATCH 32/39] reduce job sleep time Signed-off-by: Florian Bacher --- .../testdata/e2e/cluster-scoped/testobjects/cronjob.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml index ebc0e1f92507..25732d1820da 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml @@ -17,5 +17,5 @@ spec: args: - /bin/sh - -c - - "echo Running; sleep 600" + - "echo Running; sleep 120" restartPolicy: OnFailure From 6315eddc3eeb373c90503673717df668fcd345a2 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 7 Nov 2024 13:00:45 +0100 Subject: [PATCH 33/39] adapt expections Signed-off-by: Florian Bacher --- .../testdata/e2e/cluster-scoped/expected.yaml | 133 +----------------- .../cluster-scoped/testobjects/cronjob.yaml | 2 +- 2 files changed, 3 insertions(+), 132 deletions(-) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/expected.yaml index 9f7aed414369..bd61c054a78b 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/expected.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/expected.yaml @@ -395,63 +395,7 @@ resourceMetrics: scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest - - resource: - attributes: - - key: k8s.job.name - value: - stringValue: test-k8scluster-receiver-cronjob-28839770 - - key: k8s.job.uid - value: - stringValue: a38da134-af71-4bc1-a585-c9e0342f9aab - - key: k8s.namespace.name - value: - stringValue: default - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: The number of actively running pods for a job - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.job.active_pods - unit: '{pod}' - - description: The desired number of successfully finished pods the job should be run with - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.job.desired_successful_pods - unit: '{pod}' - - description: The number of pods which reached phase Failed for a job - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.job.failed_pods - unit: '{pod}' - - description: The max desired number of pods the job should run at any given time - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.job.max_parallel_pods - unit: '{pod}' - - description: The number of pods which reached phase Succeeded for a job - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.job.successful_pods - unit: '{pod}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest + - resource: attributes: - key: k8s.job.name @@ -795,33 +739,7 @@ resourceMetrics: scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest - - resource: - attributes: - - key: k8s.namespace.name - value: - stringValue: default - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: test-k8scluster-receiver-job-bzjrh - - key: k8s.pod.uid - value: - stringValue: 7e8bdace-4bce-4750-bd8c-d7359bb3e56b - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown) - gauge: - dataPoints: - - asInt: "2" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.pod.phase - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest + - resource: attributes: - key: k8s.namespace.name @@ -1855,50 +1773,3 @@ resourceMetrics: scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver version: latest - - resource: - attributes: - - key: container.id - value: - stringValue: f01b9f5343f9ba34db396889c75d6128dace385b8f0c7aed2d39866ddd0df826 - - key: container.image.name - value: - stringValue: docker.io/library/alpine - - key: container.image.tag - value: - stringValue: latest - - key: k8s.container.name - value: - stringValue: alpine - - key: k8s.namespace.name - value: - stringValue: default - - key: k8s.node.name - value: - stringValue: kind-control-plane - - key: k8s.pod.name - value: - stringValue: test-k8scluster-receiver-cronjob-28839770-9pp7g - - key: k8s.pod.uid - value: - stringValue: e388cfa8-06c3-47b6-a7a6-113d7cdda849 - schemaUrl: https://opentelemetry.io/schemas/1.18.0 - scopeMetrics: - - metrics: - - description: Whether a container has passed its readiness probe (0 for no, 1 for yes) - gauge: - dataPoints: - - asInt: "1" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.ready - - description: How many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that. - gauge: - dataPoints: - - asInt: "0" - startTimeUnixNano: "1000000" - timeUnixNano: "2000000" - name: k8s.container.restarts - unit: '{restart}' - scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver - version: latest diff --git a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml index 25732d1820da..ebc0e1f92507 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/testobjects/cronjob.yaml @@ -17,5 +17,5 @@ spec: args: - /bin/sh - -c - - "echo Running; sleep 120" + - "echo Running; sleep 600" restartPolicy: OnFailure From 14aa5c6c0e789b03ea6cac0df2d7d27852ebeedd Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 7 Nov 2024 13:15:00 +0100 Subject: [PATCH 34/39] adapt expections Signed-off-by: Florian Bacher --- .../testdata/e2e/cluster-scoped/expected.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/expected.yaml b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/expected.yaml index bd61c054a78b..90959796c9c5 100644 --- a/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/expected.yaml +++ b/receiver/k8sclusterreceiver/testdata/e2e/cluster-scoped/expected.yaml @@ -695,7 +695,7 @@ resourceMetrics: stringValue: kind-control-plane - key: k8s.pod.name value: - stringValue: test-k8scluster-receiver-cronjob-28839770-9pp7g + stringValue: test-k8scluster-receiver-job-28839770-9pp7g - key: k8s.pod.uid value: stringValue: e388cfa8-06c3-47b6-a7a6-113d7cdda849 From 10e9267a041a7244b457132f4a974ba97e3bf029 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 7 Nov 2024 13:25:51 +0100 Subject: [PATCH 35/39] remove debug logs that are hopefully not needed anymore Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index b1dafcb2a3f8..19890d5897dc 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -295,7 +295,6 @@ func waitForData(t *testing.T, entriesNum int, mc *consumertest.MetricsSink) { if len(mc.AllMetrics()) == 0 { return false } - t.Logf("received %d metrics", mc.AllMetrics()[len(mc.AllMetrics())-1].ResourceMetrics().Len()) return mc.AllMetrics()[len(mc.AllMetrics())-1].ResourceMetrics().Len() == entriesNum }, time.Duration(timeoutMinutes)*time.Minute, 1*time.Second, "failed to receive %d entries, received %d metrics in %d minutes", entriesNum, From c1810ec524732155e8a83795b552dcf90ea55691 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Fri, 8 Nov 2024 07:27:42 +0100 Subject: [PATCH 36/39] revert changes to test logic Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 19890d5897dc..99c4a515e006 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -7,23 +7,22 @@ package k8sclusterreceiver import ( "context" + "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/receiver/otlpreceiver" + "go.opentelemetry.io/collector/receiver/receivertest" "path/filepath" "strings" "testing" "time" "github.com/google/uuid" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/pmetric" - "go.opentelemetry.io/collector/receiver/otlpreceiver" - "go.opentelemetry.io/collector/receiver/receivertest" - - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" ) const expectedFileClusterScoped = "./testdata/e2e/cluster-scoped/expected.yaml" @@ -69,7 +68,7 @@ func TestE2EClusterScoped(t *testing.T) { } }) - wantEntries := expected.ResourceMetrics().Len() // Minimal number of metrics to wait for. + wantEntries := 10 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) replaceWithStar := func(string) string { return "*" } @@ -192,7 +191,7 @@ func TestE2ENamespaceScoped(t *testing.T) { } }) - wantEntries := expected.ResourceMetrics().Len() // Minimal number of metrics to wait for. + wantEntries := 10 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) replaceWithStar := func(string) string { return "*" } @@ -290,12 +289,9 @@ func startUpSink(t *testing.T, mc *consumertest.MetricsSink) func() { } func waitForData(t *testing.T, entriesNum int, mc *consumertest.MetricsSink) { - timeoutMinutes := 6 + timeoutMinutes := 3 require.Eventuallyf(t, func() bool { - if len(mc.AllMetrics()) == 0 { - return false - } - return mc.AllMetrics()[len(mc.AllMetrics())-1].ResourceMetrics().Len() == entriesNum + return len(mc.AllMetrics()) > entriesNum }, time.Duration(timeoutMinutes)*time.Minute, 1*time.Second, "failed to receive %d entries, received %d metrics in %d minutes", entriesNum, len(mc.AllMetrics()), timeoutMinutes) From 4a673dcc4f7a9172f2596c2317a79753396a8dc3 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Fri, 8 Nov 2024 08:18:30 +0100 Subject: [PATCH 37/39] extract common helper functions Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 119 +++++++++--------------- 1 file changed, 42 insertions(+), 77 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 99c4a515e006..6758d4af051e 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -71,46 +71,6 @@ func TestE2EClusterScoped(t *testing.T) { wantEntries := 10 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) - replaceWithStar := func(string) string { return "*" } - shortenNames := func(value string) string { - if strings.HasPrefix(value, "coredns") { - return "coredns" - } - if strings.HasPrefix(value, "kindnet") { - return "kindnet" - } - if strings.HasPrefix(value, "kube-apiserver") { - return "kube-apiserver" - } - if strings.HasPrefix(value, "kube-proxy") { - return "kube-proxy" - } - if strings.HasPrefix(value, "kube-scheduler") { - return "kube-scheduler" - } - if strings.HasPrefix(value, "kube-controller-manager") { - return "kube-controller-manager" - } - if strings.HasPrefix(value, "local-path-provisioner") { - return "local-path-provisioner" - } - if strings.HasPrefix(value, "otelcol") { - return "otelcol" - } - if strings.HasPrefix(value, "test-k8scluster-receiver-cronjob") { - return "test-k8scluster-receiver-cronjob" - } - if strings.HasPrefix(value, "test-k8scluster-receiver-job") { - return "test-k8scluster-receiver-job" - } - return value - } - containerImageShorten := func(value string) string { - // Extracts the image name by removing the repository prefix. - // Also removes any architecture identifier suffix, if present, by applying shortenNames. - return shortenNames(value[(strings.LastIndex(value, "/") + 1):]) - } - require.NoError(t, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1], pmetrictest.IgnoreTimestamp(), pmetrictest.IgnoreStartTimestamp(), @@ -194,43 +154,6 @@ func TestE2ENamespaceScoped(t *testing.T) { wantEntries := 10 // Minimal number of metrics to wait for. waitForData(t, wantEntries, metricsConsumer) - replaceWithStar := func(string) string { return "*" } - shortenNames := func(value string) string { - if strings.HasPrefix(value, "coredns") { - return "coredns" - } - if strings.HasPrefix(value, "kindnet") { - return "kindnet" - } - if strings.HasPrefix(value, "kube-apiserver") { - return "kube-apiserver" - } - if strings.HasPrefix(value, "kube-proxy") { - return "kube-proxy" - } - if strings.HasPrefix(value, "kube-scheduler") { - return "kube-scheduler" - } - if strings.HasPrefix(value, "kube-controller-manager") { - return "kube-controller-manager" - } - if strings.HasPrefix(value, "local-path-provisioner") { - return "local-path-provisioner" - } - if strings.HasPrefix(value, "otelcol") { - return "otelcol" - } - if strings.HasPrefix(value, "test-k8scluster-receiver-cronjob") { - return "test-k8scluster-receiver-cronjob" - } - if strings.HasPrefix(value, "test-k8scluster-receiver-job") { - return "test-k8scluster-receiver-job" - } - return value - } - containerImageShorten := func(value string) string { - return value[(strings.LastIndex(value, "/") + 1):] - } require.NoError(t, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1], pmetrictest.IgnoreTimestamp(), pmetrictest.IgnoreStartTimestamp(), @@ -274,6 +197,48 @@ func TestE2ENamespaceScoped(t *testing.T) { ) } +func shortenNames(value string) string { + if strings.HasPrefix(value, "coredns") { + return "coredns" + } + if strings.HasPrefix(value, "kindnet") { + return "kindnet" + } + if strings.HasPrefix(value, "kube-apiserver") { + return "kube-apiserver" + } + if strings.HasPrefix(value, "kube-proxy") { + return "kube-proxy" + } + if strings.HasPrefix(value, "kube-scheduler") { + return "kube-scheduler" + } + if strings.HasPrefix(value, "kube-controller-manager") { + return "kube-controller-manager" + } + if strings.HasPrefix(value, "local-path-provisioner") { + return "local-path-provisioner" + } + if strings.HasPrefix(value, "otelcol") { + return "otelcol" + } + if strings.HasPrefix(value, "test-k8scluster-receiver-cronjob") { + return "test-k8scluster-receiver-cronjob" + } + if strings.HasPrefix(value, "test-k8scluster-receiver-job") { + return "test-k8scluster-receiver-job" + } + return value +} + +func replaceWithStar(_ string) string { return "*" } + +func containerImageShorten(value string) string { + // Extracts the image name by removing the repository prefix. + // Also removes any architecture identifier suffix, if present, by applying shortenNames. + return shortenNames(value[(strings.LastIndex(value, "/") + 1):]) +} + func startUpSink(t *testing.T, mc *consumertest.MetricsSink) func() { f := otlpreceiver.NewFactory() cfg := f.CreateDefaultConfig().(*otlpreceiver.Config) From 86eeb7eee07c90a819c7c163494b45acfba60932 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Fri, 8 Nov 2024 11:53:13 +0100 Subject: [PATCH 38/39] re-add comment for generating golden file Signed-off-by: Florian Bacher --- receiver/k8sclusterreceiver/e2e_test.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 6758d4af051e..39dca32392b4 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -7,22 +7,24 @@ package k8sclusterreceiver import ( "context" - "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/receiver/otlpreceiver" - "go.opentelemetry.io/collector/receiver/receivertest" "path/filepath" "strings" "testing" "time" + "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/receiver/otlpreceiver" + "go.opentelemetry.io/collector/receiver/receivertest" + "github.com/google/uuid" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/pmetric" + + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" ) const expectedFileClusterScoped = "./testdata/e2e/cluster-scoped/expected.yaml" @@ -69,6 +71,8 @@ func TestE2EClusterScoped(t *testing.T) { }) wantEntries := 10 // Minimal number of metrics to wait for. + // the commented line below writes the received list of metrics to the expected.yaml + // golden.WriteMetrics(t, expectedFileClusterScoped, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1]) waitForData(t, wantEntries, metricsConsumer) require.NoError(t, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1], @@ -152,6 +156,8 @@ func TestE2ENamespaceScoped(t *testing.T) { }) wantEntries := 10 // Minimal number of metrics to wait for. + // the commented line below writes the received list of metrics to the expected.yaml + // golden.WriteMetrics(t, expectedFileNamespaceScoped, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1]) waitForData(t, wantEntries, metricsConsumer) require.NoError(t, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1], From e2d8720174dc7850b544c34151554b9508a59743 Mon Sep 17 00:00:00 2001 From: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> Date: Mon, 18 Nov 2024 14:03:01 -0500 Subject: [PATCH 39/39] make generate --- receiver/k8sclusterreceiver/e2e_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 846a27473763..cebb087686b5 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -28,12 +28,12 @@ import ( ) const ( - expectedFileClusterScoped = "./testdata/e2e/cluster-scoped/expected.yaml" - expectedFileNamespaceScoped = "./testdata/e2e/namespace-scoped/expected.yaml" + expectedFileClusterScoped = "./testdata/e2e/cluster-scoped/expected.yaml" + expectedFileNamespaceScoped = "./testdata/e2e/namespace-scoped/expected.yaml" - testObjectsDirClusterScoped = "./testdata/e2e/cluster-scoped/testobjects" - testObjectsDirNamespaceScoped = "./testdata/e2e/namespace-scoped/testobjects" - testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" + testObjectsDirClusterScoped = "./testdata/e2e/cluster-scoped/testobjects" + testObjectsDirNamespaceScoped = "./testdata/e2e/namespace-scoped/testobjects" + testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" ) // TestE2EClusterScoped tests the k8s cluster receiver with a real k8s cluster.