@@ -59,16 +59,16 @@ var identityBufferPool = sync.Pool{
5959 },
6060}
6161
62- type State struct {
62+ type state struct {
6363 sync.Mutex
64- PrevPoint ValuePoint
64+ prevPoint valuePoint
6565}
6666
67- type DeltaValue struct {
67+ type deltaValue struct {
6868 StartTimestamp pcommon.Timestamp
6969 FloatValue float64
7070 IntValue int64
71- HistogramValue * HistogramPoint
71+ HistogramValue * histogramPoint
7272}
7373
7474func NewMetricTracker (ctx context.Context , logger * zap.Logger , maxStaleness time.Duration , initalValue InitialValue ) * MetricTracker {
@@ -92,7 +92,7 @@ type MetricTracker struct {
9292 startTime pcommon.Timestamp
9393}
9494
95- func (t * MetricTracker ) Convert (in MetricPoint ) (out DeltaValue , valid bool ) {
95+ func (t * MetricTracker ) Convert (in metricPoint ) (out deltaValue , valid bool ) {
9696 metricID := in .Identity
9797 metricPoint := in .Value
9898 if ! metricID .IsSupportedMetricType () {
@@ -112,8 +112,8 @@ func (t *MetricTracker) Convert(in MetricPoint) (out DeltaValue, valid bool) {
112112 hashableID := b .String ()
113113 identityBufferPool .Put (b )
114114
115- s , ok := t .states .LoadOrStore (hashableID , & State {
116- PrevPoint : metricPoint ,
115+ s , ok := t .states .LoadOrStore (hashableID , & state {
116+ prevPoint : metricPoint ,
117117 })
118118 if ! ok {
119119 switch metricID .MetricType {
@@ -141,16 +141,16 @@ func (t *MetricTracker) Convert(in MetricPoint) (out DeltaValue, valid bool) {
141141
142142 valid = true
143143
144- state := s .(* State )
144+ state := s .(* state )
145145 state .Lock ()
146146 defer state .Unlock ()
147147
148- out .StartTimestamp = state .PrevPoint .ObservedTimestamp
148+ out .StartTimestamp = state .prevPoint .ObservedTimestamp
149149
150150 switch metricID .MetricType {
151151 case pmetric .MetricTypeHistogram :
152152 value := metricPoint .HistogramValue
153- prevValue := state .PrevPoint .HistogramValue
153+ prevValue := state .prevPoint .HistogramValue
154154 if math .IsNaN (value .Sum ) {
155155 value .Sum = prevValue .Sum
156156 }
@@ -174,7 +174,7 @@ func (t *MetricTracker) Convert(in MetricPoint) (out DeltaValue, valid bool) {
174174 case pmetric .MetricTypeSum :
175175 if metricID .IsFloatVal () {
176176 value := metricPoint .FloatValue
177- prevValue := state .PrevPoint .FloatValue
177+ prevValue := state .prevPoint .FloatValue
178178 delta := value - prevValue
179179
180180 // Detect reset (non-monotonic sums are not converted)
@@ -185,7 +185,7 @@ func (t *MetricTracker) Convert(in MetricPoint) (out DeltaValue, valid bool) {
185185 out .FloatValue = delta
186186 } else {
187187 value := metricPoint .IntValue
188- prevValue := state .PrevPoint .IntValue
188+ prevValue := state .prevPoint .IntValue
189189 delta := value - prevValue
190190
191191 // Detect reset (non-monotonic sums are not converted)
@@ -198,13 +198,13 @@ func (t *MetricTracker) Convert(in MetricPoint) (out DeltaValue, valid bool) {
198198 case pmetric .MetricTypeEmpty , pmetric .MetricTypeGauge , pmetric .MetricTypeExponentialHistogram , pmetric .MetricTypeSummary :
199199 }
200200
201- state .PrevPoint = metricPoint
201+ state .prevPoint = metricPoint
202202 return
203203}
204204
205205func (t * MetricTracker ) removeStale (staleBefore pcommon.Timestamp ) {
206206 t .states .Range (func (key , value any ) bool {
207- s := value .(* State )
207+ s := value .(* state )
208208
209209 // There is a known race condition here.
210210 // Because the state may be in the process of updating at the
@@ -220,7 +220,7 @@ func (t *MetricTracker) removeStale(staleBefore pcommon.Timestamp) {
220220 // not be persisted. The next update will load an entirely
221221 // new state.
222222 s .Lock ()
223- lastObserved := s .PrevPoint .ObservedTimestamp
223+ lastObserved := s .prevPoint .ObservedTimestamp
224224 s .Unlock ()
225225 if lastObserved < staleBefore {
226226 t .logger .Debug ("removing stale state key" , zap .String ("key" , key .(string )))
@@ -243,3 +243,38 @@ func (t *MetricTracker) sweeper(ctx context.Context, remove func(pcommon.Timesta
243243 }
244244 }
245245}
246+
247+ // GetStartTimestamp returns the StartTimestamp field of deltaValue
248+ func (dv * deltaValue ) GetStartTimestamp () pcommon.Timestamp {
249+ return dv .StartTimestamp
250+ }
251+
252+ // GetFloatValue returns the FloatValue field of deltaValue
253+ func (dv * deltaValue ) GetFloatValue () float64 {
254+ return dv .FloatValue
255+ }
256+
257+ // GetIntValue returns the IntValue field of deltaValue
258+ func (dv * deltaValue ) GetIntValue () int64 {
259+ return dv .IntValue
260+ }
261+
262+ // GetHistogramValue returns the HistogramValue field of deltaValue
263+ func (dv * deltaValue ) GetHistogramValue () * histogramPoint {
264+ return dv .HistogramValue
265+ }
266+
267+ // GetCount returns the Count field of histogramPoint
268+ func (hp * histogramPoint ) GetCount () uint64 {
269+ return hp .Count
270+ }
271+
272+ // GetSum returns the Sum field of histogramPoint
273+ func (hp * histogramPoint ) GetSum () float64 {
274+ return hp .Sum
275+ }
276+
277+ // GetBuckets returns the Buckets field of histogramPoint
278+ func (hp * histogramPoint ) GetBuckets () []uint64 {
279+ return hp .Buckets
280+ }
0 commit comments