Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ebd6c8

Browse files
authored
Add throughput performance tests for OTLP exporter (open-telemetry#1491)
1 parent 4195360 commit 8ebd6c8

File tree

2 files changed

+84
-5
lines changed

2 files changed

+84
-5
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,14 @@ jobs:
6363
- name: run tox
6464
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
6565
- name: Find and merge benchmarks
66-
# TODO: Add at least one benchmark to every package type to remove this
67-
if: matrix.package == 'core'
66+
id: find_and_merge_benchmarks
6867
run: >-
6968
jq -s '.[0].benchmarks = ([.[].benchmarks] | add)
7069
| if .[0].benchmarks == null then null else .[0] end'
71-
opentelemetry-*/tests/*${{ matrix.package }}*-benchmark.json > output.json
70+
$(find . -name '*${{ matrix.package }}*-benchmark.json') > output.json
71+
&& echo "::set-output name=json_plaintext::$(cat output.json)"
7272
- name: Report on benchmark results
73-
# TODO: Add at least one benchmark to every package type to remove this
74-
if: matrix.package == 'core'
73+
if: steps.find_and_merge_benchmarks.outputs.json_plaintext != 'null'
7574
uses: rhysd/github-action-benchmark@v1
7675
with:
7776
name: OpenTelemetry Python Benchmarks - Python ${{ env[matrix.python-version ]}} - ${{ matrix.package }}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 unittest.mock import patch
16+
17+
from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
18+
from opentelemetry.sdk.trace import TracerProvider, sampling
19+
from opentelemetry.sdk.trace.export import (
20+
BatchExportSpanProcessor,
21+
SimpleExportSpanProcessor,
22+
)
23+
24+
25+
def get_tracer_with_processor(span_processor_class):
26+
span_processor = span_processor_class(OTLPSpanExporter())
27+
tracer = TracerProvider(
28+
active_span_processor=span_processor, sampler=sampling.DEFAULT_ON,
29+
).get_tracer("pipeline_benchmark_tracer")
30+
return tracer
31+
32+
33+
class MockTraceServiceStub(object):
34+
def __init__(self, channel):
35+
self.Export = lambda *args, **kwargs: None
36+
37+
38+
@patch(
39+
"opentelemetry.exporter.otlp.trace_exporter.OTLPSpanExporter._stub",
40+
new=MockTraceServiceStub,
41+
)
42+
def test_simple_span_processor(benchmark):
43+
tracer = get_tracer_with_processor(SimpleExportSpanProcessor)
44+
45+
def create_spans_to_be_exported():
46+
span = tracer.start_span("benchmarkedSpan",)
47+
for i in range(10):
48+
span.set_attribute(
49+
"benchmarkAttribute_{}".format(i),
50+
"benchmarkAttrValue_{}".format(i),
51+
)
52+
span.end()
53+
54+
benchmark(create_spans_to_be_exported)
55+
56+
57+
@patch(
58+
"opentelemetry.exporter.otlp.trace_exporter.OTLPSpanExporter._stub",
59+
new=MockTraceServiceStub,
60+
)
61+
def test_batch_span_processor(benchmark):
62+
"""Runs benchmark tests using BatchExportSpanProcessor.
63+
64+
One particular call by pytest-benchmark will be much more expensive since
65+
the batch export thread will activate and consume a lot of CPU to process
66+
all the spans. For this reason, focus on the average measurement. Do not
67+
focus on the min/max measurements which will be misleading.
68+
"""
69+
tracer = get_tracer_with_processor(BatchExportSpanProcessor)
70+
71+
def create_spans_to_be_exported():
72+
span = tracer.start_span("benchmarkedSpan",)
73+
for i in range(10):
74+
span.set_attribute(
75+
"benchmarkAttribute_{}".format(i),
76+
"benchmarkAttrValue_{}".format(i),
77+
)
78+
span.end()
79+
80+
benchmark(create_spans_to_be_exported)

0 commit comments

Comments
 (0)