From 15a39bcd72feab623089a5330fc8651c79b4b26b Mon Sep 17 00:00:00 2001 From: Mrod1598 Date: Tue, 14 Jun 2022 15:31:55 -0400 Subject: [PATCH 1/7] Add Summary value extraction functions --- processor/transformprocessor/README.md | 6 + .../internal/metrics/functions.go | 86 ++++++++++++- .../internal/metrics/functions_test.go | 120 ++++++++++++++++++ .../internal/metrics/metrics.go | 5 + .../internal/metrics/processor.go | 1 + 5 files changed, 216 insertions(+), 2 deletions(-) diff --git a/processor/transformprocessor/README.md b/processor/transformprocessor/README.md index 9be2f27eee96..6465abfc34b1 100644 --- a/processor/transformprocessor/README.md +++ b/processor/transformprocessor/README.md @@ -41,6 +41,12 @@ Metric only functions: - `convert_sum_to_gauge()` - Converts incoming metrics of type "Sum" to type "Gauge", retaining the metric's datapoints. Noop for metrics that are not of type "Sum". **NOTE:** This function may cause a metric to break semantics for [Gauge metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#gauge). Use at your own risk. +- `convert_summary_count_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Count" Value. +**NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. + +- `convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Sum" Value. +**NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. + - `convert_gauge_to_sum(aggregation_temporality, is_monotonic)` - `aggregation_temporality` specifies the resultant metric's aggregation temporality. `aggregation_temporality` may be `"cumulative"` or `"delta"`. `is_monotonic` specifies the resultant metric's monotonicity. `is_monotonic` is a boolean. Converts incoming metrics of type "Gauge" to type "Sum", retaining the metric's datapoints and setting its aggregation temporality and monotonicity accordingly. Noop for metrics that are not of type "Gauge". **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. diff --git a/processor/transformprocessor/internal/metrics/functions.go b/processor/transformprocessor/internal/metrics/functions.go index 10c10b86252c..da8a6e003a10 100644 --- a/processor/transformprocessor/internal/metrics/functions.go +++ b/processor/transformprocessor/internal/metrics/functions.go @@ -24,8 +24,10 @@ import ( // registry is a map of names to functions for metrics pipelines var registry = map[string]interface{}{ - "convert_sum_to_gauge": convertSumToGauge, - "convert_gauge_to_sum": convertGaugeToSum, + "convert_sum_to_gauge": convertSumToGauge, + "convert_gauge_to_sum": convertGaugeToSum, + "convert_summary_sum_val_to_sum": convertSummarySumValToSum, + "convert_summary_count_val_to_sum": convertSummaryCountValToSum, } func init() { @@ -95,3 +97,83 @@ func convertGaugeToSum(stringAggTemp string, monotonic bool) (common.ExprFunc, e return nil }, nil } + +func convertSummarySumValToSum(stringAggTemp string, monotonic bool) (common.ExprFunc, error) { + var aggTemp pmetric.MetricAggregationTemporality + switch stringAggTemp { + case "delta": + aggTemp = pmetric.MetricAggregationTemporalityDelta + case "cumulative": + aggTemp = pmetric.MetricAggregationTemporalityCumulative + default: + return nil, fmt.Errorf("unknown aggregation temporality: %s", stringAggTemp) + } + return func(ctx common.TransformContext) interface{} { + mtc, ok := ctx.(metricTransformContext) + if !ok { + return nil + } + + metric := mtc.GetMetric() + if metric.DataType() != pmetric.MetricDataTypeSummary { + return nil + } + + sumMetric := mtc.GetMetrics().AppendEmpty() + sumMetric.SetDescription(metric.Description()) + sumMetric.SetName(metric.Name() + "_sum") + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumMetric.Sum().SetAggregationTemporality(aggTemp) + sumMetric.Sum().SetIsMonotonic(monotonic) + + sumDps := sumMetric.Sum().DataPoints() + dps := metric.Summary().DataPoints() + for i := 0; i < dps.Len(); i++ { + dp := dps.At(i) + sumDp := sumDps.AppendEmpty() + dp.Attributes().CopyTo(sumDp.Attributes()) + sumDp.SetDoubleVal(dp.Sum()) + } + return nil + }, nil +} + +func convertSummaryCountValToSum(stringAggTemp string, monotonic bool) (common.ExprFunc, error) { + var aggTemp pmetric.MetricAggregationTemporality + switch stringAggTemp { + case "delta": + aggTemp = pmetric.MetricAggregationTemporalityDelta + case "cumulative": + aggTemp = pmetric.MetricAggregationTemporalityCumulative + default: + return nil, fmt.Errorf("unknown aggregation temporality: %s", stringAggTemp) + } + return func(ctx common.TransformContext) interface{} { + mtc, ok := ctx.(metricTransformContext) + if !ok { + return nil + } + + metric := mtc.GetMetric() + if metric.DataType() != pmetric.MetricDataTypeSummary { + return nil + } + + sumMetric := mtc.GetMetrics().AppendEmpty() + sumMetric.SetDescription(metric.Description()) + sumMetric.SetName(metric.Name() + "_count") + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumMetric.Sum().SetAggregationTemporality(aggTemp) + sumMetric.Sum().SetIsMonotonic(monotonic) + + sumDps := sumMetric.Sum().DataPoints() + dps := metric.Summary().DataPoints() + for i := 0; i < dps.Len(); i++ { + dp := dps.At(i) + sumDp := sumDps.AppendEmpty() + dp.Attributes().CopyTo(sumDp.Attributes()) + sumDp.SetIntVal(int64(dp.Count())) + } + return nil + }, nil +} diff --git a/processor/transformprocessor/internal/metrics/functions_test.go b/processor/transformprocessor/internal/metrics/functions_test.go index 05b41203decb..f1df42391f57 100644 --- a/processor/transformprocessor/internal/metrics/functions_test.go +++ b/processor/transformprocessor/internal/metrics/functions_test.go @@ -1868,3 +1868,123 @@ func Test_newFunctionCall_Metric_Gauge(t *testing.T) { }) } } + +func getTestSummaryMetric() pmetric.Metric { + metricInput := pmetric.NewMetric() + metricInput.SetDataType(pmetric.MetricDataTypeSummary) + metricInput.SetName("summary_metric") + input := metricInput.Summary().DataPoints().AppendEmpty() + input.SetCount(100) + input.SetSum(12.34) + + qVal1 := input.QuantileValues().AppendEmpty() + qVal1.SetValue(1) + qVal1.SetQuantile(.99) + + qVal2 := input.QuantileValues().AppendEmpty() + qVal2.SetValue(2) + qVal2.SetQuantile(.95) + + qVal3 := input.QuantileValues().AppendEmpty() + qVal3.SetValue(3) + qVal3.SetQuantile(.50) + + attrs := getTestAttributes() + attrs.CopyTo(input.Attributes()) + return metricInput +} + +func getTestAttributes() pcommon.Map { + attrs := pcommon.NewMap() + attrs.InsertString("test", "hello world") + attrs.InsertInt("test2", 3) + attrs.InsertBool("test3", true) + return attrs +} + +func TestConvertSummaryTransforms(t *testing.T) { + tests := []struct { + name string + inv common.Invocation + want func(pmetric.MetricSlice) + }{ + { + name: "convert_summary_count_val_to_sum", + inv: common.Invocation{ + Function: "convert_summary_count_val_to_sum", + Arguments: []common.Value{ + { + String: testhelper.Strp("delta"), + }, + { + Bool: (*common.Boolean)(testhelper.Boolp(false)), + }, + }, + }, + want: func(metrics pmetric.MetricSlice) { + summaryMetric := getTestSummaryMetric() + summaryMetric.CopyTo(metrics.AppendEmpty()) + sumMetric := metrics.AppendEmpty() + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) + sumMetric.Sum().SetIsMonotonic(false) + + sumMetric.SetName("summary_metric_count") + dp := sumMetric.Sum().DataPoints().AppendEmpty() + dp.SetIntVal(100) + + attrs := getTestAttributes() + attrs.CopyTo(dp.Attributes()) + }, + }, + { + name: "convert_summary_sum_val_to_sum", + inv: common.Invocation{ + Function: "convert_summary_sum_val_to_sum", + Arguments: []common.Value{ + { + String: testhelper.Strp("delta"), + }, + { + Bool: (*common.Boolean)(testhelper.Boolp(false)), + }, + }, + }, + want: func(metrics pmetric.MetricSlice) { + summaryMetric := getTestSummaryMetric() + summaryMetric.CopyTo(metrics.AppendEmpty()) + sumMetric := metrics.AppendEmpty() + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) + sumMetric.Sum().SetIsMonotonic(false) + + sumMetric.SetName("summary_metric_sum") + dp := sumMetric.Sum().DataPoints().AppendEmpty() + dp.SetDoubleVal(12.34) + + attrs := getTestAttributes() + attrs.CopyTo(dp.Attributes()) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actualMetrics := pmetric.NewMetricSlice() + summaryMetric := getTestSummaryMetric() + summaryMetric.CopyTo(actualMetrics.AppendEmpty()) + + evaluate, err := common.NewFunctionCall(tt.inv, DefaultFunctions(), ParsePath) + assert.NoError(t, err) + evaluate(metricTransformContext{ + il: pcommon.NewInstrumentationScope(), + resource: pcommon.NewResource(), + metric: summaryMetric, + metrics: actualMetrics, + }) + + expected := pmetric.NewMetricSlice() + tt.want(expected) + assert.Equal(t, expected, actualMetrics) + }) + } +} diff --git a/processor/transformprocessor/internal/metrics/metrics.go b/processor/transformprocessor/internal/metrics/metrics.go index b1df10291bdc..35c11599b59b 100644 --- a/processor/transformprocessor/internal/metrics/metrics.go +++ b/processor/transformprocessor/internal/metrics/metrics.go @@ -28,6 +28,7 @@ import ( type metricTransformContext struct { dataPoint interface{} metric pmetric.Metric + metrics pmetric.MetricSlice il pcommon.InstrumentationScope resource pcommon.Resource } @@ -48,6 +49,10 @@ func (ctx metricTransformContext) GetMetric() pmetric.Metric { return ctx.metric } +func (ctx metricTransformContext) GetMetrics() pmetric.MetricSlice { + return ctx.metrics +} + // pathGetSetter is a getSetter which has been resolved using a path expression provided by a user. type pathGetSetter struct { getter common.ExprFunc diff --git a/processor/transformprocessor/internal/metrics/processor.go b/processor/transformprocessor/internal/metrics/processor.go index 7c9a754732a2..a70546bbdc46 100644 --- a/processor/transformprocessor/internal/metrics/processor.go +++ b/processor/transformprocessor/internal/metrics/processor.go @@ -49,6 +49,7 @@ func (p *Processor) ProcessMetrics(_ context.Context, td pmetric.Metrics) (pmetr smetrics := rmetrics.ScopeMetrics().At(j) ctx.il = smetrics.Scope() metrics := smetrics.Metrics() + ctx.metrics = metrics for k := 0; k < metrics.Len(); k++ { ctx.metric = metrics.At(k) switch ctx.metric.DataType() { From d0514696835d048e85487aa86b8611385cee5201 Mon Sep 17 00:00:00 2001 From: Mrod1598 Date: Wed, 15 Jun 2022 10:05:46 -0400 Subject: [PATCH 2/7] Sepearate into seperate func files --- CHANGELOG.md | 2 +- processor/transformprocessor/README.md | 6 +- ... func_convert_summary_count_val_to_sum.go} | 54 ++++-------- ..._convert_summary_count_val_to_sum_test.go} | 45 ++++------ .../func_convert_summary_sum_val_to_sum.go | 62 ++++++++++++++ ...unc_convert_summary_sum_val_to_sum_test.go | 83 +++++++++++++++++++ 6 files changed, 178 insertions(+), 74 deletions(-) rename processor/transformprocessor/internal/metrics/{func_summary_transforms.go => func_convert_summary_count_val_to_sum.go} (55%) rename processor/transformprocessor/internal/metrics/{func_summary_transforms_test.go => func_convert_summary_count_val_to_sum_test.go} (75%) create mode 100644 processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go create mode 100644 processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 298d2decb9cd..7129021073e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,6 @@ ## 🛑 Breaking changes 🛑 - `transformprocessor`: `metric.is_monotonic` is now accessed via a bool literal instead of a string. (#10473) - - `vcenterreceiver`: Changed the attribute `effective` on `vcenter.cluster.host.count` as it will now be reported as a bool rather than a string (#10914) ### 🚩 Deprecations 🚩 @@ -22,6 +21,7 @@ - `cmd/mdatagen`: Allow attribute values of any types (#9245) - `transformprocessor`: Add byte slice literal to the grammar. Add new SpanID and TraceID functions that take a byte slice and return a Span/Trace ID. (#10487) +- `transformprocessor`: Add Summary transform functions. (#11041) - `elasticsearchreceiver`: Add integration test for elasticsearch receiver (#10165) - `datadogexporter`: Some config validation and unmarshaling steps are now done on `Validate` and `Unmarshal` instead of `Sanitize` (#8829) - `examples`: Add an example for scraping Couchbase metrics (#10894) diff --git a/processor/transformprocessor/README.md b/processor/transformprocessor/README.md index d8795da7f410..6842d56cb0a9 100644 --- a/processor/transformprocessor/README.md +++ b/processor/transformprocessor/README.md @@ -45,10 +45,10 @@ Metric only functions: - `convert_sum_to_gauge()` - Converts incoming metrics of type "Sum" to type "Gauge", retaining the metric's datapoints. Noop for metrics that are not of type "Sum". **NOTE:** This function may cause a metric to break semantics for [Gauge metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#gauge). Use at your own risk. -- `convert_summary_count_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Count" Value. -**NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. +- `convert_summary_count_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Count" Value. Noop for metrics that are not of type "Summary". +**NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. -- `convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Sum" Value. +- `convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Sum" Value. Noop for metrics that are not of type "Summary". **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. - `convert_gauge_to_sum(aggregation_temporality, is_monotonic)` - `aggregation_temporality` specifies the resultant metric's aggregation temporality. `aggregation_temporality` may be `"cumulative"` or `"delta"`. `is_monotonic` specifies the resultant metric's monotonicity. `is_monotonic` is a boolean. Converts incoming metrics of type "Gauge" to type "Sum", retaining the metric's datapoints and setting its aggregation temporality and monotonicity accordingly. Noop for metrics that are not of type "Gauge". diff --git a/processor/transformprocessor/internal/metrics/func_summary_transforms.go b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go similarity index 55% rename from processor/transformprocessor/internal/metrics/func_summary_transforms.go rename to processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go index 92936e60b09b..bda4ba72f4bd 100644 --- a/processor/transformprocessor/internal/metrics/func_summary_transforms.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go @@ -1,3 +1,17 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/metrics" import ( @@ -7,46 +21,6 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" ) -func convertSummarySumValToSum(stringAggTemp string, monotonic bool) (common.ExprFunc, error) { - var aggTemp pmetric.MetricAggregationTemporality - switch stringAggTemp { - case "delta": - aggTemp = pmetric.MetricAggregationTemporalityDelta - case "cumulative": - aggTemp = pmetric.MetricAggregationTemporalityCumulative - default: - return nil, fmt.Errorf("unknown aggregation temporality: %s", stringAggTemp) - } - return func(ctx common.TransformContext) interface{} { - mtc, ok := ctx.(metricTransformContext) - if !ok { - return nil - } - - metric := mtc.GetMetric() - if metric.DataType() != pmetric.MetricDataTypeSummary { - return nil - } - - sumMetric := mtc.GetMetrics().AppendEmpty() - sumMetric.SetDescription(metric.Description()) - sumMetric.SetName(metric.Name() + "_sum") - sumMetric.SetDataType(pmetric.MetricDataTypeSum) - sumMetric.Sum().SetAggregationTemporality(aggTemp) - sumMetric.Sum().SetIsMonotonic(monotonic) - - sumDps := sumMetric.Sum().DataPoints() - dps := metric.Summary().DataPoints() - for i := 0; i < dps.Len(); i++ { - dp := dps.At(i) - sumDp := sumDps.AppendEmpty() - dp.Attributes().CopyTo(sumDp.Attributes()) - sumDp.SetDoubleVal(dp.Sum()) - } - return nil - }, nil -} - func convertSummaryCountValToSum(stringAggTemp string, monotonic bool) (common.ExprFunc, error) { var aggTemp pmetric.MetricAggregationTemporality switch stringAggTemp { diff --git a/processor/transformprocessor/internal/metrics/func_summary_transforms_test.go b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go similarity index 75% rename from processor/transformprocessor/internal/metrics/func_summary_transforms_test.go rename to processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go index 983d5053309b..9c383b8e2d61 100644 --- a/processor/transformprocessor/internal/metrics/func_summary_transforms_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go @@ -1,3 +1,17 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package metrics import ( @@ -43,41 +57,12 @@ func getTestAttributes() pcommon.Map { return attrs } -func TestConvertSummaryTransforms(t *testing.T) { +func TestConvertSummarySumValToSum(t *testing.T) { tests := []struct { name string inv common.Invocation want func(pmetric.MetricSlice) }{ - { - name: "convert_summary_count_val_to_sum", - inv: common.Invocation{ - Function: "convert_summary_count_val_to_sum", - Arguments: []common.Value{ - { - String: testhelper.Strp("delta"), - }, - { - Bool: (*common.Boolean)(testhelper.Boolp(false)), - }, - }, - }, - want: func(metrics pmetric.MetricSlice) { - summaryMetric := getTestSummaryMetric() - summaryMetric.CopyTo(metrics.AppendEmpty()) - sumMetric := metrics.AppendEmpty() - sumMetric.SetDataType(pmetric.MetricDataTypeSum) - sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) - sumMetric.Sum().SetIsMonotonic(false) - - sumMetric.SetName("summary_metric_count") - dp := sumMetric.Sum().DataPoints().AppendEmpty() - dp.SetIntVal(100) - - attrs := getTestAttributes() - attrs.CopyTo(dp.Attributes()) - }, - }, { name: "convert_summary_sum_val_to_sum", inv: common.Invocation{ diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go new file mode 100644 index 000000000000..86d8e194012b --- /dev/null +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go @@ -0,0 +1,62 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/metrics" + +import ( + "fmt" + + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" + "go.opentelemetry.io/collector/pdata/pmetric" +) + +func convertSummarySumValToSum(stringAggTemp string, monotonic bool) (common.ExprFunc, error) { + var aggTemp pmetric.MetricAggregationTemporality + switch stringAggTemp { + case "delta": + aggTemp = pmetric.MetricAggregationTemporalityDelta + case "cumulative": + aggTemp = pmetric.MetricAggregationTemporalityCumulative + default: + return nil, fmt.Errorf("unknown aggregation temporality: %s", stringAggTemp) + } + return func(ctx common.TransformContext) interface{} { + mtc, ok := ctx.(metricTransformContext) + if !ok { + return nil + } + + metric := mtc.GetMetric() + if metric.DataType() != pmetric.MetricDataTypeSummary { + return nil + } + + sumMetric := mtc.GetMetrics().AppendEmpty() + sumMetric.SetDescription(metric.Description()) + sumMetric.SetName(metric.Name() + "_sum") + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumMetric.Sum().SetAggregationTemporality(aggTemp) + sumMetric.Sum().SetIsMonotonic(monotonic) + + sumDps := sumMetric.Sum().DataPoints() + dps := metric.Summary().DataPoints() + for i := 0; i < dps.Len(); i++ { + dp := dps.At(i) + sumDp := sumDps.AppendEmpty() + dp.Attributes().CopyTo(sumDp.Attributes()) + sumDp.SetDoubleVal(dp.Sum()) + } + return nil + }, nil +} diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go new file mode 100644 index 000000000000..8505cfba654d --- /dev/null +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go @@ -0,0 +1,83 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package metrics + +import ( + "testing" + + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common/testhelper" + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/pmetric" +) + +func TestConvertSummaryCountValToSum(t *testing.T) { + tests := []struct { + name string + inv common.Invocation + want func(pmetric.MetricSlice) + }{ + { + name: "convert_summary_count_val_to_sum", + inv: common.Invocation{ + Function: "convert_summary_count_val_to_sum", + Arguments: []common.Value{ + { + String: testhelper.Strp("delta"), + }, + { + Bool: (*common.Boolean)(testhelper.Boolp(false)), + }, + }, + }, + want: func(metrics pmetric.MetricSlice) { + summaryMetric := getTestSummaryMetric() + summaryMetric.CopyTo(metrics.AppendEmpty()) + sumMetric := metrics.AppendEmpty() + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) + sumMetric.Sum().SetIsMonotonic(false) + + sumMetric.SetName("summary_metric_count") + dp := sumMetric.Sum().DataPoints().AppendEmpty() + dp.SetIntVal(100) + + attrs := getTestAttributes() + attrs.CopyTo(dp.Attributes()) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actualMetrics := pmetric.NewMetricSlice() + summaryMetric := getTestSummaryMetric() + summaryMetric.CopyTo(actualMetrics.AppendEmpty()) + + evaluate, err := common.NewFunctionCall(tt.inv, DefaultFunctions(), ParsePath) + assert.NoError(t, err) + evaluate(metricTransformContext{ + il: pcommon.NewInstrumentationScope(), + resource: pcommon.NewResource(), + metric: summaryMetric, + metrics: actualMetrics, + }) + + expected := pmetric.NewMetricSlice() + tt.want(expected) + assert.Equal(t, expected, actualMetrics) + }) + } +} From 287a42f317c19b171efc9dddf23c965164532c4e Mon Sep 17 00:00:00 2001 From: Mrod1598 Date: Thu, 16 Jun 2022 11:24:58 -0400 Subject: [PATCH 3/7] Add clarification to readme --- processor/transformprocessor/README.md | 4 +- .../func_convert_summary_count_val_to_sum.go | 2 + ...c_convert_summary_count_val_to_sum_test.go | 162 +++++++++++++++--- .../func_convert_summary_sum_val_to_sum.go | 2 + ...unc_convert_summary_sum_val_to_sum_test.go | 122 ++++++++++--- 5 files changed, 243 insertions(+), 49 deletions(-) diff --git a/processor/transformprocessor/README.md b/processor/transformprocessor/README.md index 8d2236726ae5..611579e40f93 100644 --- a/processor/transformprocessor/README.md +++ b/processor/transformprocessor/README.md @@ -45,10 +45,10 @@ Metric only functions: - `convert_sum_to_gauge()` - Converts incoming metrics of type "Sum" to type "Gauge", retaining the metric's datapoints. Noop for metrics that are not of type "Sum". **NOTE:** This function may cause a metric to break semantics for [Gauge metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#gauge). Use at your own risk. -- `convert_summary_count_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Count" Value. Noop for metrics that are not of type "Summary". +- `convert_summary_count_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Count" Value. Noop for metrics that are not of type "Summary". The name for the new metric with be `_count`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. -- `convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Sum" Value. Noop for metrics that are not of type "Summary". +- `convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Sum" Value. Noop for metrics that are not of type "Summary". The name for the new metric with be `_sum`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. - `convert_gauge_to_sum(aggregation_temporality, is_monotonic)` - `aggregation_temporality` specifies the resultant metric's aggregation temporality. `aggregation_temporality` may be `"cumulative"` or `"delta"`. `is_monotonic` specifies the resultant metric's monotonicity. `is_monotonic` is a boolean. Converts incoming metrics of type "Gauge" to type "Sum", retaining the metric's datapoints and setting its aggregation temporality and monotonicity accordingly. Noop for metrics that are not of type "Gauge". diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go index bda4ba72f4bd..53e85819b036 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go @@ -56,6 +56,8 @@ func convertSummaryCountValToSum(stringAggTemp string, monotonic bool) (common.E sumDp := sumDps.AppendEmpty() dp.Attributes().CopyTo(sumDp.Attributes()) sumDp.SetIntVal(int64(dp.Count())) + sumDp.SetStartTimestamp(dp.StartTimestamp()) + sumDp.SetTimestamp(dp.Timestamp()) } return nil }, nil diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go index 9c383b8e2d61..0bd3e8e21b1c 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go @@ -49,6 +49,18 @@ func getTestSummaryMetric() pmetric.Metric { return metricInput } +func getTestGaugeMetric() pmetric.Metric { + metricInput := pmetric.NewMetric() + metricInput.SetDataType(pmetric.MetricDataTypeGauge) + metricInput.SetName("gauge_metric") + input := metricInput.Gauge().DataPoints().AppendEmpty() + input.SetIntVal(12) + + attrs := getTestAttributes() + attrs.CopyTo(input.Attributes()) + return metricInput +} + func getTestAttributes() pcommon.Map { attrs := pcommon.NewMap() attrs.InsertString("test", "hello world") @@ -57,14 +69,40 @@ func getTestAttributes() pcommon.Map { return attrs } -func TestConvertSummarySumValToSum(t *testing.T) { - tests := []struct { - name string - inv common.Invocation - want func(pmetric.MetricSlice) - }{ +func summaryTest(tests []summaryTestCase, t *testing.T) { + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actualMetrics := pmetric.NewMetricSlice() + tt.input.CopyTo(actualMetrics.AppendEmpty()) + + evaluate, err := common.NewFunctionCall(tt.inv, DefaultFunctions(), ParsePath) + assert.NoError(t, err) + evaluate(metricTransformContext{ + il: pcommon.NewInstrumentationScope(), + resource: pcommon.NewResource(), + metric: tt.input, + metrics: actualMetrics, + }) + + expected := pmetric.NewMetricSlice() + tt.want(expected) + assert.Equal(t, expected, actualMetrics) + }) + } +} + +type summaryTestCase struct { + name string + input pmetric.Metric + inv common.Invocation + want func(pmetric.MetricSlice) +} + +func Test_ConvertSummarySumValToSum(t *testing.T) { + tests := []summaryTestCase{ { - name: "convert_summary_sum_val_to_sum", + name: "convert_summary_sum_val_to_sum", + input: getTestSummaryMetric(), inv: common.Invocation{ Function: "convert_summary_sum_val_to_sum", Arguments: []common.Value{ @@ -92,25 +130,103 @@ func TestConvertSummarySumValToSum(t *testing.T) { attrs.CopyTo(dp.Attributes()) }, }, + { + name: "convert_summary_sum_val_to_sum (monotonic)", + input: getTestSummaryMetric(), + inv: common.Invocation{ + Function: "convert_summary_sum_val_to_sum", + Arguments: []common.Value{ + { + String: testhelper.Strp("delta"), + }, + { + Bool: (*common.Boolean)(testhelper.Boolp(true)), + }, + }, + }, + want: func(metrics pmetric.MetricSlice) { + summaryMetric := getTestSummaryMetric() + summaryMetric.CopyTo(metrics.AppendEmpty()) + sumMetric := metrics.AppendEmpty() + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) + sumMetric.Sum().SetIsMonotonic(true) + + sumMetric.SetName("summary_metric_sum") + dp := sumMetric.Sum().DataPoints().AppendEmpty() + dp.SetDoubleVal(12.34) + + attrs := getTestAttributes() + attrs.CopyTo(dp.Attributes()) + }, + }, + { + name: "convert_summary_sum_val_to_sum (cumulative)", + input: getTestSummaryMetric(), + inv: common.Invocation{ + Function: "convert_summary_sum_val_to_sum", + Arguments: []common.Value{ + { + String: testhelper.Strp("cumulative"), + }, + { + Bool: (*common.Boolean)(testhelper.Boolp(false)), + }, + }, + }, + want: func(metrics pmetric.MetricSlice) { + summaryMetric := getTestSummaryMetric() + summaryMetric.CopyTo(metrics.AppendEmpty()) + sumMetric := metrics.AppendEmpty() + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + sumMetric.Sum().SetIsMonotonic(false) + + sumMetric.SetName("summary_metric_sum") + dp := sumMetric.Sum().DataPoints().AppendEmpty() + dp.SetDoubleVal(12.34) + + attrs := getTestAttributes() + attrs.CopyTo(dp.Attributes()) + }, + }, + { + name: "convert_summary_sum_val_to_sum (no op)", + input: getTestGaugeMetric(), + inv: common.Invocation{ + Function: "convert_summary_sum_val_to_sum", + Arguments: []common.Value{ + { + String: testhelper.Strp("delta"), + }, + { + Bool: (*common.Boolean)(testhelper.Boolp(false)), + }, + }, + }, + want: func(metrics pmetric.MetricSlice) { + gaugeMetric := getTestGaugeMetric() + gaugeMetric.CopyTo(metrics.AppendEmpty()) + }, + }, + } + summaryTest(tests, t) +} + +func Test_ConvertSummarySumValToSum_validation(t *testing.T) { + tests := []struct { + name string + stringAggTemp string + }{ + { + name: "invalid aggregation temporality", + stringAggTemp: "not a real aggregation temporality", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - actualMetrics := pmetric.NewMetricSlice() - summaryMetric := getTestSummaryMetric() - summaryMetric.CopyTo(actualMetrics.AppendEmpty()) - - evaluate, err := common.NewFunctionCall(tt.inv, DefaultFunctions(), ParsePath) - assert.NoError(t, err) - evaluate(metricTransformContext{ - il: pcommon.NewInstrumentationScope(), - resource: pcommon.NewResource(), - metric: summaryMetric, - metrics: actualMetrics, - }) - - expected := pmetric.NewMetricSlice() - tt.want(expected) - assert.Equal(t, expected, actualMetrics) + _, err := convertSummarySumValToSum(tt.stringAggTemp, true) + assert.Error(t, err, "unknown aggregation temporality: not a real aggregation temporality") }) } } diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go index 86d8e194012b..72a09dc54e83 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go @@ -56,6 +56,8 @@ func convertSummarySumValToSum(stringAggTemp string, monotonic bool) (common.Exp sumDp := sumDps.AppendEmpty() dp.Attributes().CopyTo(sumDp.Attributes()) sumDp.SetDoubleVal(dp.Sum()) + sumDp.SetStartTimestamp(dp.StartTimestamp()) + sumDp.SetTimestamp(dp.Timestamp()) } return nil }, nil diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go index 8505cfba654d..d8c1f63e76e0 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go @@ -20,18 +20,14 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common/testhelper" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" ) -func TestConvertSummaryCountValToSum(t *testing.T) { - tests := []struct { - name string - inv common.Invocation - want func(pmetric.MetricSlice) - }{ +func Test_ConvertSummaryCountValToSum(t *testing.T) { + tests := []summaryTestCase{ { - name: "convert_summary_count_val_to_sum", + name: "convert_summary_count_val_to_sum", + input: getTestSummaryMetric(), inv: common.Invocation{ Function: "convert_summary_count_val_to_sum", Arguments: []common.Value{ @@ -59,25 +55,103 @@ func TestConvertSummaryCountValToSum(t *testing.T) { attrs.CopyTo(dp.Attributes()) }, }, + { + name: "convert_summary_count_val_to_sum (monotonic)", + input: getTestSummaryMetric(), + inv: common.Invocation{ + Function: "convert_summary_count_val_to_sum", + Arguments: []common.Value{ + { + String: testhelper.Strp("delta"), + }, + { + Bool: (*common.Boolean)(testhelper.Boolp(true)), + }, + }, + }, + want: func(metrics pmetric.MetricSlice) { + summaryMetric := getTestSummaryMetric() + summaryMetric.CopyTo(metrics.AppendEmpty()) + sumMetric := metrics.AppendEmpty() + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) + sumMetric.Sum().SetIsMonotonic(true) + + sumMetric.SetName("summary_metric_count") + dp := sumMetric.Sum().DataPoints().AppendEmpty() + dp.SetIntVal(100) + + attrs := getTestAttributes() + attrs.CopyTo(dp.Attributes()) + }, + }, + { + name: "convert_summary_count_val_to_sum", + input: getTestSummaryMetric(), + inv: common.Invocation{ + Function: "convert_summary_count_val_to_sum", + Arguments: []common.Value{ + { + String: testhelper.Strp("cumulative"), + }, + { + Bool: (*common.Boolean)(testhelper.Boolp(false)), + }, + }, + }, + want: func(metrics pmetric.MetricSlice) { + summaryMetric := getTestSummaryMetric() + summaryMetric.CopyTo(metrics.AppendEmpty()) + sumMetric := metrics.AppendEmpty() + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + sumMetric.Sum().SetIsMonotonic(false) + + sumMetric.SetName("summary_metric_count") + dp := sumMetric.Sum().DataPoints().AppendEmpty() + dp.SetIntVal(100) + + attrs := getTestAttributes() + attrs.CopyTo(dp.Attributes()) + }, + }, + { + name: "convert_summary_count_val_to_sum (no op)", + input: getTestGaugeMetric(), + inv: common.Invocation{ + Function: "convert_summary_count_val_to_sum", + Arguments: []common.Value{ + { + String: testhelper.Strp("delta"), + }, + { + Bool: (*common.Boolean)(testhelper.Boolp(false)), + }, + }, + }, + want: func(metrics pmetric.MetricSlice) { + gaugeMetric := getTestGaugeMetric() + gaugeMetric.CopyTo(metrics.AppendEmpty()) + }, + }, + } + summaryTest(tests, t) +} + +func Test_ConvertSummaryCountValToSum_validation(t *testing.T) { + tests := []struct { + name string + stringAggTemp string + }{ + { + name: "invalid aggregation temporality", + stringAggTemp: "not a real aggregation temporality", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - actualMetrics := pmetric.NewMetricSlice() - summaryMetric := getTestSummaryMetric() - summaryMetric.CopyTo(actualMetrics.AppendEmpty()) - - evaluate, err := common.NewFunctionCall(tt.inv, DefaultFunctions(), ParsePath) - assert.NoError(t, err) - evaluate(metricTransformContext{ - il: pcommon.NewInstrumentationScope(), - resource: pcommon.NewResource(), - metric: summaryMetric, - metrics: actualMetrics, - }) - - expected := pmetric.NewMetricSlice() - tt.want(expected) - assert.Equal(t, expected, actualMetrics) + _, err := convertSummaryCountValToSum(tt.stringAggTemp, true) + assert.Error(t, err, "unknown aggregation temporality: not a real aggregation temporality") }) } } From 58a9e907ea05a6792de03480fe6b3546bc5ed969 Mon Sep 17 00:00:00 2001 From: Mrod1598 Date: Thu, 16 Jun 2022 17:09:04 -0400 Subject: [PATCH 4/7] Add more tests --- processor/transformprocessor/README.md | 5 +- .../func_convert_summary_count_val_to_sum.go | 1 + .../func_convert_summary_sum_val_to_sum.go | 1 + .../internal/metrics/functions_test.go | 2 + .../internal/metrics/processor_test.go | 140 ++++++++++++++++-- 5 files changed, 131 insertions(+), 18 deletions(-) diff --git a/processor/transformprocessor/README.md b/processor/transformprocessor/README.md index 611579e40f93..9ddca45788d8 100644 --- a/processor/transformprocessor/README.md +++ b/processor/transformprocessor/README.md @@ -48,10 +48,11 @@ Metric only functions: - `convert_summary_count_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Count" Value. Noop for metrics that are not of type "Summary". The name for the new metric with be `_count`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. -- `convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Sum" Value. Noop for metrics that are not of type "Summary". The name for the new metric with be `_sum`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. +- `convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Sum" Value. Noop for metrics that are not of type "Summary". The name for the new metric with be `_sum`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. Any functions executed after the new metric is created will apply to that metric as well. **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. -- `convert_gauge_to_sum(aggregation_temporality, is_monotonic)` - `aggregation_temporality` specifies the resultant metric's aggregation temporality. `aggregation_temporality` may be `"cumulative"` or `"delta"`. `is_monotonic` specifies the resultant metric's monotonicity. `is_monotonic` is a boolean. Converts incoming metrics of type "Gauge" to type "Sum", retaining the metric's datapoints and setting its aggregation temporality and monotonicity accordingly. Noop for metrics that are not of type "Gauge". + +- `convert_gauge_to_sum(aggregation_temporality, is_monotonic)` - `aggregation_temporality` specifies the resultant metric's aggregation temporality. `aggregation_temporality` may be `"cumulative"` or `"delta"`. `is_monotonic` specifies the resultant metric's monotonicity. `is_monotonic` is a boolean. Converts incoming metrics of type "Gauge" to type "Sum", retaining the metric's datapoints and setting its aggregation temporality and monotonicity accordingly. Noop for metrics that are not of type "Gauge". Any functions executed after the new metric is created will apply to that metric as well. **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#sums). Use at your own risk. Supported where operations: diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go index 53e85819b036..82a8230ebf64 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go @@ -45,6 +45,7 @@ func convertSummaryCountValToSum(stringAggTemp string, monotonic bool) (common.E sumMetric := mtc.GetMetrics().AppendEmpty() sumMetric.SetDescription(metric.Description()) sumMetric.SetName(metric.Name() + "_count") + sumMetric.SetUnit(metric.Unit()) sumMetric.SetDataType(pmetric.MetricDataTypeSum) sumMetric.Sum().SetAggregationTemporality(aggTemp) sumMetric.Sum().SetIsMonotonic(monotonic) diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go index 72a09dc54e83..a033a23cc3d4 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go @@ -45,6 +45,7 @@ func convertSummarySumValToSum(stringAggTemp string, monotonic bool) (common.Exp sumMetric := mtc.GetMetrics().AppendEmpty() sumMetric.SetDescription(metric.Description()) sumMetric.SetName(metric.Name() + "_sum") + sumMetric.SetUnit(metric.Unit()) sumMetric.SetDataType(pmetric.MetricDataTypeSum) sumMetric.Sum().SetAggregationTemporality(aggTemp) sumMetric.Sum().SetIsMonotonic(monotonic) diff --git a/processor/transformprocessor/internal/metrics/functions_test.go b/processor/transformprocessor/internal/metrics/functions_test.go index e3d107c55824..65bf08dea8dd 100644 --- a/processor/transformprocessor/internal/metrics/functions_test.go +++ b/processor/transformprocessor/internal/metrics/functions_test.go @@ -26,6 +26,8 @@ func Test_DefaultFunctions(t *testing.T) { expectedFunctions := common.DefaultFunctions() expectedFunctions["convert_sum_to_gauge"] = convertSumToGauge expectedFunctions["convert_gauge_to_sum"] = convertGaugeToSum + expectedFunctions["convert_summary_sum_val_to_sum"] = convertSummarySumValToSum + expectedFunctions["convert_summary_count_val_to_sum"] = convertSummaryCountValToSum actual := DefaultFunctions() diff --git a/processor/transformprocessor/internal/metrics/processor_test.go b/processor/transformprocessor/internal/metrics/processor_test.go index f06bd219a4d2..3f6ef9639ab4 100644 --- a/processor/transformprocessor/internal/metrics/processor_test.go +++ b/processor/transformprocessor/internal/metrics/processor_test.go @@ -28,22 +28,24 @@ import ( var ( StartTime = time.Date(2020, 2, 11, 20, 26, 12, 321, time.UTC) StartTimestamp = pcommon.NewTimestampFromTime(StartTime) + TestTime = time.Date(2021, 3, 12, 21, 27, 13, 322, time.UTC) + TestTimeStamp = pcommon.NewTimestampFromTime(StartTime) ) func TestProcess(t *testing.T) { tests := []struct { - query string + query []string want func(pmetric.Metrics) }{ { - query: `set(attributes["test"], "pass") where metric.name == "operationA"`, + query: []string{`set(attributes["test"], "pass") where metric.name == "operationA"`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().InsertString("test", "pass") td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).Attributes().InsertString("test", "pass") }, }, { - query: `set(attributes["test"], "pass") where resource.attributes["host.name"] == "myhost"`, + query: []string{`set(attributes["test"], "pass") where resource.attributes["host.name"] == "myhost"`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().InsertString("test", "pass") td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).Attributes().InsertString("test", "pass") @@ -51,10 +53,12 @@ func TestProcess(t *testing.T) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1).Histogram().DataPoints().At(1).Attributes().InsertString("test", "pass") td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(2).ExponentialHistogram().DataPoints().At(0).Attributes().InsertString("test", "pass") td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(2).ExponentialHistogram().DataPoints().At(1).Attributes().InsertString("test", "pass") + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(3).Summary().DataPoints().At(0).Attributes().InsertString("test", "pass") + }, }, { - query: `keep_keys(attributes, "attr2") where metric.name == "operationA"`, + query: []string{`keep_keys(attributes, "attr2") where metric.name == "operationA"`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().Clear() td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().InsertString("attr2", "test2") @@ -63,29 +67,31 @@ func TestProcess(t *testing.T) { }, }, { - query: `set(metric.description, "test") where attributes["attr1"] == "test1"`, + query: []string{`set(metric.description, "test") where attributes["attr1"] == "test1"`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).SetDescription("test") td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1).SetDescription("test") td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(2).SetDescription("test") + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(3).SetDescription("test") }, }, { - query: `set(metric.unit, "new unit")`, + query: []string{`set(metric.unit, "new unit")`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).SetUnit("new unit") td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1).SetUnit("new unit") td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(2).SetUnit("new unit") + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(3).SetUnit("new unit") }, }, { - query: `set(metric.description, "Sum") where metric.type == "Sum"`, + query: []string{`set(metric.description, "Sum") where metric.type == "Sum"`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).SetDescription("Sum") }, }, { - query: `set(metric.aggregation_temporality, 1) where metric.aggregation_temporality == 0`, + query: []string{`set(metric.aggregation_temporality, 1) where metric.aggregation_temporality == 0`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1).Histogram().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) @@ -93,48 +99,125 @@ func TestProcess(t *testing.T) { }, }, { - query: `set(metric.is_monotonic, true) where metric.is_monotonic == false`, + query: []string{`set(metric.is_monotonic, true) where metric.is_monotonic == false`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().SetIsMonotonic(true) }, }, { - query: `set(attributes["test"], "pass") where count == 1`, + query: []string{`set(attributes["test"], "pass") where count == 1`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1).Histogram().DataPoints().At(0).Attributes().InsertString("test", "pass") td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(2).ExponentialHistogram().DataPoints().At(0).Attributes().InsertString("test", "pass") }, }, { - query: `set(attributes["test"], "pass") where scale == 1`, + query: []string{`set(attributes["test"], "pass") where scale == 1`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(2).ExponentialHistogram().DataPoints().At(0).Attributes().InsertString("test", "pass") }, }, { - query: `set(attributes["test"], "pass") where zero_count == 1`, + query: []string{`set(attributes["test"], "pass") where zero_count == 1`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(2).ExponentialHistogram().DataPoints().At(0).Attributes().InsertString("test", "pass") }, }, { - query: `set(attributes["test"], "pass") where positive.offset == 1`, + query: []string{`set(attributes["test"], "pass") where positive.offset == 1`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(2).ExponentialHistogram().DataPoints().At(0).Attributes().InsertString("test", "pass") }, }, { - query: `set(attributes["test"], "pass") where negative.offset == 1`, + query: []string{`set(attributes["test"], "pass") where negative.offset == 1`}, want: func(td pmetric.Metrics) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(2).ExponentialHistogram().DataPoints().At(0).Attributes().InsertString("test", "pass") }, }, + { + query: []string{`convert_summary_count_val_to_sum("delta", true) where metric.name == "operationD"`}, + want: func(td pmetric.Metrics) { + sumMetric := td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().AppendEmpty() + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumDp := sumMetric.Sum().DataPoints().AppendEmpty() + + summaryMetric := pmetric.NewMetric() + fillMetricFour(summaryMetric) + summaryDp := summaryMetric.Summary().DataPoints().At(0) + + sumMetric.SetDescription(summaryMetric.Description()) + sumMetric.SetName(summaryMetric.Name() + "_count") + sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) + sumMetric.Sum().SetIsMonotonic(true) + sumMetric.SetUnit(summaryMetric.Unit()) + + summaryDp.Attributes().CopyTo(sumDp.Attributes()) + sumDp.SetIntVal(int64(summaryDp.Count())) + sumDp.SetStartTimestamp(StartTimestamp) + sumDp.SetTimestamp(TestTimeStamp) + }, + }, + { + query: []string{`convert_summary_sum_val_to_sum("delta", true) where metric.name == "operationD"`}, + want: func(td pmetric.Metrics) { + sumMetric := td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().AppendEmpty() + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumDp := sumMetric.Sum().DataPoints().AppendEmpty() + + summaryMetric := pmetric.NewMetric() + fillMetricFour(summaryMetric) + summaryDp := summaryMetric.Summary().DataPoints().At(0) + + sumMetric.SetDescription(summaryMetric.Description()) + sumMetric.SetName(summaryMetric.Name() + "_sum") + sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) + sumMetric.Sum().SetIsMonotonic(true) + sumMetric.SetUnit(summaryMetric.Unit()) + + summaryDp.Attributes().CopyTo(sumDp.Attributes()) + sumDp.SetDoubleVal(summaryDp.Sum()) + sumDp.SetStartTimestamp(StartTimestamp) + sumDp.SetTimestamp(TestTimeStamp) + }, + }, + { + query: []string{ + `convert_summary_sum_val_to_sum("delta", true) where metric.name == "operationD"`, + `set(metric.unit, "new unit")`, + }, + want: func(td pmetric.Metrics) { + sumMetric := td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().AppendEmpty() + sumMetric.SetDataType(pmetric.MetricDataTypeSum) + sumDp := sumMetric.Sum().DataPoints().AppendEmpty() + + summaryMetric := pmetric.NewMetric() + fillMetricFour(summaryMetric) + summaryDp := summaryMetric.Summary().DataPoints().At(0) + + sumMetric.SetDescription(summaryMetric.Description()) + sumMetric.SetName(summaryMetric.Name() + "_sum") + sumMetric.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) + sumMetric.Sum().SetIsMonotonic(true) + sumMetric.SetUnit("new unit") + + summaryDp.Attributes().CopyTo(sumDp.Attributes()) + sumDp.SetDoubleVal(summaryDp.Sum()) + sumDp.SetStartTimestamp(StartTimestamp) + sumDp.SetTimestamp(TestTimeStamp) + + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).SetUnit("new unit") + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1).SetUnit("new unit") + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(2).SetUnit("new unit") + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(3).SetUnit("new unit") + }, + }, } for _, tt := range tests { - t.Run(tt.query, func(t *testing.T) { + t.Run(tt.query[0], func(t *testing.T) { td := constructMetrics() - processor, err := NewProcessor([]string{tt.query}, DefaultFunctions(), component.ProcessorCreateSettings{}) + processor, err := NewProcessor(tt.query, DefaultFunctions(), component.ProcessorCreateSettings{}) assert.NoError(t, err) _, err = processor.ProcessMetrics(context.Background(), td) @@ -156,6 +239,7 @@ func constructMetrics() pmetric.Metrics { fillMetricOne(rm0ils0.Metrics().AppendEmpty()) fillMetricTwo(rm0ils0.Metrics().AppendEmpty()) fillMetricThree(rm0ils0.Metrics().AppendEmpty()) + fillMetricFour(rm0ils0.Metrics().AppendEmpty()) return td } @@ -221,3 +305,27 @@ func fillMetricThree(m pmetric.Metric) { dataPoint1.Attributes().InsertString("attr2", "test2") dataPoint1.Attributes().InsertString("attr3", "test3") } + +func fillMetricFour(m pmetric.Metric) { + m.SetName("operationD") + m.SetDescription("operationD description") + m.SetUnit("operationD unit") + m.SetDataType(pmetric.MetricDataTypeSummary) + + dataPoint0 := m.Summary().DataPoints().AppendEmpty() + dataPoint0.SetStartTimestamp(StartTimestamp) + dataPoint0.SetTimestamp(TestTimeStamp) + dataPoint0.Attributes().InsertString("attr1", "test1") + dataPoint0.Attributes().InsertString("attr2", "test2") + dataPoint0.Attributes().InsertString("attr3", "test3") + dataPoint0.SetCount(1234) + dataPoint0.SetSum(12.34) + + quantileDataPoint0 := dataPoint0.QuantileValues().AppendEmpty() + quantileDataPoint0.SetQuantile(.99) + quantileDataPoint0.SetValue(123) + + quantileDataPoint1 := dataPoint0.QuantileValues().AppendEmpty() + quantileDataPoint1.SetQuantile(.95) + quantileDataPoint1.SetValue(321) +} From 8560c4d4add6ee015049ca8bc9bce9320d0cf3f9 Mon Sep 17 00:00:00 2001 From: Mrod1598 Date: Fri, 17 Jun 2022 09:19:05 -0400 Subject: [PATCH 5/7] Update readme note --- processor/transformprocessor/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/transformprocessor/README.md b/processor/transformprocessor/README.md index 9ddca45788d8..16f9df0e2571 100644 --- a/processor/transformprocessor/README.md +++ b/processor/transformprocessor/README.md @@ -48,11 +48,11 @@ Metric only functions: - `convert_summary_count_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Count" Value. Noop for metrics that are not of type "Summary". The name for the new metric with be `_count`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. -- `convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Sum" Value. Noop for metrics that are not of type "Summary". The name for the new metric with be `_sum`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. Any functions executed after the new metric is created will apply to that metric as well. +- `convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Sum" Value. Noop for metrics that are not of type "Summary". The name for the new metric with be `_sum`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. The new metric that is created will be passed to all functions in the metrics queries list. Function conditions will apply. **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. -- `convert_gauge_to_sum(aggregation_temporality, is_monotonic)` - `aggregation_temporality` specifies the resultant metric's aggregation temporality. `aggregation_temporality` may be `"cumulative"` or `"delta"`. `is_monotonic` specifies the resultant metric's monotonicity. `is_monotonic` is a boolean. Converts incoming metrics of type "Gauge" to type "Sum", retaining the metric's datapoints and setting its aggregation temporality and monotonicity accordingly. Noop for metrics that are not of type "Gauge". Any functions executed after the new metric is created will apply to that metric as well. +- `convert_gauge_to_sum(aggregation_temporality, is_monotonic)` - `aggregation_temporality` specifies the resultant metric's aggregation temporality. `aggregation_temporality` may be `"cumulative"` or `"delta"`. `is_monotonic` specifies the resultant metric's monotonicity. `is_monotonic` is a boolean. Converts incoming metrics of type "Gauge" to type "Sum", retaining the metric's datapoints and setting its aggregation temporality and monotonicity accordingly. Noop for metrics that are not of type "Gauge". The new metric that is created will be passed to all functions in the metrics queries list. Function conditions will apply. **NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#sums). Use at your own risk. Supported where operations: From b575af749e9692ed0aed7317c816a1a825db2123 Mon Sep 17 00:00:00 2001 From: Mrod1598 Date: Fri, 17 Jun 2022 09:44:55 -0400 Subject: [PATCH 6/7] gofmt --- .../metrics/func_convert_summary_count_val_to_sum.go | 3 ++- .../metrics/func_convert_summary_count_val_to_sum_test.go | 5 +++-- .../internal/metrics/func_convert_summary_sum_val_to_sum.go | 3 ++- .../metrics/func_convert_summary_sum_val_to_sum_test.go | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go index 82a8230ebf64..f37b0a6fea08 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum.go @@ -17,8 +17,9 @@ package metrics // import "github.com/open-telemetry/opentelemetry-collector-con import ( "fmt" - "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" "go.opentelemetry.io/collector/pdata/pmetric" + + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" ) func convertSummaryCountValToSum(stringAggTemp string, monotonic bool) (common.ExprFunc, error) { diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go index 0bd3e8e21b1c..de5e13db11db 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go @@ -17,11 +17,12 @@ package metrics import ( "testing" - "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" - "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common/testhelper" "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" + + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common/testhelper" ) func getTestSummaryMetric() pmetric.Metric { diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go index a033a23cc3d4..b8e8f6dccd99 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum.go @@ -17,8 +17,9 @@ package metrics // import "github.com/open-telemetry/opentelemetry-collector-con import ( "fmt" - "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" "go.opentelemetry.io/collector/pdata/pmetric" + + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" ) func convertSummarySumValToSum(stringAggTemp string, monotonic bool) (common.ExprFunc, error) { diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go index d8c1f63e76e0..6941f3fd0016 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go @@ -17,10 +17,11 @@ package metrics import ( "testing" - "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" - "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common/testhelper" "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/pdata/pmetric" + + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common/testhelper" ) func Test_ConvertSummaryCountValToSum(t *testing.T) { From ef382cea28206176727d8e93fdb712e287c05a4b Mon Sep 17 00:00:00 2001 From: Mrod1598 Date: Mon, 20 Jun 2022 10:14:51 -0400 Subject: [PATCH 7/7] Fix links --- processor/transformprocessor/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/transformprocessor/README.md b/processor/transformprocessor/README.md index a120b9fcbcbe..53b16391f1c4 100644 --- a/processor/transformprocessor/README.md +++ b/processor/transformprocessor/README.md @@ -46,10 +46,10 @@ Metric only functions: **NOTE:** This function may cause a metric to break semantics for [Gauge metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#gauge). Use at your own risk. - `convert_summary_count_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Count" Value. Noop for metrics that are not of type "Summary". The name for the new metric with be `_count`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. -**NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. +**NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#sums). Use at your own risk. - `convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic)` - Creates a new Sum metric out of incoming metrics of type "Summary" with a "Sum" Value. Noop for metrics that are not of type "Summary". The name for the new metric with be `_sum`. The fields that are copied are: `timestamp`, `starttimestamp`, `attibutes`, and `description`. The new metric that is created will be passed to all functions in the metrics queries list. Function conditions will apply. -**NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#sums). Use at your own risk. +**NOTE:** This function may cause a metric to break semantics for [Sum metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#sums). Use at your own risk. - `convert_gauge_to_sum(aggregation_temporality, is_monotonic)` - `aggregation_temporality` specifies the resultant metric's aggregation temporality. `aggregation_temporality` may be `"cumulative"` or `"delta"`. `is_monotonic` specifies the resultant metric's monotonicity. `is_monotonic` is a boolean. Converts incoming metrics of type "Gauge" to type "Sum", retaining the metric's datapoints and setting its aggregation temporality and monotonicity accordingly. Noop for metrics that are not of type "Gauge". The new metric that is created will be passed to all functions in the metrics queries list. Function conditions will apply.