From baa55f71cb79a5d0e01a757ef2bebc74d3a49da5 Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Fri, 16 Jan 2026 19:09:50 +0100 Subject: [PATCH 1/2] Add e2e test for eks detector Signed-off-by: Israel Blancas --- .../resourcedetectionprocessor/e2e_test.go | 42 ++++++ .../eks/collector/01-eks-api-cert-secret.yaml | 78 +++++++++++ .../eks/collector/02-eks-api-configmap.yaml | 67 ++++++++++ .../eks/collector/03-eks-api-deployment.yaml | 44 +++++++ .../e2e/eks/collector/04-eks-api-service.yaml | 12 ++ .../e2e/eks/collector/05-imds-configmap.yaml | 92 +++++++++++++ .../e2e/eks/collector/06-imds-deployment.yaml | 35 +++++ .../e2e/eks/collector/07-imds-service.yaml | 12 ++ .../eks/collector/08-fake-sa-configmap.yaml | 30 +++++ .../e2e/eks/collector/10-configmap.yaml | 56 ++++++++ .../e2e/eks/collector/11-serviceaccount.yaml | 6 + .../e2e/eks/collector/12-service.yaml | 12 ++ .../e2e/eks/collector/13-deployment.yaml | 102 +++++++++++++++ .../testdata/e2e/eks/expected.yaml | 122 ++++++++++++++++++ 14 files changed, 710 insertions(+) create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/01-eks-api-cert-secret.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/02-eks-api-configmap.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/03-eks-api-deployment.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/04-eks-api-service.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/05-imds-configmap.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/06-imds-deployment.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/07-imds-service.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/08-fake-sa-configmap.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/10-configmap.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/11-serviceaccount.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/12-service.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/13-deployment.yaml create mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/expected.yaml diff --git a/processor/resourcedetectionprocessor/e2e_test.go b/processor/resourcedetectionprocessor/e2e_test.go index 7729d576e6255..c915a0f3d8a44 100644 --- a/processor/resourcedetectionprocessor/e2e_test.go +++ b/processor/resourcedetectionprocessor/e2e_test.go @@ -140,6 +140,48 @@ func TestE2ESystemDetector(t *testing.T) { }, 3*time.Minute, 1*time.Second) } +// TestE2EEKSDetector validates the eks detector using mocked Kubernetes and EC2 metadata endpoints. +func TestE2EEKSDetector(t *testing.T) { + var expected pmetric.Metrics + expectedFile := filepath.Join("testdata", "e2e", "eks", "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", "eks", "collector"), map[string]string{}, "") + + defer func() { + for _, obj := range collectorObjs { + require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName()) + } + }() + + wantEntries := 10 + waitForData(t, wantEntries, metricsConsumer) + + require.EventuallyWithT(t, func(tt *assert.CollectT) { + assert.NoError(tt, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1], + pmetrictest.IgnoreTimestamp(), + pmetrictest.IgnoreStartTimestamp(), + pmetrictest.IgnoreScopeVersion(), + pmetrictest.IgnoreResourceMetricsOrder(), + pmetrictest.IgnoreMetricsOrder(), + pmetrictest.IgnoreScopeMetricsOrder(), + pmetrictest.IgnoreMetricDataPointsOrder(), + pmetrictest.IgnoreMetricValues(), + pmetrictest.IgnoreSubsequentDataPoints("system.cpu.time"), + ), + ) + }, 3*time.Minute, 1*time.Second) +} + // TestE2EGCPDetector validates that the gcp detector can populate Compute Engine // metadata by pointing the metadata client to a fake metadata server. func TestE2EGCPDetector(t *testing.T) { diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/01-eks-api-cert-secret.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/01-eks-api-cert-secret.yaml new file mode 100644 index 0000000000000..1068e6216439c --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/01-eks-api-cert-secret.yaml @@ -0,0 +1,78 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Name }}-eks-api-cert + namespace: default +type: Opaque +stringData: + ca.crt: | + -----BEGIN CERTIFICATE----- + MIIDDTCCAfWgAwIBAgIUHKur5/XvROOXy9Wd3R8HY8zCKr4wDQYJKoZIhvcNAQEL + BQAwFjEUMBIGA1UEAwwLZmFrZS1la3MtY2EwHhcNMjYwMTEzMTUyNDMxWhcNMzYw + MTExMTUyNDMxWjAWMRQwEgYDVQQDDAtmYWtlLWVrcy1jYTCCASIwDQYJKoZIhvcN + AQEBBQADggEPADCCAQoCggEBAI08VJ8dm6CG7dMzzLGESt9xWu9mmXh6oHT1Ajw1 + QpuLLxl28IjUhAxvdGN7+/+Key3E5eIb4yHLELxrkd2AYQYUHC4F0+r1Hi2It5Fi + CB9+kzo1THQ0Uhwh7h239XWgm9J0SIh5Ew1YU23++1YBQser1HfUg8b92wKkr2KQ + AGHZtoTC2HAnhGyhoIF14v8+uGBjJA7FhprSVjtRKJ87JU92IqbcHhH1hZzI1eTS + LP5u5j6xfQIub86FOGMlWEDDqj+YBv0pqtXrzdJXzjwUiekyaHXmO+fL5I7Il5SX + WoIuAiGH7Ok3RUwriuKciBMzen8sJ+7/J4qskpB8B1ThyJUCAwEAAaNTMFEwHQYD + VR0OBBYEFIJq4GRDFkNgIxskxIKF5gY7EfhfMB8GA1UdIwQYMBaAFIJq4GRDFkNg + IxskxIKF5gY7EfhfMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEB + AIW/TBnMsJfmQKl/SEIbfABJjbCiw8ctGKJ7qYcwS8C6zwi6cA//MV6293FmuCGY + yTdSWhtLF1Iik9kqnBdySIsFZxibBNu8JOggIQcAoSAwfPUbZvlZ1Bv6K8s3pv26 + jojObrjmXyAPtrZXkseroPrIDsNAPe5U3V9ZISKQFk0Jz0ALRumioeXDz37B2D61 + 121dLqmRo931CJ8ycj9Ziy1gqWdSZbVvnWGo/115OwLQf5WIHTI0DdCyzK/n5bYs + iZCYuTOJqfj+boNa98InV4TYDlC3nYRnY4dl/PFW74Q3PsiWB5VbeLDJXVGyDp+Y + eoULusLKrB+wAJMMSr/4jEU= + -----END CERTIFICATE----- + tls.crt: | + -----BEGIN CERTIFICATE----- + MIIDgDCCAmigAwIBAgIUTJl4wWhguJflswUZHVd/WwA3yC4wDQYJKoZIhvcNAQEL + BQAwFjEUMBIGA1UEAwwLZmFrZS1la3MtY2EwHhcNMjYwMTEzMTUyNDMxWhcNMzYw + MTExMTUyNDMxWjAeMRwwGgYDVQQDDBNla3MtYXBpLmRlZmF1bHQuc3ZjMIIBIjAN + BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA/YZ6fk2Yn7lNgpBr+ZIrgZ9n1Ov0 + cU4ywlgg9snkSqouqWAxXXTZbflGWBVimGHbBEaPZaUhXuAxExfxHQNF/PQ5x66l + nBqHCIZObRJBat1F1OrC19zGPOYIDUSK+3MNyHs0dIsduYhGIMvkQTQj2/Bvauzu + u+6dDz91poAL4Gz4tW9uDFlsW8AWU019luyjDZHu3cFzmh/IZJ5avUJ9YTP09RKi + HveOIHSBCv9AaNe+w3124Mo31HL5XIYPlerOxodIIMQy+GZhmSEoi4ImtE42q1YX + v5YoBanPuax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DHiF0gewK399XUMCZRif5qB7Q1QC + TpYCBdc8TIYvAVU+mIFWSK/EGUa88mV0H2VQVHUCgYEAvGD1lQ6ssH0Fax0w2tsf + zv5lVuDW9kd1QBAkzXLZXksvJsXW0ozyKJf4AWz0P8XqaNcIzezsats8f8xsXg80 + PJ/GvHH/g4ynRl41aJ49BjpEOC3D3jCEd35rETJECLZ9hbGH7oGuJTtvSu7c1uYS + pYobVTFrCAAW5JK0Pp90HZg= + -----END PRIVATE KEY----- diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/02-eks-api-configmap.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/02-eks-api-configmap.yaml new file mode 100644 index 0000000000000..586573a587a05 --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/02-eks-api-configmap.yaml @@ -0,0 +1,67 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Name }}-eks-api-config + namespace: default +data: + server.py: | + import json + import os + import ssl + from http.server import BaseHTTPRequestHandler, HTTPServer + + NODE_NAME = os.environ.get("FAKE_NODE_NAME", "fake-node") + PROVIDER_ID = os.environ.get("FAKE_PROVIDER_ID", "aws:///us-west-2a/i-0abc123456789") + + class Handler(BaseHTTPRequestHandler): + def do_GET(self): + if self.path == "/healthz": + body = b"ok" + self.send_response(200) + self.send_header("Content-Type", "text/plain; charset=utf-8") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + return + + if self.path == "/version": + payload = {"gitVersion": "v1.29.0-eks-123456"} + body = json.dumps(payload).encode("utf-8") + self.send_response(200) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + return + + if self.path.startswith("/api/v1/nodes/"): + node_name = self.path.split("/")[-1] + payload = { + "apiVersion": "v1", + "kind": "Node", + "metadata": {"name": node_name}, + "spec": {"providerID": PROVIDER_ID}, + } + body = json.dumps(payload).encode("utf-8") + self.send_response(200) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + return + + self.send_response(404) + self.end_headers() + + def log_message(self, fmt, *args): + return + + if __name__ == "__main__": + cert_file = os.environ.get("TLS_CERT_FILE") + key_file = os.environ.get("TLS_KEY_FILE") + port = int(os.environ.get("PORT", "8443")) + httpd = HTTPServer(("", port), Handler) + context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + context.load_cert_chain(certfile=cert_file, keyfile=key_file) + httpd.socket = context.wrap_socket(httpd.socket, server_side=True) + httpd.serve_forever() diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/03-eks-api-deployment.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/03-eks-api-deployment.yaml new file mode 100644 index 0000000000000..1d584c1fe0ad1 --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/03-eks-api-deployment.yaml @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Name }}-eks-api + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: {{ .Name }}-eks-api + template: + metadata: + labels: + app: {{ .Name }}-eks-api + spec: + containers: + - name: api-server + image: python:3.13-alpine + imagePullPolicy: IfNotPresent + command: + - python3 + - /scripts/server.py + env: + - name: TLS_CERT_FILE + value: /certs/tls.crt + - name: TLS_KEY_FILE + value: /certs/tls.key + - name: PORT + value: "8443" + ports: + - containerPort: 8443 + name: https + volumeMounts: + - name: script + mountPath: /scripts + - name: certs + mountPath: /certs + volumes: + - name: script + configMap: + name: {{ .Name }}-eks-api-config + - name: certs + secret: + secretName: {{ .Name }}-eks-api-cert diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/04-eks-api-service.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/04-eks-api-service.yaml new file mode 100644 index 0000000000000..bf2590d30b9a1 --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/04-eks-api-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Name }}-eks-api + namespace: default +spec: + selector: + app: {{ .Name }}-eks-api + ports: + - name: https + port: 8443 + targetPort: https diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/05-imds-configmap.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/05-imds-configmap.yaml new file mode 100644 index 0000000000000..a1f29d74c37e8 --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/05-imds-configmap.yaml @@ -0,0 +1,92 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Name }}-imds-config + namespace: default +data: + server.py: | + import json + import os + from http.server import BaseHTTPRequestHandler, HTTPServer + + INSTANCE_DOCUMENT = { + "accountId": "123456789012", + "architecture": "x86_64", + "availabilityZone": "us-west-2a", + "imageId": "ami-0abc123456789", + "instanceId": "i-0abc123456789", + "instanceType": "m5.large", + "privateIp": "10.0.0.10", + "region": "us-west-2", + "version": "2017-09-30", + } + HOSTNAME = "ip-10-0-0-10.us-west-2.compute.internal" + + TOKEN_VALUE = "test-token" + + class Handler(BaseHTTPRequestHandler): + def do_PUT(self): + if self.path == "/latest/api/token": + ttl = self.headers.get("X-aws-ec2-metadata-token-ttl-seconds") + if ttl is None: + self.send_response(400) + self.end_headers() + return + body = TOKEN_VALUE.encode("utf-8") + self.send_response(200) + self.send_header("Content-Type", "text/plain") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + return + self.send_response(404) + self.end_headers() + + def do_GET(self): + # Allow requests with or without metadata token for simplicity + if self.path == "/healthz": + body = b"ok" + self.send_response(200) + self.send_header("Content-Type", "text/plain; charset=utf-8") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + return + + if self.path == "/latest/dynamic/instance-identity/document": + body = json.dumps(INSTANCE_DOCUMENT).encode("utf-8") + self.send_response(200) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + return + + if self.path == "/latest/meta-data/instance-id": + body = INSTANCE_DOCUMENT["instanceId"].encode("utf-8") + self.send_response(200) + self.send_header("Content-Type", "text/plain") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + return + + if self.path == "/latest/meta-data/hostname": + body = HOSTNAME.encode("utf-8") + self.send_response(200) + self.send_header("Content-Type", "text/plain") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + return + + self.send_response(404) + self.end_headers() + + def log_message(self, fmt, *args): + return + + if __name__ == "__main__": + port = int(os.environ.get("PORT", "8080")) + httpd = HTTPServer(("", port), Handler) + httpd.serve_forever() diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/06-imds-deployment.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/06-imds-deployment.yaml new file mode 100644 index 0000000000000..6e183697fc4ac --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/06-imds-deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Name }}-imds + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: {{ .Name }}-imds + template: + metadata: + labels: + app: {{ .Name }}-imds + spec: + containers: + - name: imds + image: python:3.13-alpine + imagePullPolicy: IfNotPresent + command: + - python3 + - /scripts/server.py + env: + - name: PORT + value: "8080" + ports: + - containerPort: 8080 + name: http + volumeMounts: + - name: script + mountPath: /scripts + volumes: + - name: script + configMap: + name: {{ .Name }}-imds-config diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/07-imds-service.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/07-imds-service.yaml new file mode 100644 index 0000000000000..b9477b8846067 --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/07-imds-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Name }}-imds + namespace: default +spec: + selector: + app: {{ .Name }}-imds + ports: + - name: http + port: 8080 + targetPort: http diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/08-fake-sa-configmap.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/08-fake-sa-configmap.yaml new file mode 100644 index 0000000000000..f070fbca30c0a --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/08-fake-sa-configmap.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Name }}-fake-sa + namespace: default +data: + token: | + fake-service-account-token + namespace: | + default + ca.crt: | + -----BEGIN CERTIFICATE----- + MIIDDTCCAfWgAwIBAgIUHKur5/XvROOXy9Wd3R8HY8zCKr4wDQYJKoZIhvcNAQEL + BQAwFjEUMBIGA1UEAwwLZmFrZS1la3MtY2EwHhcNMjYwMTEzMTUyNDMxWhcNMzYw + MTExMTUyNDMxWjAWMRQwEgYDVQQDDAtmYWtlLWVrcy1jYTCCASIwDQYJKoZIhvcN + AQEBBQADggEPADCCAQoCggEBAI08VJ8dm6CG7dMzzLGESt9xWu9mmXh6oHT1Ajw1 + QpuLLxl28IjUhAxvdGN7+/+Key3E5eIb4yHLELxrkd2AYQYUHC4F0+r1Hi2It5Fi + CB9+kzo1THQ0Uhwh7h239XWgm9J0SIh5Ew1YU23++1YBQser1HfUg8b92wKkr2KQ + AGHZtoTC2HAnhGyhoIF14v8+uGBjJA7FhprSVjtRKJ87JU92IqbcHhH1hZzI1eTS + LP5u5j6xfQIub86FOGMlWEDDqj+YBv0pqtXrzdJXzjwUiekyaHXmO+fL5I7Il5SX + WoIuAiGH7Ok3RUwriuKciBMzen8sJ+7/J4qskpB8B1ThyJUCAwEAAaNTMFEwHQYD + VR0OBBYEFIJq4GRDFkNgIxskxIKF5gY7EfhfMB8GA1UdIwQYMBaAFIJq4GRDFkNg + IxskxIKF5gY7EfhfMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEB + AIW/TBnMsJfmQKl/SEIbfABJjbCiw8ctGKJ7qYcwS8C6zwi6cA//MV6293FmuCGY + yTdSWhtLF1Iik9kqnBdySIsFZxibBNu8JOggIQcAoSAwfPUbZvlZ1Bv6K8s3pv26 + jojObrjmXyAPtrZXkseroPrIDsNAPe5U3V9ZISKQFk0Jz0ALRumioeXDz37B2D61 + 121dLqmRo931CJ8ycj9Ziy1gqWdSZbVvnWGo/115OwLQf5WIHTI0DdCyzK/n5bYs + iZCYuTOJqfj+boNa98InV4TYDlC3nYRnY4dl/PFW74Q3PsiWB5VbeLDJXVGyDp+Y + eoULusLKrB+wAJMMSr/4jEU= + -----END CERTIFICATE----- diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/10-configmap.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/10-configmap.yaml new file mode 100644 index 0000000000000..3c09e15a22d35 --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/10-configmap.yaml @@ -0,0 +1,56 @@ +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: + resourcedetection: + detectors: [eks] + timeout: 2s + override: false + eks: + node_from_env_var: K8S_NODE_NAME + resource_attributes: + cloud.account.id: + enabled: true + cloud.availability_zone: + enabled: true + cloud.region: + enabled: true + host.id: + enabled: true + host.name: + enabled: true + host.type: + enabled: true + host.image.id: + enabled: true + receivers: + hostmetrics: + collection_interval: 1s + scrapers: + cpu: + service: + telemetry: + logs: + level: "debug" + extensions: + - health_check + pipelines: + metrics: + receivers: + - hostmetrics + processors: + - resourcedetection + exporters: + - otlp diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/11-serviceaccount.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/11-serviceaccount.yaml new file mode 100644 index 0000000000000..5a4c9cc9b5c46 --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/11-serviceaccount.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ .Name }}-sa + namespace: default +automountServiceAccountToken: false diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/12-service.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/12-service.yaml new file mode 100644 index 0000000000000..061f2ed2f4f65 --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/12-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Name }} + namespace: default +spec: + selector: + app: {{ .Name }} + ports: + - name: otlp-grpc + port: 4317 + targetPort: 4317 diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/13-deployment.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/13-deployment.yaml new file mode 100644 index 0000000000000..aad1d3caebc92 --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/13-deployment.yaml @@ -0,0 +1,102 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Name }} + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: {{ .Name }} + template: + metadata: + labels: + app: {{ .Name }} + spec: + serviceAccountName: {{ .Name }}-sa + automountServiceAccountToken: false + initContainers: + - name: wait-for-api + image: curlimages/curl:8.6.0 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -c + - > + until curl -sk https://{{ .Name }}-eks-api.default.svc.cluster.local:8443/healthz; + do + sleep 1; + done + - name: wait-for-imds + image: curlimages/curl:8.6.0 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -c + - > + until curl -sf http://{{ .Name }}-imds.default.svc.cluster.local:8080/healthz; + do + sleep 1; + done + containers: + - name: otelcol + image: otelcontribcol:latest + imagePullPolicy: Never + env: + - name: KUBERNETES_SERVICE_HOST + value: "{{ .Name }}-eks-api.default.svc.cluster.local" + - name: KUBERNETES_SERVICE_PORT + value: "8443" + - name: KUBERNETES_PORT + value: "tcp://{{ .Name }}-eks-api.default.svc.cluster.local:8443" + - name: KUBERNETES_PORT_443_TCP + value: "tcp://{{ .Name }}-eks-api.default.svc.cluster.local:8443" + - name: KUBERNETES_PORT_443_TCP_ADDR + value: "{{ .Name }}-eks-api.default.svc.cluster.local" + - name: KUBERNETES_PORT_443_TCP_PORT + value: "8443" + - name: KUBERNETES_PORT_443_TCP_PROTO + value: "tcp" + - name: AWS_REGION + value: us-west-2 + - name: AWS_ACCESS_KEY_ID + value: fake + - name: AWS_SECRET_ACCESS_KEY + value: fake + - name: AWS_EC2_METADATA_SERVICE_ENDPOINT + value: "http://{{ .Name }}-imds.default.svc.cluster.local:8080" + - name: AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE + value: IPv4 + - name: K8S_NODE_NAME + value: fake-node + args: + - "--config=/conf/relay" + ports: + - containerPort: 4317 + name: otlp-grpc + volumeMounts: + - name: config + mountPath: /conf + - name: fake-sa + mountPath: /var/run/secrets/kubernetes.io/serviceaccount + - name: collector-tmp + mountPath: /tmp + volumes: + - name: config + configMap: + name: {{ .Name }}-config + items: + - key: relay + path: relay + - name: fake-sa + configMap: + name: {{ .Name }}-fake-sa + items: + - key: token + path: token + - key: namespace + path: namespace + - key: ca.crt + path: ca.crt + - name: collector-tmp + emptyDir: {} diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/expected.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/expected.yaml new file mode 100644 index 0000000000000..d9e1fcfcf992d --- /dev/null +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/expected.yaml @@ -0,0 +1,122 @@ +resourceMetrics: + - resource: + attributes: + - key: cloud.account.id + value: + stringValue: "123456789012" + - key: cloud.availability_zone + value: + stringValue: us-west-2a + - key: cloud.platform + value: + stringValue: aws_eks + - key: cloud.provider + value: + stringValue: aws + - key: cloud.region + value: + stringValue: us-west-2 + - key: host.id + value: + stringValue: i-0abc123456789 + - key: host.image.id + value: + stringValue: ami-0abc123456789 + - key: host.name + value: + stringValue: ip-10-0-0-10.us-west-2.compute.internal + - key: host.type + value: + stringValue: m5.large + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: Total seconds each logical CPU spent on each mode. + name: system.cpu.time + sum: + aggregationTemporality: 2 + dataPoints: + - asDouble: 1.0 + attributes: + - key: cpu + value: + stringValue: cpu0 + - key: state + value: + stringValue: idle + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 1.0 + attributes: + - key: cpu + value: + stringValue: cpu0 + - key: state + value: + stringValue: interrupt + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 1.0 + attributes: + - key: cpu + value: + stringValue: cpu0 + - key: state + value: + stringValue: nice + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 1.0 + attributes: + - key: cpu + value: + stringValue: cpu0 + - key: state + value: + stringValue: softirq + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 1.0 + attributes: + - key: cpu + value: + stringValue: cpu0 + - key: state + value: + stringValue: steal + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 1.0 + attributes: + - key: cpu + value: + stringValue: cpu0 + - key: state + value: + stringValue: system + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 1.0 + attributes: + - key: cpu + value: + stringValue: cpu0 + - key: state + value: + stringValue: user + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 1.0 + attributes: + - key: cpu + value: + stringValue: cpu0 + - key: state + value: + stringValue: wait + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + isMonotonic: true + unit: s + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper From 9876af0ac5a77d748c761bbf7377dc0d3f33382e Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Mon, 19 Jan 2026 20:23:07 +0100 Subject: [PATCH 2/2] Apply feedback from code review Signed-off-by: Israel Blancas --- ...nfigmap.yaml => 05-fake-sa-configmap.yaml} | 0 .../e2e/eks/collector/05-imds-configmap.yaml | 92 ------------------- .../{10-configmap.yaml => 06-configmap.yaml} | 0 .../e2e/eks/collector/06-imds-deployment.yaml | 35 ------- .../e2e/eks/collector/07-imds-service.yaml | 12 --- ...iceaccount.yaml => 07-serviceaccount.yaml} | 0 .../{12-service.yaml => 08-service.yaml} | 0 ...{13-deployment.yaml => 09-deployment.yaml} | 21 ++--- .../testdata/e2e/eks/expected.yaml | 14 +-- 9 files changed, 15 insertions(+), 159 deletions(-) rename processor/resourcedetectionprocessor/testdata/e2e/eks/collector/{08-fake-sa-configmap.yaml => 05-fake-sa-configmap.yaml} (100%) delete mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/05-imds-configmap.yaml rename processor/resourcedetectionprocessor/testdata/e2e/eks/collector/{10-configmap.yaml => 06-configmap.yaml} (100%) delete mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/06-imds-deployment.yaml delete mode 100644 processor/resourcedetectionprocessor/testdata/e2e/eks/collector/07-imds-service.yaml rename processor/resourcedetectionprocessor/testdata/e2e/eks/collector/{11-serviceaccount.yaml => 07-serviceaccount.yaml} (100%) rename processor/resourcedetectionprocessor/testdata/e2e/eks/collector/{12-service.yaml => 08-service.yaml} (100%) rename processor/resourcedetectionprocessor/testdata/e2e/eks/collector/{13-deployment.yaml => 09-deployment.yaml} (87%) diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/08-fake-sa-configmap.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/05-fake-sa-configmap.yaml similarity index 100% rename from processor/resourcedetectionprocessor/testdata/e2e/eks/collector/08-fake-sa-configmap.yaml rename to processor/resourcedetectionprocessor/testdata/e2e/eks/collector/05-fake-sa-configmap.yaml diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/05-imds-configmap.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/05-imds-configmap.yaml deleted file mode 100644 index a1f29d74c37e8..0000000000000 --- a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/05-imds-configmap.yaml +++ /dev/null @@ -1,92 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ .Name }}-imds-config - namespace: default -data: - server.py: | - import json - import os - from http.server import BaseHTTPRequestHandler, HTTPServer - - INSTANCE_DOCUMENT = { - "accountId": "123456789012", - "architecture": "x86_64", - "availabilityZone": "us-west-2a", - "imageId": "ami-0abc123456789", - "instanceId": "i-0abc123456789", - "instanceType": "m5.large", - "privateIp": "10.0.0.10", - "region": "us-west-2", - "version": "2017-09-30", - } - HOSTNAME = "ip-10-0-0-10.us-west-2.compute.internal" - - TOKEN_VALUE = "test-token" - - class Handler(BaseHTTPRequestHandler): - def do_PUT(self): - if self.path == "/latest/api/token": - ttl = self.headers.get("X-aws-ec2-metadata-token-ttl-seconds") - if ttl is None: - self.send_response(400) - self.end_headers() - return - body = TOKEN_VALUE.encode("utf-8") - self.send_response(200) - self.send_header("Content-Type", "text/plain") - self.send_header("Content-Length", str(len(body))) - self.end_headers() - self.wfile.write(body) - return - self.send_response(404) - self.end_headers() - - def do_GET(self): - # Allow requests with or without metadata token for simplicity - if self.path == "/healthz": - body = b"ok" - self.send_response(200) - self.send_header("Content-Type", "text/plain; charset=utf-8") - self.send_header("Content-Length", str(len(body))) - self.end_headers() - self.wfile.write(body) - return - - if self.path == "/latest/dynamic/instance-identity/document": - body = json.dumps(INSTANCE_DOCUMENT).encode("utf-8") - self.send_response(200) - self.send_header("Content-Type", "application/json") - self.send_header("Content-Length", str(len(body))) - self.end_headers() - self.wfile.write(body) - return - - if self.path == "/latest/meta-data/instance-id": - body = INSTANCE_DOCUMENT["instanceId"].encode("utf-8") - self.send_response(200) - self.send_header("Content-Type", "text/plain") - self.send_header("Content-Length", str(len(body))) - self.end_headers() - self.wfile.write(body) - return - - if self.path == "/latest/meta-data/hostname": - body = HOSTNAME.encode("utf-8") - self.send_response(200) - self.send_header("Content-Type", "text/plain") - self.send_header("Content-Length", str(len(body))) - self.end_headers() - self.wfile.write(body) - return - - self.send_response(404) - self.end_headers() - - def log_message(self, fmt, *args): - return - - if __name__ == "__main__": - port = int(os.environ.get("PORT", "8080")) - httpd = HTTPServer(("", port), Handler) - httpd.serve_forever() diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/10-configmap.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/06-configmap.yaml similarity index 100% rename from processor/resourcedetectionprocessor/testdata/e2e/eks/collector/10-configmap.yaml rename to processor/resourcedetectionprocessor/testdata/e2e/eks/collector/06-configmap.yaml diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/06-imds-deployment.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/06-imds-deployment.yaml deleted file mode 100644 index 6e183697fc4ac..0000000000000 --- a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/06-imds-deployment.yaml +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ .Name }}-imds - namespace: default -spec: - replicas: 1 - selector: - matchLabels: - app: {{ .Name }}-imds - template: - metadata: - labels: - app: {{ .Name }}-imds - spec: - containers: - - name: imds - image: python:3.13-alpine - imagePullPolicy: IfNotPresent - command: - - python3 - - /scripts/server.py - env: - - name: PORT - value: "8080" - ports: - - containerPort: 8080 - name: http - volumeMounts: - - name: script - mountPath: /scripts - volumes: - - name: script - configMap: - name: {{ .Name }}-imds-config diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/07-imds-service.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/07-imds-service.yaml deleted file mode 100644 index b9477b8846067..0000000000000 --- a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/07-imds-service.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ .Name }}-imds - namespace: default -spec: - selector: - app: {{ .Name }}-imds - ports: - - name: http - port: 8080 - targetPort: http diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/11-serviceaccount.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/07-serviceaccount.yaml similarity index 100% rename from processor/resourcedetectionprocessor/testdata/e2e/eks/collector/11-serviceaccount.yaml rename to processor/resourcedetectionprocessor/testdata/e2e/eks/collector/07-serviceaccount.yaml diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/12-service.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/08-service.yaml similarity index 100% rename from processor/resourcedetectionprocessor/testdata/e2e/eks/collector/12-service.yaml rename to processor/resourcedetectionprocessor/testdata/e2e/eks/collector/08-service.yaml diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/13-deployment.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/09-deployment.yaml similarity index 87% rename from processor/resourcedetectionprocessor/testdata/e2e/eks/collector/13-deployment.yaml rename to processor/resourcedetectionprocessor/testdata/e2e/eks/collector/09-deployment.yaml index aad1d3caebc92..feebce0a44ca4 100644 --- a/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/13-deployment.yaml +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/collector/09-deployment.yaml @@ -27,18 +27,13 @@ spec: do sleep 1; done - - name: wait-for-imds - image: curlimages/curl:8.6.0 - imagePullPolicy: IfNotPresent - command: - - /bin/sh - - -c - - > - until curl -sf http://{{ .Name }}-imds.default.svc.cluster.local:8080/healthz; - do - sleep 1; - done containers: + - name: ec2-metadata-mock + image: public.ecr.aws/aws-ec2/amazon-ec2-metadata-mock:v1.13.0 + imagePullPolicy: IfNotPresent + ports: + - containerPort: 1338 + name: metadata - name: otelcol image: otelcontribcol:latest imagePullPolicy: Never @@ -58,13 +53,13 @@ spec: - name: KUBERNETES_PORT_443_TCP_PROTO value: "tcp" - name: AWS_REGION - value: us-west-2 + value: us-east-1 - name: AWS_ACCESS_KEY_ID value: fake - name: AWS_SECRET_ACCESS_KEY value: fake - name: AWS_EC2_METADATA_SERVICE_ENDPOINT - value: "http://{{ .Name }}-imds.default.svc.cluster.local:8080" + value: "http://localhost:1338" - name: AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE value: IPv4 - name: K8S_NODE_NAME diff --git a/processor/resourcedetectionprocessor/testdata/e2e/eks/expected.yaml b/processor/resourcedetectionprocessor/testdata/e2e/eks/expected.yaml index d9e1fcfcf992d..5f5e094a2b3ed 100644 --- a/processor/resourcedetectionprocessor/testdata/e2e/eks/expected.yaml +++ b/processor/resourcedetectionprocessor/testdata/e2e/eks/expected.yaml @@ -3,10 +3,10 @@ resourceMetrics: attributes: - key: cloud.account.id value: - stringValue: "123456789012" + stringValue: "0123456789" - key: cloud.availability_zone value: - stringValue: us-west-2a + stringValue: us-east-1f - key: cloud.platform value: stringValue: aws_eks @@ -15,19 +15,19 @@ resourceMetrics: stringValue: aws - key: cloud.region value: - stringValue: us-west-2 + stringValue: us-east-1 - key: host.id value: - stringValue: i-0abc123456789 + stringValue: i-1234567890abcdef0 - key: host.image.id value: - stringValue: ami-0abc123456789 + stringValue: ami-0b69ea66ff7391e80 - key: host.name value: - stringValue: ip-10-0-0-10.us-west-2.compute.internal + stringValue: ip-172-16-34-43.ec2.internal - key: host.type value: - stringValue: m5.large + stringValue: m4.xlarge schemaUrl: https://opentelemetry.io/schemas/1.9.0 scopeMetrics: - metrics: