Skip to content

Commit

Permalink
Change the argument order
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed Aug 2, 2023
1 parent ee201ee commit c4964a6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
13 changes: 6 additions & 7 deletions processor/transformprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<original metric name>_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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand All @@ -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
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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")
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c4964a6

Please sign in to comment.