27
27
28
28
"""
29
29
from abc import ABC , abstractmethod
30
- from enum import Enum
31
- from typing import List , Union
30
+ from typing import Dict , List , Tuple , Type , Union
32
31
33
- from opentelemetry .metrics .time_series import (
34
- CounterTimeSeries ,
35
- GaugeTimeSeries ,
36
- MeasureTimeSeries ,
32
+ from opentelemetry .metrics .handle import (
33
+ CounterHandle ,
34
+ GaugeHandle ,
35
+ MeasureHandle ,
37
36
)
38
37
from opentelemetry .trace import SpanContext
39
38
@@ -47,19 +46,30 @@ class Meter:
47
46
for the exported metric are deferred.
48
47
"""
49
48
50
- # TODO: RecordBatch
49
+ def record_batch (
50
+ self ,
51
+ label_tuples : Dict [str , str ],
52
+ record_tuples : List [Tuple ["Metric" , Union [float , int ]]],
53
+ ) -> None :
54
+ """Atomically records a batch of `Metric` and value pairs.
51
55
56
+ Allows the functionality of acting upon multiple metrics with
57
+ a single API call. Implementations should find handles that match
58
+ the key-value pairs in the label tuples.
52
59
53
- class ValueType (Enum ):
54
- FLOAT = 0
55
- INT = 1
60
+ Args:
61
+ label_tuples: A collection of key value pairs that will be matched
62
+ against to record for the metric-handle that has those labels.
63
+ record_tuples: A list of pairs of `Metric` s and the
64
+ corresponding value to record for that metric.
65
+ """
56
66
57
67
58
68
def create_counter (
59
69
name : str ,
60
70
description : str ,
61
71
unit : str ,
62
- value_type : "ValueType" ,
72
+ value_type : Union [ Type [ float ], Type [ int ]] ,
63
73
is_bidirectional : bool = False ,
64
74
label_keys : List [str ] = None ,
65
75
span_context : SpanContext = None ,
@@ -91,7 +101,7 @@ def create_gauge(
91
101
name : str ,
92
102
description : str ,
93
103
unit : str ,
94
- value_type : "ValueType" ,
104
+ value_type : Union [ Type [ float ], Type [ int ]] ,
95
105
is_unidirectional : bool = False ,
96
106
label_keys : List [str ] = None ,
97
107
span_context : SpanContext = None ,
@@ -122,7 +132,7 @@ def create_measure(
122
132
name : str ,
123
133
description : str ,
124
134
unit : str ,
125
- value_type : "ValueType" ,
135
+ value_type : Union [ Type [ float ], Type [ int ]] ,
126
136
is_non_negative : bool = False ,
127
137
label_keys : List [str ] = None ,
128
138
span_context : SpanContext = None ,
@@ -157,82 +167,71 @@ class Metric(ABC):
157
167
"""
158
168
159
169
@abstractmethod
160
- def get_or_create_time_series (self , label_values : List [str ]) -> "object" :
161
- """Gets a timeseries , used for repeated-use of metrics instruments.
170
+ def get_handle (self , label_values : List [str ]) -> "object" :
171
+ """Gets a handle , used for repeated-use of metrics instruments.
162
172
163
- If the provided label values are not already associated with this
164
- metric, a new timeseries is returned, otherwise it returns the existing
165
- timeseries with the exact label values. The timeseries returned
166
- contains logic and behaviour specific to the type of metric that
167
- overrides this function.
173
+ Handles are useful to reduce the cost of repeatedly recording a metric
174
+ with a pre-defined set of label values. All metric kinds (counter,
175
+ gauge, measure) support declaring a set of required label keys. The
176
+ values corresponding to these keys should be specified in every handle.
177
+ "Unspecified" label values, in cases where a handle is requested but
178
+ a value was not provided are permitted.
168
179
169
180
Args:
170
181
label_values: A list of label values that will be associated
171
- with the return timeseries .
182
+ with the return handle .
172
183
"""
173
184
174
- def remove_time_series (self , label_values : List [str ]) -> None :
175
- """Removes the timeseries from the Metric, if present.
185
+ def remove_handle (self , label_values : List [str ]) -> None :
186
+ """Removes the handle from the Metric, if present.
176
187
177
- The timeseries with matching label values will be removed.
188
+ The handle with matching label values will be removed.
178
189
179
190
args:
180
191
label_values: The list of label values to match against.
181
192
"""
182
193
183
194
def clear (self ) -> None :
184
- """Removes all timeseries from the `Metric`."""
195
+ """Removes all handles from the `Metric`."""
185
196
186
197
187
198
class FloatCounter (Metric ):
188
199
"""A counter type metric that holds float values."""
189
200
190
- def get_or_create_time_series (
191
- self , label_values : List [str ]
192
- ) -> "CounterTimeSeries" :
193
- """Gets a `CounterTimeSeries` with a float value."""
201
+ def get_handle (self , label_values : List [str ]) -> "CounterHandle" :
202
+ """Gets a `CounterHandle` with a float value."""
194
203
195
204
196
205
class IntCounter (Metric ):
197
206
"""A counter type metric that holds int values."""
198
207
199
- def get_or_create_time_series (
200
- self , label_values : List [str ]
201
- ) -> "CounterTimeSeries" :
202
- """Gets a `CounterTimeSeries` with an int value."""
208
+ def get_handle (self , label_values : List [str ]) -> "CounterHandle" :
209
+ """Gets a `CounterHandle` with an int value."""
203
210
204
211
205
212
class FloatGauge (Metric ):
206
213
"""A gauge type metric that holds float values."""
207
214
208
- def get_or_create_time_series (
209
- self , label_values : List [str ]
210
- ) -> "GaugeTimeSeries" :
211
- """Gets a `GaugeTimeSeries` with a float value."""
215
+ def get_handle (self , label_values : List [str ]) -> "GaugeHandle" :
216
+ """Gets a `GaugeHandle` with a float value."""
212
217
213
218
214
219
class IntGauge (Metric ):
215
220
"""A gauge type metric that holds int values."""
216
221
217
- def get_or_create_time_series (
218
- self , label_values : List [str ]
219
- ) -> "GaugeTimeSeries" :
220
- """Gets a `GaugeTimeSeries` with an int value."""
222
+ def get_handle (self , label_values : List [str ]) -> "GaugeHandle" :
223
+ """Gets a `GaugeHandle` with an int value."""
221
224
222
225
223
226
class FloatMeasure (Metric ):
224
227
"""A measure type metric that holds float values."""
225
228
226
- def get_or_create_time_series (
227
- self , label_values : List [str ]
228
- ) -> "MeasureTimeSeries" :
229
- """Gets a `MeasureTimeSeries` with a float value."""
229
+ def get_handle (self , label_values : List [str ]) -> "MeasureHandle" :
230
+ """Gets a `MeasureHandle` with a float value."""
230
231
231
232
232
233
class IntMeasure (Metric ):
233
234
"""A measure type metric that holds int values."""
234
235
235
- def get_or_create_time_series (
236
- self , label_values : List [str ]
237
- ) -> "MeasureTimeSeries" :
238
- """Gets a `MeasureTimeSeries` with an int value."""
236
+ def get_handle (self , label_values : List [str ]) -> "MeasureHandle" :
237
+ """Gets a `MeasureHandle` with an int value."""
0 commit comments