diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 58732af41..f5e48c9eb 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -1,5 +1,5 @@ steps: - - label: ":elasticsearch: :python: ES Python ({{ matrix.python }})" + - label: ":elasticsearch: :python: ES Python ({{ matrix.python }}) {{ matrix.nox_session }} " agents: provider: "gcp" env: @@ -7,6 +7,7 @@ steps: TEST_SUITE: "platinum" STACK_VERSION: "8.11.0-SNAPSHOT" PYTHON_CONNECTION_CLASS: "{{ matrix.connection }}" + NOX_SESSION: "{{ matrix.nox_session }}" matrix: setup: python: @@ -19,4 +20,15 @@ steps: connection: - "urllib3" - "requests" + nox_session: + - "test" + adjustments: + - with: + python: "3.7" + connection: "urllib3" + nox_session: "test_otel" + - with: + python: "3.12" + connection: "urllib3" + nox_session: "test_otel" command: ./.buildkite/run-tests diff --git a/.buildkite/run-repository.sh b/.buildkite/run-repository.sh index 466b906cc..2f1f3c263 100755 --- a/.buildkite/run-repository.sh +++ b/.buildkite/run-repository.sh @@ -18,6 +18,7 @@ echo -e "\033[34;1mINFO:\033[0m URL ${ELASTICSEARCH_URL}\033[0m" echo -e "\033[34;1mINFO:\033[0m VERSION ${ELASTICSEARCH_VERSION}\033[0m" echo -e "\033[34;1mINFO:\033[0m CONTAINER ${ELASTICSEARCH_CONTAINER}\033[0m" echo -e "\033[34;1mINFO:\033[0m TEST_SUITE ${TEST_SUITE}\033[0m" +echo -e "\033[34;1mINFO:\033[0m NOX_SESSION ${NOX_SESSION}\033[0m" echo -e "\033[34;1mINFO:\033[0m PYTHON_VERSION ${PYTHON_VERSION}\033[0m" echo -e "\033[34;1mINFO:\033[0m PYTHON_CONNECTION_CLASS ${PYTHON_CONNECTION_CLASS}\033[0m" @@ -45,4 +46,4 @@ docker run \ --name elasticsearch-py \ --rm \ elastic/elasticsearch-py \ - nox -s test-${PYTHON_VERSION} + nox -s ${NOX_SESSION}-${PYTHON_VERSION} diff --git a/dev-requirements.txt b/dev-requirements.txt index 0167b2e1d..b5b92c283 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -19,9 +19,6 @@ nox numpy pandas -opentelemetry-api -opentelemetry-sdk - # Testing the 'search_mvt' API response mapbox-vector-tile # Python 3.7 gets an old version of mapbox-vector-tile, requiring an diff --git a/noxfile.py b/noxfile.py index 10a57815a..b166bf79a 100644 --- a/noxfile.py +++ b/noxfile.py @@ -32,13 +32,9 @@ INSTALL_ENV = {"AIOHTTP_NO_EXTENSIONS": "1"} -@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]) -def test(session): - session.install(".[async,requests]", env=INSTALL_ENV, silent=False) - session.install("-r", "dev-requirements.txt", silent=False) - +def pytest_argv(): junit_xml = os.path.join(SOURCE_DIR, "junit", "elasticsearch-py-junit.xml") - pytest_argv = [ + return [ "pytest", "--cov-report=term-missing", "--cov=elasticsearch", @@ -48,7 +44,29 @@ def test(session): "--cache-clear", "-vv", ] - session.run(*pytest_argv) + + +@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]) +def test(session): + session.install(".[async,requests]", env=INSTALL_ENV, silent=False) + session.install("-r", "dev-requirements.txt", silent=False) + + session.run(*pytest_argv()) + + +@nox.session(python=["3.7", "3.12"]) +def test_otel(session): + session.install(".[async,requests]", env=INSTALL_ENV, silent=False) + session.install( + "opentelemetry-api", + "opentelemetry-sdk", + "-r", + "dev-requirements.txt", + silent=False, + ) + + argv = pytest_argv() + ["-m", "otel"] + session.run(*argv, env={"TEST_WITH_OTEL": "1"}) @nox.session() diff --git a/setup.cfg b/setup.cfg index d54c7cd19..d8e0ce63d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,6 +4,7 @@ ignore = E203, E266, E501, W503 [tool:pytest] junit_family=legacy addopts = -vvv --cov-report=term-missing --cov=elasticsearch --cov-config=.coveragerc +markers = otel [tool:isort] profile=black diff --git a/test_elasticsearch/test_server/test_otel.py b/test_elasticsearch/test_server/test_otel.py index cb420c06f..b90dab8d6 100644 --- a/test_elasticsearch/test_server/test_otel.py +++ b/test_elasticsearch/test_server/test_otel.py @@ -15,13 +15,29 @@ # specific language governing permissions and limitations # under the License. -from opentelemetry import trace -from opentelemetry.sdk.trace import TracerProvider, export -from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter +import os + +import pytest import elasticsearch from test_elasticsearch.utils import CA_CERTS +try: + from opentelemetry import trace + from opentelemetry.sdk.trace import TracerProvider, export + from opentelemetry.sdk.trace.export.in_memory_span_exporter import ( + InMemorySpanExporter, + ) +except ModuleNotFoundError: + pass + +pytestmark = [ + pytest.mark.skipif( + "TEST_WITH_OTEL" not in os.environ, reason="TEST_WITH_OTEL is not set" + ), + pytest.mark.otel, +] + def test_otel_end_to_end(monkeypatch, elasticsearch_url: str): # Sets the global default tracer provider