Skip to content

[receiver/kubeletstats] Add feature gate for cpu utilization metrics' deprecation #35139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/kubeletstats_featuregate_metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: kubeletstats

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Introduce feature gate for deprecation of container.cpu.utilization, k8s.pod.cpu.utilization and k8s.node.cpu.utilization metrics

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35139]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
20 changes: 20 additions & 0 deletions receiver/kubeletstatsreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,23 @@ rules:
resources: ["nodes/proxy"]
verbs: ["get"]
```

### Warning about metrics' deprecation

The following metrics will be renamed in a future version:
- `k8s.node.cpu.utilization` (renamed to `k8s.node.cpu.usage`)
- `k8s.pod.cpu.utilization` (renamed to `k8s.pod.cpu.usage`)
- `container.cpu.utilization` (renamed to `container.cpu.usage`)

The above metrics show usage counted in CPUs and it's not a percentage of used resources.
These metrics were previously incorrectly named using the utilization term.

#### `receiver.kubeletstats.enableCPUUsageMetrics` feature gate

- alpha: when enabled it makes the `.cpu.usage` metrics enabled by default, disabling the `.cpu.utilization` metrics
- 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.
- stable: `.cpu.usage` metrics are enabled by default and the deprecated metrics are completely removed.
- removed three releases after stable.

More information about the deprecation plan and
the background reasoning can be found at https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27885.
37 changes: 36 additions & 1 deletion receiver/kubeletstatsreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scraperhelper"
"go.uber.org/zap"
Expand All @@ -20,7 +21,16 @@ import (
)

const (
metricGroupsConfig = "metric_groups"
metricGroupsConfig = "metric_groups"
enableCPUUsageMetricsFeatureFlag = "receiver.kubeletstats.enableCPUUsageMetrics"
)

var enableCPUUsageMetrics = featuregate.GlobalRegistry().MustRegister(
enableCPUUsageMetricsFeatureFlag,
featuregate.StageAlpha,
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"),
featuregate.WithRegisterFromVersion("v0.110.0"),
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27885"),
)

var defaultMetricGroups = []kubelet.MetricGroup{
Expand Down Expand Up @@ -68,6 +78,31 @@ func createMetricsReceiver(
return nil, err
}

if enableCPUUsageMetrics.IsEnabled() {
if cfg.MetricsBuilderConfig.Metrics.ContainerCPUUtilization.Enabled {
cfg.MetricsBuilderConfig.Metrics.ContainerCPUUtilization.Enabled = false
cfg.MetricsBuilderConfig.Metrics.ContainerCPUUsage.Enabled = true
}
if cfg.MetricsBuilderConfig.Metrics.K8sPodCPUUtilization.Enabled {
cfg.MetricsBuilderConfig.Metrics.K8sPodCPUUtilization.Enabled = false
cfg.MetricsBuilderConfig.Metrics.K8sPodCPUUsage.Enabled = true
}
if cfg.MetricsBuilderConfig.Metrics.K8sNodeCPUUtilization.Enabled {
cfg.MetricsBuilderConfig.Metrics.K8sNodeCPUUtilization.Enabled = false
cfg.MetricsBuilderConfig.Metrics.K8sNodeCPUUsage.Enabled = true
}
} else {
if cfg.MetricsBuilderConfig.Metrics.ContainerCPUUtilization.Enabled {
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.")
}
if cfg.MetricsBuilderConfig.Metrics.K8sPodCPUUtilization.Enabled {
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.")
}
if cfg.MetricsBuilderConfig.Metrics.K8sNodeCPUUtilization.Enabled {
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.")
}
}

scrp, err := newKubletScraper(rest, set, rOptions, cfg.MetricsBuilderConfig, cfg.NodeName)
if err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions receiver/kubeletstatsreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
go.opentelemetry.io/collector/confmap v1.16.0
go.opentelemetry.io/collector/consumer v0.110.0
go.opentelemetry.io/collector/consumer/consumertest v0.110.0
go.opentelemetry.io/collector/featuregate v1.16.0
go.opentelemetry.io/collector/filter v0.110.0
go.opentelemetry.io/collector/pdata v1.16.0
go.opentelemetry.io/collector/pipeline v0.110.0
Expand Down Expand Up @@ -56,6 +57,7 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down
4 changes: 4 additions & 0 deletions receiver/kubeletstatsreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions receiver/kubeletstatsreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ metrics:
enabled: true
description: "Node CPU utilization"
warnings:
if_enabled: "WARNING: This metric will be disabled in a future release. Use metric k8s.node.cpu.usage instead."
if_enabled: "This metric will be disabled in a future release. Use metric k8s.node.cpu.usage instead."
unit: "1"
gauge:
value_type: double
Expand Down Expand Up @@ -364,7 +364,7 @@ metrics:
enabled: true
description: "Container CPU utilization"
warnings:
if_enabled: "WARNING: This metric will be disabled in a future release. Use metric container.cpu.usage instead."
if_enabled: "This metric will be disabled in a future release. Use metric container.cpu.usage instead."
unit: "1"
gauge:
value_type: double
Expand Down
Loading