diff --git a/deploy/helm/CHANGELOG.md b/deploy/helm/CHANGELOG.md index 21e1d0e3..257a5de0 100644 --- a/deploy/helm/CHANGELOG.md +++ b/deploy/helm/CHANGELOG.md @@ -7,13 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased -## [2.8.0-alpha.2] - 2023-09-14 +## [2.8.0-alpha.2] - 2023-09-22 ### Added - Add monitoring windows node logs +### Fixed +- Detection of Node name for Fargate Nodes's metrics ## [2.8.0-alpha.1] - 2023-09-11 diff --git a/deploy/helm/metrics-collector-config.yaml b/deploy/helm/metrics-collector-config.yaml index 59ce5426..3f20e883 100644 --- a/deploy/helm/metrics-collector-config.yaml +++ b/deploy/helm/metrics-collector-config.yaml @@ -50,31 +50,16 @@ processors: datapoint: - 'attributes["container"] == "POD" and IsMatch(metric.name, "container_network_.*|k8s.container.*") == true' - - # unify attributes - attributes/unify_node_attribute: - include: - match_type: regexp - metric_names: - - container_.* - - kube_node_.* - - kube_pod_info - - kube_pod_container_resource_requests - - kube_pod_container_resource_limits - - kube_pod_init_container_resource_requests - - kube_pod_init_container_resource_limits - actions: - - key: k8s.node.name - from_attribute: node - action: insert -{{- if not .Values.aws_fargate.enabled }} - - key: k8s.node.name - from_attribute: kubernetes_io_hostname - action: insert -{{- end }} - - key: k8s.node.name - from_attribute: service.instance.id - action: insert + transform/unify_node_attribute: + metric_statements: + - context: datapoint + statements: + # when available, use "node" attribute for Node name + - set(attributes["k8s.node.name"], attributes["node"]) where IsMatch(metric.name, "^(container_.*)|(kube_node_.*)|(kube_pod_info)|(kube_pod_container_resource_requests)|(kube_pod_container_resource_limits)|(kube_pod_init_container_resource_requests)|(kube_pod_init_container_resource_limits)$") == true and attributes["k8s.node.name"] == nil + # "kubernetes_io_hostname", unlike "service.instance.id", provides a nice Node name in environments like local Docker, but for Fargate, its value is different from the other attributes + - set(attributes["k8s.node.name"], attributes["kubernetes_io_hostname"]) where IsMatch(metric.name, "^(container_.*)|(kube_node_.*)|(kube_pod_info)|(kube_pod_container_resource_requests)|(kube_pod_container_resource_limits)|(kube_pod_init_container_resource_requests)|(kube_pod_init_container_resource_limits)$") == true and attributes["eks_amazonaws_com_compute_type"] != "fargate" and attributes["k8s.node.name"] == nil + # use "service.instance.id" for Node name when the above attributes are not available + - set(attributes["k8s.node.name"], resource.attributes["service.instance.id"]) where IsMatch(metric.name, "^(container_.*)|(kube_node_.*)|(kube_pod_info)|(kube_pod_container_resource_requests)|(kube_pod_container_resource_limits)|(kube_pod_init_container_resource_requests)|(kube_pod_init_container_resource_limits)$") == true and attributes["k8s.node.name"] == nil attributes/unify_volume_attribute: include: @@ -1483,7 +1468,7 @@ service: - filter/receiver - transform - filter/remove_internal - - attributes/unify_node_attribute + - transform/unify_node_attribute - attributes/unify_volume_attribute - attributes/identify_init_container - attributes/identify_standard_container diff --git a/deploy/helm/tests/__snapshot__/metrics-collector-config-map-fargate_test.yaml.snap b/deploy/helm/tests/__snapshot__/metrics-collector-config-map-fargate_test.yaml.snap index 17e2c857..b76ceff9 100644 --- a/deploy/helm/tests/__snapshot__/metrics-collector-config-map-fargate_test.yaml.snap +++ b/deploy/helm/tests/__snapshot__/metrics-collector-config-map-fargate_test.yaml.snap @@ -334,24 +334,6 @@ Metrics config should match snapshot when using default values: match_type: regexp metric_names: - .* - attributes/unify_node_attribute: - actions: - - action: insert - from_attribute: node - key: k8s.node.name - - action: insert - from_attribute: service.instance.id - key: k8s.node.name - include: - match_type: regexp - metric_names: - - container_.* - - kube_node_.* - - kube_pod_info - - kube_pod_container_resource_requests - - kube_pod_container_resource_limits - - kube_pod_init_container_resource_requests - - kube_pod_init_container_resource_limits attributes/unify_volume_attribute: actions: - action: insert @@ -1926,6 +1908,20 @@ Metrics config should match snapshot when using default values: - delete_key(resource.attributes, "sw.k8s.job.found") - delete_key(resource.attributes, "sw.k8s.cronjob.found") - delete_key(resource.attributes, "sw.k8s.node.found") + transform/unify_node_attribute: + metric_statements: + - context: datapoint + statements: + - set(attributes["k8s.node.name"], attributes["node"]) where IsMatch(metric.name, + "^(container_.*)|(kube_node_.*)|(kube_pod_info)|(kube_pod_container_resource_requests)|(kube_pod_container_resource_limits)|(kube_pod_init_container_resource_requests)|(kube_pod_init_container_resource_limits)$") + == true and attributes["k8s.node.name"] == nil + - set(attributes["k8s.node.name"], attributes["kubernetes_io_hostname"]) where + IsMatch(metric.name, "^(container_.*)|(kube_node_.*)|(kube_pod_info)|(kube_pod_container_resource_requests)|(kube_pod_container_resource_limits)|(kube_pod_init_container_resource_requests)|(kube_pod_init_container_resource_limits)$") + == true and attributes["eks_amazonaws_com_compute_type"] != "fargate" and + attributes["k8s.node.name"] == nil + - set(attributes["k8s.node.name"], resource.attributes["service.instance.id"]) + where IsMatch(metric.name, "^(container_.*)|(kube_node_.*)|(kube_pod_info)|(kube_pod_container_resource_requests)|(kube_pod_container_resource_limits)|(kube_pod_init_container_resource_requests)|(kube_pod_init_container_resource_limits)$") + == true and attributes["k8s.node.name"] == nil receivers: k8s_events: null prometheus/kube-state-metrics: @@ -1988,7 +1984,7 @@ Metrics config should match snapshot when using default values: - filter/receiver - transform - filter/remove_internal - - attributes/unify_node_attribute + - transform/unify_node_attribute - attributes/unify_volume_attribute - attributes/identify_init_container - attributes/identify_standard_container diff --git a/deploy/helm/tests/__snapshot__/metrics-collector-config-map_test.yaml.snap b/deploy/helm/tests/__snapshot__/metrics-collector-config-map_test.yaml.snap index 3a67f7fa..b76ceff9 100644 --- a/deploy/helm/tests/__snapshot__/metrics-collector-config-map_test.yaml.snap +++ b/deploy/helm/tests/__snapshot__/metrics-collector-config-map_test.yaml.snap @@ -334,27 +334,6 @@ Metrics config should match snapshot when using default values: match_type: regexp metric_names: - .* - attributes/unify_node_attribute: - actions: - - action: insert - from_attribute: node - key: k8s.node.name - - action: insert - from_attribute: kubernetes_io_hostname - key: k8s.node.name - - action: insert - from_attribute: service.instance.id - key: k8s.node.name - include: - match_type: regexp - metric_names: - - container_.* - - kube_node_.* - - kube_pod_info - - kube_pod_container_resource_requests - - kube_pod_container_resource_limits - - kube_pod_init_container_resource_requests - - kube_pod_init_container_resource_limits attributes/unify_volume_attribute: actions: - action: insert @@ -1929,6 +1908,20 @@ Metrics config should match snapshot when using default values: - delete_key(resource.attributes, "sw.k8s.job.found") - delete_key(resource.attributes, "sw.k8s.cronjob.found") - delete_key(resource.attributes, "sw.k8s.node.found") + transform/unify_node_attribute: + metric_statements: + - context: datapoint + statements: + - set(attributes["k8s.node.name"], attributes["node"]) where IsMatch(metric.name, + "^(container_.*)|(kube_node_.*)|(kube_pod_info)|(kube_pod_container_resource_requests)|(kube_pod_container_resource_limits)|(kube_pod_init_container_resource_requests)|(kube_pod_init_container_resource_limits)$") + == true and attributes["k8s.node.name"] == nil + - set(attributes["k8s.node.name"], attributes["kubernetes_io_hostname"]) where + IsMatch(metric.name, "^(container_.*)|(kube_node_.*)|(kube_pod_info)|(kube_pod_container_resource_requests)|(kube_pod_container_resource_limits)|(kube_pod_init_container_resource_requests)|(kube_pod_init_container_resource_limits)$") + == true and attributes["eks_amazonaws_com_compute_type"] != "fargate" and + attributes["k8s.node.name"] == nil + - set(attributes["k8s.node.name"], resource.attributes["service.instance.id"]) + where IsMatch(metric.name, "^(container_.*)|(kube_node_.*)|(kube_pod_info)|(kube_pod_container_resource_requests)|(kube_pod_container_resource_limits)|(kube_pod_init_container_resource_requests)|(kube_pod_init_container_resource_limits)$") + == true and attributes["k8s.node.name"] == nil receivers: k8s_events: null prometheus/kube-state-metrics: @@ -1991,7 +1984,7 @@ Metrics config should match snapshot when using default values: - filter/receiver - transform - filter/remove_internal - - attributes/unify_node_attribute + - transform/unify_node_attribute - attributes/unify_volume_attribute - attributes/identify_init_container - attributes/identify_standard_container diff --git a/tests/integration/expected_output.json b/tests/integration/expected_output.json index 3ae3e6f3..08150fb9 100644 --- a/tests/integration/expected_output.json +++ b/tests/integration/expected_output.json @@ -14133,80 +14133,6 @@ "scopeMetrics": [ { "metrics": [ - { - "gauge": { - "dataPoints": [ - { - "asDouble": 0.25, - "attributes": [ - { - "key": "endpoint", - "value": { - "stringValue": "http" - } - }, - { - "key": "prometheus", - "value": { - "stringValue": "prometheus-system/kube-prometheus-kube-prome-prometheus" - } - }, - { - "key": "prometheus_replica", - "value": { - "stringValue": "prometheus-kube-prometheus-kube-prome-prometheus-0" - } - }, - { - "key": "service", - "value": { - "stringValue": "test-service" - } - } - ], - "timeUnixNano": "0" - } - ] - }, - "name": "k8s.kube_pod_init_container_resource_requests_cpu_cores" - }, - { - "gauge": { - "dataPoints": [ - { - "asDouble": 67108864, - "attributes": [ - { - "key": "endpoint", - "value": { - "stringValue": "http" - } - }, - { - "key": "prometheus", - "value": { - "stringValue": "prometheus-system/kube-prometheus-kube-prome-prometheus" - } - }, - { - "key": "prometheus_replica", - "value": { - "stringValue": "prometheus-kube-prometheus-kube-prome-prometheus-0" - } - }, - { - "key": "service", - "value": { - "stringValue": "test-service" - } - } - ], - "timeUnixNano": "0" - } - ] - }, - "name": "k8s.kube_pod_init_container_resource_requests_memory_bytes" - }, { "gauge": { "dataPoints": [ @@ -16960,6 +16886,225 @@ } ] }, + { + "resource": { + "attributes": [ + { + "key": "container", + "value": { + "stringValue": "test-container" + } + }, + { + "key": "http.scheme", + "value": { + "stringValue": "http" + } + }, + { + "key": "k8s.cluster.name", + "value": { + "stringValue": "cluster name" + } + }, + { + "key": "k8s.container.name", + "value": { + "stringValue": "test-container" + } + }, + { + "key": "k8s.namespace.annotations.description", + "value": { + "stringValue": "This is a test namespace." + } + }, + { + "key": "k8s.namespace.labels.app", + "value": { + "stringValue": "test-app" + } + }, + { + "key": "k8s.namespace.labels.kubernetes.io/metadata.name", + "value": { + "stringValue": "test-namespace" + } + }, + { + "key": "k8s.namespace.labels.purpose", + "value": { + "stringValue": "testing" + } + }, + { + "key": "k8s.namespace.name", + "value": { + "stringValue": "test-namespace" + } + }, + { + "key": "k8s.pod.annotations.test-annotation", + "value": { + "stringValue": "test-value" + } + }, + { + "key": "k8s.pod.labels.app", + "value": { + "stringValue": "test-pod" + } + }, + { + "key": "k8s.pod.name", + "value": { + "stringValue": "test-pod" + } + }, + { + "key": "k8s.pod.uid", + "value": { + "stringValue": "c7f7a05a-a1b5-4fd0-a611-8e2a0e7acbf6" + } + }, + { + "key": "namespace", + "value": { + "stringValue": "test-namespace" + } + }, + { + "key": "net.host.name", + "value": { + "stringValue": "test-node" + } + }, + { + "key": "net.host.port", + "value": { + "stringValue": "" + } + }, + { + "key": "pod", + "value": { + "stringValue": "test-pod" + } + }, + { + "key": "sw.k8s.agent.app.version", + "value": { + "stringValue": "0.8.3" + } + }, + { + "key": "sw.k8s.agent.manifest.version", + "value": { + "stringValue": "2.8.0-alpha.2" + } + }, + { + "key": "sw.k8s.cluster.uid", + "value": { + "stringValue": "cluster-uid-123456789" + } + }, + { + "key": "sw.k8s.container.init", + "value": { + "stringValue": "true" + } + }, + { + "key": "uid", + "value": { + "stringValue": "c7f7a05a-a1b5-4fd0-a611-8e2a0e7acbf6" + } + } + ] + }, + "scopeMetrics": [ + { + "metrics": [ + { + "gauge": { + "dataPoints": [ + { + "asDouble": 0.25, + "attributes": [ + { + "key": "endpoint", + "value": { + "stringValue": "http" + } + }, + { + "key": "prometheus", + "value": { + "stringValue": "prometheus-system/kube-prometheus-kube-prome-prometheus" + } + }, + { + "key": "prometheus_replica", + "value": { + "stringValue": "prometheus-kube-prometheus-kube-prome-prometheus-0" + } + }, + { + "key": "service", + "value": { + "stringValue": "test-service" + } + } + ], + "timeUnixNano": "0" + } + ] + }, + "name": "k8s.kube_pod_init_container_resource_requests_cpu_cores" + }, + { + "gauge": { + "dataPoints": [ + { + "asDouble": 67108864, + "attributes": [ + { + "key": "endpoint", + "value": { + "stringValue": "http" + } + }, + { + "key": "prometheus", + "value": { + "stringValue": "prometheus-system/kube-prometheus-kube-prome-prometheus" + } + }, + { + "key": "prometheus_replica", + "value": { + "stringValue": "prometheus-kube-prometheus-kube-prome-prometheus-0" + } + }, + { + "key": "service", + "value": { + "stringValue": "test-service" + } + } + ], + "timeUnixNano": "0" + } + ] + }, + "name": "k8s.kube_pod_init_container_resource_requests_memory_bytes" + } + ], + "scope": {} + } + ] + }, { "resource": { "attributes": [ diff --git a/tests/integration/test_metric_collection.py b/tests/integration/test_metric_collection.py index a8cb9df6..34dbbfbc 100644 --- a/tests/integration/test_metric_collection.py +++ b/tests/integration/test_metric_collection.py @@ -126,7 +126,7 @@ def assert_test_metric_names_found(content): missing_metric_names = [ name for name in expected_metric_names if name not in metric_names] - error = f'Some specific metric names are not found in the response\ + error = f'Some specific metric names are not found in the response. \ Missing metrics: {missing_metric_names}' return (metric_matches, error)