Skip to content

Commit a564114

Browse files
committed
unexport internal State struct and PrevPoint field
- State -> state (unexported internal implementation detail) - PrevPoint -> prevPoint (unexported internal field) - Keeps public API structs (ValuePoint, HistogramPoint, MetricPoint, DeltaValue) exported as intended
1 parent 2c1fb33 commit a564114

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

processor/cumulativetodeltaprocessor/internal/tracking/tracker.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ 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

6767
type DeltaValue struct {
@@ -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

205205
func (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)))

processor/cumulativetodeltaprocessor/internal/tracking/tracker_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,29 +257,29 @@ func Test_metricTracker_removeStale(t *testing.T) {
257257

258258
type fields struct {
259259
MaxStaleness time.Duration
260-
States map[string]*State
260+
States map[string]*state
261261
}
262262
tests := []struct {
263263
name string
264264
fields fields
265-
wantOut map[string]*State
265+
wantOut map[string]*state
266266
}{
267267
{
268268
name: "Removes stale entry, leaves fresh entry",
269269
fields: fields{
270270
MaxStaleness: 0, // This logic isn't tested here
271-
States: map[string]*State{
271+
States: map[string]*state{
272272
"stale": {
273-
PrevPoint: stalePoint,
273+
prevPoint: stalePoint,
274274
},
275275
"fresh": {
276-
PrevPoint: freshPoint,
276+
prevPoint: freshPoint,
277277
},
278278
},
279279
},
280-
wantOut: map[string]*State{
280+
wantOut: map[string]*state{
281281
"fresh": {
282-
PrevPoint: freshPoint,
282+
prevPoint: freshPoint,
283283
},
284284
},
285285
},
@@ -295,9 +295,9 @@ func Test_metricTracker_removeStale(t *testing.T) {
295295
}
296296
tr.removeStale(currentTime)
297297

298-
gotOut := make(map[string]*State)
298+
gotOut := make(map[string]*state)
299299
tr.states.Range(func(key, value any) bool {
300-
gotOut[key.(string)] = value.(*State)
300+
gotOut[key.(string)] = value.(*state)
301301
return true
302302
})
303303
assert.Equal(t, tt.wantOut, gotOut)

0 commit comments

Comments
 (0)