Skip to content

Commit

Permalink
[chore] [receiver/k8s_cluster] update the tests to cover all the exis…
Browse files Browse the repository at this point in the history
…ting k8s node metrics (#23841)
  • Loading branch information
atoulme committed Jun 29, 2023
1 parent 9a521ed commit 377f666
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
2 changes: 1 addition & 1 deletion receiver/k8sclusterreceiver/internal/node/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func TestNodeMetricsReportCPUMetrics(t *testing.T) {
n := testutils.NewNode("1")
m := GetMetrics(receivertest.NewNopCreateSettings(), n, []string{"Ready", "MemoryPressure"}, []string{"cpu", "memory", "ephemeral-storage", "storage"})
m := GetMetrics(receivertest.NewNopCreateSettings(), n, []string{"Ready", "MemoryPressure", "DiskPressure", "NetworkUnavailable", "PIDPressure", "OutOfDisk"}, []string{"cpu", "memory", "ephemeral-storage", "storage", "pods", "hugepages-1Gi", "hugepages-2Mi"})
expected, err := golden.ReadMetrics(filepath.Join("testdata", "expected.yaml"))
require.NoError(t, err)
require.NoError(t, pmetrictest.CompareMetrics(expected, m,
Expand Down
48 changes: 33 additions & 15 deletions receiver/k8sclusterreceiver/internal/node/testdata/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,54 @@ resourceMetrics:
schemaUrl: https://opentelemetry.io/schemas/1.18.0
scopeMetrics:
- metrics:
- description: Whether this node is Ready (1), not Ready (0) or in an unknown state (-1)
- description: How many CPU cores remaining that the node can allocate to pods
gauge:
dataPoints:
- asInt: "1"
name: k8s.node.condition_ready
- asDouble: 0.123
name: k8s.node.allocatable_cpu
unit: '{cores}'
- description: How many bytes of ephemeral storage remaining that the node can allocate to pods
gauge:
dataPoints:
- asInt: "1234"
name: k8s.node.allocatable_ephemeral_storage
unit: By
- description: How many bytes of RAM memory remaining that the node can allocate to pods
gauge:
dataPoints:
- asInt: "456"
name: k8s.node.allocatable_memory
unit: By
- description: Whether this node is DiskPressure (1), not DiskPressure (0) or in an unknown state (-1)
gauge:
dataPoints:
- asInt: "0"
name: k8s.node.condition_disk_pressure
unit: "1"
- description: Whether this node is MemoryPressure (1), not MemoryPressure (0) or in an unknown state (-1)
gauge:
dataPoints:
- asInt: "0"
name: k8s.node.condition_memory_pressure
unit: "1"
- description: How many CPU cores remaining that the node can allocate to pods
- description: Whether this node is NetworkUnavailable (1), not NetworkUnavailable (0) or in an unknown state (-1)
gauge:
dataPoints:
- asDouble: 0.123
name: k8s.node.allocatable_cpu
unit: "{cores}"
- description: How many bytes of RAM memory remaining that the node can allocate to pods
- asInt: "0"
name: k8s.node.condition_network_unavailable
unit: "1"
- description: Whether this node is PidPressure (1), not PidPressure (0) or in an unknown state (-1)
gauge:
dataPoints:
- asInt: "456"
name: k8s.node.allocatable_memory
unit: "By"
- description: How many bytes of ephemeral storage remaining that the node can allocate to pods
- asInt: "0"
name: k8s.node.condition_pid_pressure
unit: "1"
- description: Whether this node is Ready (1), not Ready (0) or in an unknown state (-1)
gauge:
dataPoints:
- asInt: "1234"
name: k8s.node.allocatable_ephemeral_storage
unit: "By"
- asInt: "1"
name: k8s.node.condition_ready
unit: "1"
scope:
name: otelcol/k8sclusterreceiver
version: latest
19 changes: 16 additions & 3 deletions receiver/k8sclusterreceiver/internal/testutils/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,31 @@ func NewNode(id string) *corev1.Node {
Status: corev1.NodeStatus{
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
Type: corev1.NodeDiskPressure,
Status: corev1.ConditionFalse,
},
{
Status: corev1.ConditionFalse,
Type: corev1.NodeMemoryPressure,
Status: corev1.ConditionFalse,
},
{
Type: corev1.NodeNetworkUnavailable,
Status: corev1.ConditionFalse,
},
{
Type: corev1.NodePIDPressure,
Status: corev1.ConditionFalse,
},
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
Allocatable: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewMilliQuantity(123, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(456, resource.DecimalSI),
corev1.ResourceEphemeralStorage: *resource.NewQuantity(1234, resource.DecimalSI),
corev1.ResourcePods: *resource.NewQuantity(12, resource.DecimalSI),
},
},
}
Expand Down

0 comments on commit 377f666

Please sign in to comment.