forked from Kuadrant/testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Module with Jaeger client for traces management""" | ||
|
||
from typing import Optional, Iterator | ||
|
||
import httpx | ||
import backoff | ||
from apyproxy import ApyProxy | ||
|
||
|
||
class Jaeger: | ||
"""Jaeger client for traces management""" | ||
|
||
def __init__(self, collector_url: str, query_url: str): | ||
self.collector_url = collector_url | ||
self.query = ApyProxy(query_url, session=httpx.Client(verify=False)) | ||
|
||
def _get_traces(self, operation: str) -> Iterator[dict]: | ||
"""Get traces from jaeger 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 jaeger 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": | ||
if 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 jaeger 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 |
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