Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xrmx authored and fcollonval committed Nov 6, 2024
1 parent c2d85c0 commit de27bbc
Showing 1 changed file with 160 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as OTLPResource,
)
from opentelemetry.sdk.metrics import Exemplar
from opentelemetry.sdk.metrics.export import (
AggregationTemporality,
Buckets,
Expand All @@ -55,6 +56,9 @@


class TestOTLPMetricsEncoder(unittest.TestCase):
span_id = int("6e0c63257de34c92", 16)
trace_id = int("d4cda95b652f4a1592b449d5929fda1b", 16)

histogram = Metric(
name="histogram",
description="foo",
Expand All @@ -65,6 +69,22 @@ class TestOTLPMetricsEncoder(unittest.TestCase):
attributes={"a": 1, "b": True},
start_time_unix_nano=1641946016139533244,
time_unix_nano=1641946016139533244,
exemplars=[
Exemplar(
{"filtered": "banana"},
298.0,
1641946016139533400,
span_id,
trace_id,
),
Exemplar(
{"filtered": "banana"},
298.0,
1641946016139533400,
None,
None,
),
],
count=5,
sum=67,
bucket_counts=[1, 4],
Expand Down Expand Up @@ -460,7 +480,34 @@ def test_encode_histogram(self):
sum=67,
bucket_counts=[1, 4],
explicit_bounds=[10.0, 20.0],
exemplars=[],
exemplars=[
pb2.Exemplar(
time_unix_nano=1641946016139533400,
as_double=298,
span_id=b"n\x0cc%}\xe3L\x92",
trace_id=b"\xd4\xcd\xa9[e/J\x15\x92\xb4I\xd5\x92\x9f\xda\x1b",
filtered_attributes=[
KeyValue(
key="filtered",
value=AnyValue(
string_value="banana"
),
)
],
),
pb2.Exemplar(
time_unix_nano=1641946016139533400,
as_double=298,
filtered_attributes=[
KeyValue(
key="filtered",
value=AnyValue(
string_value="banana"
),
)
],
),
],
max=18.0,
min=8.0,
)
Expand Down Expand Up @@ -563,7 +610,34 @@ def test_encode_multiple_scope_histogram(self):
sum=67,
bucket_counts=[1, 4],
explicit_bounds=[10.0, 20.0],
exemplars=[],
exemplars=[
pb2.Exemplar(
time_unix_nano=1641946016139533400,
as_double=298,
span_id=b"n\x0cc%}\xe3L\x92",
trace_id=b"\xd4\xcd\xa9[e/J\x15\x92\xb4I\xd5\x92\x9f\xda\x1b",
filtered_attributes=[
KeyValue(
key="filtered",
value=AnyValue(
string_value="banana"
),
)
],
),
pb2.Exemplar(
time_unix_nano=1641946016139533400,
as_double=298,
filtered_attributes=[
KeyValue(
key="filtered",
value=AnyValue(
string_value="banana"
),
)
],
),
],
max=18.0,
min=8.0,
)
Expand Down Expand Up @@ -598,7 +672,34 @@ def test_encode_multiple_scope_histogram(self):
sum=67,
bucket_counts=[1, 4],
explicit_bounds=[10.0, 20.0],
exemplars=[],
exemplars=[
pb2.Exemplar(
time_unix_nano=1641946016139533400,
as_double=298,
span_id=b"n\x0cc%}\xe3L\x92",
trace_id=b"\xd4\xcd\xa9[e/J\x15\x92\xb4I\xd5\x92\x9f\xda\x1b",
filtered_attributes=[
KeyValue(
key="filtered",
value=AnyValue(
string_value="banana"
),
)
],
),
pb2.Exemplar(
time_unix_nano=1641946016139533400,
as_double=298,
filtered_attributes=[
KeyValue(
key="filtered",
value=AnyValue(
string_value="banana"
),
)
],
),
],
max=18.0,
min=8.0,
)
Expand Down Expand Up @@ -640,7 +741,34 @@ def test_encode_multiple_scope_histogram(self):
sum=67,
bucket_counts=[1, 4],
explicit_bounds=[10.0, 20.0],
exemplars=[],
exemplars=[
pb2.Exemplar(
time_unix_nano=1641946016139533400,
as_double=298,
span_id=b"n\x0cc%}\xe3L\x92",
trace_id=b"\xd4\xcd\xa9[e/J\x15\x92\xb4I\xd5\x92\x9f\xda\x1b",
filtered_attributes=[
KeyValue(
key="filtered",
value=AnyValue(
string_value="banana"
),
)
],
),
pb2.Exemplar(
time_unix_nano=1641946016139533400,
as_double=298,
filtered_attributes=[
KeyValue(
key="filtered",
value=AnyValue(
string_value="banana"
),
)
],
),
],
max=18.0,
min=8.0,
)
Expand Down Expand Up @@ -682,7 +810,34 @@ def test_encode_multiple_scope_histogram(self):
sum=67,
bucket_counts=[1, 4],
explicit_bounds=[10.0, 20.0],
exemplars=[],
exemplars=[
pb2.Exemplar(
time_unix_nano=1641946016139533400,
as_double=298,
span_id=b"n\x0cc%}\xe3L\x92",
trace_id=b"\xd4\xcd\xa9[e/J\x15\x92\xb4I\xd5\x92\x9f\xda\x1b",
filtered_attributes=[
KeyValue(
key="filtered",
value=AnyValue(
string_value="banana"
),
)
],
),
pb2.Exemplar(
time_unix_nano=1641946016139533400,
as_double=298,
filtered_attributes=[
KeyValue(
key="filtered",
value=AnyValue(
string_value="banana"
),
)
],
),
],
max=18.0,
min=8.0,
)
Expand Down

0 comments on commit de27bbc

Please sign in to comment.