|
| 1 | +# Copyright The OpenTelemetry Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from opentelemetry.exporter.otlp.json.common.metrics_encoder import ( |
| 16 | + encode_metrics, |
| 17 | +) |
| 18 | +from opentelemetry.sdk.metrics import Exemplar |
| 19 | +from tests import ( |
| 20 | + SPAN_ID, |
| 21 | + TIME, |
| 22 | + TRACE_ID, |
| 23 | + make_exponential_histogram, |
| 24 | + make_gauge, |
| 25 | + make_histogram, |
| 26 | + make_metrics_data, |
| 27 | + make_sum, |
| 28 | +) |
| 29 | + |
| 30 | + |
| 31 | +def test_benchmark_encode_sum(benchmark): |
| 32 | + data = make_metrics_data([make_sum()]) |
| 33 | + benchmark(encode_metrics, data) |
| 34 | + |
| 35 | + |
| 36 | +def test_benchmark_encode_gauge(benchmark): |
| 37 | + data = make_metrics_data([make_gauge()]) |
| 38 | + benchmark(encode_metrics, data) |
| 39 | + |
| 40 | + |
| 41 | +def test_benchmark_encode_histogram(benchmark): |
| 42 | + data = make_metrics_data([ |
| 43 | + make_histogram( |
| 44 | + exemplars=[ |
| 45 | + Exemplar({"sampled": "true"}, 298.0, TIME, SPAN_ID, TRACE_ID), |
| 46 | + ], |
| 47 | + ) |
| 48 | + ]) |
| 49 | + benchmark(encode_metrics, data) |
| 50 | + |
| 51 | + |
| 52 | +def test_benchmark_encode_exponential_histogram(benchmark): |
| 53 | + data = make_metrics_data([make_exponential_histogram()]) |
| 54 | + benchmark(encode_metrics, data) |
| 55 | + |
| 56 | + |
| 57 | +def test_benchmark_encode_mixed_metrics(benchmark): |
| 58 | + data = make_metrics_data([ |
| 59 | + make_sum(name="counter"), |
| 60 | + make_gauge(name="gauge"), |
| 61 | + make_histogram( |
| 62 | + name="histogram", |
| 63 | + exemplars=[ |
| 64 | + Exemplar({"sampled": "true"}, 298.0, TIME, SPAN_ID, TRACE_ID), |
| 65 | + ], |
| 66 | + ), |
| 67 | + make_exponential_histogram(name="exp_histogram"), |
| 68 | + ]) |
| 69 | + benchmark(encode_metrics, data) |
0 commit comments