Skip to content

Commit

Permalink
fix per aneurysm9's comment
Browse files Browse the repository at this point in the history
Signed-off-by: Loc Mai <[email protected]>
  • Loading branch information
locmai committed Apr 4, 2023
1 parent 7b5aa64 commit 1979cbf
Showing 1 changed file with 5 additions and 30 deletions.
35 changes: 5 additions & 30 deletions exporter/prometheusexporter/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (a *lastValueAccumulator) accumulateHistogram(metric pmetric.Metric, il pco

switch histogram.AggregationTemporality() {
case pmetric.AggregationTemporalityDelta:
AccumulateHistogramValues(mv.value.Histogram().DataPoints().At(0), ip, m.Histogram().DataPoints().AppendEmpty())
accumulateHistogramValues(mv.value.Histogram().DataPoints().At(0), ip, m.Histogram().DataPoints().AppendEmpty())
case pmetric.AggregationTemporalityCumulative:
if ip.Timestamp().AsTime().Before(mv.value.Histogram().DataPoints().At(0).Timestamp().AsTime()) {
// only keep datapoint with latest timestamp
Expand Down Expand Up @@ -335,32 +335,7 @@ func copyMetricMetadata(metric pmetric.Metric) pmetric.Metric {
return m
}

func AccumulateNumericValues(prev, current, dest pmetric.NumberDataPoint) {
if current.StartTimestamp().AsTime().Before(prev.StartTimestamp().AsTime()) {
dest.SetStartTimestamp(current.StartTimestamp())
} else {
dest.SetStartTimestamp(prev.StartTimestamp())
}

older := prev
newer := current
if current.Timestamp().AsTime().Before(prev.Timestamp().AsTime()) {
older = current
newer = prev
}

newer.Attributes().CopyTo(dest.Attributes())
dest.SetTimestamp(newer.Timestamp())

switch newer.ValueType() {
case pmetric.NumberDataPointValueTypeDouble:
dest.SetDoubleValue(newer.DoubleValue() + older.DoubleValue())
case pmetric.NumberDataPointValueTypeInt:
dest.SetIntValue(newer.IntValue() + older.IntValue())
}
}

func AccumulateHistogramValues(prev, current, dest pmetric.HistogramDataPoint) {
func accumulateHistogramValues(prev, current, dest pmetric.HistogramDataPoint) {
if current.StartTimestamp().AsTime().Before(prev.StartTimestamp().AsTime()) {
dest.SetStartTimestamp(current.StartTimestamp())
} else {
Expand Down Expand Up @@ -399,16 +374,16 @@ func AccumulateHistogramValues(prev, current, dest pmetric.HistogramDataPoint) {
for i := 0; i < newer.BucketCounts().Len(); i++ {
counts[i] = newer.BucketCounts().At(i) + older.BucketCounts().At(i)
}
// dest.SetBucketCounts(pcommon.NewImmutableUInt64Slice(counts))
dest.BucketCounts().FromRaw(counts)
} else {
// use new value if bucket bounds do not match
dest.SetCount(newer.Count())
if newer.HasSum() {
dest.SetSum(newer.Sum())
}

// dest.SetBucketCounts(newer.BucketCounts())
dest.BucketCounts().FromRaw(newer.BucketCounts().AsRaw())
}

// dest.SetExplicitBounds(newer.ExplicitBounds())
dest.ExplicitBounds().FromRaw(newer.ExplicitBounds().AsRaw())
}

0 comments on commit 1979cbf

Please sign in to comment.