@@ -88,16 +88,19 @@ def add(self, val):
8888 with self ._value_lock :
8989 self .value += val
9090
91+ def _set (self , val ):
92+ if not isinstance (val , six .integer_types ):
93+ raise ValueError ("GaugePointLong only supports integer types" )
94+ with self ._value_lock :
95+ self .value = val
96+
9197 def set (self , val ):
9298 """Set the current value to `val`.
9399
94100 :type val: int
95101 :param val: Value to set.
96102 """
97- if not isinstance (val , six .integer_types ):
98- raise ValueError ("GaugePointLong only supports integer types" )
99- with self ._value_lock :
100- self .value = val
103+ self ._set (val )
101104
102105 def get_value (self ):
103106 """Get the current value.
@@ -143,14 +146,17 @@ def add(self, val):
143146 with self ._value_lock :
144147 self .value += val
145148
149+ def _set (self , val ):
150+ with self ._value_lock :
151+ self .value = float (val )
152+
146153 def set (self , val ):
147154 """Set the current value to `val`.
148155
149156 :type val: float
150157 :param val: Value to set.
151158 """
152- with self ._value_lock :
153- self .value = float (val )
159+ self ._set (val )
154160
155161 def get_value (self ):
156162 """Get the current value.
@@ -180,7 +186,9 @@ class DerivedGaugePoint(GaugePoint):
180186 :type func: function
181187 :param func: The function to track.
182188
183- :type gauge_point: :class:`GaugePointLong` or :class:`GaugePointDouble`
189+ :type gauge_point: :class:`GaugePointLong`, :class:`GaugePointDouble`,
190+ :class:`opencensus.metrics.export.cumulative.CumulativePointLong`, or
191+ :class:`opencensus.metrics.export.cumulative.CumulativePointDouble`
184192 :param gauge_point: The underlying `GaugePoint`.
185193 """
186194 def __init__ (self , func , gauge_point ):
@@ -202,13 +210,14 @@ def get_value(self):
202210
203211 :rtype: int, float, or None
204212 :return: The current value of the wrapped function, or `None` if it no
205- longer exists.
213+ longer exists.
206214 """
207215 try :
208- self .gauge_point .set (self .func ()())
209- # The underlying function has been GC'd
210- except TypeError :
216+ val = self .func ()()
217+ except TypeError : # The underlying function has been GC'd
211218 return None
219+
220+ self .gauge_point ._set (val )
212221 return self .gauge_point .get_value ()
213222
214223 def to_point_value (self ):
@@ -218,9 +227,9 @@ def to_point_value(self):
218227 measurement as a side-effect.
219228
220229 :rtype: :class:`opencensus.metrics.export.value.ValueLong`,
221- :class:`opencensus.metrics.export.value.ValueDouble`, or None
230+ :class:`opencensus.metrics.export.value.ValueDouble`, or None
222231 :return: The point value conversion of the underlying `GaugePoint`, or
223- None if the tracked function no longer exists.
232+ None if the tracked function no longer exists.
224233 """
225234 if self .get_value () is None :
226235 return None
@@ -309,7 +318,9 @@ def point_type(self): # pragma: NO COVER
309318class Gauge (BaseGauge ):
310319 """A set of mutable, instantaneous measurements of the same type.
311320
312- End users should use :class:`LongGauge` or :class:`DoubleGauge` instead of
321+ End users should use :class:`LongGauge`, :class:`DoubleGauge`,
322+ :class:`opencensus.metrics.export.cumulative.LongCumulative`, or
323+ :class:`opencensus.metrics.export.cumulative.DoubleCumulative` instead of
313324 using this class directly.
314325
315326 The constructor arguments are used to create a
@@ -328,9 +339,12 @@ def get_or_create_time_series(self, label_values):
328339 :type label_values: list(:class:`LabelValue`)
329340 :param label_values: The measurement's label values.
330341
331- :rtype: :class:`GaugePointLong` or :class:`GaugePointDouble`
342+ :rtype: :class:`GaugePointLong`, :class:`GaugePointDouble`
343+ :class:`opencensus.metrics.export.cumulative.CumulativePointLong`,
344+ or
345+ :class:`opencensus.metrics.export.cumulative.CumulativePointDouble`
332346 :return: A mutable point that represents the last value of the
333- measurement.
347+ measurement.
334348 """
335349 if label_values is None :
336350 raise ValueError
@@ -347,9 +361,12 @@ def get_or_create_default_time_series(self):
347361 values. When this gauge is exported as a metric via `get_metric` the
348362 time series associated with this point will have null label values.
349363
350- :rtype: :class:`GaugePointLong` or :class:`GaugePointDouble`
364+ :rtype: :class:`GaugePointLong`, :class:`GaugePointDouble`
365+ :class:`opencensus.metrics.export.cumulative.CumulativePointLong`,
366+ or
367+ :class:`opencensus.metrics.export.cumulative.CumulativePointDouble`
351368 :return: A mutable point that represents the last value of the
352- measurement.
369+ measurement.
353370 """
354371 return self ._get_or_create_time_series (self .default_label_values )
355372
@@ -380,8 +397,10 @@ class DerivedGauge(BaseGauge):
380397 Each of a `DerivedGauge`'s measurements are associated with a function
381398 which is called when the gauge is exported.
382399
383- End users should use :class:`DerivedLongGauge` or
384- :class:`DerivedDoubleGauge` instead of using this class directly.
400+ End users should use :class:`DerivedLongGauge`, :class:`DerivedDoubleGauge`
401+ :class:`opencensus.metrics.export.cumulative.DerivedLongCumulative`, or
402+ :class:`opencensus.metrics.export.cumulative.DerivedDoubleCumulative`
403+ instead of using this class directly.
385404 """
386405
387406 def _create_time_series (self , label_values , func ):
@@ -452,18 +471,19 @@ def __repr__(self):
452471 ))
453472
454473 def add_gauge (self , gauge ):
455- """Add `gauge` to the registry and return it .
474+ """Add `gauge` to the registry.
456475
457476 Raises a `ValueError` if another gauge with the same name already
458477 exists in the registry.
459478
460479 :type gauge: class:`LongGauge`, class:`DoubleGauge`,
461- :class:`DerivedLongGauge`, or :class:`DerivedDoubleGauge`
480+ :class:`opencensus.metrics.export.cumulative.LongCumulative`,
481+ :class:`opencensus.metrics.export.cumulative.DoubleCumulative`,
482+ :class:`DerivedLongGauge`, :class:`DerivedDoubleGauge`
483+ :class:`opencensus.metrics.export.cumulative.DerivedLongCumulative`,
484+ or
485+ :class:`opencensus.metrics.export.cumulative.DerivedDoubleCumulative`
462486 :param gauge: The gauge to add to the registry.
463-
464- :type gauge: class:`LongGauge`, class:`DoubleGauge`,
465- :class:`DerivedLongGauge`, or :class:`DerivedDoubleGauge`
466- :return: The gauge that was added to the registry.
467487 """
468488 if gauge is None :
469489 raise ValueError
0 commit comments