Skip to content

Commit

Permalink
Add authorino tracing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
averevki committed Feb 13, 2024
1 parent 55d9b74 commit 8bd9b05
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
12 changes: 12 additions & 0 deletions testsuite/openshift/authorino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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)

Expand Down
Empty file.
18 changes: 18 additions & 0 deletions testsuite/tests/kuadrant/authorino/tracing/conftest.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions testsuite/tests/kuadrant/authorino/tracing/test_tracing.py
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 30 additions & 0 deletions testsuite/tests/kuadrant/authorino/tracing/test_tracing_tags.py
Original file line number Diff line number Diff line change
@@ -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}"')

0 comments on commit 8bd9b05

Please sign in to comment.