From c4964a6d18cd5202f10335f3fbfa8a20e09293a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Wed, 2 Aug 2023 12:27:26 +0200 Subject: [PATCH] Change the argument order --- processor/transformprocessor/README.md | 13 ++++++------- .../internal/metrics/func_extract_sum_metric.go | 8 ++++---- .../metrics/func_extract_sum_metric_test.go | 4 ++-- .../internal/metrics/processor_test.go | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/processor/transformprocessor/README.md b/processor/transformprocessor/README.md index 5c2f7ff0268a..298a59bebaf3 100644 --- a/processor/transformprocessor/README.md +++ b/processor/transformprocessor/README.md @@ -220,24 +220,23 @@ Examples: ### extract_sum_metric -> **Note** This function supports Histograms, ExponentialHistograms and Summaries +> **Note** This function supports Histograms, ExponentialHistograms and Summaries. -`extract_sum_metric(aggregation_temporality, is_monotonic)` +`extract_sum_metric(is_monotonic, aggregation_temporality)` The `extract_sum_metric` function creates a new Sum metric from a Histogram, ExponentialHistogram or Summary's sum value. -`aggregation_temporality` is an enum(`AGGREGATION_TEMPORALITY_DELTA` or `AGGREGATION_TEMPORALITY_CUMULATIVE`) representing the desired aggregation temporality of the new metric. `is_monotonic` is a boolean representing the monotonicity of the new metric. +`is_monotonic` is a boolean representing the monotonicity of the new metric. `aggregation_temporality` is an enum(`AGGREGATION_TEMPORALITY_DELTA` or `AGGREGATION_TEMPORALITY_CUMULATIVE`) representing the desired aggregation temporality of the new metric. The name for the new metric will 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 statements 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. +> **Warning** 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 only if you're confident you know what the resulting monotonicity and aggregation temporality should be. Examples: -- `extract_sum_metric("delta", true)` +- `extract_sum_metric(true, AGGREGATION_TEMPORALITY_DELTA)` - -- `extract_sum_metric("cumulative", false)` +- `extract_sum_metric(false, AGGREGATION_TEMPORALITY_CUMULATIVE)` ### convert_summary_count_val_to_sum diff --git a/processor/transformprocessor/internal/metrics/func_extract_sum_metric.go b/processor/transformprocessor/internal/metrics/func_extract_sum_metric.go index a2619ba5084d..99521881e4bd 100644 --- a/processor/transformprocessor/internal/metrics/func_extract_sum_metric.go +++ b/processor/transformprocessor/internal/metrics/func_extract_sum_metric.go @@ -15,8 +15,8 @@ import ( ) type extractSumMetricArguments struct { - AggTemp ottl.Enum `ottlarg:"0"` - Monotonic bool `ottlarg:"1"` + Monotonic bool `ottlarg:"0"` + AggTemp ottl.Enum `ottlarg:"1"` } func newExtractSumMetricFactory() ottl.Factory[ottlmetric.TransformContext] { @@ -30,7 +30,7 @@ func createExtractSumMetricFunction(_ ottl.FunctionContext, oArgs ottl.Arguments return nil, fmt.Errorf("extractSumMetricFactory args must be of type *extractSumMetricArguments") } - return extractSumMetric(args.AggTemp, args.Monotonic) + return extractSumMetric(args.Monotonic, args.AggTemp) } // this interface helps unify the logic for extracting data from different histogram types @@ -43,7 +43,7 @@ type SumCountDataPoint interface { Timestamp() pcommon.Timestamp } -func extractSumMetric(aggTempEnum ottl.Enum, monotonic bool) (ottl.ExprFunc[ottlmetric.TransformContext], error) { +func extractSumMetric(monotonic bool, aggTempEnum ottl.Enum) (ottl.ExprFunc[ottlmetric.TransformContext], error) { aggTemp := pmetric.AggregationTemporality(aggTempEnum) switch aggTemp { case pmetric.AggregationTemporalityDelta, pmetric.AggregationTemporalityCumulative: diff --git a/processor/transformprocessor/internal/metrics/func_extract_sum_metric_test.go b/processor/transformprocessor/internal/metrics/func_extract_sum_metric_test.go index fdf538c66a17..ca8369720aab 100644 --- a/processor/transformprocessor/internal/metrics/func_extract_sum_metric_test.go +++ b/processor/transformprocessor/internal/metrics/func_extract_sum_metric_test.go @@ -408,7 +408,7 @@ func Test_extractSumMetric(t *testing.T) { actualMetrics := pmetric.NewMetricSlice() tt.input.CopyTo(actualMetrics.AppendEmpty()) - evaluate, err := extractSumMetric(ottl.Enum(tt.temporality), tt.monotonicity) + evaluate, err := extractSumMetric(tt.monotonicity, ottl.Enum(tt.temporality)) assert.NoError(t, err) _, err = evaluate(nil, ottlmetric.NewTransformContext(tt.input, actualMetrics, pcommon.NewInstrumentationScope(), pcommon.NewResource())) @@ -435,7 +435,7 @@ func Test_extractSumMetric_validation(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - _, err := extractSumMetric(tt.aggTemp, true) + _, err := extractSumMetric(true, tt.aggTemp) assert.Error(t, err, "unknown aggregation temporality: not a real aggregation temporality") }) } diff --git a/processor/transformprocessor/internal/metrics/processor_test.go b/processor/transformprocessor/internal/metrics/processor_test.go index 414d5af1b20f..817df31113b4 100644 --- a/processor/transformprocessor/internal/metrics/processor_test.go +++ b/processor/transformprocessor/internal/metrics/processor_test.go @@ -100,7 +100,7 @@ func Test_ProcessMetrics_MetricContext(t *testing.T) { want func(pmetric.Metrics) }{ { - statements: []string{`extract_sum_metric(AGGREGATION_TEMPORALITY_DELTA, true) where name == "operationB"`}, + statements: []string{`extract_sum_metric(true, AGGREGATION_TEMPORALITY_DELTA) where name == "operationB"`}, want: func(td pmetric.Metrics) { sumMetric := td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().AppendEmpty() sumDp := sumMetric.SetEmptySum().DataPoints().AppendEmpty()