Skip to content

Commit

Permalink
[chore] avoid unnecessary use of any in CumulativeToDeltaProcessor (#…
Browse files Browse the repository at this point in the history
…35166)

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Sep 13, 2024
1 parent 6f22c7d commit 19b01db
Showing 1 changed file with 39 additions and 41 deletions.
80 changes: 39 additions & 41 deletions processor/cumulativetodeltaprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (ctdp *cumulativeToDeltaProcessor) processMetrics(_ context.Context, md pme
MetricUnit: m.Unit(),
MetricIsMonotonic: ms.IsMonotonic(),
}
ctdp.convertDataPoints(ms.DataPoints(), baseIdentity)
ctdp.convertNumberDataPoints(ms.DataPoints(), baseIdentity)
ms.SetAggregationTemporality(pmetric.AggregationTemporalityDelta)
return ms.DataPoints().Len() == 0
case pmetric.MetricTypeHistogram:
Expand Down Expand Up @@ -116,47 +116,45 @@ func (ctdp *cumulativeToDeltaProcessor) shouldConvertMetric(metricName string) b
(ctdp.excludeFS == nil || !ctdp.excludeFS.Matches(metricName))
}

func (ctdp *cumulativeToDeltaProcessor) convertDataPoints(in any, baseIdentity tracking.MetricIdentity) {
if dps, ok := in.(pmetric.NumberDataPointSlice); ok {
dps.RemoveIf(func(dp pmetric.NumberDataPoint) bool {
id := baseIdentity
id.StartTimestamp = dp.StartTimestamp()
id.Attributes = dp.Attributes()
id.MetricValueType = dp.ValueType()
point := tracking.ValuePoint{
ObservedTimestamp: dp.Timestamp(),
}

if dp.Flags().NoRecordedValue() {
// drop points with no value
return true
}
if id.IsFloatVal() {
// Do not attempt to transform NaN values
if math.IsNaN(dp.DoubleValue()) {
return false
}
point.FloatValue = dp.DoubleValue()
} else {
point.IntValue = dp.IntValue()
}
trackingPoint := tracking.MetricPoint{
Identity: id,
Value: point,
}
delta, valid := ctdp.deltaCalculator.Convert(trackingPoint)
if !valid {
return true
}
dp.SetStartTimestamp(delta.StartTimestamp)
if id.IsFloatVal() {
dp.SetDoubleValue(delta.FloatValue)
} else {
dp.SetIntValue(delta.IntValue)
func (ctdp *cumulativeToDeltaProcessor) convertNumberDataPoints(dps pmetric.NumberDataPointSlice, baseIdentity tracking.MetricIdentity) {
dps.RemoveIf(func(dp pmetric.NumberDataPoint) bool {
id := baseIdentity
id.StartTimestamp = dp.StartTimestamp()
id.Attributes = dp.Attributes()
id.MetricValueType = dp.ValueType()
point := tracking.ValuePoint{
ObservedTimestamp: dp.Timestamp(),
}

if dp.Flags().NoRecordedValue() {
// drop points with no value
return true
}
if id.IsFloatVal() {
// Do not attempt to transform NaN values
if math.IsNaN(dp.DoubleValue()) {
return false
}
return false
})
}
point.FloatValue = dp.DoubleValue()
} else {
point.IntValue = dp.IntValue()
}
trackingPoint := tracking.MetricPoint{
Identity: id,
Value: point,
}
delta, valid := ctdp.deltaCalculator.Convert(trackingPoint)
if !valid {
return true
}
dp.SetStartTimestamp(delta.StartTimestamp)
if id.IsFloatVal() {
dp.SetDoubleValue(delta.FloatValue)
} else {
dp.SetIntValue(delta.IntValue)
}
return false
})
}

func (ctdp *cumulativeToDeltaProcessor) convertHistogramDataPoints(in any, baseIdentity tracking.MetricIdentity) {
Expand Down

0 comments on commit 19b01db

Please sign in to comment.