Skip to content

Commit e4e8c20

Browse files
committed
nits
1 parent b158e59 commit e4e8c20

File tree

3 files changed

+25
-43
lines changed

3 files changed

+25
-43
lines changed

docs/examples/exemplars/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ and they may focus on measurements with abnormally high/low values.
4545
.. literalinclude:: trace_exemplars.py
4646
:language: python
4747
:lines: 1-
48+
4849
Currently only the Google Cloud Monitoring exporter supports uploading these exemplars.

opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/aggregate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, config=None):
4242
self.config = config
4343
else:
4444
self.config = {}
45-
self.checkpoint_exemplars = list()
45+
self.checkpoint_exemplars = []
4646

4747
@abc.abstractmethod
4848
def update(self, value, dropped_labels=None):

opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/exemplars.py

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,23 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""
16-
Exemplars are sample data points for aggregators. For more information, see the `spec <https://github.com/open-telemetry/oteps/pull/113>`_
15+
"""Exemplars are sample data points for aggregators. For more information, see the `spec <https://github.com/open-telemetry/oteps/pull/113>`_
1716
18-
Every synchronous aggregator is instrumented with two exemplar recorders:
19-
1. A "trace" exemplar sampler, which only samples exemplars if they have a sampled trace context (and can pick exemplars with other biases, ie min + max).
20-
2. A "statistical" exemplar sampler, which samples exemplars without bias (ie no preferenced for traced exemplars)
17+
Every synchronous aggregator is instrumented with two exemplar recorders:
18+
1. A "trace" exemplar sampler, which only samples exemplars if they have a sampled trace context (and can pick exemplars with other biases, ie min + max).
19+
2. A "statistical" exemplar sampler, which samples exemplars without bias (ie no preferenced for traced exemplars)
2120
22-
To use an exemplar recorder, pass in two arguments to the aggregator config in views (see the :ref:`Exemplars` example for an example):
23-
"num_exemplars": The number of exemplars to record (if applicable, in each bucket). Note that in non-statistical mode the recorder may not use "num_exemplars"
24-
"statistical_exemplars": If exemplars should be recorded statistically
21+
To use an exemplar recorder, pass in two arguments to the aggregator config in views (see the :ref:`Exemplars` example for an example):
22+
"num_exemplars": The number of exemplars to record (if applicable, in each bucket). Note that in non-statistical mode the recorder may not use "num_exemplars"
23+
"statistical_exemplars": If exemplars should be recorded statistically
2524
26-
For exemplars to be recorded, `num_exemplars` must be greater than 0.
25+
For exemplars to be recorded, `num_exemplars` must be greater than 0.
2726
"""
2827

2928
import abc
3029
import itertools
3130
import random
32-
from typing import List, Optional, Tuple, Union
31+
from typing import List, Optional, Tuple, Type, Union
3332

3433
from opentelemetry.context import get_current
3534
from opentelemetry.util import time_ns
@@ -95,7 +94,8 @@ def sample_count(self):
9594
"""For statistical exemplars, how many measurements a single exemplar represents"""
9695
return self._sample_count
9796

98-
def set_sample_count(self, count: float):
97+
@sample_count.setter
98+
def sample_count(self, count: float):
9999
self._sample_count = count
100100

101101

@@ -122,11 +122,14 @@ def sample_set(self):
122122
Return the list of exemplars that have been sampled
123123
"""
124124

125-
@abc.abstractmethod
126125
def merge(self, set1: List[Exemplar], set2: List[Exemplar]):
127126
"""
128-
Given two lists of sampled exemplars, merge them while maintaining the invariants specified by this sampler
127+
Assume that set2 is the latest set of exemplars.
128+
For simplicity, we will just keep set2 and assume set1 has already been exported.
129+
This may need to change with a different SDK implementation.
129130
"""
131+
#pylint: disable=unused-argument,no-self-use
132+
return set2
130133

131134
@abc.abstractmethod
132135
def reset(self):
@@ -162,14 +165,6 @@ def sample(self, exemplar: Exemplar, **kwargs):
162165
if replace_index < self._k:
163166
self._sample_set[replace_index] = exemplar
164167

165-
def merge(self, set1: List[Exemplar], set2: List[Exemplar]):
166-
"""
167-
Assume that set2 is the latest set of exemplars.
168-
For simplicity, we will just keep set2 and assume set1 has already been exported.
169-
This may need to change with a different SDK implementation.
170-
"""
171-
return set2
172-
173168
@property
174169
def sample_set(self):
175170
if self._statistical:
@@ -212,14 +207,6 @@ def sample(self, exemplar: Exemplar, **kwargs):
212207
def sample_set(self):
213208
return self._sample_set
214209

215-
def merge(self, set1: List[Exemplar], set2: List[Exemplar]):
216-
"""
217-
Assume that set2 is the latest set of exemplars.
218-
For simplicity, we will just keep set2 and assume set1 has already been exported.
219-
This may need to change with a different SDK implementation.
220-
"""
221-
return set2
222-
223210
def reset(self):
224211
self._sample_set = []
225212

@@ -233,7 +220,7 @@ class BucketedExemplarSampler(ExemplarSampler):
233220
"""
234221

235222
def __init__(
236-
self, k: int, statistical: bool = False, boundaries: list = None
223+
self, k: int, statistical: bool = False, boundaries: List[float] = None
237224
):
238225
super().__init__(k)
239226
self._boundaries = boundaries
@@ -242,7 +229,9 @@ def __init__(
242229
for _ in range(len(self._boundaries) + 1)
243230
]
244231

245-
def sample(self, exemplar: Exemplar, **kwargs):
232+
def sample(
233+
self, exemplar: Exemplar, **kwargs
234+
):
246235
bucket_index = kwargs.get("bucket_index")
247236
if bucket_index is None:
248237
return
@@ -253,18 +242,10 @@ def sample(self, exemplar: Exemplar, **kwargs):
253242
def sample_set(self):
254243
return list(
255244
itertools.chain.from_iterable(
256-
[sampler.sample_set for sampler in self._sample_set]
245+
sampler.sample_set for sampler in self._sample_set
257246
)
258247
)
259248

260-
def merge(self, set1: List[Exemplar], set2: List[Exemplar]):
261-
"""
262-
Assume that set2 is the latest set of exemplars.
263-
For simplicity, we will just keep set2 and assume set1 has already been exported.
264-
This may need to change with a different SDK implementation.
265-
"""
266-
return set2
267-
268249
def reset(self):
269250
for sampler in self._sample_set:
270251
sampler.reset()
@@ -280,8 +261,8 @@ class ExemplarManager:
280261
def __init__(
281262
self,
282263
config: dict,
283-
default_exemplar_sampler: ExemplarSampler,
284-
statistical_exemplar_sampler: ExemplarSampler,
264+
default_exemplar_sampler: Type[ExemplarSampler],
265+
statistical_exemplar_sampler: Type[ExemplarSampler],
285266
**kwargs
286267
):
287268
if config:

0 commit comments

Comments
 (0)