Skip to content

Commit b3ab961

Browse files
authored
Move benchmarks outside of tests directory (open-telemetry#4033)
Fixes open-telemetry#4029
1 parent 49bfc29 commit b3ab961

File tree

11 files changed

+17
-129
lines changed

11 files changed

+17
-129
lines changed

.github/workflows/benchmarks.yml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,25 @@ on:
77
jobs:
88
sdk-benchmarks:
99
env:
10-
py312: "3.12"
11-
RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-sdk-${{ matrix.os }}
1210
runs-on: self-hosted
13-
strategy:
14-
# Ensures the entire test matrix is run, even if one permutation fails
15-
fail-fast: false
16-
matrix:
17-
python-version: [py312]
18-
os: [ubuntu-20.04, windows-2019]
1911
steps:
2012
- name: Checkout Core Repo @ SHA - ${{ github.sha }}
2113
uses: actions/checkout@v4
22-
- name: Set up Python ${{ env[matrix.python-version] }}
14+
- name: Set up Python
2315
uses: actions/setup-python@v5
2416
with:
25-
python-version: ${{ env[matrix.python-version] }}
17+
python-version: "3.12"
2618
architecture: 'x64'
2719
- name: Install tox
2820
run: pip install tox
29-
- name: Cache tox environment
30-
# Preserves .tox directory between runs for faster installs
31-
uses: actions/cache@v4
32-
with:
33-
path: |
34-
.tox
35-
~/.cache/pip
36-
key: v3-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini',
37-
'dev-requirements.txt') }}-core
3821
- name: Run tox
39-
run: tox -f ${{ matrix.python-version }}-sdk -- -k opentelemetry-sdk/tests/performance/benchmarks --benchmark-json=opentelemetry-sdk/tests/output.json
22+
run: tox -e benchmark-opentelemetry-sdk -- -k opentelemetry-sdk/benchmarks --benchmark-json=opentelemetry-sdk/output.json
4023
- name: Report on SDK benchmark results
4124
uses: benchmark-action/github-action-benchmark@v1
4225
with:
43-
name: OpenTelemetry Python SDK Benchmarks - Python ${{ env[matrix.python-version ]}} - SDK
26+
name: OpenTelemetry Python SDK Benchmarks
4427
tool: pytest
45-
output-file-path: opentelemetry-sdk/tests/output.json
28+
output-file-path: opentelemetry-sdk/output.json
4629
gh-pages-branch: gh-pages
4730
github-token: ${{ secrets.GITHUB_TOKEN }}
4831
# Make a commit on `gh-pages` with benchmarks from previous step

.github/workflows/test.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ jobs:
9292
- name: Windows does not let git check out files with long names
9393
if: ${{ matrix.os == 'windows-2019'}}
9494
run: git config --system core.longpaths true
95-
- name: run pytest with --benchmark-skip
96-
if: ${{ matrix.package == 'sdk' || matrix.package == 'exporter-otlp-proto-grpc' }}
97-
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-skip
98-
- name: run pytest without --benchmark-skip
99-
if: ${{ !(matrix.package == 'sdk' || matrix.package == 'exporter-otlp-proto-grpc') }}
95+
- name: run tox
10096
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra
10197
misc:
10298
strategy:
@@ -217,4 +213,4 @@ jobs:
217213
key: v3-tox-cache-${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os
218214
}}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-contrib
219215
- name: run tox
220-
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-skip
216+
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,6 @@ docs/examples/django/db.sqlite3
6666

6767
# Semantic conventions
6868
scripts/semconv/semantic-conventions
69+
70+
# Benchmark result files
71+
*-benchmark.json

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ The continuation integration overrides that environment variable with as per the
126126

127127
### Benchmarks
128128

129-
Running the `tox` tests also runs the performance tests if any are available. Benchmarking tests are done with `pytest-benchmark` and they output a table with results to the console.
129+
Some packages have benchmark tests. To run them, run `tox -f benchmark`. Benchmark tests use `pytest-benchmark` and they output a table with results to the console.
130130

131131
To write benchmarks, simply use the [pytest benchmark fixture](https://pytest-benchmark.readthedocs.io/en/latest/usage.html#usage) like the following:
132132

@@ -142,10 +142,10 @@ def test_simple_start_span(benchmark):
142142
benchmark(benchmark_start_as_current_span, "benchmarkedSpan", 42)
143143
```
144144

145-
Make sure the test file is under the `tests/performance/benchmarks/` folder of
145+
Make sure the test file is under the `benchmarks/` folder of
146146
the package it is benchmarking and further has a path that corresponds to the
147147
file in the package it is testing. Make sure that the file name begins with
148-
`test_benchmark_`. (e.g. `opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py`)
148+
`test_benchmark_`. (e.g. `opentelemetry-sdk/benchmarks/trace/propagation/test_benchmark_b3_format.py`)
149149

150150
## Pull Requests
151151

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest-benchmark==4.0.0

opentelemetry-sdk/tests/performance/resource-usage/trace/profile_resource_usage_batch_export.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

opentelemetry-sdk/tests/performance/resource-usage/trace/profile_resource_usage_simple_export.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ envlist =
1717

1818
py3{8,9,10,11,12}-opentelemetry-sdk
1919
pypy3-opentelemetry-sdk
20+
benchmark-opentelemetry-sdk
2021

2122
py3{8,9,10,11,12}-opentelemetry-semantic-conventions
2223
pypy3-opentelemetry-semantic-conventions
@@ -113,6 +114,7 @@ commands_pre =
113114
api: pip install -r {toxinidir}/opentelemetry-api/test-requirements.txt
114115

115116
sdk: pip install -r {toxinidir}/opentelemetry-sdk/test-requirements.txt
117+
benchmark-opentelemetry-sdk: pip install -r {toxinidir}/opentelemetry-sdk/benchmark-requirements.txt
116118

117119
semantic-conventions: pip install -r {toxinidir}/opentelemetry-semantic-conventions/test-requirements.txt
118120

@@ -168,6 +170,7 @@ commands_pre =
168170
commands =
169171
api: pytest {toxinidir}/opentelemetry-api/tests {posargs}
170172
sdk: pytest {toxinidir}/opentelemetry-sdk/tests {posargs}
173+
benchmark-opentelemetry-sdk: pytest {toxinidir}/opentelemetry-sdk/benchmarks {posargs} --benchmark-json=sdk-benchmark.json
171174
protobuf: pytest {toxinidir}/opentelemetry-proto/tests {posargs}
172175
semantic-conventions: pytest {toxinidir}/opentelemetry-semantic-conventions/tests {posargs}
173176
getting-started: pytest {toxinidir}/docs/getting_started/tests {posargs}

0 commit comments

Comments
 (0)