Skip to content

Commit

Permalink
[transformprocessor]: Remove unnecessary data copy when transform sum…
Browse files Browse the repository at this point in the history
… to/from gauge (#35177)

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Sep 16, 2024
1 parent 7734698 commit 943c736
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
22 changes: 22 additions & 0 deletions .chloggen/rm-copy-transformprocessor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: transformprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove unnecessary data copy when transform sum to/from gauge

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35177]

# 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: [user]
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func convertGaugeToSum(stringAggTemp string, monotonic bool) (ottl.ExprFunc[ottl
metric.SetEmptySum().SetAggregationTemporality(aggTemp)
metric.Sum().SetIsMonotonic(monotonic)

// Setting the data type removed all the data points, so we must copy them back to the metric.
dps.CopyTo(metric.Sum().DataPoints())
// Setting the data type removed all the data points, so we must move them back to the metric.
dps.MoveAndAppendTo(metric.Sum().DataPoints())

return nil, nil
}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func convertDatapointGaugeToSum(stringAggTemp string, monotonic bool) (ottl.Expr
metric.SetEmptySum().SetAggregationTemporality(aggTemp)
metric.Sum().SetIsMonotonic(monotonic)

// Setting the data type removed all the data points, so we must copy them back to the metric.
dps.CopyTo(metric.Sum().DataPoints())
// Setting the data type removed all the data points, so we must move them back to the metric.
dps.MoveAndAppendTo(metric.Sum().DataPoints())

return nil, nil
}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func convertSumToGauge() (ottl.ExprFunc[ottlmetric.TransformContext], error) {
dps := metric.Sum().DataPoints()

// Setting the data type removed all the data points, so we must copy them back to the metric.
dps.CopyTo(metric.SetEmptyGauge().DataPoints())
dps.MoveAndAppendTo(metric.SetEmptyGauge().DataPoints())

return nil, nil
}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func convertDatapointSumToGauge() (ottl.ExprFunc[ottldatapoint.TransformContext]

dps := metric.Sum().DataPoints()

// Setting the data type removed all the data points, so we must copy them back to the metric.
dps.CopyTo(metric.SetEmptyGauge().DataPoints())
// Setting the data type removed all the data points, so we must move them back to the metric.
dps.MoveAndAppendTo(metric.SetEmptyGauge().DataPoints())

return nil, nil
}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func createExtractSumMetricFunction(_ ottl.FunctionContext, oArgs ottl.Arguments
return extractSumMetric(args.Monotonic)
}

// this interface helps unify the logic for extracting data from different histogram types
// SumCountDataPoint interface helps unify the logic for extracting data from different histogram types
// all supported metric types' datapoints implement it
type SumCountDataPoint interface {
Attributes() pcommon.Map
Expand Down

0 comments on commit 943c736

Please sign in to comment.