Skip to content
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

[receiver/kubeletstats] Enable by default the .cpu.usage metrics #34217

Closed
27 changes: 27 additions & 0 deletions .chloggen/kubeletstats_fix_defaults.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: breaking

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Enable CPU usage metrics by default.

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

# (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: "Metrics enabled by default: `container.cpu.usage`, `k8s.pod.cpu.usage`, `k8s.node.cpu.usage`"

# 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]
48 changes: 24 additions & 24 deletions receiver/kubeletstatsreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ Total cumulative CPU time (sum of all cores) spent by the container/pod/node sin
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Double | Cumulative | true |

### container.cpu.usage

Total CPU usage (sum of all cores per second) averaged over the sample window

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {cpu} | Gauge | Double |

### container.cpu.utilization

Container CPU utilization
Expand Down Expand Up @@ -108,6 +116,14 @@ Total cumulative CPU time (sum of all cores) spent by the container/pod/node sin
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Double | Cumulative | true |

### k8s.node.cpu.usage

Total CPU usage (sum of all cores per second) averaged over the sample window

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {cpu} | Gauge | Double |

### k8s.node.cpu.utilization

Node CPU utilization
Expand Down Expand Up @@ -226,6 +242,14 @@ Total cumulative CPU time (sum of all cores) spent by the container/pod/node sin
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Double | Cumulative | true |

### k8s.pod.cpu.usage

Total CPU usage (sum of all cores per second) averaged over the sample window

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {cpu} | Gauge | Double |

### k8s.pod.cpu.utilization

Pod CPU utilization
Expand Down Expand Up @@ -386,14 +410,6 @@ metrics:
enabled: true
```

### container.cpu.usage

Total CPU usage (sum of all cores per second) averaged over the sample window

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {cpu} | Gauge | Double |

### container.uptime

The time since the container started
Expand Down Expand Up @@ -450,14 +466,6 @@ Container memory utilization as a ratio of the container's requests
| ---- | ----------- | ---------- |
| 1 | Gauge | Double |

### k8s.node.cpu.usage

Total CPU usage (sum of all cores per second) averaged over the sample window

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {cpu} | Gauge | Double |

### k8s.node.uptime

The time since the node started
Expand All @@ -474,14 +482,6 @@ Pod cpu utilization as a ratio of the node's capacity
| ---- | ----------- | ---------- |
| 1 | Gauge | Double |

### k8s.pod.cpu.usage

Total CPU usage (sum of all cores per second) averaged over the sample window

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {cpu} | Gauge | Double |

### k8s.pod.cpu_limit_utilization

Pod cpu utilization as a ratio of the pod's total container limits. If any container is missing a limit the metric is not emitted.
Expand Down
11 changes: 11 additions & 0 deletions receiver/kubeletstatsreceiver/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ import (

const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing"

// The test requires a prebuilt otelcontribcol image uploaded to a kind k8s cluster defined in
// `/tmp/kube-config-otelcol-e2e-testing`. Run the following commands prior to running the test locally:
//
// kind create cluster --kubeconfig=/tmp/kube-config-otelcol-e2e-testing --config=./.github/workflows/configs/e2e-kind-config.yaml # Run from the top level dir of the repository
// make docker-otelcontribcol
// KUBECONFIG=/tmp/kube-config-otelcol-e2e-testing kind load docker-image otelcontribcol:latest
// kubectl --kubeconfig=/tmp/kube-config-otelcol-e2e-testing get csr -o=jsonpath='{range.items[?(@.spec.signerName=="kubernetes.io/kubelet-serving")]}{.metadata.name}{" "}{end}' | xargs kubectl --kubeconfig=/tmp/kube-config-otelcol-e2e-testing certificate approve
func TestE2E(t *testing.T) {

var expected pmetric.Metrics
Expand All @@ -53,6 +60,10 @@ func TestE2E(t *testing.T) {
wantEntries := 10 // Minimal number of metrics to wait for.
waitForData(t, wantEntries, metricsConsumer)

// Uncomment to regenerate '*_expected.yaml' files
// md := metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1]
// golden.WriteMetrics(t, expectedFile, md)

require.NoError(t, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1],
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
Expand Down

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.

6 changes: 3 additions & 3 deletions receiver/kubeletstatsreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ attributes:

metrics:
k8s.node.cpu.usage:
enabled: false
enabled: true
description: "Total CPU usage (sum of all cores per second) averaged over the sample window"
unit: "{cpu}"
gauge:
Expand Down Expand Up @@ -198,7 +198,7 @@ metrics:
aggregation_temporality: cumulative
attributes: []
k8s.pod.cpu.usage:
enabled: false
enabled: true
description: "Total CPU usage (sum of all cores per second) averaged over the sample window"
unit: "{cpu}"
gauge:
Expand Down Expand Up @@ -355,7 +355,7 @@ metrics:
aggregation_temporality: cumulative
attributes: []
container.cpu.usage:
enabled: false
enabled: true
description: "Total CPU usage (sum of all cores per second) averaged over the sample window"
unit: "{cpu}"
gauge:
Expand Down
6 changes: 3 additions & 3 deletions receiver/kubeletstatsreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const (
numVolumes = 8

// Number of metrics by resource
nodeMetrics = 15
podMetrics = 15
containerMetrics = 11
nodeMetrics = 16
podMetrics = 16
containerMetrics = 12
volumeMetrics = 5
)

Expand Down
Loading