Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Exponential Histogram #2964

Merged
merged 50 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9580cf0
Bump werkzeug in /docs/examples/fork-process-model/flask-gunicorn (#3…
dependabot[bot] Feb 21, 2023
24ddca6
Refactor buckets interface
ocelotl Nov 29, 2022
e841dbd
Add missing test case
ocelotl Nov 30, 2022
26fbc9c
Remove wrong return
ocelotl Nov 30, 2022
6c9e1d0
Add comments
ocelotl Nov 30, 2022
159227c
Refactor object resetting
ocelotl Nov 30, 2022
863a24f
More fixes
ocelotl Nov 30, 2022
e86acac
Refactor exporting of buckets
ocelotl Nov 30, 2022
81a4f2a
Fix bug
ocelotl Nov 30, 2022
f81921d
Fix spelling
ocelotl Nov 30, 2022
daadb21
Update opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggr…
ocelotl Dec 6, 2022
7489dbf
Update opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggr…
ocelotl Dec 6, 2022
1991c97
Fix exception messages
ocelotl Dec 6, 2022
1937415
Remove scaling check
ocelotl Dec 6, 2022
168d14b
Fix typo
ocelotl Dec 6, 2022
7e64efe
Remove wrong instrument
ocelotl Dec 6, 2022
6345504
Update opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggr…
ocelotl Dec 6, 2022
ee9c41d
Add attribute setting lo lock scope
ocelotl Dec 8, 2022
673c6bf
Update opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/expo…
ocelotl Dec 8, 2022
6be38cc
Fix collect
ocelotl Dec 8, 2022
dd61e5b
Remove unreachable code
ocelotl Dec 8, 2022
6393111
Fix exporter test cases
ocelotl Dec 9, 2022
b220a64
Add comment
ocelotl Jan 2, 2023
0b9903c
Expand lock scope
ocelotl Jan 3, 2023
d1d1138
Revert "Expand lock scope"
ocelotl Jan 4, 2023
e79204d
Expand lock scope
ocelotl Jan 4, 2023
264fb49
Add min_max_size test case
ocelotl Jan 5, 2023
090cd96
Fix lint
ocelotl Jan 5, 2023
e28372b
Use properties for buckets attributes
ocelotl Jan 7, 2023
9001f38
Fix bug
ocelotl Jan 19, 2023
aa2aa90
Add comment
ocelotl Jan 19, 2023
305db85
WIP
ocelotl Jan 27, 2023
4a115bc
Reset values at the beginning of collect
ocelotl Feb 13, 2023
c9a735b
Merging WIP
ocelotl Feb 14, 2023
fda2cee
Add merge submethods
ocelotl Feb 14, 2023
42577a2
Refactor to use auxiliary methods
ocelotl Feb 15, 2023
48bee33
Add downscale method
ocelotl Feb 16, 2023
019883d
WIP
ocelotl Feb 16, 2023
ceed22e
Finish merge
ocelotl Feb 16, 2023
e48a1d8
Refactor storage of positive and negative WIP
ocelotl Feb 17, 2023
7c3e5cb
WIP
ocelotl Feb 21, 2023
bfb9fbf
Add test_merge_simple_event_test
ocelotl Feb 21, 2023
da2c89e
WIP
ocelotl Feb 21, 2023
f0cc7fd
WIP
ocelotl Feb 22, 2023
410e5e8
WIP
ocelotl Feb 22, 2023
48ecdda
WIP
ocelotl Feb 22, 2023
9b4a720
Fix lint
ocelotl Feb 22, 2023
80059d3
Fix lint
ocelotl Feb 22, 2023
232911d
Add delta test case
ocelotl Feb 22, 2023
e26ff69
Avoid using current_point attributes
ocelotl Feb 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix formatting of ConsoleMetricExporter.
([#3197](https://github.com/open-telemetry/opentelemetry-python/pull/3197))

## Version 1.16.0/0.37b0 (2023-02-17)
- Add exponential histogram
([#2964](https://github.com/open-telemetry/opentelemetry-python/pull/2964))

## Version 1.16.0/0.37b0 (2023-02-15)

- Change ``__all__`` to be statically defined.
([#3143](https://github.com/open-telemetry/opentelemetry-python/pull/3143))
- Remove the ability to set a global metric prefix for Prometheus exporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
ResourceMetrics,
ScopeMetrics,
Sum,
ExponentialHistogram as ExponentialHistogramType,
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
)

_logger = getLogger(__name__)
Expand Down Expand Up @@ -266,6 +267,51 @@ def _translate_data(
metric.data.is_monotonic
)
pb2_metric.sum.data_points.append(pt)

elif isinstance(metric.data, ExponentialHistogramType):
for data_point in metric.data.data_points:

if data_point.positive.bucket_counts:
positive = pb2.ExponentialHistogramDataPoint.Buckets(
offset=data_point.positive.offset,
bucket_counts=data_point.positive.bucket_counts,
)
else:
positive = None

if data_point.negative.bucket_counts:
negative = pb2.ExponentialHistogramDataPoint.Buckets(
offset=data_point.negative.offset,
bucket_counts=data_point.negative.bucket_counts,
)
else:
negative = None

pt = pb2.ExponentialHistogramDataPoint(
attributes=self._translate_attributes(
data_point.attributes
),
time_unix_nano=data_point.time_unix_nano,
start_time_unix_nano=(
data_point.start_time_unix_nano
),
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
count=data_point.count,
sum=data_point.sum,
scale=data_point.scale,
zero_count=data_point.zero_count,
positive=positive,
negative=negative,
flags=data_point.flags,
max=data_point.max,
min=data_point.min,
)
pb2_metric.exponential_histogram.aggregation_temporality = (
metric.data.aggregation_temporality
)
pb2_metric.exponential_histogram.data_points.append(
pt
)

else:
_logger.warning(
"unsupported data type %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@
ObservableUpDownCounter,
UpDownCounter,
)
from opentelemetry.sdk.metrics.export import AggregationTemporality, Gauge
from opentelemetry.sdk.metrics.export import AggregationTemporality, Buckets
from opentelemetry.sdk.metrics.export import (
ExponentialHistogram as ExponentialHistogramType,
)
from opentelemetry.sdk.metrics.export import (
ExponentialHistogramDataPoint,
Gauge,
)
from opentelemetry.sdk.metrics.export import Histogram as HistogramType
from opentelemetry.sdk.metrics.export import (
HistogramDataPoint,
Expand Down Expand Up @@ -163,6 +170,31 @@ def setUp(self):
),
)

exponential_histogram = Metric(
name="exponential_histogram",
description="description",
unit="unit",
data=ExponentialHistogramType(
data_points=[
ExponentialHistogramDataPoint(
attributes={"a": 1, "b": True},
start_time_unix_nano=0,
time_unix_nano=1,
count=2,
sum=3,
scale=4,
zero_count=5,
positive=Buckets(offset=6, bucket_counts=[7, 8]),
negative=Buckets(offset=9, bucket_counts=[10, 11]),
flags=12,
min=13.0,
max=14.0,
)
],
aggregation_temporality=AggregationTemporality.DELTA,
),
)

self.metrics = {
"sum_int": MetricsData(
resource_metrics=[
Expand Down Expand Up @@ -276,6 +308,28 @@ def setUp(self):
)
]
),
"exponential_histogram": MetricsData(
resource_metrics=[
ResourceMetrics(
resource=Resource(
attributes={"a": 1, "b": False},
schema_url="resource_schema_url",
),
scope_metrics=[
ScopeMetrics(
scope=SDKInstrumentationScope(
name="first_name",
version="first_version",
schema_url="insrumentation_scope_schema_url",
),
metrics=[exponential_histogram],
schema_url="instrumentation_scope_schema_url",
)
],
schema_url="resource_schema_url",
)
]
),
}

self.multiple_scope_histogram = MetricsData(
Expand Down Expand Up @@ -896,6 +950,80 @@ def test_translate_histogram(self):
actual = self.exporter._translate_data(self.metrics["histogram"])
self.assertEqual(expected, actual)

def test_translate_exponential_histogram(self):
expected = ExportMetricsServiceRequest(
resource_metrics=[
pb2.ResourceMetrics(
resource=OTLPResource(
attributes=[
KeyValue(key="a", value=AnyValue(int_value=1)),
KeyValue(
key="b", value=AnyValue(bool_value=False)
),
]
),
scope_metrics=[
pb2.ScopeMetrics(
scope=InstrumentationScope(
name="first_name", version="first_version"
),
metrics=[
pb2.Metric(
name="exponential_histogram",
unit="unit",
description="description",
exponential_histogram=pb2.ExponentialHistogram(
data_points=[
pb2.ExponentialHistogramDataPoint(
attributes=[
KeyValue(
key="a",
value=AnyValue(
int_value=1
),
),
KeyValue(
key="b",
value=AnyValue(
bool_value=True
),
),
],
start_time_unix_nano=0,
time_unix_nano=1,
count=2,
sum=3,
scale=4,
zero_count=5,
positive=pb2.ExponentialHistogramDataPoint.Buckets(
offset=6,
bucket_counts=[7, 8],
),
negative=pb2.ExponentialHistogramDataPoint.Buckets(
offset=9,
bucket_counts=[10, 11],
),
flags=12,
exemplars=[],
min=13.0,
max=14.0,
)
],
aggregation_temporality=AggregationTemporality.DELTA,
),
)
],
)
],
)
]
)
# pylint: disable=protected-access
actual = self.exporter._translate_data(
self.metrics["exponential_histogram"]
)
self.assertEqual(expected, actual)

def test_translate_multiple_scope_histogram(self):
expected = ExportMetricsServiceRequest(
resource_metrics=[
Expand Down
Loading