diff --git a/testsuite/openshift/authorino.py b/testsuite/openshift/authorino.py index 9b7b1857..3beea16b 100644 --- a/testsuite/openshift/authorino.py +++ b/testsuite/openshift/authorino.py @@ -45,6 +45,9 @@ def create_instance( cluster_wide=False, label_selectors: List[str] = None, listener_certificate_secret=None, + tracing_endpoint: str = None, + tracing_tags: dict[str, str] = None, + tracing_insecure: bool = False, log_level=None, ): """Creates base instance""" @@ -68,6 +71,15 @@ def create_instance( if listener_certificate_secret: model["spec"]["listener"]["tls"] = {"enabled": True, "certSecretRef": {"name": listener_certificate_secret}} + if tracing_endpoint: + model["spec"].setdefault("tracing", {})["endpoint"] = tracing_endpoint + + if tracing_tags: + model["spec"].setdefault("tracing", {})["tags"] = tracing_tags + + if tracing_insecure: + model["spec"].setdefault("tracing", {})["insecure"] = tracing_insecure + with openshift.context: return cls(model) diff --git a/testsuite/tests/kuadrant/authorino/tracing/__init__.py b/testsuite/tests/kuadrant/authorino/tracing/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/testsuite/tests/kuadrant/authorino/tracing/conftest.py b/testsuite/tests/kuadrant/authorino/tracing/conftest.py new file mode 100644 index 00000000..9b87bfc2 --- /dev/null +++ b/testsuite/tests/kuadrant/authorino/tracing/conftest.py @@ -0,0 +1,18 @@ +"""Conftest for tracing tests""" + +import pytest + + +@pytest.fixture(scope="module") +def authorino_parameters(authorino_parameters, jaeger): + """Deploy authorino with tracing enabled""" + authorino_parameters["tracing_endpoint"] = jaeger.collector_url + authorino_parameters["tracing_insecure"] = True + return authorino_parameters + + +@pytest.fixture(scope="module") +def authorization(authorization): + """Add response with 'request.id' to found this traced request later in Jaeger""" + authorization.responses.add_simple("request.id") + return authorization diff --git a/testsuite/tests/kuadrant/authorino/tracing/test_tracing.py b/testsuite/tests/kuadrant/authorino/tracing/test_tracing.py new file mode 100644 index 00000000..6723c363 --- /dev/null +++ b/testsuite/tests/kuadrant/authorino/tracing/test_tracing.py @@ -0,0 +1,18 @@ +"""Test tracing with Jaeger""" + +import pytest + +from testsuite.utils import extract_response + +pytestmark = [pytest.mark.authorino, pytest.mark.standalone_only] + + +def test_tracing(client, auth, jaeger): + """Send request and check if it's trace is saved to Jaeger""" + response = client.get("/get", auth=auth) + assert response.status_code == 200 + + request_id = extract_response(response) % None + assert request_id is not None + + assert jaeger.find_trace("Check", request_id) diff --git a/testsuite/tests/kuadrant/authorino/tracing/test_tracing_tags.py b/testsuite/tests/kuadrant/authorino/tracing/test_tracing_tags.py new file mode 100644 index 00000000..9d638666 --- /dev/null +++ b/testsuite/tests/kuadrant/authorino/tracing/test_tracing_tags.py @@ -0,0 +1,30 @@ +"""Test custom tags set for request traces""" + +import pytest + +from testsuite.utils import extract_response + +pytestmark = [pytest.mark.authorino, pytest.mark.standalone_only] + + +TAG_KEY = "test-key" +TAG_VALUE = "test-value" + + +@pytest.fixture(scope="module") +def authorino_parameters(authorino_parameters): + """Deploy authorino with tracing enabled and custom tags set""" + authorino_parameters["tracing_tags"] = {TAG_KEY: TAG_VALUE} + return authorino_parameters + + +def test_tracing_tags(client, auth, jaeger): + """Send request and check if it's trace with custom tags is saved to Jaeger""" + response = client.get("/get", auth=auth) + assert response.status_code == 200 + + request_id = extract_response(response) % None + assert request_id is not None + + # extra quotes are added by authorino and are a bug for now + assert jaeger.find_tagged_trace("Check", request_id, f'"{TAG_KEY}', f'{TAG_VALUE}"')