Skip to content

Commit d4f79cb

Browse files
authored
Merge pull request #2580 from clavinjune/main
docs(customresourcestate): add example to expose same metrics with different label
2 parents 662afca + 9cf257a commit d4f79cb

File tree

1 file changed

+280
-0
lines changed

1 file changed

+280
-0
lines changed

docs/metrics/extend/customresourcestate-metrics.md

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ spec:
3232
# in YAML files, | allows a multi-line string to be passed as a flag value
3333
# see https://yaml-multiline.info
3434
- |
35+
kind: CustomResourceStateMetrics
3536
spec:
3637
resources:
3738
- groupVersionKind:
@@ -65,6 +66,7 @@ spec:
6566
# in YAML files, | allows a multi-line string to be passed as a flag value
6667
# see https://yaml-multiline.info
6768
- |
69+
kind: CustomResourceStateMetrics
6870
spec:
6971
resources:
7072
- groupVersionKind:
@@ -254,6 +256,73 @@ kube_customresource_ref_info{customresource_group="myteam.io", customresource_ki
254256
kube_customresource_ref_info{customresource_group="myteam.io", customresource_kind="Foo", customresource_version="v1", name="foo",ref="foo_with_extensions"} 1
255257
```
256258

259+
#### Same Metrics with Different Labels
260+
261+
```yaml
262+
recommendation:
263+
containerRecommendations:
264+
- containerName: consumer
265+
lowerBound:
266+
cpu: 100m
267+
memory: 262144k
268+
```
269+
270+
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:
271+
272+
```
273+
kind: CustomResourceStateMetrics
274+
spec:
275+
resources:
276+
- groupVersionKind:
277+
group: autoscaling.k8s.io
278+
kind: "VerticalPodAutoscaler"
279+
version: "v1"
280+
labelsFromPath:
281+
verticalpodautoscaler: [metadata, name]
282+
namespace: [metadata, namespace]
283+
target_api_version: [apiVersion]
284+
target_kind: [spec, targetRef, kind]
285+
target_name: [spec, targetRef, name]
286+
metrics:
287+
# for memory
288+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound"
289+
help: "Minimum memory resources the container can use before the VerticalPodAutoscaler updater evicts it."
290+
commonLabels:
291+
unit: "byte"
292+
resource: "memory"
293+
each:
294+
type: Gauge
295+
gauge:
296+
path: [status, recommendation, containerRecommendations]
297+
labelsFromPath:
298+
container: [containerName]
299+
valueFrom: [lowerBound, memory]
300+
# for CPU
301+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound"
302+
help: "Minimum cpu resources the container can use before the VerticalPodAutoscaler updater evicts it."
303+
commonLabels:
304+
unit: "core"
305+
resource: "cpu"
306+
each:
307+
type: Gauge
308+
gauge:
309+
path: [status, recommendation, containerRecommendations]
310+
labelsFromPath:
311+
container: [containerName]
312+
valueFrom: [lowerBound, cpu]
313+
```
314+
315+
Produces the following metrics:
316+
317+
```prometheus
318+
# HELP kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound Minimum memory resources the container can use before the VerticalPodAutoscaler updater evicts it.
319+
# TYPE kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound gauge
320+
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
321+
# HELP kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound Minimum cpu resources the container can use before the VerticalPodAutoscaler updater evicts it.
322+
# TYPE kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound gauge
323+
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
324+
```
325+
257326
#### VerticalPodAutoscaler
258327

259328
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:
@@ -292,6 +361,217 @@ spec:
292361

293362
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`).
294363

