Skip to content

Commit bcbff63

Browse files
committed
fix min and max and value
1 parent 56020a5 commit bcbff63

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

opentelemetry-proto/src/transform/metrics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ pub mod tonic {
282282
time_unix_nano: to_nanos(sum.time()),
283283
exemplars: dp.exemplars().map(Into::into).collect(),
284284
flags: TonicDataPointFlags::default() as u32,
285-
value: Some(dp.value.into()),
285+
value: Some(dp.value().into()),
286286
})
287287
.collect(),
288288
aggregation_temporality: TonicTemporality::from(sum.temporality()).into(),
@@ -305,7 +305,7 @@ pub mod tonic {
305305
time_unix_nano: to_nanos(gauge.time()),
306306
exemplars: dp.exemplars().map(Into::into).collect(),
307307
flags: TonicDataPointFlags::default() as u32,
308-
value: Some(dp.value.into()),
308+
value: Some(dp.value().into()),
309309
})
310310
.collect(),
311311
}

opentelemetry-sdk/src/metrics/data/mod.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub struct GaugeDataPoint<T> {
169169
/// time series.
170170
pub(crate) attributes: Vec<KeyValue>,
171171
/// The value of this data point.
172-
pub value: T,
172+
pub(crate) value: T,
173173
/// The sampled [Exemplar]s collected during the time series.
174174
pub(crate) exemplars: Vec<Exemplar<T>>,
175175
}
@@ -186,6 +186,13 @@ impl<T> GaugeDataPoint<T> {
186186
}
187187
}
188188

189+
impl<T: Copy> GaugeDataPoint<T> {
190+
/// Returns the value of this data point.
191+
pub fn value(&self) -> T {
192+
self.value
193+
}
194+
}
195+
189196
/// A measurement of the current value of an instrument.
190197
#[derive(Debug, Clone)]
191198
pub struct Gauge<T> {
@@ -238,6 +245,13 @@ impl<T> SumDataPoint<T> {
238245
}
239246
}
240247

248+
impl<T: Copy> SumDataPoint<T> {
249+
/// Returns the value of this data point.
250+
pub fn value(&self) -> T {
251+
self.value
252+
}
253+
}
254+
241255
/// Represents the sum of all measurements of values from an instrument.
242256
#[derive(Debug, Clone)]
243257
pub struct Sum<T> {
@@ -334,9 +348,9 @@ pub struct HistogramDataPoint<T> {
334348
pub(crate) bucket_counts: Vec<u64>,
335349

336350
/// The minimum value recorded.
337-
pub min: Option<T>,
351+
pub(crate) min: Option<T>,
338352
/// The maximum value recorded.
339-
pub max: Option<T>,
353+
pub(crate) max: Option<T>,
340354
/// The sum of the values recorded.
341355
pub(crate) sum: T,
342356

@@ -376,6 +390,18 @@ impl<T> HistogramDataPoint<T> {
376390
}
377391
}
378392

393+
impl<T: Copy> HistogramDataPoint<T> {
394+
/// Returns the minimum value recorded.
395+
pub fn min(&self) -> Option<T> {
396+
self.min
397+
}
398+
399+
/// Returns the maximum value recorded.
400+
pub fn max(&self) -> Option<T> {
401+
self.max
402+
}
403+
}
404+
379405
/// The histogram of all measurements of values from an instrument.
380406
#[derive(Debug, Clone)]
381407
pub struct ExponentialHistogram<T> {

opentelemetry-stdout/src/metrics/exporter.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn print_metrics<'a>(metrics: impl Iterator<Item = &'a ScopeMetrics>) {
105105

106106
fn print_info<T>(data: &MetricData<T>)
107107
where
108-
T: Debug,
108+
T: Debug + Copy,
109109
{
110110
match data {
111111
MetricData::Gauge(gauge) => {
@@ -156,7 +156,7 @@ fn print_sum<T: Debug>(sum: &Sum<T>) {
156156
print_sum_data_points(sum.data_points());
157157
}
158158

159-
fn print_gauge<T: Debug>(gauge: &Gauge<T>) {
159+
fn print_gauge<T: Debug + Copy>(gauge: &Gauge<T>) {
160160
println!("\t\tGauge DataPoints");
161161
if let Some(start_time) = gauge.start_time() {
162162
let datetime: DateTime<Utc> = start_time.into();
@@ -173,7 +173,7 @@ fn print_gauge<T: Debug>(gauge: &Gauge<T>) {
173173
print_gauge_data_points(gauge.data_points());
174174
}
175175

176-
fn print_histogram<T: Debug>(histogram: &Histogram<T>) {
176+
fn print_histogram<T: Debug + Copy>(histogram: &Histogram<T>) {
177177
if histogram.temporality() == Temporality::Cumulative {
178178
println!("\t\tTemporality : Cumulative");
179179
} else {
@@ -206,31 +206,31 @@ fn print_sum_data_points<'a, T: Debug + 'a>(
206206
}
207207
}
208208

209-
fn print_gauge_data_points<'a, T: Debug + 'a>(
209+
fn print_gauge_data_points<'a, T: Debug + Copy + 'a>(
210210
data_points: impl Iterator<Item = &'a GaugeDataPoint<T>>,
211211
) {
212212
for (i, data_point) in data_points.enumerate() {
213213
println!("\t\tDataPoint #{}", i);
214-
println!("\t\t\tValue : {:#?}", data_point.value);
214+
println!("\t\t\tValue : {:#?}", data_point.value());
215215
println!("\t\t\tAttributes :");
216216
for kv in data_point.attributes() {
217217
println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str());
218218
}
219219
}
220220
}
221221

222-
fn print_hist_data_points<'a, T: Debug + 'a>(
222+
fn print_hist_data_points<'a, T: Debug + Copy + 'a>(
223223
data_points: impl Iterator<Item = &'a HistogramDataPoint<T>>,
224224
) {
225225
for (i, data_point) in data_points.enumerate() {
226226
println!("\t\tDataPoint #{}", i);
227227
println!("\t\t\tCount : {}", data_point.count());
228228
println!("\t\t\tSum : {:?}", data_point.sum());
229-
if let Some(min) = &data_point.min {
229+
if let Some(min) = &data_point.min() {
230230
println!("\t\t\tMin : {:?}", min);
231231
}
232232

233-
if let Some(max) = &data_point.max {
233+
if let Some(max) = &data_point.max() {
234234
println!("\t\t\tMax : {:?}", max);
235235
}
236236

0 commit comments

Comments
 (0)