@@ -135,34 +135,65 @@ impl<T> From<ExponentialHistogram<T>> for MetricData<T> {
135135pub struct GaugeDataPoint < T > {
136136 /// Attributes is the set of key value pairs that uniquely identify the
137137 /// time series.
138- pub attributes : Vec < KeyValue > ,
138+ pub ( crate ) attributes : Vec < KeyValue > ,
139139 /// The value of this data point.
140140 pub value : T ,
141141 /// The sampled [Exemplar]s collected during the time series.
142- pub exemplars : Vec < Exemplar < T > > ,
142+ pub ( crate ) exemplars : Vec < Exemplar < T > > ,
143+ }
144+
145+ impl < T > GaugeDataPoint < T > {
146+ /// Returns an iterator over the attributes in [GaugeDataPoint].
147+ pub fn attributes ( & self ) -> impl Iterator < Item = & KeyValue > {
148+ self . attributes . iter ( )
149+ }
150+
151+ /// Returns an iterator over the exemplars in [GaugeDataPoint].
152+ pub fn exemplars ( & self ) -> impl Iterator < Item = & Exemplar < T > > {
153+ self . exemplars . iter ( )
154+ }
143155}
144156
145157/// A measurement of the current value of an instrument.
146158#[ derive( Debug , Clone ) ]
147159pub struct Gauge < T > {
148160 /// Represents individual aggregated measurements with unique attributes.
149- pub data_points : Vec < GaugeDataPoint < T > > ,
161+ pub ( crate ) data_points : Vec < GaugeDataPoint < T > > ,
150162 /// The time when the time series was started.
151163 pub start_time : Option < SystemTime > ,
152164 /// The time when the time series was recorded.
153165 pub time : SystemTime ,
154166}
155167
168+ impl < T > Gauge < T > {
169+ /// Returns an iterator over the [GaugeDataPoint]s in [Gauge].
170+ pub fn data_points ( & self ) -> impl Iterator < Item = & GaugeDataPoint < T > > {
171+ self . data_points . iter ( )
172+ }
173+ }
174+
156175/// DataPoint is a single data point in a time series.
157176#[ derive( Debug , Clone , PartialEq ) ]
158177pub struct SumDataPoint < T > {
159178 /// Attributes is the set of key value pairs that uniquely identify the
160179 /// time series.
161- pub attributes : Vec < KeyValue > ,
180+ pub ( crate ) attributes : Vec < KeyValue > ,
162181 /// The value of this data point.
163182 pub value : T ,
164183 /// The sampled [Exemplar]s collected during the time series.
165- pub exemplars : Vec < Exemplar < T > > ,
184+ pub ( crate ) exemplars : Vec < Exemplar < T > > ,
185+ }
186+
187+ impl < T > SumDataPoint < T > {
188+ /// Returns an iterator over the attributes in [SumDataPoint].
189+ pub fn attributes ( & self ) -> impl Iterator < Item = & KeyValue > {
190+ self . attributes . iter ( )
191+ }
192+
193+ /// Returns an iterator over the exemplars in [SumDataPoint].
194+ pub fn exemplars ( & self ) -> impl Iterator < Item = & Exemplar < T > > {
195+ self . exemplars . iter ( )
196+ }
166197}
167198
168199/// Represents the sum of all measurements of values from an instrument.
@@ -192,7 +223,7 @@ impl<T> Sum<T> {
192223#[ derive( Debug , Clone ) ]
193224pub struct Histogram < T > {
194225 /// Individual aggregated measurements with unique attributes.
195- pub data_points : Vec < HistogramDataPoint < T > > ,
226+ pub ( crate ) data_points : Vec < HistogramDataPoint < T > > ,
196227 /// The time when the time series was started.
197228 pub start_time : SystemTime ,
198229 /// The time when the time series was recorded.
@@ -202,11 +233,18 @@ pub struct Histogram<T> {
202233 pub temporality : Temporality ,
203234}
204235
236+ impl < T > Histogram < T > {
237+ /// Returns an iterator over the [HistogramDataPoint]s in [Histogram].
238+ pub fn data_points ( & self ) -> impl Iterator < Item = & HistogramDataPoint < T > > {
239+ self . data_points . iter ( )
240+ }
241+ }
242+
205243/// A single histogram data point in a time series.
206244#[ derive( Debug , Clone , PartialEq ) ]
207245pub struct HistogramDataPoint < T > {
208246 /// The set of key value pairs that uniquely identify the time series.
209- pub attributes : Vec < KeyValue > ,
247+ pub ( crate ) attributes : Vec < KeyValue > ,
210248 /// The number of updates this histogram has been calculated with.
211249 pub count : u64 ,
212250 /// The upper bounds of the buckets of the histogram.
@@ -224,14 +262,26 @@ pub struct HistogramDataPoint<T> {
224262 pub sum : T ,
225263
226264 /// The sampled [Exemplar]s collected during the time series.
227- pub exemplars : Vec < Exemplar < T > > ,
265+ pub ( crate ) exemplars : Vec < Exemplar < T > > ,
266+ }
267+
268+ impl < T > HistogramDataPoint < T > {
269+ /// Returns an iterator over the attributes in [HistogramDataPoint].
270+ pub fn attributes ( & self ) -> impl Iterator < Item = & KeyValue > {
271+ self . attributes . iter ( )
272+ }
273+
274+ /// Returns an iterator over the exemplars in [HistogramDataPoint].
275+ pub fn exemplars ( & self ) -> impl Iterator < Item = & Exemplar < T > > {
276+ self . exemplars . iter ( )
277+ }
228278}
229279
230280/// The histogram of all measurements of values from an instrument.
231281#[ derive( Debug , Clone ) ]
232282pub struct ExponentialHistogram < T > {
233283 /// The individual aggregated measurements with unique attributes.
234- pub data_points : Vec < ExponentialHistogramDataPoint < T > > ,
284+ pub ( crate ) data_points : Vec < ExponentialHistogramDataPoint < T > > ,
235285 /// When the time series was started.
236286 pub start_time : SystemTime ,
237287 /// The time when the time series was recorded.
@@ -241,11 +291,18 @@ pub struct ExponentialHistogram<T> {
241291 pub temporality : Temporality ,
242292}
243293
294+ impl < T > ExponentialHistogram < T > {
295+ /// Returns an iterator over the [ExponentialHistogramDataPoint]s in [ExponentialHistogram].
296+ pub fn data_points ( & self ) -> impl Iterator < Item = & ExponentialHistogramDataPoint < T > > {
297+ self . data_points . iter ( )
298+ }
299+ }
300+
244301/// A single exponential histogram data point in a time series.
245302#[ derive( Debug , Clone , PartialEq ) ]
246303pub struct ExponentialHistogramDataPoint < T > {
247304 /// The set of key value pairs that uniquely identify the time series.
248- pub attributes : Vec < KeyValue > ,
305+ pub ( crate ) attributes : Vec < KeyValue > ,
249306
250307 /// The number of updates this histogram has been calculated with.
251308 pub count : usize ,
@@ -283,7 +340,19 @@ pub struct ExponentialHistogramDataPoint<T> {
283340 pub zero_threshold : f64 ,
284341
285342 /// The sampled exemplars collected during the time series.
286- pub exemplars : Vec < Exemplar < T > > ,
343+ pub ( crate ) exemplars : Vec < Exemplar < T > > ,
344+ }
345+
346+ impl < T > ExponentialHistogramDataPoint < T > {
347+ /// Returns an iterator over the attributes in [ExponentialHistogramDataPoint].
348+ pub fn attributes ( & self ) -> impl Iterator < Item = & KeyValue > {
349+ self . attributes . iter ( )
350+ }
351+
352+ /// Returns an iterator over the exemplars in [ExponentialHistogramDataPoint].
353+ pub fn exemplars ( & self ) -> impl Iterator < Item = & Exemplar < T > > {
354+ self . exemplars . iter ( )
355+ }
287356}
288357
289358/// A set of bucket counts, encoded in a contiguous array of counts.
@@ -304,7 +373,7 @@ pub struct ExponentialBucket {
304373pub struct Exemplar < T > {
305374 /// The attributes recorded with the measurement but filtered out of the
306375 /// time series' aggregated data.
307- pub filtered_attributes : Vec < KeyValue > ,
376+ pub ( crate ) filtered_attributes : Vec < KeyValue > ,
308377 /// The time when the measurement was recorded.
309378 pub time : SystemTime ,
310379 /// The measured value.
@@ -319,6 +388,13 @@ pub struct Exemplar<T> {
319388 pub trace_id : [ u8 ; 16 ] ,
320389}
321390
391+ impl < T > Exemplar < T > {
392+ /// Returns an iterator over the filtered attributes in [Exemplar].
393+ pub fn filtered_attributes ( & self ) -> impl Iterator < Item = & KeyValue > {
394+ self . filtered_attributes . iter ( )
395+ }
396+ }
397+
322398#[ cfg( test) ]
323399mod tests {
324400
0 commit comments