Skip to content

Commit

Permalink
rename to k8s.container.cpu.node.utilization
Browse files Browse the repository at this point in the history
Signed-off-by: ChrsMark <chrismarkou92@gmail.com>
  • Loading branch information
ChrsMark committed May 31, 2024
1 parent fb652fc commit ceb5d34
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .chloggen/k8s_container_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ change_type: 'enhancement'
component: kubeletstatsreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add k8s.container.cpu.node_limit_utilization metric
note: Add k8s.container.cpu.node.utilization metric

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [27885]
Expand Down
10 changes: 0 additions & 10 deletions internal/k8sconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,3 @@ func NewNodeSharedInformer(client k8s.Interface, nodeName string, watchSyncPerio
)
return informer
}

// IgnoreDeletedFinalStateUnknown returns the object wrapped in
// DeletedFinalStateUnknown. Useful in OnDelete resource event handlers that do
// not need the additional context.
func IgnoreDeletedFinalStateUnknown(obj any) any {
if obj, ok := obj.(cache.DeletedFinalStateUnknown); ok {
return obj.Obj
}
return obj
}
6 changes: 3 additions & 3 deletions receiver/kubeletstatsreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ receivers:
- pod
```

### Collect k8s.container.cpu.node_limit_utilization as ratio of total node's capacity
### Collect k8s.container.cpu.node.utilization as ratio of total node's capacity

In order to calculate the `k8s.container.cpu.node_limit_utilization` metric, the information of the node's capacity
In order to calculate the `k8s.container.cpu.node.utilization` metric, the information of the node's capacity
must be retrieved from the k8s API. In this, the `k8s_api_config` needs to be set.
In addition, the node name must be identified properly. The `K8S_NODE_NAME` env var can be set using the
downward API inside the collector pod spec as follows:
Expand All @@ -244,7 +244,7 @@ receivers:
k8s_api_config:
auth_type: serviceAccount
metrics:
k8s.container.cpu_limit_utilization:
k8s.container.cpu.node.utilization:
enabled: true
```

Expand Down
4 changes: 2 additions & 2 deletions receiver/kubeletstatsreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (cfg *Config) Unmarshal(componentParser *confmap.Conf) error {
}

