Skip to content

Commit 0e9b898

Browse files
add deletion timestamp and fmt readme
1 parent 75085a2 commit 0e9b898

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Horizontal Pod Autoscaler Metrics
22

3-
| Metric name | Metric type | Description | Labels/tags | Status |
4-
| ---------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
5-
| kube_horizontalpodautoscaler_info | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; <br> `scaletargetref_api_version`=&lt;hpa-target-api-version&gt; <br> `scaletargetref_kind`=&lt;hpa-target-kind&gt; <br> `scaletargetref_name`=&lt;hpa-target-name&gt; | EXPERIMENTAL |
3+
| Metric name | Metric type | Description | Labels/tags | Status |
4+
| ---------------------------------------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
5+
| kube_horizontalpodautoscaler_info | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; <br> `scaletargetref_api_version`=&lt;hpa-target-api-version&gt; <br> `scaletargetref_kind`=&lt;hpa-target-kind&gt; <br> `scaletargetref_name`=&lt;hpa-target-name&gt; | EXPERIMENTAL |
66
| kube_horizontalpodautoscaler_annotations | Gauge | Kubernetes annotations converted to Prometheus labels controlled via [--metric-annotations-allowlist](../../developer/cli-arguments.md) | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | EXPERIMENTAL |
77
| kube_horizontalpodautoscaler_labels | Gauge | Kubernetes labels converted to Prometheus labels controlled via [--metric-labels-allowlist](../../developer/cli-arguments.md) | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
8-
| kube_horizontalpodautoscaler_metadata_generation | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
9-
| kube_horizontalpodautoscaler_spec_max_replicas | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
10-
| kube_horizontalpodautoscaler_spec_min_replicas | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
11-
| kube_horizontalpodautoscaler_spec_target_metric | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; <br> `metric_name`=&lt;metric-name&gt; <br> `metric_target_type`=&lt;value\|utilization\|average&gt; | EXPERIMENTAL |
12-
| kube_horizontalpodautoscaler_status_target_metric | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; <br> `metric_name`=&lt;metric-name&gt; <br> `metric_target_type`=&lt;value\|utilization\|average&gt; | EXPERIMENTAL |
13-
| kube_horizontalpodautoscaler_status_condition | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; <br> `condition`=&lt;hpa-condition&gt; <br> `status`=&lt;true\|false\|unknown&gt; | STABLE |
14-
| kube_horizontalpodautoscaler_status_current_replicas | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
15-
| kube_horizontalpodautoscaler_status_desired_replicas | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
16-
| kube_horizontalpodautoscaler_created | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | EXPERIMENTAL |
8+
| kube_horizontalpodautoscaler_metadata_generation | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
9+
| kube_horizontalpodautoscaler_spec_max_replicas | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
10+
| kube_horizontalpodautoscaler_spec_min_replicas | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
11+
| kube_horizontalpodautoscaler_spec_target_metric | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; <br> `metric_name`=&lt;metric-name&gt; <br> `metric_target_type`=&lt;value\|utilization\|average&gt; | EXPERIMENTAL |
12+
| kube_horizontalpodautoscaler_status_target_metric | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; <br> `metric_name`=&lt;metric-name&gt; <br> `metric_target_type`=&lt;value\|utilization\|average&gt; | EXPERIMENTAL |
13+
| kube_horizontalpodautoscaler_status_condition | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; <br> `condition`=&lt;hpa-condition&gt; <br> `status`=&lt;true\|false\|unknown&gt; | STABLE |
14+
| kube_horizontalpodautoscaler_status_current_replicas | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
15+
| kube_horizontalpodautoscaler_status_desired_replicas | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | STABLE |
16+
| kube_horizontalpodautoscaler_created | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | EXPERIMENTAL |
17+
| kube_horizontalpodautoscaler_deletion_timestamp | Gauge | | `horizontalpodautoscaler`=&lt;hpa-name&gt; <br> `namespace`=&lt;hpa-namespace&gt; | EXPERIMENTAL |

internal/store/horizontalpodautoscaler.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
6767
createHPALabels(allowLabelsList),
6868
createHPAStatusCondition(),
6969
createHPACreated(),
70+
createHPADeletionTimestamp(),
7071
}
7172
}
7273

@@ -437,3 +438,26 @@ func createHPACreated() generator.FamilyGenerator {
437438
}),
438439
)
439440
}
441+
442+
func createHPADeletionTimestamp() generator.FamilyGenerator {
443+
return *generator.NewFamilyGeneratorWithStability(
444+
"kube_horizontalpodautoscaler_deletion_timestamp",
445+
"Unix deletion timestamp",
446+
metric.Gauge,
447+
basemetrics.ALPHA,
448+
"",
449+
wrapHPAFunc(func(a *autoscaling.HorizontalPodAutoscaler) *metric.Family {
450+
ms := []*metric.Metric{}
451+
452+
if !a.DeletionTimestamp.IsZero() {
453+
ms = append(ms, &metric.Metric{
454+
Value: float64(a.DeletionTimestamp.Unix()),
455+
})
456+
}
457+
458+
return &metric.Family{
459+
Metrics: ms,
460+
}
461+
}),
462+
)
463+
}

