-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from averevki/test-authorino-tracing
Test authorino tracing
- Loading branch information
Showing
12 changed files
with
183 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Conftest for tracing tests""" | ||
|
||
import pytest | ||
|
||
from testsuite.openshift.authorino import TracingOptions | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorino_parameters(authorino_parameters, tracing): | ||
"""Deploy authorino with tracing enabled""" | ||
insecure_tracing = not tracing.client.verify | ||
authorino_parameters["tracing"] = TracingOptions(endpoint=tracing.collector_url, insecure=insecure_tracing) | ||
return authorino_parameters | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorization(authorization): | ||
"""Add response with 'request.id' to found traced request with it""" | ||
authorization.responses.add_simple("request.id") | ||
return authorization |
18 changes: 18 additions & 0 deletions
18
testsuite/tests/kuadrant/authorino/tracing/test_tracing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Test tracing""" | ||
|
||
import pytest | ||
|
||
from testsuite.utils import extract_response | ||
|
||
pytestmark = [pytest.mark.authorino, pytest.mark.standalone_only] | ||
|
||
|
||
def test_tracing(client, auth, tracing): | ||
"""Send request and check if it's trace is saved into the tracing client""" | ||
response = client.get("/get", auth=auth) | ||
assert response.status_code == 200 | ||
|
||
request_id = extract_response(response) % None | ||
assert request_id is not None | ||
|
||
assert tracing.find_trace("Check", request_id) |
30 changes: 30 additions & 0 deletions
30
testsuite/tests/kuadrant/authorino/tracing/test_tracing_tags.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
@pytest.mark.issue("https://github.com/Kuadrant/authorino-operator/issues/171") | ||
def test_tracing_tags(client, auth, tracing): | ||
"""Send request and check if it's trace with custom tags is saved into the tracing client""" | ||
response = client.get("/get", auth=auth) | ||
assert response.status_code == 200 | ||
|
||
request_id = extract_response(response) % None | ||
assert request_id is not None | ||
|
||
assert tracing.find_tagged_trace("Check", request_id, TAG_KEY, TAG_VALUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Module with Tracing client for traces management""" | ||
|
||
from typing import Optional, Iterator | ||
|
||
import backoff | ||
from apyproxy import ApyProxy | ||
|
||
from testsuite.httpx import KuadrantClient | ||
|
||
|
||
class TracingClient: | ||
"""Tracing client for traces management""" | ||
|
||
def __init__(self, collector_url: str, query_url: str, client: KuadrantClient = None): | ||
self.collector_url = collector_url | ||
self.client = client or KuadrantClient(verify=False) | ||
self.query = ApyProxy(query_url, session=self.client) | ||
|
||
def _get_traces(self, operation: str) -> Iterator[dict]: | ||
"""Get traces from tracing client by operation name""" | ||
params = {"service": "authorino", "operation": operation} | ||
response = self.query.api.traces.get(params=params) | ||
return reversed(response.json()["data"]) | ||
|
||
@backoff.on_predicate(backoff.fibo, lambda x: x is None, max_tries=5, jitter=None) | ||
def find_trace(self, operation: str, request_id: str) -> Optional[dict]: | ||
"""Find trace in tracing client by operation and authorino request id""" | ||
for trace in self._get_traces(operation): # pylint: disable=too-many-nested-blocks | ||
for span in trace["spans"]: | ||
if span["operationName"] == operation: | ||
for tag in span["tags"]: | ||
if tag["key"] == "authorino.request_id" and tag["value"] == request_id: | ||
return trace | ||
return None | ||
|
||
def find_tagged_trace(self, operation: str, request_id: str, tag_key: str, tag_value: str) -> Optional[dict]: | ||
"""Find trace in tracing client by operation, authorino request id and tag key-value pair""" | ||
if trace := self.find_trace(operation, request_id): | ||
for process in trace["processes"]: | ||
for proc_tag in trace["processes"][process]["tags"]: | ||
if proc_tag["key"] == tag_key and proc_tag["value"] == tag_value: | ||
return trace | ||
return None |