Skip to content

Commit 2855069

Browse files
authored
Merge pull request #6518 from ehashman/stable-metrics
Add metrics stability documentation from KEP-1209
2 parents 94ed8aa + e2163b9 commit 2855069

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

contributors/devel/sig-instrumentation/instrumentation.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ For this types of metric exposition, the
8585
[exporter guidelines](https://prometheus.io/docs/instrumenting/writing_exporters/)
8686
apply additionally.
8787

88+
## Metrics Stability
89+
90+
Please see our documentation on Kubernetes [metrics stability](/contributors/devel/sig-instrumentation/metric-stability.md).
91+
8892
## Naming
8993

9094
General [metric and label naming best practices](https://prometheus.io/docs/practices/naming/) apply.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Metric Stability
2+
3+
[KEP-1209] introduced the concept of metric stability to Kubernetes. When metrics graduate to the `STABLE` `StabilityLevel`, we provide guarantees to consumers of those metrics so they can confidently build alerting and monitoring platforms.
4+
5+
## Stability Classes
6+
7+
There are currently two stability classes for metrics: (1) Alpha, (2) Stable. These classes are intended to make explicit the API contract between the control-plane and the consumer of control-plane metrics.
8+
9+
### Alpha
10+
11+
__Alpha__ metrics have __*no*__ stability guarantees; as such they can be modified or deleted at any time. All Kubernetes metrics begin as alpha metrics.
12+
13+
An example of an alpha metric follows:
14+
15+
```go
16+
var alphaMetricDefinition = kubemetrics.CounterOpts{
17+
Name: "some_alpha_metric",
18+
Help: "some description",
19+
StabilityLevel: kubemetrics.ALPHA, // this is also a custom metadata field
20+
DeprecatedVersion: "1.15", // this can optionally be included on alpha metrics, although there is no change to contractual stability guarantees
21+
}
22+
```
23+
24+
### Stable
25+
26+
__Stable__ metrics can be guaranteed to *not change*, except that the metric may become marked deprecated for a future Kubernetes version.
27+
28+
An example of a stable metric follows:
29+
30+
```go
31+
var deprecatedMetricDefinition = kubemetrics.CounterOpts{
32+
Name: "some_deprecated_metric",
33+
Help: "some description",
34+
StabilityLevel: kubemetrics.STABLE, // this is also a custom metadata field
35+
DeprecatedVersion: "1.15", // this is a custom metadata field
36+
}
37+
```
38+
39+
By *not change*, we mean three things:
40+
41+
1. the metric itself will not be deleted ([or renamed](#metric-renaming))
42+
2. the type of metric will not be modified
43+
3. no labels can be added **or** removed from this metric
44+
45+
From an ingestion point of view, it is backwards-compatible to add or remove possible __values__ for labels which already do exist (but __not__ labels themselves). Therefore, adding or removing __values__ from an existing label is permissible. Stable metrics can also be marked as __deprecated__ for a future Kubernetes version, since this is a metadata field and does not actually change the metric itself.
46+
47+
**Removing or adding labels from stable metrics is not permissible.** In order to add/remove a label to an existing stable metric, one would have to introduce a new metric and deprecate the stable one; otherwise this would violate compatibility agreements.
48+
49+
## API Review
50+
51+
Graduating a metric to a stable state is a contractual API agreement, as such, it would be desirable to require an api-review (to sig-instrumentation) for graduating or deprecating a metric (in line with current Kubernetes [api-review processes](https://github.com/kubernetes/community/blob/master/sig-architecture/api-review-process.md)).
52+
53+
We use a verification script to flag stable metric changes for review by SIG Instrumentation approvers.
54+
55+
## Metric Renaming
56+
57+
Metric renaming is be tantamount to deleting a metric and introducing a new one. Accordingly, metric renaming will also be disallowed for stable metrics.
58+
59+
## Deprecation Lifecycle
60+
61+
Metrics can be annotated with a Kubernetes version, from which point that metric will be considered deprecated. This allows us to indicate that a metric is slated for future removal and provides the consumer a reasonable window in which they can make changes to their monitoring infrastructure which depends on this metric.
62+
63+
While deprecation policies only actually change stability guarantees for __stable__ metrics (and not __alpha__ ones), deprecation information may however be optionally provided on alpha metrics to help component owners inform users of future intent, to help with transition plans (this change was made at the request of @dashpole, who helpfully pointed out that it would be nice to be able signal future intent even for alpha metrics).
64+
65+
When a stable metric undergoes the deprecation process, we are signaling that the metric will eventually be deleted. The lifecyle looks roughly like this (each stage represents a Kubernetes release):
66+
67+
__Stable metric__ -> __Deprecated metric__ -> __Hidden metric__ -> __Deletion__
68+
69+
__Deprecated__ metrics have the same stability guarantees of their counterparts. If a stable metric is deprecated, then a deprecated stable metric is guaranteed to *not change*. When deprecating a stable metric, a future Kubernetes release is specified as the point from which the metric will be considered deprecated.
70+
71+
```go
72+
var someCounter = kubemetrics.CounterOpts{
73+
Name: "some_counter",
74+
Help: "this counts things",
75+
StabilityLevel: kubemetrics.STABLE,
76+
DeprecatedVersion: "1.15", // this metric is deprecated when the Kubernetes version == 1.15
77+
}
78+
````
79+
80+
__Deprecated__ metrics will have their description text prefixed with a deprecation notice string '(Deprecated from x.y)' and a warning log will be emitted during metric registration (in the spirit of the official [Kubernetes deprecation policy](https://kubernetes.io/docs/reference/using-api/deprecation-policy/#deprecating-a-flag-or-cli)).
81+
82+
Before deprecation:
83+
84+
```text
85+
# HELP some_counter this counts things
86+
# TYPE some_counter counter
87+
some_counter 0
88+
```
89+
90+
During deprecation:
91+
```text
92+
# HELP some_counter (Deprecated from 1.15) this counts things
93+
# TYPE some_counter counter
94+
some_counter 0
95+
```
96+
Like their stable metric counterparts, deprecated metrics will be automatically registered to the metrics endpoint.
97+
98+
On a subsequent release (when the metric's deprecatedVersion is equal to current_kubernetes_version - 1)), a deprecated metric will become a __hidden metric__. _Unlike_ their deprecated counterparts, hidden metrics will __*no longer be automatically registered*__ to the metrics endpoint (hence hidden). However, they can be explicitly enabled through a command line flag on the binary (i.e. '--show-hidden-metrics-for-version=<previous minor release>'). This is to provide cluster admins an escape hatch to properly migrate off of a deprecated metric, if they were not able to react to the earlier deprecation warnings. Hidden metrics should be deleted after one release.
99+
100+
101+
[KEP-1209]: https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1209-metrics-stability

0 commit comments

Comments
 (0)