Skip to content

Commit

Permalink
Add performance testing + tests for sdk span creation
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanielRN committed Dec 3, 2020
1 parent 50f5c6c commit 6e5d7f1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,37 @@ jobs:
key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core
- name: run tox
run: tox -e ${{ matrix.tox-environment }}
benchmark:
env:
# We use these variables to convert between tox and GHA version literals
py35: 3.5
py36: 3.6
py37: 3.7
py38: 3.8
pypy3: pypy3
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
matrix:
python-version: [ py35, py36, py37, py38, pypy3 ]
os: [ ubuntu-latest ]
steps:
- name: Checkout Core Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v2
- name: Set up Python ${{ env[matrix.python-version] }}
uses: actions/setup-python@v2
with:
python-version: ${{ env[matrix.python-version] }}
- name: Install tox
run: pip install -U tox-factor
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v2
with:
path: .tox
key: tox-cache-${{ matrix.python-version }}-benchmark-${{ matrix.os }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core
- name: run tox
run: tox -f ${{ matrix.python-version }}-benchmark
contrib-build:
env:
# We use these variables to convert between tox and GHA version literals
Expand Down
51 changes: 51 additions & 0 deletions opentelemetry-sdk/benchmarks/trace/test_benchmark__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import opentelemetry.sdk.trace as trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import sampling

tracer = trace.TracerProvider(
sampler=sampling.DEFAULT_ON,
resource=Resource(
{
"service.name": "A123456789",
"service.version": "1.34567890",
"service.instance.id": "123ab456-a123-12ab-12ab-12340a1abc12",
}
),
).get_tracer("sdk_tracer_provider")


def test_b3_propagator_start_span(benchmark):
def benchmark_start_as_current_span():
span = tracer.start_span(
"benchmarkedSpan",
attributes={"long.attribute": -10000000001000000000}
)
span.add_event("benchmarkEvent")
span.end()

benchmark(benchmark_start_as_current_span)


def test_b3_propagator_start_as_current_span(benchmark):
def benchmark_start_as_current_span():
with tracer.start_as_current_span(
"benchmarkedSpan",
attributes={"long.attribute": -10000000001000000000}
) as span:
span.add_event("benchmarkEvent")

benchmark(benchmark_start_as_current_span)
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ envlist =
deps =
-c dev-requirements.txt
test: pytest
benchmark: pytest-benchmark
coverage: pytest
coverage: pytest-cov
mypy,mypyinstalled: mypy
Expand All @@ -78,13 +79,17 @@ changedir =
test-exporter-prometheus: exporter/opentelemetry-exporter-prometheus/tests
test-exporter-zipkin: exporter/opentelemetry-exporter-zipkin/tests

benchmark-core-sdk: opentelemetry-sdk/benchmarks

commands_pre =
; Install without -e to test the actual installation
py3{5,6,7,8}: python -m pip install -U pip setuptools wheel
; Install common packages for all the tests. These are not needed in all the
; cases but it saves a lot of boilerplate in this file.
test: pip install {toxinidir}/opentelemetry-api {toxinidir}/opentelemetry-sdk {toxinidir}/tests/util

benchmark: pip install {toxinidir}/opentelemetry-api {toxinidir}/opentelemetry-sdk

test-core-proto: pip install {toxinidir}/opentelemetry-proto
instrumentation: pip install {toxinidir}/opentelemetry-instrumentation

Expand Down Expand Up @@ -114,6 +119,7 @@ commands_pre =

commands =
test: pytest {posargs}
benchmark: pytest {posargs}
coverage: {toxinidir}/scripts/coverage.sh

mypy: mypy --namespace-packages opentelemetry-api/src/opentelemetry/
Expand Down

0 comments on commit 6e5d7f1

Please sign in to comment.