From a4d64fb9935bc82a78c15e25cd11879b70f35128 Mon Sep 17 00:00:00 2001 From: clavinjune <24659468+clavinjune@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:02:00 +0700 Subject: [PATCH 1/5] docs(customresourestate): add example to expose same metrics with different label Signed-off-by: clavinjune <24659468+clavinjune@users.noreply.github.com> --- .../extend/customresourcestate-metrics.md | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/docs/metrics/extend/customresourcestate-metrics.md b/docs/metrics/extend/customresourcestate-metrics.md index bc5559714..542376fe0 100644 --- a/docs/metrics/extend/customresourcestate-metrics.md +++ b/docs/metrics/extend/customresourcestate-metrics.md @@ -254,6 +254,73 @@ kube_customresource_ref_info{customresource_group="myteam.io", customresource_ki kube_customresource_ref_info{customresource_group="myteam.io", customresource_kind="Foo", customresource_version="v1", name="foo",ref="foo_with_extensions"} 1 ``` +#### Same Metrics with Different Labels + +```yaml + recommendation: + containerRecommendations: + - containerName: consumer + lowerBound: + cpu: 100m + memory: 262144k +``` + +For example in VPA we have above attributes and we want to have a same metrics for both CPU and Memory, you can use below config: + +``` +kind: CustomResourceStateMetrics +spec: + resources: + - groupVersionKind: + group: autoscaling.k8s.io + kind: "VerticalPodAutoscaler" + version: "v1" + labelsFromPath: + verticalpodautoscaler: [metadata, name] + namespace: [metadata, namespace] + target_api_version: [apiVersion] + target_kind: [spec, targetRef, kind] + target_name: [spec, targetRef, name] + metrics: + # for memory + - name: "verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound" + help: "Minimum memory resources the container can use before the VerticalPodAutoscaler updater evicts it." + commonLabels: + unit: "byte" + resource: "memory" + each: + type: Gauge + gauge: + path: [status, recommendation, containerRecommendations] + labelsFromPath: + container: [containerName] + valueFrom: [lowerBound, memory] + # for CPU + - name: "verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound" + help: "Minimum cpu resources the container can use before the VerticalPodAutoscaler updater evicts it." + commonLabels: + unit: "core" + resource: "cpu" + each: + type: Gauge + gauge: + path: [status, recommendation, containerRecommendations] + labelsFromPath: + container: [containerName] + valueFrom: [lowerBound, cpu] +``` + +Produces the following metrics: + +```prometheus +# HELP kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound Minimum memory resources the container can use before the VerticalPodAutoscaler updater evicts it. +# TYPE kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound gauge +kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound{container="consumer",customresource_group="autoscaling.k8s.io",customresource_kind="VerticalPodAutoscaler",customresource_version="v1",namespace="namespace-example",resource="memory",target_api_version="apps/v1",target_kind="Deployment",target_name="target-name-example",unit="byte",verticalpodautoscaler="vpa-example"} 123456 +# HELP kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound Minimum cpu resources the container can use before the VerticalPodAutoscaler updater evicts it. +# TYPE kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound gauge +kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound{container="consumer",customresource_group="autoscaling.k8s.io",customresource_kind="VerticalPodAutoscaler",customresource_version="v1",namespace="namespace-example",resource="cpu",target_api_version="apps/v1",target_kind="Deployment",target_name="target-name-example",unit="core",verticalpodautoscaler="vpa-example"} 0.1 +``` + #### VerticalPodAutoscaler In v2.9.0 the `vericalpodautoscalers` resource was removed from the list of default resources. In order to generate metrics for `verticalpodautoscalers`, you can use the following Custom Resource State config: From 1412eaa18334d47ac9c91f43819c5bfd92956952 Mon Sep 17 00:00:00 2001 From: clavinjune <24659468+clavinjune@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:07:39 +0700 Subject: [PATCH 2/5] docs(customresourestate): add kind on the example Signed-off-by: clavinjune <24659468+clavinjune@users.noreply.github.com> --- docs/metrics/extend/customresourcestate-metrics.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/metrics/extend/customresourcestate-metrics.md b/docs/metrics/extend/customresourcestate-metrics.md index 542376fe0..950a31e00 100644 --- a/docs/metrics/extend/customresourcestate-metrics.md +++ b/docs/metrics/extend/customresourcestate-metrics.md @@ -32,6 +32,7 @@ spec: # in YAML files, | allows a multi-line string to be passed as a flag value # see https://yaml-multiline.info - | + kind: CustomResourceStateMetrics spec: resources: - groupVersionKind: @@ -65,6 +66,7 @@ spec: # in YAML files, | allows a multi-line string to be passed as a flag value # see https://yaml-multiline.info - | + kind: CustomResourceStateMetrics spec: resources: - groupVersionKind: From 89f8110d61dc2a19c8517a34b68591e5bcee1d9c Mon Sep 17 00:00:00 2001 From: clavinjune <24659468+clavinjune@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:51:46 +0700 Subject: [PATCH 3/5] docs(customresourestate): add example to re-expose all VPA metrics Signed-off-by: clavinjune <24659468+clavinjune@users.noreply.github.com> --- .../extend/customresourcestate-metrics.md | 210 ++++++++++++++++++ 1 file changed, 210 insertions(+) diff --git a/docs/metrics/extend/customresourcestate-metrics.md b/docs/metrics/extend/customresourcestate-metrics.md index 950a31e00..fd1e016f0 100644 --- a/docs/metrics/extend/customresourcestate-metrics.md +++ b/docs/metrics/extend/customresourcestate-metrics.md @@ -361,6 +361,216 @@ spec: The above configuration was tested on [this](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/examples/hamster.yaml) VPA configuration, with an added annotation (`foo: 123`). +#### All VerticalPodAutoscaler Metrics + +As an addition for the above configuration, here's the complete `CustomResourceStateMetrics` spec to re-enable all of the VPA metrics which are removed from the list of the default resources: + +
+ + VPA CustomResourceStateMetrics +```yaml +kind: CustomResourceStateMetrics +spec: + resources: + - groupVersionKind: + group: autoscaling.k8s.io + kind: "VerticalPodAutoscaler" + version: "v1" + labelsFromPath: + namespace: [metadata, namespace] + target_api_version: [spec, targetRef, apiVersion] + target_kind: [spec, targetRef, kind] + target_name: [spec, targetRef, name] + verticalpodautoscaler: [metadata, name] + metricNamePrefix: "kube" + metrics: + # kube_verticalpodautoscaler_annotations + - name: "verticalpodautoscaler_annotations" + help: "Kubernetes annotations converted to Prometheus labels." + each: + type: Info + info: + labelsFromPath: + # annotation_*: [metadata, annotations] + name: [metadata, name] + # kube_verticalpodautoscaler_labels + - name: "verticalpodautoscaler_labels" + help: "Kubernetes labels converted to Prometheus labels." + each: + type: Info + info: + labelsFromPath: + # label_*: [metadata, labels] + name: [metadata, name] + # kube_verticalpodautoscaler_spec_updatepolicy_updatemode + - name: "verticalpodautoscaler_spec_updatepolicy_updatemode" + help: "Update mode of the VerticalPodAutoscaler." + each: + type: StateSet + stateSet: + labelName: "update_mode" + path: [spec, updatePolicy, updateMode] + list: ["Auto", "Initial", "Off", "Recreate"] + # Memory kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_minallowed + - name: "verticalpodautoscaler_spec_resourcepolicy_container_policies_minallowed" + help: "Minimum memory resources the VerticalPodAutoscaler can set for containers matching the name." + commonLabels: + unit: "byte" + resource: "memory" + each: + type: Gauge + gauge: + path: [spec, resourcePolicy, containerPolicies] + labelsFromPath: + container: [containerName] + valueFrom: [minAllowed, memory] + # CPU kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_minallowed + - name: "verticalpodautoscaler_spec_resourcepolicy_container_policies_minallowed" + help: "Minimum cpu resources the VerticalPodAutoscaler can set for containers matching the name." + commonLabels: + unit: "core" + resource: "cpu" + each: + type: Gauge + gauge: + path: [spec, resourcePolicy, containerPolicies] + labelsFromPath: + container: [containerName] + valueFrom: [minAllowed, cpu] + # Memory kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_maxallowed + - name: "verticalpodautoscaler_spec_resourcepolicy_container_policies_maxallowed" + help: "Maximum memory resources the VerticalPodAutoscaler can set for containers matching the name." + commonLabels: + unit: "byte" + resource: "memory" + each: + type: Gauge + gauge: + path: [spec, resourcePolicy, containerPolicies] + labelsFromPath: + container: [containerName] + valueFrom: [maxAllowed, memory] + # CPU kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_maxallowed + - name: "verticalpodautoscaler_spec_resourcepolicy_container_policies_maxallowed" + help: "Maximum cpu resources the VerticalPodAutoscaler can set for containers matching the name." + commonLabels: + unit: "core" + resource: "cpu" + each: + type: Gauge + gauge: + path: [spec, resourcePolicy, containerPolicies] + labelsFromPath: + container: [containerName] + valueFrom: [maxAllowed, cpu] + # Memory kube_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound + - name: "verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound" + help: "Minimum memory resources the container can use before the VerticalPodAutoscaler updater evicts it." + commonLabels: + unit: "byte" + resource: "memory" + each: + type: Gauge + gauge: + path: [status, recommendation, containerRecommendations] + labelsFromPath: + container: [containerName] + valueFrom: [lowerBound, memory] + # CPU kube_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound + - name: "verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound" + help: "Minimum cpu resources the container can use before the VerticalPodAutoscaler updater evicts it." + commonLabels: + unit: "core" + resource: "cpu" + each: + type: Gauge + gauge: + path: [status, recommendation, containerRecommendations] + labelsFromPath: + container: [containerName] + valueFrom: [lowerBound, cpu] + # Memory kube_verticalpodautoscaler_status_recommendation_containerrecommendations_upperbound + - name: "verticalpodautoscaler_status_recommendation_containerrecommendations_upperbound" + help: "Maximum memory resources the container can use before the VerticalPodAutoscaler updater evicts it." + commonLabels: + unit: "byte" + resource: "memory" + each: + type: Gauge + gauge: + path: [status, recommendation, containerRecommendations] + labelsFromPath: + container: [containerName] + valueFrom: [upperBound, memory] + # CPU kube_verticalpodautoscaler_status_recommendation_containerrecommendations_upperbound + - name: "verticalpodautoscaler_status_recommendation_containerrecommendations_upperbound" + help: "Maximum cpu resources the container can use before the VerticalPodAutoscaler updater evicts it." + commonLabels: + unit: "core" + resource: "cpu" + each: + type: Gauge + gauge: + path: [status, recommendation, containerRecommendations] + labelsFromPath: + container: [containerName] + valueFrom: [upperBound, cpu] + # Memory kube_verticalpodautoscaler_status_recommendation_containerrecommendations_target + - name: "verticalpodautoscaler_status_recommendation_containerrecommendations_target" + help: "Target memory resources the VerticalPodAutoscaler recommends for the container." + commonLabels: + unit: "byte" + resource: "memory" + each: + type: Gauge + gauge: + path: [status, recommendation, containerRecommendations] + labelsFromPath: + container: [containerName] + valueFrom: [target, memory] + # CPU kube_verticalpodautoscaler_status_recommendation_containerrecommendations_target + - name: "verticalpodautoscaler_status_recommendation_containerrecommendations_target" + help: "Target cpu resources the VerticalPodAutoscaler recommends for the container." + commonLabels: + unit: "core" + resource: "cpu" + each: + type: Gauge + gauge: + path: [status, recommendation, containerRecommendations] + labelsFromPath: + container: [containerName] + valueFrom: [target, cpu] + # Memory kube_verticalpodautoscaler_status_recommendation_containerrecommendations_uncappedtarget + - name: "verticalpodautoscaler_status_recommendation_containerrecommendations_uncappedtarget" + help: "Target memory resources the VerticalPodAutoscaler recommends for the container ignoring bounds." + commonLabels: + unit: "byte" + resource: "memory" + each: + type: Gauge + gauge: + path: [status, recommendation, containerRecommendations] + labelsFromPath: + container: [containerName] + valueFrom: [uncappedTarget, memory] + # CPU kube_verticalpodautoscaler_status_recommendation_containerrecommendations_uncappedtarget + - name: "verticalpodautoscaler_status_recommendation_containerrecommendations_uncappedtarget" + help: "Target memory resources the VerticalPodAutoscaler recommends for the container ignoring bounds." + commonLabels: + unit: "core" + resource: "cpu" + each: + type: Gauge + gauge: + path: [status, recommendation, containerRecommendations] + labelsFromPath: + container: [containerName] + valueFrom: [uncappedTarget, cpu] +``` + +
+ ### Metric types The configuration supports three kind of metrics from the [OpenMetrics specification](https://github.com/prometheus/OpenMetrics/blob/v1.0.0/specification/OpenMetrics.md). From ae38bc4e67879628cf2a815d1f0cf9f39887ec76 Mon Sep 17 00:00:00 2001 From: clavinjune <24659468+clavinjune@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:53:54 +0700 Subject: [PATCH 4/5] docs(customresourestate): fix All VerticalPodAutoscaler Metrics section Signed-off-by: clavinjune <24659468+clavinjune@users.noreply.github.com> --- docs/metrics/extend/customresourcestate-metrics.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/metrics/extend/customresourcestate-metrics.md b/docs/metrics/extend/customresourcestate-metrics.md index fd1e016f0..2091cdff0 100644 --- a/docs/metrics/extend/customresourcestate-metrics.md +++ b/docs/metrics/extend/customresourcestate-metrics.md @@ -368,6 +368,7 @@ As an addition for the above configuration, here's the complete `CustomResourceS
VPA CustomResourceStateMetrics + ```yaml kind: CustomResourceStateMetrics spec: From 387bd8b2442f8dbd533f71f997090c64059edc37 Mon Sep 17 00:00:00 2001 From: clavinjune <24659468+clavinjune@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:54:54 +0700 Subject: [PATCH 5/5] docs(customresourestate): fix All VerticalPodAutoscaler Metrics section Signed-off-by: clavinjune <24659468+clavinjune@users.noreply.github.com> --- docs/metrics/extend/customresourcestate-metrics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/metrics/extend/customresourcestate-metrics.md b/docs/metrics/extend/customresourcestate-metrics.md index 2091cdff0..52f42f8c4 100644 --- a/docs/metrics/extend/customresourcestate-metrics.md +++ b/docs/metrics/extend/customresourcestate-metrics.md @@ -570,7 +570,7 @@ spec: valueFrom: [uncappedTarget, cpu] ``` -
+
### Metric types