diff --git a/cloudbuild.yaml b/cloudbuild.yaml index d42ab974..df88bd1e 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -26,7 +26,7 @@ steps: - push - gcr.io/$PROJECT_ID/opentelemetry-operations-python-e2e-test-server:$SHORT_SHA - - name: gcr.io/opentelemetry-ops-e2e/opentelemetry-operations-e2e-testing:0.5.10 + - name: gcr.io/opentelemetry-ops-e2e/opentelemetry-operations-e2e-testing:$_TEST_SERVER_TAG id: run-tests dir: / env: @@ -37,5 +37,7 @@ steps: - --network=cloudbuild logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs +substitutions: + _TEST_SERVER_TAG: 0.5.11 images: - gcr.io/$PROJECT_ID/opentelemetry-operations-python-e2e-test-server:$SHORT_SHA diff --git a/e2e-test-server/e2e_test_server/constants.py b/e2e-test-server/e2e_test_server/constants.py index 3a043ac1..9d9489bd 100644 --- a/e2e-test-server/e2e_test_server/constants.py +++ b/e2e-test-server/e2e_test_server/constants.py @@ -14,5 +14,5 @@ INSTRUMENTING_MODULE_NAME = "opentelemetry-ops-e2e-test-server" SCENARIO = "scenario" -STATUS = "status" -TEST_ID = "test-id" +STATUS_CODE = "status_code" +TEST_ID = "test_id" diff --git a/e2e-test-server/e2e_test_server/scenarios.py b/e2e-test-server/e2e_test_server/scenarios.py index 2cbc3721..c58ac417 100644 --- a/e2e-test-server/e2e_test_server/scenarios.py +++ b/e2e-test-server/e2e_test_server/scenarios.py @@ -17,6 +17,8 @@ from dataclasses import dataclass from typing import Any, Iterator, Mapping +from google.rpc import code_pb2 + from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor @@ -28,12 +30,11 @@ @dataclass class Response: - # HTTP style status code, even for pubsub - status: int + status_code: code_pb2.Code @contextlib.contextmanager -def _tracer_setup(carrier: Mapping[str, str]) -> Iterator[tuple[str, Tracer]]: +def _tracer_setup(carrier: Mapping[str, str]) -> Iterator[Tracer]: """\ Context manager with common setup for tracing endpoints @@ -56,7 +57,7 @@ def _tracer_setup(carrier: Mapping[str, str]) -> Iterator[tuple[str, Tracer]]: def health(test_id: str, headers: Mapping[str, str], body: bytes) -> Response: - return Response(status=200) + return Response(status_code=code_pb2.OK) def basicTrace( @@ -68,4 +69,4 @@ def basicTrace( with tracer.start_span("basicTrace", attributes={TEST_ID: test_id}): pass - return Response(status=200) + return Response(status_code=code_pb2.OK) diff --git a/e2e-test-server/e2e_test_server/server.py b/e2e-test-server/e2e_test_server/server.py index 8cddf2bf..6ec1b9f1 100644 --- a/e2e-test-server/e2e_test_server/server.py +++ b/e2e-test-server/e2e_test_server/server.py @@ -18,7 +18,8 @@ from google.cloud.pubsub_v1.subscriber.message import Message from . import scenarios -from .constants import SCENARIO, STATUS, TEST_ID +from .constants import SCENARIO, STATUS_CODE, TEST_ID +from google.rpc import code_pb2 PROJECT_ID = os.environ["PROJECT_ID"] REQUEST_SUBSCRIPTION_NAME = os.environ["REQUEST_SUBSCRIPTION_NAME"] @@ -34,16 +35,19 @@ def pubsub_pull() -> None: subscriber = pubsub_v1.SubscriberClient() subscription_path = subscriber.subscription_path( - PROJECT_ID, REQUEST_SUBSCRIPTION_NAME, + PROJECT_ID, + REQUEST_SUBSCRIPTION_NAME, ) def respond(test_id: str, res: scenarios.Response) -> None: """Respond to the test runner that we finished executing the scenario""" data = bytes() - attributes = {TEST_ID: test_id, STATUS: str(res.status)} + attributes = {TEST_ID: test_id, STATUS_CODE: str(res.status_code)} print(f"publishing {data=} and {attributes=}") publisher.publish( - response_topic, bytes(), **attributes, + response_topic, + bytes(), + **attributes, ) def pubsub_callback(message: Message) -> None: @@ -58,7 +62,10 @@ def pubsub_callback(message: Message) -> None: publisher.publish( response_topic, f'Expected attribute "{SCENARIO}" is missing', - **{TEST_ID: test_id, "status": 500}, + **{ + TEST_ID: test_id, + STATUS_CODE: str(code_pb2.INVALID_ARGUMENT), + }, ) scenario = message.attributes[SCENARIO] @@ -68,7 +75,7 @@ def pubsub_callback(message: Message) -> None: scenarioFunc = scenarios.basicTrace else: scenarioFunc = lambda *args, **kwargs: scenarios.Response( - status=404 + status_code=str(code_pb2.UNIMPLEMENTED) ) res = scenarioFunc(test_id, message.attributes, message.data) diff --git a/e2e-test-server/requirements.txt b/e2e-test-server/requirements.txt index 77608e3c..a535efe5 100644 --- a/e2e-test-server/requirements.txt +++ b/e2e-test-server/requirements.txt @@ -4,3 +4,4 @@ opentelemetry-sdk opentelemetry-api Flask google-cloud-pubsub +googleapis-common-protos