37
37
ValueT = TypeVar ("ValueT" , int , float )
38
38
39
39
40
- class DefaultMetricHandle :
41
- """The default MetricHandle .
40
+ class DefaultBoundInstrument :
41
+ """The default bound metric instrument .
42
42
43
- Used when no MetricHandle implementation is available.
43
+ Used when no bound instrument implementation is available.
44
44
"""
45
45
46
46
def add (self , value : ValueT ) -> None :
47
- """No-op implementation of `CounterHandle ` add.
47
+ """No-op implementation of `BoundCounter ` add.
48
48
49
49
Args:
50
- value: The value to add to the handle .
50
+ value: The value to add to the bound metric instrument .
51
51
"""
52
52
53
53
def record (self , value : ValueT ) -> None :
54
- """No-op implementation of `MeasureHandle ` record.
54
+ """No-op implementation of `BoundMeasure ` record.
55
55
56
56
Args:
57
- value: The value to record to the handle .
57
+ value: The value to record to the bound metric instrument .
58
58
"""
59
59
60
60
61
- class CounterHandle :
61
+ class BoundCounter :
62
62
def add (self , value : ValueT ) -> None :
63
- """Increases the value of the handle by ``value``.
63
+ """Increases the value of the bound counter by ``value``.
64
64
65
65
Args:
66
- value: The value to add to the handle .
66
+ value: The value to add to the bound counter .
67
67
"""
68
68
69
69
70
- class MeasureHandle :
70
+ class BoundMeasure :
71
71
def record (self , value : ValueT ) -> None :
72
- """Records the given ``value`` to this handle .
72
+ """Records the given ``value`` to this bound measure .
73
73
74
74
Args:
75
- value: The value to record to the handle .
75
+ value: The value to record to the bound measure .
76
76
"""
77
77
78
78
79
79
class LabelSet (abc .ABC ):
80
80
"""A canonicalized set of labels useful for preaggregation
81
81
82
82
Re-usable LabelSet objects provide a potential optimization for scenarios
83
- where handles might not be effective. For example, if the LabelSet will be
84
- re-used but only used once per metrics, handles do not offer any
85
- optimization. It may best to pre-compute a canonicalized LabelSet once and
86
- re-use it with the direct calling convention. LabelSets are immutable and
87
- should be opaque in implementation.
83
+ where bound metric instruments might not be effective. For example, if the
84
+ LabelSet will be re-used but only used once per metrics, bound metric
85
+ instruments do not offer any optimization. It may best to pre-compute a
86
+ canonicalized LabelSet once and re-use it with the direct calling
87
+ convention. LabelSets are immutable and should be opaque in implementation.
88
88
"""
89
89
90
90
@@ -99,66 +99,67 @@ class Metric(abc.ABC):
99
99
"""Base class for various types of metrics.
100
100
101
101
Metric class that inherit from this class are specialized with the type of
102
- handle that the metric holds.
102
+ bound metric instrument that the metric holds.
103
103
"""
104
104
105
105
@abc .abstractmethod
106
- def get_handle (self , label_set : LabelSet ) -> "object" :
107
- """Gets a handle, used for repeated-use of metrics instruments .
106
+ def bind (self , label_set : LabelSet ) -> "object" :
107
+ """Gets a bound metric instrument .
108
108
109
- Handles are useful to reduce the cost of repeatedly recording a metric
110
- with a pre-defined set of label values. All metric kinds (counter,
111
- measure) support declaring a set of required label keys. The
112
- values corresponding to these keys should be specified in every handle.
113
- "Unspecified" label values, in cases where a handle is requested but
114
- a value was not provided are permitted.
109
+ Bound metric instruments are useful to reduce the cost of repeatedly
110
+ recording a metric with a pre-defined set of label values. All metric
111
+ kinds (counter, measure) support declaring a set of required label
112
+ keys. The values corresponding to these keys should be specified in
113
+ every bound metric instrument. "Unspecified" label values, in cases
114
+ where a bound metric instrument is requested but a value was not
115
+ provided are permitted.
115
116
116
117
Args:
117
- label_set: `LabelSet` to associate with the returned handle .
118
+ label_set: `LabelSet` to associate with the bound instrument .
118
119
"""
119
120
120
121
121
122
class DefaultMetric (Metric ):
122
123
"""The default Metric used when no Metric implementation is available."""
123
124
124
- def get_handle (self , label_set : LabelSet ) -> "DefaultMetricHandle " :
125
- """Gets a `DefaultMetricHandle `.
125
+ def bind (self , label_set : LabelSet ) -> "DefaultBoundInstrument " :
126
+ """Gets a `DefaultBoundInstrument `.
126
127
127
128
Args:
128
- label_set: `LabelSet` to associate with the returned handle .
129
+ label_set: `LabelSet` to associate with the bound instrument .
129
130
"""
130
- return DefaultMetricHandle ()
131
+ return DefaultBoundInstrument ()
131
132
132
133
def add (self , value : ValueT , label_set : LabelSet ) -> None :
133
134
"""No-op implementation of `Counter` add.
134
135
135
136
Args:
136
137
value: The value to add to the counter metric.
137
- label_set: `LabelSet` to associate with the returned handle .
138
+ label_set: `LabelSet` to associate with the bound instrument .
138
139
"""
139
140
140
141
def record (self , value : ValueT , label_set : LabelSet ) -> None :
141
142
"""No-op implementation of `Measure` record.
142
143
143
144
Args:
144
145
value: The value to record to this measure metric.
145
- label_set: `LabelSet` to associate with the returned handle .
146
+ label_set: `LabelSet` to associate with the bound instrument .
146
147
"""
147
148
148
149
149
150
class Counter (Metric ):
150
151
"""A counter type metric that expresses the computation of a sum."""
151
152
152
- def get_handle (self , label_set : LabelSet ) -> "CounterHandle " :
153
- """Gets a `CounterHandle `."""
154
- return CounterHandle ()
153
+ def bind (self , label_set : LabelSet ) -> "BoundCounter " :
154
+ """Gets a `BoundCounter `."""
155
+ return BoundCounter ()
155
156
156
157
def add (self , value : ValueT , label_set : LabelSet ) -> None :
157
158
"""Increases the value of the counter by ``value``.
158
159
159
160
Args:
160
161
value: The value to add to the counter metric.
161
- label_set: `LabelSet` to associate with the returned handle .
162
+ label_set: `LabelSet` to associate with the returned bound counter .
162
163
"""
163
164
164
165
@@ -168,21 +169,22 @@ class Measure(Metric):
168
169
Measure metrics represent raw statistics that are recorded.
169
170
"""
170
171
171
- def get_handle (self , label_set : LabelSet ) -> "MeasureHandle " :
172
- """Gets a `MeasureHandle` with a float value ."""
173
- return MeasureHandle ()
172
+ def bind (self , label_set : LabelSet ) -> "BoundMeasure " :
173
+ """Gets a `BoundMeasure` ."""
174
+ return BoundMeasure ()
174
175
175
176
def record (self , value : ValueT , label_set : LabelSet ) -> None :
176
177
"""Records the ``value`` to the measure.
177
178
178
179
Args:
179
180
value: The value to record to this measure metric.
180
- label_set: `LabelSet` to associate with the returned handle .
181
+ label_set: `LabelSet` to associate with the returned bound measure .
181
182
"""
182
183
183
184
184
185
class Observer (abc .ABC ):
185
- """An observer type metric instrument used to capture a current set of values.
186
+ """An observer type metric instrument used to capture a current set of
187
+ values.
186
188
187
189
188
190
Observer instruments are asynchronous, a callback is invoked with the
@@ -283,16 +285,15 @@ def record_batch(
283
285
) -> None :
284
286
"""Atomically records a batch of `Metric` and value pairs.
285
287
286
- Allows the functionality of acting upon multiple metrics with
287
- a single API call. Implementations should find metric and handles that
288
- match the key-value pairs in the label tuples .
288
+ Allows the functionality of acting upon multiple metrics with a single
289
+ API call. Implementations should find bound metric instruments that
290
+ match the key-value pairs in the labelset .
289
291
290
- Args:
291
- label_set: The `LabelSet` associated with all measurements in
292
- the batch. A measurement is a tuple, representing the `Metric`
293
- being recorded and the corresponding value to record.
294
- record_tuples: A sequence of pairs of `Metric` s and the
295
- corresponding value to record for that metric.
292
+ Args: label_set: The `LabelSet` associated with all measurements in the
293
+ batch. A measurement is a tuple, representing the `Metric` being
294
+ recorded and the corresponding value to record. record_tuples: A
295
+ sequence of pairs of `Metric` s and the corresponding value to
296
+ record for that metric.
296
297
"""
297
298
298
299
@abc .abstractmethod
0 commit comments