internal/store/horizontalpodautoscaler_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func TestHPAStore(t *testing.T) {
4848
# HELP kube_horizontalpodautoscaler_status_current_replicas [STABLE] Current number of replicas of pods managed by this autoscaler.
4949
# HELP kube_horizontalpodautoscaler_status_desired_replicas [STABLE] Desired number of replicas of pods managed by this autoscaler.
5050
# HELP kube_horizontalpodautoscaler_created Unix creation timestamp
51+
# HELP kube_horizontalpodautoscaler_deletion_timestamp Unix deletion timestamp
5152
# TYPE kube_horizontalpodautoscaler_info gauge
5253
# TYPE kube_horizontalpodautoscaler_annotations gauge
5354
# TYPE kube_horizontalpodautoscaler_labels gauge
@@ -60,6 +61,7 @@ func TestHPAStore(t *testing.T) {
6061
# TYPE kube_horizontalpodautoscaler_status_current_replicas gauge
6162
# TYPE kube_horizontalpodautoscaler_status_desired_replicas gauge
6263
# TYPE kube_horizontalpodautoscaler_created gauge
64+
# TYPE kube_horizontalpodautoscaler_deletion_timestamp gauge
6365
`
6466
cases := []generateMetricsTestCase{
6567
{
@@ -69,6 +71,7 @@ func TestHPAStore(t *testing.T) {
6971
Generation: 2,
7072
Name: "hpa1",
7173
CreationTimestamp: metav1.Time{Time: time.Unix(1500000000, 0)},
74+
DeletionTimestamp: &metav1.Time{Time: time.Unix(1800000000, 0)},
7275
Namespace: "ns1",
7376
Labels: map[string]string{
7477
"app": "foobar",
@@ -238,6 +241,7 @@ func TestHPAStore(t *testing.T) {
238241
kube_horizontalpodautoscaler_status_current_replicas{horizontalpodautoscaler="hpa1",namespace="ns1"} 2
239242
kube_horizontalpodautoscaler_status_desired_replicas{horizontalpodautoscaler="hpa1",namespace="ns1"} 2
240243
kube_horizontalpodautoscaler_created{horizontalpodautoscaler="hpa1",namespace="ns1"} 1.5e+09
244+
kube_horizontalpodautoscaler_deletion_timestamp{horizontalpodautoscaler="hpa1",namespace="ns1"} 1.8e+09
241245
`,
242246
MetricNames: []string{
243247
"kube_horizontalpodautoscaler_info",
@@ -252,6 +256,7 @@ func TestHPAStore(t *testing.T) {
252256
"kube_horizontalpodautoscaler_annotations",
253257
"kube_horizontalpodautoscaler_labels",
254258
"kube_horizontalpodautoscaler_created",
259+
"kube_horizontalpodautoscaler_deletion_timestamp",
255260
},
256261
},
257262
{
@@ -264,6 +269,7 @@ func TestHPAStore(t *testing.T) {
264269
Generation: 2,
265270
Name: "hpa2",
266271
CreationTimestamp: metav1.Time{Time: time.Unix(1500000000, 0)},
272+
DeletionTimestamp: &metav1.Time{Time: time.Unix(1800000000, 0)},
267273
Namespace: "ns1",
268274
Labels: map[string]string{
269275
"app": "foobar",
@@ -416,6 +422,7 @@ func TestHPAStore(t *testing.T) {
416422
kube_horizontalpodautoscaler_status_current_replicas{horizontalpodautoscaler="hpa2",namespace="ns1"} 2
417423
kube_horizontalpodautoscaler_status_desired_replicas{horizontalpodautoscaler="hpa2",namespace="ns1"} 2
418424
kube_horizontalpodautoscaler_created{horizontalpodautoscaler="hpa2",namespace="ns1"} 1.5e+09
425+
kube_horizontalpodautoscaler_deletion_timestamp{horizontalpodautoscaler="hpa2",namespace="ns1"} 1.8e+09
419426
`,
420427
MetricNames: []string{
421428
"kube_horizontalpodautoscaler_info",
@@ -430,6 +437,7 @@ func TestHPAStore(t *testing.T) {
430437
"kube_horizontalpodautoscaler_annotation",
431438
"kube_horizontalpodautoscaler_labels",
432439
"kube_horizontalpodautoscaler_created",
440+
"kube_horizontalpodautoscaler_deletion_timestamp",
433441
},
434442
},
435443
}

0 commit comments

Comments
 (0)