1
1
// Copyright The OpenTelemetry Authors
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
- package starttimecache // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricstarttimeprocessor/internal/starttimecache"
4
+ package datapointstorage // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricstarttimeprocessor/internal/starttimecache"
5
5
6
6
import (
7
7
"sync"
@@ -30,7 +30,7 @@ import (
30
30
// The gc strategy uses a standard mark-and-sweep approach - each time a timeseriesMap is accessed,
31
31
// it is marked. Similarly, each time a timeseriesInfo is accessed, it is also marked.
32
32
//
33
- // At the end of each StartTimeCache.get (), if the last time the StartTimeCache was gc'd exceeds the 'gcInterval',
33
+ // At the end of each StartTimeCache.Get (), if the last time the StartTimeCache was gc'd exceeds the 'gcInterval',
34
34
// the StartTimeCache is locked and any timeseriesMaps that are unmarked are removed from the StartTimeCache
35
35
// otherwise the timeseriesMap is gc'd
36
36
//
@@ -57,20 +57,20 @@ type TimeseriesInfo struct {
57
57
}
58
58
59
59
type NumberInfo struct {
60
- StartTime pcommon.Timestamp
61
- PreviousValue float64
60
+ StartTime pcommon.Timestamp
61
+ Value float64
62
62
}
63
63
64
64
type HistogramInfo struct {
65
- StartTime pcommon.Timestamp
66
- PreviousCount uint64
67
- PreviousSum float64
65
+ StartTime pcommon.Timestamp
66
+ Count uint64
67
+ Sum float64
68
68
}
69
69
70
70
type SummaryInfo struct {
71
- StartTime pcommon.Timestamp
72
- PreviousCount uint64
73
- PreviousSum float64
71
+ StartTime pcommon.Timestamp
72
+ Count uint64
73
+ Sum float64
74
74
}
75
75
76
76
type TimeseriesKey struct {
@@ -157,8 +157,8 @@ func newTimeseriesMap() *TimeseriesMap {
157
157
return & TimeseriesMap {Mark : true , TsiMap : map [TimeseriesKey ]* TimeseriesInfo {}}
158
158
}
159
159
160
- // StartTimeCache maps from a resource to a map of timeseries instances for the resource.
161
- type StartTimeCache struct {
160
+ // DataPointCache maps from a resource to a map of timeseries instances for the resource.
161
+ type DataPointCache struct {
162
162
sync.RWMutex
163
163
// The mutex is used to protect access to the member fields. It is acquired for most of
164
164
// get() and also acquired by gc().
@@ -168,13 +168,13 @@ type StartTimeCache struct {
168
168
resourceMap map [[16 ]byte ]* TimeseriesMap
169
169
}
170
170
171
- // NewStartTimeCache creates a new (empty) JobsMap.
172
- func NewStartTimeCache (gcInterval time.Duration ) * StartTimeCache {
173
- return & StartTimeCache {gcInterval : gcInterval , lastGC : time .Now (), resourceMap : make (map [[16 ]byte ]* TimeseriesMap )}
171
+ // NewDataPointCache creates a new (empty) JobsMap.
172
+ func NewDataPointCache (gcInterval time.Duration ) * DataPointCache {
173
+ return & DataPointCache {gcInterval : gcInterval , lastGC : time .Now (), resourceMap : make (map [[16 ]byte ]* TimeseriesMap )}
174
174
}
175
175
176
176
// Remove jobs and timeseries that have aged out.
177
- func (c * StartTimeCache ) gc () {
177
+ func (c * DataPointCache ) gc () {
178
178
c .Lock ()
179
179
defer c .Unlock ()
180
180
// once the structure is locked, confirm that gc() is still necessary
@@ -196,7 +196,7 @@ func (c *StartTimeCache) gc() {
196
196
}
197
197
198
198
// Speculatively check if gc() is necessary, recheck once the structure is locked
199
- func (c * StartTimeCache ) MaybeGC () {
199
+ func (c * DataPointCache ) MaybeGC () {
200
200
c .RLock ()
201
201
defer c .RUnlock ()
202
202
if time .Since (c .lastGC ) > c .gcInterval {
@@ -205,7 +205,7 @@ func (c *StartTimeCache) MaybeGC() {
205
205
}
206
206
207
207
// Fetches the TimeseriesMap for the given resource hash. Creates a new map if required.
208
- func (c * StartTimeCache ) Get (resourceHash [16 ]byte ) * TimeseriesMap {
208
+ func (c * DataPointCache ) Get (resourceHash [16 ]byte ) * TimeseriesMap {
209
209
// a read lock is taken here as we will not need to modify resourceMap if the target timeseriesMap is available.
210
210
c .RLock ()
211
211
tsm , ok := c .resourceMap [resourceHash ]
0 commit comments