From a5fba8de38e3a10000095c0a9888e2cc5c044d2b Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Wed, 25 Sep 2024 16:18:18 -0700 Subject: [PATCH 1/8] [processor/metricsgeneration] Fix panic when using a sum metric for calculations --- .../metricsgeneration_relax_type_req.yaml | 27 + processor/metricsgenerationprocessor/go.mod | 8 + processor/metricsgenerationprocessor/go.sum | 4 + .../processor_test.go | 45 + .../testdata/filesystem_metrics_expected.yaml | 1205 +++++++++++++++++ .../testdata/filesystem_metrics_input.yaml | 802 +++++++++++ processor/metricsgenerationprocessor/utils.go | 17 +- 7 files changed, 2104 insertions(+), 4 deletions(-) create mode 100644 .chloggen/metricsgeneration_relax_type_req.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/filesystem_metrics_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/filesystem_metrics_input.yaml diff --git a/.chloggen/metricsgeneration_relax_type_req.yaml b/.chloggen/metricsgeneration_relax_type_req.yaml new file mode 100644 index 000000000000..e2065d54988a --- /dev/null +++ b/.chloggen/metricsgeneration_relax_type_req.yaml @@ -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: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: metricsgenerationprocessor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Allow metric calculations to be done on sum metrics + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [] + +# (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: + +# 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: [] diff --git a/processor/metricsgenerationprocessor/go.mod b/processor/metricsgenerationprocessor/go.mod index 5e7e10e33aa9..a6c55a7bfee5 100644 --- a/processor/metricsgenerationprocessor/go.mod +++ b/processor/metricsgenerationprocessor/go.mod @@ -3,6 +3,8 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/processor/metri go 1.22.0 require ( + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.110.0 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.0.0-00010101000000-000000000000 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.110.0 go.opentelemetry.io/collector/confmap v1.16.0 @@ -15,6 +17,7 @@ require ( ) require ( + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -29,6 +32,7 @@ require ( github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect go.opentelemetry.io/collector/component/componentstatus v0.110.0 // indirect @@ -59,3 +63,7 @@ retract ( v0.76.1 v0.65.0 ) + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden => ../../pkg/golden + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest diff --git a/processor/metricsgenerationprocessor/go.sum b/processor/metricsgenerationprocessor/go.sum index e195251f7c4d..6989f9cbc311 100644 --- a/processor/metricsgenerationprocessor/go.sum +++ b/processor/metricsgenerationprocessor/go.sum @@ -1,3 +1,5 @@ +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -38,6 +40,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0 h1:KYBzbgQyCz4i5zjzs0iBOFuNh2vagaw2seqvZ7Lftxk= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0/go.mod h1:zLtbGLswPAKzTHM4C1Pcxb+PgNHgo6aGVZQtQaeBtec= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= diff --git a/processor/metricsgenerationprocessor/processor_test.go b/processor/metricsgenerationprocessor/processor_test.go index 49cd25058abe..dee3b41d3729 100644 --- a/processor/metricsgenerationprocessor/processor_test.go +++ b/processor/metricsgenerationprocessor/processor_test.go @@ -5,6 +5,7 @@ package metricsgenerationprocessor import ( "context" + "path/filepath" "testing" "time" @@ -14,6 +15,9 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/processor/processortest" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" ) type testMetric struct { @@ -384,3 +388,44 @@ func getOutputForIntGaugeTest() pmetric.Metrics { return intGaugeOutputMetrics } + +func TestSumCalculateNewMetric(t *testing.T) { + next := new(consumertest.MetricsSink) + cfg := &Config{ + Rules: []Rule{ + { + Name: "system.filesystem.capacity", + Unit: "bytes", + Type: "calculate", + Metric1: "system.filesystem.usage", + Metric2: "system.filesystem.utilization", + Operation: "divide", + }, + }, + } + factory := NewFactory() + mgp, err := factory.CreateMetricsProcessor( + context.Background(), + processortest.NewNopSettings(), + cfg, + next, + ) + assert.NotNil(t, mgp) + assert.NoError(t, err) + + assert.True(t, mgp.Capabilities().MutatesData) + require.NoError(t, mgp.Start(context.Background(), nil)) + + inputMetrics, err := golden.ReadMetrics(filepath.Join(".", "testdata", "filesystem_metrics_input.yaml")) + assert.NoError(t, err) + + err = mgp.ConsumeMetrics(context.Background(), inputMetrics) + assert.NoError(t, err) + + got := next.AllMetrics() + // golden.WriteMetrics(t, filepath.Join(".", "testdata", "filesystem_metrics_expected.yaml"), got[0]) + expected, err := golden.ReadMetrics(filepath.Join(".", "testdata", "filesystem_metrics_expected.yaml")) + assert.NoError(t, err) + assert.Len(t, got, 1) + pmetrictest.CompareMetrics(expected, got[0]) +} diff --git a/processor/metricsgenerationprocessor/testdata/filesystem_metrics_expected.yaml b/processor/metricsgenerationprocessor/testdata/filesystem_metrics_expected.yaml new file mode 100644 index 000000000000..d5820664a5f4 --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/filesystem_metrics_expected.yaml @@ -0,0 +1,1205 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: FileSystem inodes used. + name: system.filesystem.inodes.usage + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "2183953600" + attributes: + - key: device + value: + stringValue: /dev/disk1s1 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "4770142" + attributes: + - key: device + value: + stringValue: /dev/disk1s1 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "2183953600" + attributes: + - key: device + value: + stringValue: /dev/disk1s2 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Preboot + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "1813" + attributes: + - key: device + value: + stringValue: /dev/disk1s2 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Preboot + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "2183953600" + attributes: + - key: device + value: + stringValue: /dev/disk1s4s1 + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: / + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "404475" + attributes: + - key: device + value: + stringValue: /dev/disk1s4s1 + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: / + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "2183953600" + attributes: + - key: device + value: + stringValue: /dev/disk1s5 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Update + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "24" + attributes: + - key: device + value: + stringValue: /dev/disk1s5 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Update + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "2183953600" + attributes: + - key: device + value: + stringValue: /dev/disk1s6 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/VM + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "4" + attributes: + - key: device + value: + stringValue: /dev/disk1s6 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/VM + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /dev + - key: state + value: + stringValue: free + - key: type + value: + stringValue: devfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "666" + attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /dev + - key: state + value: + stringValue: used + - key: type + value: + stringValue: devfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data/home + - key: state + value: + stringValue: free + - key: type + value: + stringValue: autofs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data/home + - key: state + value: + stringValue: used + - key: type + value: + stringValue: autofs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: '{inodes}' + - description: Filesystem bytes used. + name: system.filesystem.usage + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "223636848640" + attributes: + - key: device + value: + stringValue: /dev/disk1s1 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: /dev/disk1s1 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "276326326272" + attributes: + - key: device + value: + stringValue: /dev/disk1s1 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "223636848640" + attributes: + - key: device + value: + stringValue: /dev/disk1s2 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Preboot + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: /dev/disk1s2 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Preboot + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "276326326272" + attributes: + - key: device + value: + stringValue: /dev/disk1s2 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Preboot + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "223636848640" + attributes: + - key: device + value: + stringValue: /dev/disk1s4s1 + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: / + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: /dev/disk1s4s1 + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: / + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "276326326272" + attributes: + - key: device + value: + stringValue: /dev/disk1s4s1 + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: / + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "223636848640" + attributes: + - key: device + value: + stringValue: /dev/disk1s5 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Update + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: /dev/disk1s5 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Update + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "276326326272" + attributes: + - key: device + value: + stringValue: /dev/disk1s5 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Update + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "223636848640" + attributes: + - key: device + value: + stringValue: /dev/disk1s6 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/VM + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: /dev/disk1s6 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/VM + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "276326326272" + attributes: + - key: device + value: + stringValue: /dev/disk1s6 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/VM + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /dev + - key: state + value: + stringValue: free + - key: type + value: + stringValue: devfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /dev + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: devfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "197120" + attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /dev + - key: state + value: + stringValue: used + - key: type + value: + stringValue: devfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data/home + - key: state + value: + stringValue: free + - key: type + value: + stringValue: autofs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data/home + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: autofs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asInt: "0" + attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data/home + - key: state + value: + stringValue: used + - key: type + value: + stringValue: autofs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: Fraction of filesystem bytes used. + gauge: + dataPoints: + - asDouble: 0.5526933585071281 + attributes: + - key: device + value: + stringValue: /dev/disk1s1 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0.5526933585071281 + attributes: + - key: device + value: + stringValue: /dev/disk1s2 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Preboot + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0.5526933585071281 + attributes: + - key: device + value: + stringValue: /dev/disk1s4s1 + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: / + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0.5526933585071281 + attributes: + - key: device + value: + stringValue: /dev/disk1s5 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Update + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0.5526933585071281 + attributes: + - key: device + value: + stringValue: /dev/disk1s6 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/VM + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 1 + attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /dev + - key: type + value: + stringValue: devfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data/home + - key: type + value: + stringValue: autofs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: system.filesystem.utilization + unit: "1" + - gauge: + dataPoints: + - asDouble: 4.046309679639759e+11 + attributes: + - key: device + value: + stringValue: /dev/disk1s1 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: /dev/disk1s1 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 4.99963174912e+11 + attributes: + - key: device + value: + stringValue: /dev/disk1s1 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 4.046309679639759e+11 + attributes: + - key: device + value: + stringValue: /dev/disk1s2 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Preboot + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: /dev/disk1s2 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Preboot + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 4.99963174912e+11 + attributes: + - key: device + value: + stringValue: /dev/disk1s2 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Preboot + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 4.046309679639759e+11 + attributes: + - key: device + value: + stringValue: /dev/disk1s4s1 + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: / + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: /dev/disk1s4s1 + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: / + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 4.99963174912e+11 + attributes: + - key: device + value: + stringValue: /dev/disk1s4s1 + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: / + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 4.046309679639759e+11 + attributes: + - key: device + value: + stringValue: /dev/disk1s5 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Update + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: /dev/disk1s5 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Update + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 4.99963174912e+11 + attributes: + - key: device + value: + stringValue: /dev/disk1s5 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Update + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 4.046309679639759e+11 + attributes: + - key: device + value: + stringValue: /dev/disk1s6 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/VM + - key: state + value: + stringValue: free + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: /dev/disk1s6 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/VM + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 4.99963174912e+11 + attributes: + - key: device + value: + stringValue: /dev/disk1s6 + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/VM + - key: state + value: + stringValue: used + - key: type + value: + stringValue: apfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /dev + - key: state + value: + stringValue: free + - key: type + value: + stringValue: devfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /dev + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: devfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 356653.46247770725 + attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /dev + - key: state + value: + stringValue: used + - key: type + value: + stringValue: devfs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data/home + - key: state + value: + stringValue: free + - key: type + value: + stringValue: autofs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data/home + - key: state + value: + stringValue: reserved + - key: type + value: + stringValue: autofs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + - asDouble: 0 + attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /System/Volumes/Data/home + - key: state + value: + stringValue: used + - key: type + value: + stringValue: autofs + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: system.filesystem.capacity + unit: bytes + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: 0.110.0-dev diff --git a/processor/metricsgenerationprocessor/testdata/filesystem_metrics_input.yaml b/processor/metricsgenerationprocessor/testdata/filesystem_metrics_input.yaml new file mode 100644 index 000000000000..6e4fee3c6c5c --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/filesystem_metrics_input.yaml @@ -0,0 +1,802 @@ +resourceMetrics: + - resource: {} + scopeMetrics: + - scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: 0.110.0-dev + metrics: + - name: system.filesystem.inodes.usage + description: FileSystem inodes used. + unit: "{inodes}" + sum: + dataPoints: + - attributes: + - key: device + value: + stringValue: "/dev/disk1s4s1" + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: "/" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '404475' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s4s1" + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: "/" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '2183953600' + - attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/dev" + - key: type + value: + stringValue: devfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '666' + - attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/dev" + - key: type + value: + stringValue: devfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s2" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Preboot" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '1813' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s2" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Preboot" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '2183953600' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s6" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/VM" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '4' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s6" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/VM" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '2183953600' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s5" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Update" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '24' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s5" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Update" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '2183953600' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s1" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '4770142' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s1" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '2183953600' + - attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data/home" + - key: type + value: + stringValue: autofs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data/home" + - key: type + value: + stringValue: autofs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + aggregationTemporality: 2 + - name: system.filesystem.usage + description: Filesystem bytes used. + unit: By + sum: + dataPoints: + - attributes: + - key: device + value: + stringValue: "/dev/disk1s4s1" + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: "/" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '276326326272' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s4s1" + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: "/" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '223636848640' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s4s1" + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: "/" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: reserved + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/dev" + - key: type + value: + stringValue: devfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '197120' + - attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/dev" + - key: type + value: + stringValue: devfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/dev" + - key: type + value: + stringValue: devfs + - key: state + value: + stringValue: reserved + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s2" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Preboot" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '276326326272' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s2" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Preboot" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '223636848640' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s2" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Preboot" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: reserved + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s6" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/VM" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '276326326272' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s6" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/VM" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '223636848640' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s6" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/VM" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: reserved + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s5" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Update" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '276326326272' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s5" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Update" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '223636848640' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s5" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Update" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: reserved + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s1" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '276326326272' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s1" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '223636848640' + - attributes: + - key: device + value: + stringValue: "/dev/disk1s1" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data" + - key: type + value: + stringValue: apfs + - key: state + value: + stringValue: reserved + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data/home" + - key: type + value: + stringValue: autofs + - key: state + value: + stringValue: used + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data/home" + - key: type + value: + stringValue: autofs + - key: state + value: + stringValue: free + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + - attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data/home" + - key: type + value: + stringValue: autofs + - key: state + value: + stringValue: reserved + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asInt: '0' + aggregationTemporality: 2 + - name: system.filesystem.utilization + description: Fraction of filesystem bytes used. + unit: '1' + gauge: + dataPoints: + - attributes: + - key: device + value: + stringValue: "/dev/disk1s4s1" + - key: mode + value: + stringValue: ro + - key: mountpoint + value: + stringValue: "/" + - key: type + value: + stringValue: apfs + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asDouble: 0.5526933585071281 + - attributes: + - key: device + value: + stringValue: devfs + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/dev" + - key: type + value: + stringValue: devfs + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asDouble: 1 + - attributes: + - key: device + value: + stringValue: "/dev/disk1s2" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Preboot" + - key: type + value: + stringValue: apfs + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asDouble: 0.5526933585071281 + - attributes: + - key: device + value: + stringValue: "/dev/disk1s6" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/VM" + - key: type + value: + stringValue: apfs + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asDouble: 0.5526933585071281 + - attributes: + - key: device + value: + stringValue: "/dev/disk1s5" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Update" + - key: type + value: + stringValue: apfs + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asDouble: 0.5526933585071281 + - attributes: + - key: device + value: + stringValue: "/dev/disk1s1" + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data" + - key: type + value: + stringValue: apfs + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asDouble: 0.5526933585071281 + - attributes: + - key: device + value: + stringValue: map auto_home + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: "/System/Volumes/Data/home" + - key: type + value: + stringValue: autofs + startTimeUnixNano: '1726497870000000000' + timeUnixNano: '1727303734559741000' + asDouble: 0 + schemaUrl: https://opentelemetry.io/schemas/1.9.0 diff --git a/processor/metricsgenerationprocessor/utils.go b/processor/metricsgenerationprocessor/utils.go index af613fdb0992..ee82c1668d28 100644 --- a/processor/metricsgenerationprocessor/utils.go +++ b/processor/metricsgenerationprocessor/utils.go @@ -41,7 +41,7 @@ func getMetricValue(metric pmetric.Metric) float64 { } // generateMetrics creates a new metric based on the given rule and add it to the Resource Metric. -// The value for newly calculated metrics is always a floting point number and the dataType is set +// The value for newly calculated metrics is always a floating point number and the dataType is set // as MetricTypeDoubleGauge. func generateMetrics(rm pmetric.ResourceMetrics, operand2 float64, rule internalRule, logger *zap.Logger) { ilms := rm.ScopeMetrics() @@ -53,14 +53,23 @@ func generateMetrics(rm pmetric.ResourceMetrics, operand2 float64, rule internal if metric.Name() == rule.metric1 { newMetric := appendMetric(ilm, rule.name, rule.unit) newMetric.SetEmptyGauge() - addDoubleGaugeDataPoints(metric, newMetric, operand2, rule.operation, logger) + addDoubleDataPoints(metric, newMetric, operand2, rule.operation, logger) } } } } -func addDoubleGaugeDataPoints(from pmetric.Metric, to pmetric.Metric, operand2 float64, operation string, logger *zap.Logger) { - dataPoints := from.Gauge().DataPoints() +// Note: the to metric must be a gauge. +func addDoubleDataPoints(from pmetric.Metric, to pmetric.Metric, operand2 float64, operation string, logger *zap.Logger) { + var dataPoints pmetric.NumberDataPointSlice + + switch metricType := from.Type(); metricType { + case pmetric.MetricTypeGauge: + dataPoints = from.Gauge().DataPoints() + case pmetric.MetricTypeSum: + dataPoints = from.Sum().DataPoints() + } + for i := 0; i < dataPoints.Len(); i++ { fromDataPoint := dataPoints.At(i) var operand1 float64 From f5b305a55a8c139d1809451286a8f466dc9624d3 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Wed, 25 Sep 2024 16:23:21 -0700 Subject: [PATCH 2/8] Update .chloggen/metricsgeneration_relax_type_req.yaml --- .chloggen/metricsgeneration_relax_type_req.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/metricsgeneration_relax_type_req.yaml b/.chloggen/metricsgeneration_relax_type_req.yaml index e2065d54988a..cd8ba247c435 100644 --- a/.chloggen/metricsgeneration_relax_type_req.yaml +++ b/.chloggen/metricsgeneration_relax_type_req.yaml @@ -10,7 +10,7 @@ component: metricsgenerationprocessor note: Allow metric calculations to be done on sum metrics # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. -issues: [] +issues: [35428] # (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. From e4987133826a5cd061299c3a27afe2be4517a1b8 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Wed, 25 Sep 2024 16:28:36 -0700 Subject: [PATCH 3/8] Fix lint --- processor/metricsgenerationprocessor/processor_test.go | 6 +++++- .../internal/metadata/generated_metrics_test.go | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/processor/metricsgenerationprocessor/processor_test.go b/processor/metricsgenerationprocessor/processor_test.go index dee3b41d3729..4b92eb2fe940 100644 --- a/processor/metricsgenerationprocessor/processor_test.go +++ b/processor/metricsgenerationprocessor/processor_test.go @@ -427,5 +427,9 @@ func TestSumCalculateNewMetric(t *testing.T) { expected, err := golden.ReadMetrics(filepath.Join(".", "testdata", "filesystem_metrics_expected.yaml")) assert.NoError(t, err) assert.Len(t, got, 1) - pmetrictest.CompareMetrics(expected, got[0]) + err = pmetrictest.CompareMetrics(expected, got[0], + pmetrictest.IgnoreMetricDataPointsOrder(), + pmetrictest.IgnoreStartTimestamp(), + pmetrictest.IgnoreTimestamp()) + assert.NoError(t, err) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_test.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_test.go index 364ff9518fb8..3638e94ef8b7 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_test.go @@ -3,6 +3,7 @@ package metadata import ( + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" "testing" "github.com/stretchr/testify/assert" From f8beea053aec5748d324de5ed3c0d49f8bbc6d10 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Wed, 25 Sep 2024 16:37:37 -0700 Subject: [PATCH 4/8] Update receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_test.go --- .../internal/metadata/generated_metrics_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_test.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_test.go index 3638e94ef8b7..364ff9518fb8 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_test.go @@ -3,7 +3,6 @@ package metadata import ( - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" "testing" "github.com/stretchr/testify/assert" From e56994f1fb2fdcbab9c25290af1b50445c8bdcf4 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Thu, 26 Sep 2024 09:21:55 -0700 Subject: [PATCH 5/8] make crosslink --- processor/metricsgenerationprocessor/go.mod | 2 ++ 1 file changed, 2 insertions(+) diff --git a/processor/metricsgenerationprocessor/go.mod b/processor/metricsgenerationprocessor/go.mod index a6c55a7bfee5..8c32c4326333 100644 --- a/processor/metricsgenerationprocessor/go.mod +++ b/processor/metricsgenerationprocessor/go.mod @@ -67,3 +67,5 @@ retract ( replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden => ../../pkg/golden replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../pkg/pdatautil From a2e698fcc52efdd5a1c8b1c5b1b0b2a6bfd5fa78 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Thu, 26 Sep 2024 13:25:13 -0700 Subject: [PATCH 6/8] make gotidy --- processor/metricsgenerationprocessor/go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/processor/metricsgenerationprocessor/go.sum b/processor/metricsgenerationprocessor/go.sum index 6989f9cbc311..12d9a3eacfd4 100644 --- a/processor/metricsgenerationprocessor/go.sum +++ b/processor/metricsgenerationprocessor/go.sum @@ -40,8 +40,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0 h1:KYBzbgQyCz4i5zjzs0iBOFuNh2vagaw2seqvZ7Lftxk= -github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0/go.mod h1:zLtbGLswPAKzTHM4C1Pcxb+PgNHgo6aGVZQtQaeBtec= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= From ba5e2e2e6d745ed2bfcce5723d96728ceef9441d Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Thu, 26 Sep 2024 15:57:41 -0700 Subject: [PATCH 7/8] Created metrics will have same type as configured `metric1` --- .../metricsgenerationprocessor/README.md | 10 +- .../processor_test.go | 65 ++++++++++++- .../testdata/filesystem_metrics_expected.yaml | 4 +- .../add_gauge_gauge_expected.yaml | 32 +++++++ .../metric_types/add_gauge_sum_expected.yaml | 32 +++++++ .../metric_types/add_sum_gauge_expected.yaml | 32 +++++++ .../metric_types/add_sum_sum_expected.yaml | 32 +++++++ .../divide_gauge_sum_expected.yaml | 32 +++++++ .../divide_sum_gauge_expected.yaml | 32 +++++++ .../gauge_sum_metrics_config.yaml | 96 +++++++++++++++++++ .../metric_types/gauge_sum_metrics_input.yaml | 25 +++++ .../multiply_gauge_sum_expected.yaml | 32 +++++++ .../multiply_sum_gauge_expected.yaml | 32 +++++++ .../percent_gauge_sum_expected.yaml | 32 +++++++ .../percent_sum_gauge_expected.yaml | 32 +++++++ .../subtract_gauge_sum_expected.yaml | 32 +++++++ .../subtract_sum_gauge_expected.yaml | 32 +++++++ processor/metricsgenerationprocessor/utils.go | 49 +++++++--- 18 files changed, 610 insertions(+), 23 deletions(-) create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/add_gauge_gauge_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/add_gauge_sum_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/add_sum_gauge_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/add_sum_sum_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/divide_gauge_sum_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/divide_sum_gauge_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/gauge_sum_metrics_config.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/gauge_sum_metrics_input.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/multiply_gauge_sum_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/multiply_sum_gauge_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/percent_gauge_sum_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/percent_sum_gauge_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/subtract_gauge_sum_expected.yaml create mode 100644 processor/metricsgenerationprocessor/testdata/metric_types/subtract_sum_gauge_expected.yaml diff --git a/processor/metricsgenerationprocessor/README.md b/processor/metricsgenerationprocessor/README.md index 3d81bcad46f7..42498a5ca312 100644 --- a/processor/metricsgenerationprocessor/README.md +++ b/processor/metricsgenerationprocessor/README.md @@ -16,12 +16,14 @@ ## Description -The metrics generation processor (`experimental_metricsgenerationprocessor`) can be used to create new metrics using existing metrics following a given rule. Currently it supports following two approaches for creating a new metric. +The metrics generation processor (`experimental_metricsgenerationprocessor`) can be used to create new metrics using existing metrics following a given rule. This processor currently supports the following two approaches for creating a new metric. -1. It can create a new metric from two existing metrics by applying one of the following arithmetic operations: add, subtract, multiply, divide and percent. One use case is to calculate the `pod.memory.utilization` metric like the following equation- +1. It can create a new metric from two existing metrics by applying one of the following arithmetic operations: add, subtract, multiply, divide, or percent. One use case is to calculate the `pod.memory.utilization` metric like the following equation- `pod.memory.utilization` = (`pod.memory.usage.bytes` / `node.memory.limit`) 1. It can create a new metric by scaling the value of an existing metric with a given constant number. One use case is to convert `pod.memory.usage` metric values from Megabytes to Bytes (multiply the existing metric's value by 1,048,576) +Note: The created metric's type is inherited from the metric configured as `metric1`. + ## Configuration Configuration is specified through a list of generation rules. Generation rules find the metrics which @@ -43,10 +45,10 @@ processors: # type describes how the new metric will be generated. It can be one of `calculate` or `scale`. calculate generates a metric applying the given operation on two operand metrics. scale operates only on operand1 metric to generate the new metric. type: {calculate, scale} - # This is a required field. + # This is a required field. This must be a gauge or sum metric. metric1: - # This field is required only if the type is "calculate". + # This field is required only if the type is "calculate". When required, this must be a gauge or sum metric. metric2: # Operation specifies which arithmetic operation to apply. It must be one of the five supported operations. diff --git a/processor/metricsgenerationprocessor/processor_test.go b/processor/metricsgenerationprocessor/processor_test.go index 4b92eb2fe940..ef0e62ebfd84 100644 --- a/processor/metricsgenerationprocessor/processor_test.go +++ b/processor/metricsgenerationprocessor/processor_test.go @@ -5,12 +5,14 @@ package metricsgenerationprocessor import ( "context" + "fmt" "path/filepath" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" @@ -416,7 +418,7 @@ func TestSumCalculateNewMetric(t *testing.T) { assert.True(t, mgp.Capabilities().MutatesData) require.NoError(t, mgp.Start(context.Background(), nil)) - inputMetrics, err := golden.ReadMetrics(filepath.Join(".", "testdata", "filesystem_metrics_input.yaml")) + inputMetrics, err := golden.ReadMetrics(filepath.Join("testdata", "filesystem_metrics_input.yaml")) assert.NoError(t, err) err = mgp.ConsumeMetrics(context.Background(), inputMetrics) @@ -424,7 +426,7 @@ func TestSumCalculateNewMetric(t *testing.T) { got := next.AllMetrics() // golden.WriteMetrics(t, filepath.Join(".", "testdata", "filesystem_metrics_expected.yaml"), got[0]) - expected, err := golden.ReadMetrics(filepath.Join(".", "testdata", "filesystem_metrics_expected.yaml")) + expected, err := golden.ReadMetrics(filepath.Join("testdata", "filesystem_metrics_expected.yaml")) assert.NoError(t, err) assert.Len(t, got, 1) err = pmetrictest.CompareMetrics(expected, got[0], @@ -433,3 +435,62 @@ func TestSumCalculateNewMetric(t *testing.T) { pmetrictest.IgnoreTimestamp()) assert.NoError(t, err) } + +func TestResultingMetricTypes(t *testing.T) { + testCaseNames := []string{ + "add_sum_sum", + "add_gauge_gauge", + "add_gauge_sum", + "add_sum_gauge", + "multiply_gauge_sum", + "multiply_sum_gauge", + "divide_gauge_sum", + "divide_sum_gauge", + "subtract_gauge_sum", + "subtract_sum_gauge", + "percent_sum_gauge", + "percent_gauge_sum", + } + + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "metric_types", "gauge_sum_metrics_config.yaml")) + assert.NoError(t, err) + + for _, testCase := range testCaseNames { + next := new(consumertest.MetricsSink) + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(fmt.Sprintf("%s/%s", "experimental_metricsgeneration", testCase)) + require.NoError(t, err) + require.NoError(t, sub.Unmarshal(cfg)) + + mgp, err := factory.CreateMetricsProcessor( + context.Background(), + processortest.NewNopSettings(), + cfg, + next, + ) + assert.NotNil(t, mgp) + assert.NoError(t, err) + + assert.True(t, mgp.Capabilities().MutatesData) + require.NoError(t, mgp.Start(context.Background(), nil)) + + inputMetrics, err := golden.ReadMetrics(filepath.Join("testdata", "metric_types", "gauge_sum_metrics_input.yaml")) + assert.NoError(t, err) + + err = mgp.ConsumeMetrics(context.Background(), inputMetrics) + assert.NoError(t, err) + + got := next.AllMetrics() + // golden.WriteMetrics(t, filepath.Join("testdata", "metric_types", fmt.Sprintf("%s_%s", testCase, "expected.yaml")), got[0]) + expected, err := golden.ReadMetrics(filepath.Join("testdata", "metric_types", fmt.Sprintf("%s_%s", testCase, "expected.yaml"))) + assert.NoError(t, err) + assert.Len(t, got, 1) + err = pmetrictest.CompareMetrics(expected, got[0], + pmetrictest.IgnoreMetricDataPointsOrder(), + pmetrictest.IgnoreStartTimestamp(), + pmetrictest.IgnoreTimestamp()) + assert.NoError(t, err) + } +} diff --git a/processor/metricsgenerationprocessor/testdata/filesystem_metrics_expected.yaml b/processor/metricsgenerationprocessor/testdata/filesystem_metrics_expected.yaml index d5820664a5f4..b2ac2ec86563 100644 --- a/processor/metricsgenerationprocessor/testdata/filesystem_metrics_expected.yaml +++ b/processor/metricsgenerationprocessor/testdata/filesystem_metrics_expected.yaml @@ -797,7 +797,8 @@ resourceMetrics: timeUnixNano: "2000000" name: system.filesystem.utilization unit: "1" - - gauge: + - name: system.filesystem.capacity + sum: dataPoints: - asDouble: 4.046309679639759e+11 attributes: @@ -1198,7 +1199,6 @@ resourceMetrics: stringValue: autofs startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: system.filesystem.capacity unit: bytes scope: name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/add_gauge_gauge_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/add_gauge_gauge_expected.yaml new file mode 100644 index 000000000000..9bfcbb8c0c9f --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/add_gauge_gauge_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - gauge: + dataPoints: + - asDouble: 100 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: new_metric + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/add_gauge_sum_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/add_gauge_sum_expected.yaml new file mode 100644 index 000000000000..ee7c710d0414 --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/add_gauge_sum_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - gauge: + dataPoints: + - asDouble: 1050 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: new_metric + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/add_sum_gauge_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/add_sum_gauge_expected.yaml new file mode 100644 index 000000000000..1769886855bb --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/add_sum_gauge_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - name: new_metric + sum: + dataPoints: + - asDouble: 1050 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/add_sum_sum_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/add_sum_sum_expected.yaml new file mode 100644 index 000000000000..a198c0c8a435 --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/add_sum_sum_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - name: new_metric + sum: + dataPoints: + - asDouble: 2000 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/divide_gauge_sum_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/divide_gauge_sum_expected.yaml new file mode 100644 index 000000000000..dc7a2f34c64c --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/divide_gauge_sum_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - gauge: + dataPoints: + - asDouble: 50000 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: new_metric + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/divide_sum_gauge_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/divide_sum_gauge_expected.yaml new file mode 100644 index 000000000000..1aea52d63388 --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/divide_sum_gauge_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - name: new_metric + sum: + dataPoints: + - asDouble: 20 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/gauge_sum_metrics_config.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/gauge_sum_metrics_config.yaml new file mode 100644 index 000000000000..9af299c78caa --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/gauge_sum_metrics_config.yaml @@ -0,0 +1,96 @@ +experimental_metricsgeneration/add_sum_sum: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: sum + metric2: sum + operation: add +experimental_metricsgeneration/add_gauge_gauge: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: gauge + metric2: gauge + operation: add +experimental_metricsgeneration/add_gauge_sum: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: gauge + metric2: sum + operation: add +experimental_metricsgeneration/add_sum_gauge: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: sum + metric2: gauge + operation: add +experimental_metricsgeneration/multiply_gauge_sum: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: gauge + metric2: sum + operation: multiply +experimental_metricsgeneration/multiply_sum_gauge: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: sum + metric2: gauge + operation: multiply +experimental_metricsgeneration/divide_gauge_sum: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: gauge + metric2: sum + operation: multiply +experimental_metricsgeneration/divide_sum_gauge: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: sum + metric2: gauge + operation: divide +experimental_metricsgeneration/subtract_gauge_sum: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: gauge + metric2: sum + operation: subtract +experimental_metricsgeneration/subtract_sum_gauge: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: sum + metric2: gauge + operation: subtract +experimental_metricsgeneration/percent_gauge_sum: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: gauge + metric2: sum + operation: percent +experimental_metricsgeneration/percent_sum_gauge: + rules: + - name: new_metric + unit: percent + type: calculate + metric1: sum + metric2: gauge + operation: percent \ No newline at end of file diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/gauge_sum_metrics_input.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/gauge_sum_metrics_input.yaml new file mode 100644 index 000000000000..cc63a8a46ead --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/gauge_sum_metrics_input.yaml @@ -0,0 +1,25 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: "50" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/multiply_gauge_sum_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/multiply_gauge_sum_expected.yaml new file mode 100644 index 000000000000..dc7a2f34c64c --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/multiply_gauge_sum_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - gauge: + dataPoints: + - asDouble: 50000 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: new_metric + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/multiply_sum_gauge_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/multiply_sum_gauge_expected.yaml new file mode 100644 index 000000000000..1e6a0afba6c0 --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/multiply_sum_gauge_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - name: new_metric + sum: + dataPoints: + - asDouble: 50000 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/percent_gauge_sum_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/percent_gauge_sum_expected.yaml new file mode 100644 index 000000000000..345f5a96576b --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/percent_gauge_sum_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - gauge: + dataPoints: + - asDouble: 5 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: new_metric + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/percent_sum_gauge_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/percent_sum_gauge_expected.yaml new file mode 100644 index 000000000000..a198c0c8a435 --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/percent_sum_gauge_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - name: new_metric + sum: + dataPoints: + - asDouble: 2000 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/subtract_gauge_sum_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/subtract_gauge_sum_expected.yaml new file mode 100644 index 000000000000..d2ab7b52109f --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/subtract_gauge_sum_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - gauge: + dataPoints: + - asDouble: -950 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: new_metric + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/testdata/metric_types/subtract_sum_gauge_expected.yaml b/processor/metricsgenerationprocessor/testdata/metric_types/subtract_sum_gauge_expected.yaml new file mode 100644 index 000000000000..190498b748f5 --- /dev/null +++ b/processor/metricsgenerationprocessor/testdata/metric_types/subtract_sum_gauge_expected.yaml @@ -0,0 +1,32 @@ +resourceMetrics: + - resource: {} + schemaUrl: https://opentelemetry.io/schemas/1.9.0 + scopeMetrics: + - metrics: + - description: foo + name: sum + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "1000" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: By + - description: bar + gauge: + dataPoints: + - asDouble: 50 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + name: gauge + unit: "1" + - name: new_metric + sum: + dataPoints: + - asDouble: 950 + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + unit: percent + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper + version: latest diff --git a/processor/metricsgenerationprocessor/utils.go b/processor/metricsgenerationprocessor/utils.go index ee82c1668d28..beb001a383b1 100644 --- a/processor/metricsgenerationprocessor/utils.go +++ b/processor/metricsgenerationprocessor/utils.go @@ -4,6 +4,8 @@ package metricsgenerationprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricsgenerationprocessor" import ( + "fmt" + "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" ) @@ -25,24 +27,31 @@ func getNameToMetricMap(rm pmetric.ResourceMetrics) map[string]pmetric.Metric { // getMetricValue returns the value of the first data point from the given metric. func getMetricValue(metric pmetric.Metric) float64 { - if metric.Type() == pmetric.MetricTypeGauge { - dataPoints := metric.Gauge().DataPoints() - if dataPoints.Len() > 0 { - switch dataPoints.At(0).ValueType() { - case pmetric.NumberDataPointValueTypeDouble: - return dataPoints.At(0).DoubleValue() - case pmetric.NumberDataPointValueTypeInt: - return float64(dataPoints.At(0).IntValue()) - } - } + var dataPoints pmetric.NumberDataPointSlice + + switch metricType := metric.Type(); metricType { + case pmetric.MetricTypeGauge: + dataPoints = metric.Gauge().DataPoints() + case pmetric.MetricTypeSum: + dataPoints = metric.Sum().DataPoints() + default: return 0 } + + if dataPoints.Len() > 0 { + switch dataPoints.At(0).ValueType() { + case pmetric.NumberDataPointValueTypeDouble: + return dataPoints.At(0).DoubleValue() + case pmetric.NumberDataPointValueTypeInt: + return float64(dataPoints.At(0).IntValue()) + } + } + return 0 } // generateMetrics creates a new metric based on the given rule and add it to the Resource Metric. -// The value for newly calculated metrics is always a floating point number and the dataType is set -// as MetricTypeDoubleGauge. +// The value for newly calculated metrics is always a floating point number. func generateMetrics(rm pmetric.ResourceMetrics, operand2 float64, rule internalRule, logger *zap.Logger) { ilms := rm.ScopeMetrics() for i := 0; i < ilms.Len(); i++ { @@ -52,22 +61,25 @@ func generateMetrics(rm pmetric.ResourceMetrics, operand2 float64, rule internal metric := metricSlice.At(j) if metric.Name() == rule.metric1 { newMetric := appendMetric(ilm, rule.name, rule.unit) - newMetric.SetEmptyGauge() addDoubleDataPoints(metric, newMetric, operand2, rule.operation, logger) } } } } -// Note: the to metric must be a gauge. func addDoubleDataPoints(from pmetric.Metric, to pmetric.Metric, operand2 float64, operation string, logger *zap.Logger) { var dataPoints pmetric.NumberDataPointSlice switch metricType := from.Type(); metricType { case pmetric.MetricTypeGauge: + to.SetEmptyGauge() dataPoints = from.Gauge().DataPoints() case pmetric.MetricTypeSum: + to.SetEmptySum() dataPoints = from.Sum().DataPoints() + default: + logger.Debug(fmt.Sprintf("Calculations are only supported on gauge or sum metric types. Given metric '%s' is of type `%s`", from.Name(), metricType.String())) + return } for i := 0; i < dataPoints.Len(); i++ { @@ -80,7 +92,14 @@ func addDoubleDataPoints(from pmetric.Metric, to pmetric.Metric, operand2 float6 operand1 = float64(fromDataPoint.IntValue()) } - neweDoubleDataPoint := to.Gauge().DataPoints().AppendEmpty() + var neweDoubleDataPoint pmetric.NumberDataPoint + switch to.Type() { + case pmetric.MetricTypeGauge: + neweDoubleDataPoint = to.Gauge().DataPoints().AppendEmpty() + case pmetric.MetricTypeSum: + neweDoubleDataPoint = to.Sum().DataPoints().AppendEmpty() + } + fromDataPoint.CopyTo(neweDoubleDataPoint) value := calculateValue(operand1, operand2, operation, logger, to.Name()) neweDoubleDataPoint.SetDoubleValue(value) From f1e5a12a65592a32a2c4f7da0cc13e24eb7a620f Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Fri, 27 Sep 2024 14:31:52 -0700 Subject: [PATCH 8/8] Update processor/metricsgenerationprocessor/go.mod --- processor/metricsgenerationprocessor/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/metricsgenerationprocessor/go.mod b/processor/metricsgenerationprocessor/go.mod index 8c32c4326333..d1c2e84f8d5f 100644 --- a/processor/metricsgenerationprocessor/go.mod +++ b/processor/metricsgenerationprocessor/go.mod @@ -4,7 +4,7 @@ go 1.22.0 require ( github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.110.0 - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.0.0-00010101000000-000000000000 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.110.0 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.110.0 go.opentelemetry.io/collector/confmap v1.16.0