364+
#### All VerticalPodAutoscaler Metrics
365+
366+
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:
367+
368+
<details>
369+
370+
<summary>VPA CustomResourceStateMetrics</summary>
371+
372+
```yaml
373+
kind: CustomResourceStateMetrics
374+
spec:
375+
resources:
376+
- groupVersionKind:
377+
group: autoscaling.k8s.io
378+
kind: "VerticalPodAutoscaler"
379+
version: "v1"
380+
labelsFromPath:
381+
namespace: [metadata, namespace]
382+
target_api_version: [spec, targetRef, apiVersion]
383+
target_kind: [spec, targetRef, kind]
384+
target_name: [spec, targetRef, name]
385+
verticalpodautoscaler: [metadata, name]
386+
metricNamePrefix: "kube"
387+
metrics:
388+
# kube_verticalpodautoscaler_annotations
389+
- name: "verticalpodautoscaler_annotations"
390+
help: "Kubernetes annotations converted to Prometheus labels."
391+
each:
392+
type: Info
393+
info:
394+
labelsFromPath:
395+
annotation_*: [metadata, annotations]
396+
name: [metadata, name]
397+
# kube_verticalpodautoscaler_labels
398+
- name: "verticalpodautoscaler_labels"
399+
help: "Kubernetes labels converted to Prometheus labels."
400+
each:
401+
type: Info
402+
info:
403+
labelsFromPath:
404+
label_*: [metadata, labels]
405+
name: [metadata, name]
406+
# kube_verticalpodautoscaler_spec_updatepolicy_updatemode
407+
- name: "verticalpodautoscaler_spec_updatepolicy_updatemode"
408+
help: "Update mode of the VerticalPodAutoscaler."
409+
each:
410+
type: StateSet
411+
stateSet:
412+
labelName: "update_mode"
413+
path: [spec, updatePolicy, updateMode]
414+
list: ["Auto", "Initial", "Off", "Recreate"]
415+
# Memory kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_minallowed_memory
416+
- name: "verticalpodautoscaler_spec_resourcepolicy_container_policies_minallowed_memory"
417+
help: "Minimum memory resources the VerticalPodAutoscaler can set for containers matching the name."
418+
commonLabels:
419+
unit: "byte"
420+
resource: "memory"
421+
each:
422+
type: Gauge
423+
gauge:
424+
path: [spec, resourcePolicy, containerPolicies]
425+
labelsFromPath:
426+
container: [containerName]
427+
valueFrom: [minAllowed, memory]
428+
# CPU kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_minallowed_cpu
429+
- name: "verticalpodautoscaler_spec_resourcepolicy_container_policies_minallowed_cpu"
430+
help: "Minimum cpu resources the VerticalPodAutoscaler can set for containers matching the name."
431+
commonLabels:
432+
unit: "core"
433+
resource: "cpu"
434+
each:
435+
type: Gauge
436+
gauge:
437+
path: [spec, resourcePolicy, containerPolicies]
438+
labelsFromPath:
439+
container: [containerName]
440+
valueFrom: [minAllowed, cpu]
441+
# Memory kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_maxallowed_memory
442+
- name: "verticalpodautoscaler_spec_resourcepolicy_container_policies_maxallowed_memory"
443+
help: "Maximum memory resources the VerticalPodAutoscaler can set for containers matching the name."
444+
commonLabels:
445+
unit: "byte"
446+
resource: "memory"
447+
each:
448+
type: Gauge
449+
gauge:
450+
path: [spec, resourcePolicy, containerPolicies]
451+
labelsFromPath:
452+
container: [containerName]
453+
valueFrom: [maxAllowed, memory]
454+
# CPU kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_maxallowed_cpu
455+
- name: "verticalpodautoscaler_spec_resourcepolicy_container_policies_maxallowed_cpu"
456+
help: "Maximum cpu resources the VerticalPodAutoscaler can set for containers matching the name."
457+
commonLabels:
458+
unit: "core"
459+
resource: "cpu"
460+
each:
461+
type: Gauge
462+
gauge:
463+
path: [spec, resourcePolicy, containerPolicies]
464+
labelsFromPath:
465+
container: [containerName]
466+
valueFrom: [maxAllowed, cpu]
467+
# Memory kube_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound_memory
468+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound_memory"
469+
help: "Minimum memory resources the container can use before the VerticalPodAutoscaler updater evicts it."
470+
commonLabels:
471+
unit: "byte"
472+
resource: "memory"
473+
each:
474+
type: Gauge
475+
gauge:
476+
path: [status, recommendation, containerRecommendations]
477+
labelsFromPath:
478+
container: [containerName]
479+
valueFrom: [lowerBound, memory]
480+
# CPU kube_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound_cpu
481+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound_cpu"
482+
help: "Minimum cpu resources the container can use before the VerticalPodAutoscaler updater evicts it."
483+
commonLabels:
484+
unit: "core"
485+
resource: "cpu"
486+
each:
487+
type: Gauge
488+
gauge:
489+
path: [status, recommendation, containerRecommendations]
490+
labelsFromPath:
491+
container: [containerName]
492+
valueFrom: [lowerBound, cpu]
493+
# Memory kube_verticalpodautoscaler_status_recommendation_containerrecommendations_upperbound_memory
494+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_upperbound_memory"
495+
help: "Maximum memory resources the container can use before the VerticalPodAutoscaler updater evicts it."
496+
commonLabels:
497+
unit: "byte"
498+
resource: "memory"
499+
each:
500+
type: Gauge
501+
gauge:
502+
path: [status, recommendation, containerRecommendations]
503+
labelsFromPath:
504+
container: [containerName]
505+
valueFrom: [upperBound, memory]
506+
# CPU kube_verticalpodautoscaler_status_recommendation_containerrecommendations_upperbound_cpu
507+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_upperbound_cpu"
508+
help: "Maximum cpu resources the container can use before the VerticalPodAutoscaler updater evicts it."
509+
commonLabels:
510+
unit: "core"
511+
resource: "cpu"
512+
each:
513+
type: Gauge
514+
gauge:
515+
path: [status, recommendation, containerRecommendations]
516+
labelsFromPath:
517+
container: [containerName]
518+
valueFrom: [upperBound, cpu]
519+
# Memory kube_verticalpodautoscaler_status_recommendation_containerrecommendations_target_memory
520+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_target_memory"
521+
help: "Target memory resources the VerticalPodAutoscaler recommends for the container."
522+
commonLabels:
523+
unit: "byte"
524+
resource: "memory"
525+
each:
526+
type: Gauge
527+
gauge:
528+
path: [status, recommendation, containerRecommendations]
529+
labelsFromPath:
530+
container: [containerName]
531+
valueFrom: [target, memory]
532+
# CPU kube_verticalpodautoscaler_status_recommendation_containerrecommendations_target_cpu
533+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_target_cpu"
534+
help: "Target cpu resources the VerticalPodAutoscaler recommends for the container."
535+
commonLabels:
536+
unit: "core"
537+
resource: "cpu"
538+
each:
539+
type: Gauge
540+
gauge:
541+
path: [status, recommendation, containerRecommendations]
542+
labelsFromPath:
543+
container: [containerName]
544+
valueFrom: [target, cpu]
545+
# Memory kube_verticalpodautoscaler_status_recommendation_containerrecommendations_uncappedtarget_memory
546+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_uncappedtarget_memory"
547+
help: "Target memory resources the VerticalPodAutoscaler recommends for the container ignoring bounds."
548+
commonLabels:
549+
unit: "byte"
550+
resource: "memory"
551+
each:
552+
type: Gauge
553+
gauge:
554+
path: [status, recommendation, containerRecommendations]
555+
labelsFromPath:
556+
container: [containerName]
557+
valueFrom: [uncappedTarget, memory]
558+
# CPU kube_verticalpodautoscaler_status_recommendation_containerrecommendations_uncappedtarget_cpu
559+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_uncappedtarget_cpu"
560+
help: "Target memory resources the VerticalPodAutoscaler recommends for the container ignoring bounds."
561+
commonLabels:
562+
unit: "core"
563+
resource: "cpu"
564+
each:
565+
type: Gauge
566+
gauge:
567+
path: [status, recommendation, containerRecommendations]
568+
labelsFromPath:
569+
container: [containerName]
570+
valueFrom: [uncappedTarget, cpu]
571+
```
572+
573+
</details>
574+
295575
### Metric types
296576

297577
The configuration supports three kind of metrics from the [OpenMetrics specification](https://github.com/prometheus/OpenMetrics/blob/v1.0.0/specification/OpenMetrics.md).

0 commit comments

Comments
 (0)