Repository navigation
Telemetry e2e test #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| [pytest] | ||
| # Used only when no test path, module or node ID is supplied on the command line. | ||
| testpaths = rhos_lightspeed_tests.tests | ||
| addopts = --verbose --junitxml=test-results.xml | ||
| addopts = --verbose --junitxml=test-results.xml -m "not telemetry" | ||
| python_files = test_*.py | ||
| python_functions = test_* | ||
| markers = | ||
| telemetry: requires telemetry-operator metrics collection and a configured Prometheus URL | ||
| llm_dependent: requires generated answer content from a real LLM |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """Verify that telemetry's Prometheus collects metrics from a Lightspeed query.""" | ||
|
|
||
| import time | ||
|
|
||
| import pytest | ||
| import requests | ||
|
|
||
|
|
||
| def _get_llm_calls_total(prometheus: dict) -> float: | ||
| """Read the total collected LLM calls from telemetry's Prometheus.""" | ||
| query_url = prometheus["url"].rstrip("/") + "/api/v1/query" | ||
|
|
||
| with requests.get( | ||
| query_url, | ||
| params={"query": "sum(ls_llm_calls_total)"}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| verify=prometheus["ca_cert_path"] or True, | ||
| timeout=prometheus["api_timeout"], | ||
| ) as response: | ||
| response.raise_for_status() | ||
| samples = response.json()["data"]["result"] | ||
|
|
||
| if not samples: | ||
| return 0 | ||
|
|
||
| _timestamp, value = samples[0]["value"] | ||
| return float(value) | ||
|
|
||
|
|
||
| @pytest.mark.telemetry | ||
| def test_query_metrics_collected_by_telemetry(client, config): | ||
| """Send a query and check that telemetry has collected a positive LLM counter.""" | ||
| prometheus = config["prometheus"] | ||
|
|
||
| question = config["query"]["default_question"] | ||
| with client.query(question) as response: | ||
| response.raise_for_status() | ||
|
|
||
| deadline = time.monotonic() + prometheus["scrape_timeout"] | ||
| llm_calls_total = 0 | ||
| while time.monotonic() < deadline: | ||
| llm_calls_total = _get_llm_calls_total(prometheus) | ||
| if llm_calls_total > 0: | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| break | ||
| time.sleep(5) | ||
|
|
||
| assert llm_calls_total > 0, ( | ||
| "Prometheus did not collect a positive ls_llm_calls_total" | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.