Skip to content
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
41 changes: 15 additions & 26 deletions remappers/hostmetrics/hostmetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,13 @@ func doTestRemap(t *testing.T, id string, remapOpts ...Option) {
{Type: Gauge, Name: "system.cpu.system.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.68), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.user.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.5), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.steal.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.15), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.iowait.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.nice.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.irq.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.softirq.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
{Type: Sum, Name: "system.cpu.cores", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(4)), Attrs: outAttr("cpu")}},
{Type: Sum, Name: "system.load.cores", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(4)), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.total.norm.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.3325), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.idle.norm.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.205), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.system.norm.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.17), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.user.norm.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.125), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.steal.norm.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0375), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.iowait.norm.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.nice.norm.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.irq.norm.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.softirq.norm.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
},
},
{
Expand All @@ -152,10 +144,6 @@ func doTestRemap(t *testing.T, id string, remapOpts ...Option) {
{Type: Gauge, Name: "system.cpu.system.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.68), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.user.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.5), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.steal.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.15), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.iowait.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.nice.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.irq.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
{Type: Gauge, Name: "system.cpu.softirq.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("cpu")}},
},
},
{
Expand Down Expand Up @@ -220,28 +208,29 @@ func doTestRemap(t *testing.T, id string, remapOpts ...Option) {
{Type: Sum, Name: "process.memory.usage", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(2048))}},
{Type: Sum, Name: "process.memory.virtual", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(128))}},
{Type: Sum, Name: "process.open_file_descriptors", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(10))}},
{Type: Sum, Name: "process.cpu.time", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(3)), Attrs: map[string]any{"state": "system"}}},
{Type: Sum, Name: "process.cpu.time", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(4)), Attrs: map[string]any{"state": "user"}}},
{Type: Sum, Name: "process.cpu.time", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(5)), Attrs: map[string]any{"state": "wait"}}},
{Type: Sum, Name: "process.disk.io", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(1024))}},
{Type: Sum, Name: "process.disk.operations", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(10))}},
{Type: Sum, Name: "process.cpu.time", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.3345), Attrs: map[string]any{"state": "system"}}},
{Type: Sum, Name: "process.cpu.time", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.5546), Attrs: map[string]any{"state": "user"}}},
{Type: Sum, Name: "process.cpu.time", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.8752), Attrs: map[string]any{"state": "wait"}}},
{Type: Sum, Name: "process.disk.io", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(1024)), Attrs: map[string]any{"direction": "read"}}},
{Type: Sum, Name: "process.disk.io", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(2048)), Attrs: map[string]any{"direction": "write"}}},
{Type: Sum, Name: "process.disk.operations", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(10)), Attrs: map[string]any{"direction": "read"}}},
{Type: Sum, Name: "process.disk.operations", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(20)), Attrs: map[string]any{"direction": "write"}}},
},
expected: []internal.TestMetric{
{Type: Sum, Name: "process.cpu.start_time", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(0)), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.num_threads", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(7)), Attrs: outAttr("process")}},
{Type: Gauge, Name: "system.process.memory.rss.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.15), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.memory.rss.bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(2048)), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.memory.size", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(128)), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.fd.open", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(10)), Attrs: outAttr("process")}},
{Type: Gauge, Name: "process.memory.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.15), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.cpu.total.value", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.cpu.system.ticks", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.cpu.user.ticks", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.cpu.total.ticks", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.io.read_bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(0)), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.io.write_bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(0)), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.io.read_ops", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(0)), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.io.write_ops", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(0)), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.cpu.total.value", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(1764.3), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.cpu.system.ticks", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(334.5), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.cpu.user.ticks", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(554.6), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.cpu.total.ticks", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(1764.3), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.io.read_bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(1024)), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.io.write_bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(2048)), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.io.read_ops", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(10)), Attrs: outAttr("process")}},
{Type: Sum, Name: "system.process.io.write_ops", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(20)), Attrs: outAttr("process")}},
{Type: Gauge, Name: "system.process.cpu.total.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("process")}},
},
},
Expand Down
8 changes: 8 additions & 0 deletions remappers/internal/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package internal

import (
"math"

"github.com/elastic/opentelemetry-lib/remappers/common"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
Expand Down Expand Up @@ -46,6 +48,12 @@ func AddMetrics(
ms.EnsureCapacity(ms.Len() + len(metrics))

for _, metric := range metrics {

//The translated metric should not be generated for a null or negative value
if (metric.IntValue != nil && *metric.IntValue <= 0) || (metric.DoubleValue != nil && (*metric.DoubleValue <= 0 || math.IsInf(*metric.DoubleValue, 0))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishleenk17 QQ: Can zero be a valid value in some cases? I wonder if we should keep the symbol <

continue
}

m := ms.AppendEmpty()
m.SetName(metric.Name)

Expand Down
5 changes: 0 additions & 5 deletions remappers/kubernetesmetrics/k8smetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,9 @@ func doTestRemap(t *testing.T, id string, remapOpts ...Option) {
expected: []internal.TestMetric{
{Type: Gauge, Name: "kubernetes.pod.cpu.usage.limit.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.26), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.pod.cpu.usage.node.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.12), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.pod.memory.usage.node.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.pod.memory.usage.limit.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.18), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Sum, Name: "kubernetes.pod.network.tx.bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(2048)), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Sum, Name: "kubernetes.pod.network.rx.bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(1024)), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.node.cpu.usage.nanocores", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.0), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.node.memory.usage.bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(0)), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.node.fs.capacity.bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(0)), Attrs: outAttr("kubeletstatsreceiver")}},
{Type: Gauge, Name: "kubernetes.node.fs.used.bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(0)), Attrs: outAttr("kubeletstatsreceiver")}},
},
},
} {
Expand Down