@@ -158,14 +158,17 @@ func (s *cumulativeSum[N]) Aggregation() metricdata.Aggregation {
158
158
return out
159
159
}
160
160
161
+ // precomputedValue is the recorded measurement value for a set of attributes.
161
162
type precomputedValue [N int64 | float64 ] struct {
162
- // measured is the value directly measured.
163
+ // measured is the last value measured for a set of attributes that were
164
+ // not filtered.
163
165
measured N
164
- // filtered is the sum of values from spatially aggregations.
166
+ // filtered is the sum of values from measurements that had their
167
+ // attributes filtered.
165
168
filtered N
166
169
}
167
170
168
- // valueMap is the storage for precomputed sums.
171
+ // precomputedMap is the storage for precomputed sums.
169
172
type precomputedMap [N int64 | float64 ] struct {
170
173
sync.Mutex
171
174
values map [attribute.Set ]precomputedValue [N ]
@@ -177,7 +180,14 @@ func newPrecomputedMap[N int64 | float64]() *precomputedMap[N] {
177
180
}
178
181
}
179
182
180
- // Aggregate records value as a cumulative sum for attr.
183
+ // Aggregate records value with the unfiltered attributes attr.
184
+ //
185
+ // If a previous measurement was made for the same attribute set:
186
+ //
187
+ // - If that measurement's attributes were not filtered, this value overwrite
188
+ // that value.
189
+ // - If that measurement's attributes were filtered, this value will be
190
+ // recorded along side that value.
181
191
func (s * precomputedMap [N ]) Aggregate (value N , attr attribute.Set ) {
182
192
s .Lock ()
183
193
v := s .values [attr ]
@@ -186,8 +196,18 @@ func (s *precomputedMap[N]) Aggregate(value N, attr attribute.Set) {
186
196
s .Unlock ()
187
197
}
188
198
189
- // filtered records value with spatially re-aggregated attrs.
190
- func (s * precomputedMap [N ]) filtered (value N , attr attribute.Set ) { // nolint: unused // Used to agg filtered.
199
+ // aggregateFiltered records value with the filtered attributes attr.
200
+ //
201
+ // If a previous measurement was made for the same attribute set:
202
+ //
203
+ // - If that measurement's attributes were not filtered, this value will be
204
+ // recorded along side that value.
205
+ // - If that measurement's attributes were filtered, this value will be
206
+ // added to it.
207
+ //
208
+ // This method should not be used if attr have not been reduced by an attribute
209
+ // filter.
210
+ func (s * precomputedMap [N ]) aggregateFiltered (value N , attr attribute.Set ) { // nolint: unused // Used to agg filtered.
191
211
s .Lock ()
192
212
v := s .values [attr ]
193
213
v .filtered += value
@@ -196,15 +216,14 @@ func (s *precomputedMap[N]) filtered(value N, attr attribute.Set) { // nolint: u
196
216
}
197
217
198
218
// NewPrecomputedDeltaSum returns an Aggregator that summarizes a set of
199
- // measurements as their pre-computed arithmetic sum . Each sum is scoped by
200
- // attributes and the aggregation cycle the measurements were made in.
219
+ // pre-computed sums . Each sum is scoped by attributes and the aggregation
220
+ // cycle the measurements were made in.
201
221
//
202
222
// The monotonic value is used to communicate the produced Aggregation is
203
223
// monotonic or not. The returned Aggregator does not make any guarantees this
204
224
// value is accurate. It is up to the caller to ensure it.
205
225
//
206
- // The output Aggregation will report recorded values as delta temporality. It
207
- // is up to the caller to ensure this is accurate.
226
+ // The output Aggregation will report recorded values as delta temporality.
208
227
func NewPrecomputedDeltaSum [N int64 | float64 ](monotonic bool ) Aggregator [N ] {
209
228
return & precomputedDeltaSum [N ]{
210
229
precomputedMap : newPrecomputedMap [N ](),
@@ -214,8 +233,8 @@ func NewPrecomputedDeltaSum[N int64 | float64](monotonic bool) Aggregator[N] {
214
233
}
215
234
}
216
235
217
- // precomputedDeltaSum summarizes a set of measurements recorded over all
218
- // aggregation cycles as the delta arithmetic sum .
236
+ // precomputedDeltaSum summarizes a set of pre-computed sums recorded over all
237
+ // aggregation cycles as the delta of these sums .
219
238
type precomputedDeltaSum [N int64 | float64 ] struct {
220
239
* precomputedMap [N ]
221
240
@@ -225,6 +244,16 @@ type precomputedDeltaSum[N int64 | float64] struct {
225
244
start time.Time
226
245
}
227
246
247
+ // Aggregation returns the recorded pre-computed sums as an Aggregation. The
248
+ // sum values are expressed as the delta between what was measured this
249
+ // collection cycle and the previous.
250
+ //
251
+ // All pre-computed sums that were recorded for attributes sets reduced by an
252
+ // attribute filter (filtered-sums) are summed together and added to any
253
+ // pre-computed sum value recorded directly for the resulting attribute set
254
+ // (unfiltered-sum). The filtered-sums are reset to zero for the next
255
+ // collection cycle, and the unfiltered-sum is kept for the next collection
256
+ // cycle.
228
257
func (s * precomputedDeltaSum [N ]) Aggregation () metricdata.Aggregation {
229
258
s .Lock ()
230
259
defer s .Unlock ()
@@ -264,15 +293,15 @@ func (s *precomputedDeltaSum[N]) Aggregation() metricdata.Aggregation {
264
293
}
265
294
266
295
// NewPrecomputedCumulativeSum returns an Aggregator that summarizes a set of
267
- // measurements as their pre-computed arithmetic sum . Each sum is scoped by
268
- // attributes and the aggregation cycle the measurements were made in.
296
+ // pre-computed sums . Each sum is scoped by attributes and the aggregation
297
+ // cycle the measurements were made in.
269
298
//
270
299
// The monotonic value is used to communicate the produced Aggregation is
271
300
// monotonic or not. The returned Aggregator does not make any guarantees this
272
301
// value is accurate. It is up to the caller to ensure it.
273
302
//
274
303
// The output Aggregation will report recorded values as cumulative
275
- // temporality. It is up to the caller to ensure this is accurate.
304
+ // temporality.
276
305
func NewPrecomputedCumulativeSum [N int64 | float64 ](monotonic bool ) Aggregator [N ] {
277
306
return & precomputedCumulativeSum [N ]{
278
307
precomputedMap : newPrecomputedMap [N ](),
@@ -281,15 +310,24 @@ func NewPrecomputedCumulativeSum[N int64 | float64](monotonic bool) Aggregator[N
281
310
}
282
311
}
283
312
284
- // precomputedCumulativeSum summarizes a set of measurements recorded over all
285
- // aggregation cycles directly as the cumulative arithmetic sum.
313
+ // precomputedCumulativeSum directly records and reports a set of pre-computed sums.
286
314
type precomputedCumulativeSum [N int64 | float64 ] struct {
287
315
* precomputedMap [N ]
288
316
289
317
monotonic bool
290
318
start time.Time
291
319
}
292
320
321
+ // Aggregation returns the recorded pre-computed sums as an Aggregation. The
322
+ // sum values are expressed directly as they are assumed to be recorded as the
323
+ // cumulative sum of a some measured phenomena.
324
+ //
325
+ // All pre-computed sums that were recorded for attributes sets reduced by an
326
+ // attribute filter (filtered-sums) are summed together and added to any
327
+ // pre-computed sum value recorded directly for the resulting attribute set
328
+ // (unfiltered-sum). The filtered-sums are reset to zero for the next
329
+ // collection cycle, and the unfiltered-sum is kept for the next collection
330
+ // cycle.
293
331
func (s * precomputedCumulativeSum [N ]) Aggregation () metricdata.Aggregation {
294
332
s .Lock ()
295
333
defer s .Unlock ()
0 commit comments