func (cfg *Config) Validate() error {
if cfg.Metrics.K8sContainerCPUNodeLimitUtilization.Enabled && cfg.NodeName == "" {
return errors.New("for k8s.container.cpu.node_limit_utilization node setting is required. Check the readme on how to set the required setting")
if cfg.Metrics.K8sContainerCPUNodeUtilization.Enabled && cfg.NodeName == "" {
return errors.New("for k8s.container.cpu.node.utilization node setting is required. Check the readme on how to set the required setting")
}
return nil
}
6 changes: 3 additions & 3 deletions receiver/kubeletstatsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestLoadConfig(t *testing.T) {
},
},
{
id: component.NewIDWithName(metadata.Type, "container_cpu_node_limit_utilization"),
id: component.NewIDWithName(metadata.Type, "container_cpu_node_utilization"),
expected: &Config{
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: duration,
Expand All @@ -192,14 +192,14 @@ func TestLoadConfig(t *testing.T) {
},
MetricsBuilderConfig: metadata.MetricsBuilderConfig{
Metrics: metadata.MetricsConfig{
K8sContainerCPUNodeLimitUtilization: metadata.MetricConfig{
K8sContainerCPUNodeUtilization: metadata.MetricConfig{
Enabled: true,
},
},
ResourceAttributes: metadata.DefaultResourceAttributesConfig(),
},
},
expectedValidationErr: "for k8s.container.cpu.node_limit_utilization node setting is required. Check the readme on how to set the required setting",
expectedValidationErr: "for k8s.container.cpu.node.utilization node setting is required. Check the readme on how to set the required setting",
},
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/kubeletstatsreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ The time since the container started
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Int | Cumulative | true |
### k8s.container.cpu.node_limit_utilization
### k8s.container.cpu.node.utilization
Container cpu utilization as a ratio of the node's capacity
Expand Down
2 changes: 1 addition & 1 deletion receiver/kubeletstatsreceiver/internal/kubelet/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func addCPUUsageMetric(
cpuMetrics.Usage(mb, currentTime, value)

if nodeCPULimit > 0 {
cpuMetrics.NodeLimitUtilization(mb, currentTime, value/nodeCPULimit)
cpuMetrics.NodeUtilization(mb, currentTime, value/nodeCPULimit)
}
if r.cpuLimit > 0 {
cpuMetrics.LimitUtilization(mb, currentTime, value/r.cpuLimit)
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.

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.

24 changes: 12 additions & 12 deletions receiver/kubeletstatsreceiver/internal/metadata/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type MetricsBuilders struct {
}

type CPUMetrics struct {
Time RecordDoubleDataPointFunc
Usage RecordDoubleDataPointFunc
Utilization RecordDoubleDataPointFunc
NodeLimitUtilization RecordDoubleDataPointFunc
LimitUtilization RecordDoubleDataPointFunc
RequestUtilization RecordDoubleDataPointFunc
Time RecordDoubleDataPointFunc
Usage RecordDoubleDataPointFunc
Utilization RecordDoubleDataPointFunc
NodeUtilization RecordDoubleDataPointFunc
LimitUtilization RecordDoubleDataPointFunc
RequestUtilization RecordDoubleDataPointFunc
}

var NodeCPUMetrics = CPUMetrics{
Expand All @@ -42,12 +42,12 @@ var PodCPUMetrics = CPUMetrics{
}

var ContainerCPUMetrics = CPUMetrics{
Time: (*MetricsBuilder).RecordContainerCPUTimeDataPoint,
Usage: (*MetricsBuilder).RecordContainerCPUUsageDataPoint,
Utilization: (*MetricsBuilder).RecordContainerCPUUtilizationDataPoint,
NodeLimitUtilization: (*MetricsBuilder).RecordK8sContainerCPUNodeLimitUtilizationDataPoint,
LimitUtilization: (*MetricsBuilder).RecordK8sContainerCPULimitUtilizationDataPoint,
RequestUtilization: (*MetricsBuilder).RecordK8sContainerCPURequestUtilizationDataPoint,
Time: (*MetricsBuilder).RecordContainerCPUTimeDataPoint,
Usage: (*MetricsBuilder).RecordContainerCPUUsageDataPoint,
Utilization: (*MetricsBuilder).RecordContainerCPUUtilizationDataPoint,
NodeUtilization: (*MetricsBuilder).RecordK8sContainerCPUNodeUtilizationDataPoint,
LimitUtilization: (*MetricsBuilder).RecordK8sContainerCPULimitUtilizationDataPoint,
RequestUtilization: (*MetricsBuilder).RecordK8sContainerCPURequestUtilizationDataPoint,
}

type MemoryMetrics struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ all_set:
enabled: true
container.uptime:
enabled: true
k8s.container.cpu.node_limit_utilization:
k8s.container.cpu.node.utilization:
enabled: true
k8s.container.cpu_limit_utilization:
enabled: true
Expand Down Expand Up @@ -174,7 +174,7 @@ none_set:
enabled: false
container.uptime:
enabled: false
k8s.container.cpu.node_limit_utilization:
k8s.container.cpu.node.utilization:
enabled: false
k8s.container.cpu_limit_utilization:
enabled: false
Expand Down
2 changes: 1 addition & 1 deletion receiver/kubeletstatsreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ metrics:
gauge:
value_type: int
attributes: []
k8s.container.cpu.node_limit_utilization:
k8s.container.cpu.node.utilization:
enabled: false
description: "Container cpu utilization as a ratio of the node's capacity"
unit: 1
Expand Down
2 changes: 1 addition & 1 deletion receiver/kubeletstatsreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func newKubletScraper(
nodeLimits: &kubelet.NodeLimits{},
}

if metricsConfig.Metrics.K8sContainerCPUNodeLimitUtilization.Enabled {
if metricsConfig.Metrics.K8sContainerCPUNodeUtilization.Enabled {
ks.nodeInformer = k8sconfig.NewNodeSharedInformer(rOptions.k8sAPIClient, nodeName, 5*time.Minute)
}

Expand Down
4 changes: 2 additions & 2 deletions receiver/kubeletstatsreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestScraper(t *testing.T) {
pmetrictest.IgnoreMetricsOrder()))
}

func TestScraperWithNodeLimitUtilization(t *testing.T) {
func TestScraperWithNodeUtilization(t *testing.T) {
watcherStarted := make(chan struct{})
// Create the fake client.
client := fake.NewSimpleClientset()
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestScraperWithNodeLimitUtilization(t *testing.T) {
options,
metadata.MetricsBuilderConfig{
Metrics: metadata.MetricsConfig{
K8sContainerCPUNodeLimitUtilization: metadata.MetricConfig{
K8sContainerCPUNodeUtilization: metadata.MetricConfig{
Enabled: true,
},
},
Expand Down
4 changes: 2 additions & 2 deletions receiver/kubeletstatsreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ kubeletstats/metric_groups:
collection_interval: 20s
auth_type: "serviceAccount"
metric_groups: [ pod, node, volume ]
kubeletstats/container_cpu_node_limit_utilization:
kubeletstats/container_cpu_node_utilization:
collection_interval: 10s
metric_groups: [ container, pod, node ]
metrics:
k8s.container.cpu.node_limit_utilization:
k8s.container.cpu.node.utilization:
enabled: true
Loading

0 comments on commit ceb5d34

Please sign in to comment.