Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit b63e927

Browse files
authored
Fix Metric repr for ValueDistributions (#559)
1 parent e33d8ea commit b63e927

3 files changed

Lines changed: 41 additions & 18 deletions

File tree

opencensus/metrics/export/metric.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,10 @@ def __init__(self, descriptor, time_series):
4343
self._check_type()
4444

4545
def __repr__(self):
46-
# Get a condensed description of a list of time series like:
47-
# (k1="v11", k2="v21", [12]), (k1="v21", k2="v22", [34])
48-
lks = [lk.key for lk in self.descriptor.label_keys]
49-
labeled_pvs = []
50-
for ts in self.time_series:
51-
labels = ", ".join('{}="{}"'.format(lk, lv)
52-
for lk, lv in zip(lks, ts.label_values))
53-
pvs = [point.value.value if point.value else None
54-
for point in ts.points]
55-
labeled_pvs.append((labels, pvs))
56-
short_ts_repr = ", ".join("({}, {})".format(ll, pvs)
57-
for ll, pvs in labeled_pvs)
58-
59-
# E.g. 'Metric((k1="v11", k2="v21", [12]), descriptor.name="name")'
60-
return ('{}({}, descriptor.name="{}")'
46+
return ('{}(time_series={}, descriptor.name="{}")'
6147
.format(
6248
type(self).__name__,
63-
short_ts_repr,
49+
"<{} TimeSeries>".format(len(self.time_series)),
6450
self.descriptor.name,
6551
))
6652

opencensus/metrics/export/time_series.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ def __init__(self, label_values, points, start_timestamp):
4747
self._start_timestamp = start_timestamp
4848

4949
def __repr__(self):
50+
points_repr = '[{}]'.format(
51+
', '.join(repr(point.value) for point in self.points))
52+
53+
lv_repr = tuple(lv.value for lv in self.label_values)
5054
return ('{}({}, label_values={}, start_timestamp={})'
5155
.format(
5256
type(self).__name__,
53-
[point.value.value for point in self.points],
54-
self.label_values,
57+
points_repr,
58+
lv_repr,
5559
self.start_timestamp
5660
))
5761

opencensus/metrics/export/value.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ def __init__(self, value, timestamp, attachments):
110110
self._timestamp = timestamp
111111
self._attachments = attachments
112112

113+
def __repr__(self):
114+
return ("{}({})"
115+
.format(
116+
type(self).__name__,
117+
self.value,
118+
))
119+
113120
@property
114121
def value(self):
115122
return self._value
@@ -138,6 +145,13 @@ def __init__(self, count, exemplar=None):
138145
self._count = count
139146
self._exemplar = exemplar
140147

148+
def __repr__(self):
149+
return ("{}({})"
150+
.format(
151+
type(self).__name__,
152+
self.count,
153+
))
154+
141155
@property
142156
def count(self):
143157
return self._count
@@ -186,6 +200,13 @@ class BucketOptions(object):
186200
def __init__(self, type_=None):
187201
self._type = type_
188202

203+
def __repr__(self):
204+
return ("{}({})"
205+
.format(
206+
type(self).__name__,
207+
self.type_,
208+
))
209+
189210
@property
190211
def type_(self):
191212
return self._type
@@ -253,6 +274,18 @@ def __init__(self,
253274
self._bucket_options = bucket_options
254275
self._buckets = buckets
255276

277+
def __repr__(self):
278+
try:
279+
bounds = self.bucket_options.type_.bounds,
280+
except AttributeError:
281+
bounds = None
282+
283+
return ("{}({})"
284+
.format(
285+
type(self).__name__,
286+
bounds
287+
))
288+
256289
@property
257290
def count(self):
258291
return self._count

0 commit comments

Comments
 (0)