Skip to content

Commit

Permalink
add remaping for the kubernetes.pod.memory.usage.node.pct metric (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: Tetiana Kravchenko <[email protected]>
  • Loading branch information
tetianakravchenko authored Jul 18, 2024
1 parent e8f309d commit d1f6396
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion remappers/kubernetesmetrics/k8smetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ func doTestRemap(t *testing.T, id string, remapOpts ...Option) {
{Type: Gauge, Name: "k8s.pod.cpu_limit_utilization", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.26), Attrs: map[string]any{"k8s.pod.name": POD, "k8s.namespace.name": NAMESPACE}}},
{Type: Gauge, Name: "k8s.pod.memory_limit_utilization", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.18), Attrs: map[string]any{"k8s.pod.name": "pod0", "k8s.pod.namespace": NAMESPACE}}},
{Type: Gauge, Name: "k8s.pod.cpu.node.utilization", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.12), Attrs: map[string]any{"k8s.pod.name": POD, "k8s.namespace.name": NAMESPACE}}},
{Type: Gauge, Name: "k8s.pod.memory.node.utilization", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.025), Attrs: map[string]any{"k8s.pod.name": "pod0", "k8s.pod.namespace": NAMESPACE}}},
{Type: Sum, Name: "k8s.pod.network.io", DP: testutils.TestDP{Ts: now, Int: testutils.Ptr(int64(1024)), Attrs: map[string]any{"device": DEVICE, "direction": "receive"}}},
{Type: Sum, Name: "k8s.pod.network.io", DP: testutils.TestDP{Ts: now, Int: testutils.Ptr(int64(2048)), Attrs: map[string]any{"device": DEVICE, "direction": "transmit"}}},
},
expected: []testutils.TestMetric{
{Type: Gauge, Name: "kubernetes.pod.cpu.usage.limit.pct", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.26), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.pod.cpu.usage.node.pct", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.12), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.pod.memory.usage.node.pct", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.0), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.pod.memory.usage.node.pct", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.025), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.pod.memory.usage.limit.pct", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.18), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Sum, Name: "kubernetes.pod.network.tx.bytes", DP: testutils.TestDP{Ts: now, Int: testutils.Ptr(int64(2048)), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Sum, Name: "kubernetes.pod.network.rx.bytes", DP: testutils.TestDP{Ts: now, Int: testutils.Ptr(int64(1024)), Attrs: outAttr("kubeletstatsreceiver")}},
Expand Down Expand Up @@ -118,6 +119,7 @@ func BenchmarkRemap(b *testing.B) {
{Type: Gauge, Name: "k8s.pod.cpu_limit_utilization", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.26), Attrs: map[string]any{"k8s.pod.name": POD, "k8s.namespace.name": NAMESPACE}}},
{Type: Gauge, Name: "k8s.pod.cpu.node.utilization", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.12), Attrs: map[string]any{"k8s.pod.name": POD, "k8s.namespace.name": NAMESPACE}}},
{Type: Gauge, Name: "k8s.pod.memory_limit_utilization", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.18), Attrs: map[string]any{"k8s.pod.name": "pod0", "k8s.pod.namespace": NAMESPACE}}},
{Type: Gauge, Name: "k8s.pod.memory.node.utilization", DP: testutils.TestDP{Ts: now, Dbl: testutils.Ptr(0.025), Attrs: map[string]any{"k8s.pod.name": "pod0", "k8s.pod.namespace": NAMESPACE}}},
{Type: Sum, Name: "k8s.pod.network.io", DP: testutils.TestDP{Ts: now, Int: testutils.Ptr(int64(1024)), Attrs: map[string]any{"device": DEVICE, "direction": "receive"}}},
{Type: Sum, Name: "k8s.pod.network.io", DP: testutils.TestDP{Ts: now, Int: testutils.Ptr(int64(2048)), Attrs: map[string]any{"device": DEVICE, "direction": "transmit"}}},
},
Expand Down
7 changes: 6 additions & 1 deletion remappers/kubernetesmetrics/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func addKubeletMetrics(
//pod
for i := 0; i < src.Len(); i++ {
metric := src.At(i)
// kubernetes.pod.memory.usage.node.pct still needs to be implemented
if metric.Name() == "k8s.pod.cpu_limit_utilization" {
dp := metric.Gauge().DataPoints().At(0)
if timestamp == 0 {
Expand All @@ -55,6 +54,12 @@ func addKubeletMetrics(
timestamp = dp.Timestamp()
}
memory_limit_utilization = dp.DoubleValue()
} else if metric.Name() == "k8s.pod.memory.node.utilization" {
dp := metric.Gauge().DataPoints().At(0)
if timestamp == 0 {
timestamp = dp.Timestamp()
}
pod_memory_usage_node = dp.DoubleValue()
} else if metric.Name() == "k8s.pod.network.io" {
dataPoints := metric.Sum().DataPoints()
for j := 0; j < dataPoints.Len(); j++ {
Expand Down

0 comments on commit d1f6396

Please sign in to comment.