Skip to content

Commit a699e0b

Browse files
committed
[receiver/kubeletstats] Add feature gate for cpu utilization metrics' deprecation
Signed-off-by: ChrsMark <[email protected]>
1 parent 7e8ebd7 commit a699e0b

File tree

6 files changed

+94
-7
lines changed

6 files changed

+94
-7
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: kubeletstats
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Introduce feature gate for deprecation of container.cpu.utilization, k8s.pod.cpu.utilization and k8s.node.cpu.utilization metrics
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35139]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/kubeletstatsreceiver/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,28 @@ rules:
285285
resources: ["nodes/proxy"]
286286
verbs: ["get"]
287287
```
288+
289+
### Warning about metrics' deprecation
290+
291+
The following metrics will be removed in a future version:
292+
- `k8s.node.cpu.utilization` (replaced by `k8s.node.cpu.usage`)
293+
- `k8s.pod.cpu.utilization` (replaced by `k8s.pod.cpu.usage`)
294+
- `container.cpu.utilization` (replaced by `container.cpu.usage`)
295+
296+
Users can use the following metrics instead:
297+
- `k8s.node.cpu.usage`
298+
- `k8s.pod.cpu.usage`
299+
- `container.cpu.usage`
300+
301+
The above metrics show usage counted in CPUs and it's not a percentage of used resources.
302+
These metrics were previously incorrectly named using the utilization term.
303+
304+
#### `receiver.kubeletstats.enableCPUUsageMetrics` feature gate
305+
306+
- alpha: when enabled it makes the `.cpu.usage` metrics enabled by default
307+
- beta: `.cpu.usage` metrics are enabled by default and any configuration enabling the deprecated `.cpu.utilization` metrics will be failing. Explicitly disabling the feature gate provides the old (deprecated) behavior.
308+
- stable: `.cpu.usage` metrics are enabled by default and the deprecated metrics are completely removed.
309+
- removed three releases after stable.
310+
311+
More information about the deprecation plan and
312+
the background reasoning can be found at https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27885.

receiver/kubeletstatsreceiver/factory.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"go.opentelemetry.io/collector/component"
1111
"go.opentelemetry.io/collector/consumer"
12+
"go.opentelemetry.io/collector/featuregate"
1213
"go.opentelemetry.io/collector/receiver"
1314
"go.opentelemetry.io/collector/receiver/scraperhelper"
1415
"go.uber.org/zap"
@@ -20,7 +21,16 @@ import (
2021
)
2122

2223
const (
23-
metricGroupsConfig = "metric_groups"
24+
metricGroupsConfig = "metric_groups"
25+
enableCPUUsageMetricsFeatureFlag = "receiver.kubeletstats.enableCPUUsageMetrics"
26+
)
27+
28+
var enableCPUUsageMetrics = featuregate.GlobalRegistry().MustRegister(
29+
enableCPUUsageMetricsFeatureFlag,
30+
featuregate.StageAlpha,
31+
featuregate.WithRegisterDescription("When enabled the container.cpu.utilization, k8s.pod.cpu.utilization and k8s.node.cpu.utilization metrics will be replaced by the container.cpu.usage, k8s.pod.cpu.usage and k8s.node.cpu.usage"),
32+
featuregate.WithRegisterFromVersion("v0.110.0"),
33+
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27885"),
2434
)
2535

2636
var defaultMetricGroups = []kubelet.MetricGroup{
@@ -68,6 +78,31 @@ func createMetricsReceiver(
6878
return nil, err
6979
}
7080

81+
if enableCPUUsageMetrics.IsEnabled() {
82+
if cfg.MetricsBuilderConfig.Metrics.ContainerCPUUtilization.Enabled {
83+
cfg.MetricsBuilderConfig.Metrics.ContainerCPUUtilization.Enabled = false
84+
cfg.MetricsBuilderConfig.Metrics.ContainerCPUUsage.Enabled = true
85+
}
86+
if cfg.MetricsBuilderConfig.Metrics.K8sPodCPUUtilization.Enabled {
87+
cfg.MetricsBuilderConfig.Metrics.K8sPodCPUUtilization.Enabled = false
88+
cfg.MetricsBuilderConfig.Metrics.K8sPodCPUUsage.Enabled = true
89+
}
90+
if cfg.MetricsBuilderConfig.Metrics.K8sNodeCPUUtilization.Enabled {
91+
cfg.MetricsBuilderConfig.Metrics.K8sNodeCPUUtilization.Enabled = false
92+
cfg.MetricsBuilderConfig.Metrics.K8sNodeCPUUsage.Enabled = true
93+
}
94+
} else {
95+
if cfg.MetricsBuilderConfig.Metrics.ContainerCPUUtilization.Enabled {
96+
set.Logger.Warn("The default metric container.cpu.utilization is being replaced by the container.cpu.usage metric. Switch now by enabling the receiver.kubeletstats.enableCPUUsageMetrics feature gate.")
97+
}
98+
if cfg.MetricsBuilderConfig.Metrics.K8sPodCPUUtilization.Enabled {
99+
set.Logger.Warn("The default metric k8s.pod.cpu.utilization is being replaced by the k8s.pod.cpu.usage metric. Switch now by enabling the receiver.kubeletstats.enableCPUUsageMetrics feature gate.")
100+
}
101+
if cfg.MetricsBuilderConfig.Metrics.K8sNodeCPUUtilization.Enabled {
102+
set.Logger.Warn("The default metric k8s.node.cpu.utilization is being replaced by the k8s.node.cpu.usage metric. Switch now by enabling the receiver.kubeletstats.enableCPUUsageMetrics feature gate.")
103+
}
104+
}
105+
71106
scrp, err := newKubletScraper(rest, set, rOptions, cfg.MetricsBuilderConfig, cfg.NodeName)
72107
if err != nil {
73108
return nil, err

receiver/kubeletstatsreceiver/internal/metadata/generated_metrics.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/kubeletstatsreceiver/internal/metadata/generated_metrics_test.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/kubeletstatsreceiver/metadata.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ metrics:
9292
enabled: true
9393
description: "Node CPU utilization"
9494
warnings:
95-
if_enabled: "WARNING: This metric will be disabled in a future release. Use metric k8s.node.cpu.usage instead."
95+
if_enabled: "This metric will be disabled in a future release. Use metric k8s.node.cpu.usage instead."
9696
unit: "1"
9797
gauge:
9898
value_type: double
@@ -364,7 +364,7 @@ metrics:
364364
enabled: true
365365
description: "Container CPU utilization"
366366
warnings:
367-
if_enabled: "WARNING: This metric will be disabled in a future release. Use metric container.cpu.usage instead."
367+
if_enabled: "This metric will be disabled in a future release. Use metric container.cpu.usage instead."
368368
unit: "1"
369369
gauge:
370370
value_type: double

0 commit comments

Comments
 (0)