Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

chore: add pytest conventions rule and apply it across integration tests (#12460)

Pandey38cc4d2bea4a
diff --git a/.claude/rules/pytest.md b/.claude/rules/pytest.md
new file mode 100644
index 0000000000..8021d8d095
--- /dev/null
+++ b/.claude/rules/pytest.md
@@ -0,0 +1,18 @@
+---
+paths:
+ - "tests/**/*.py"
+---
+
+# pytest conventions
+
+For the Python integration suite under `tests/`. Setup, running, and suite layout live in [`docs/contributing/tests/integration.md`](../../docs/contributing/tests/integration.md).
+
+- **No `_`-prefixed helper functions in test modules — this is the rule that matters most.** A reader must be able to see what a test does in its body alone, without chasing private helpers that scatter the meaning across the file. Inline the logic: an expression, a comprehension, a few repeated lines are all fine — repetition across tests is cheaper than indirection. When several tests genuinely share non-trivial setup or assertions, that is what fixtures are for — in `tests/fixtures/`, see the next rule. A module-level `_helper()` is never the answer.
+- **Fixtures live in `tests/fixtures/` — never under `integration/tests/`.** Not in test modules, not in suite `conftest.py` files. `tests/fixtures/` is the shared library (auth, signoz, clickhouse, logs/metrics/traces seeding, …): reuse what's there before writing anything new; when a new fixture is genuinely needed, add it to the matching `tests/fixtures/` module and register new modules in `tests/conftest.py` `pytest_plugins`. **The one exception: SigNoz-level fixtures in a suite's `conftest.py`.** A suite that needs its own SigNoz spun up with different envs (`create_signoz`/`create_migrator` with `env_overrides` + `cache_key` — e.g. basepath, metricreduction, querier_json_body) keeps that in its `conftest.py`; that is always okay.
+- **Fixtures own their cleanup.** When a test needs seeded state, put the seed + cleanup pair in a fixture (`yield`, then tear down) so tests in the same suite don't interfere — the pattern `insert_metrics` sets: yield a callable, truncate on teardown.
+- **Fixture-factory over indirect parametrization.** A fixture that yields a callable (e.g. `insert_metrics(metrics)`) is clearer than `@pytest.mark.parametrize(..., indirect=True)` + `request.param` — the value is an explicit argument, not resolved by magic.
+- **Skip at collection, not inside the test body.** Use `pytest.param(..., marks=pytest.mark.skip(reason="…"))` so a skipped case shows as SKIPPED-with-reason **and** short-circuits before its fixtures run (no environment spin-up for a test that won't execute).
+- **Test config comes from explicit `--flags`, not the environment.** Wire configuration as pytest options declared in `tests/conftest.py` (`pytest_addoption` — e.g. `--sqlstore-provider`, `--clickhouse-version`); do **not** add `os.environ` fallbacks inside tests or fixtures.
+- **snake_case parametrize ids.** `ids=["fill_gaps", "fill_zero"]`, not camelCase.
+- **Name suite files with the two-digit prefix (`NN_*.py`).** `pyproject.toml` restricts collection to `[0-9][0-9]_*.py` (plus the bootstrap `setup.py` / `run.py`) — a file that doesn't match is silently never collected.
+- **Always run pytest from `tests/`.** `--import-mode=importlib` is what allows same-basename files across suites (`querier/01_logs.py` vs `rawexportdata/01_logs.py`), but it disables pytest's implicit `sys.path` injection — `import fixtures` only resolves via `pythonpath = ["."]` from that rootdir.
diff --git a/tests/conftest.py b/tests/conftest.py
index c5f13e3798..1a61cbfe07 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -34,6 +34,9 @@ pytest_plugins = [
"fixtures.role",
"fixtures.savedview",
"fixtures.seed_golden_dataset",
+ "fixtures.dashboards",
+ "fixtures.inframonitoring",
+ "fixtures.querier",
]
diff --git a/tests/fixtures/clickhouse.py b/tests/fixtures/clickhouse.py
index 172a32e53f..135fe8fa7a 100644
--- a/tests/fixtures/clickhouse.py
+++ b/tests/fixtures/clickhouse.py
@@ -329,9 +329,6 @@ def clickhouse(
request: pytest.FixtureRequest,
pytestconfig: pytest.Config,
) -> types.TestContainerClickhouse:
- """
- Package-scoped fixture for Clickhouse TestContainer.
- """
return create_clickhouse(
tmpfs=tmpfs,
network=network,
diff --git a/tests/fixtures/cloudintegrations.py b/tests/fixtures/cloudintegrations.py
index 3d4e4cf19d..67dd567593 100644
--- a/tests/fixtures/cloudintegrations.py
+++ b/tests/fixtures/cloudintegrations.py
@@ -1,5 +1,3 @@
-"""Fixtures for cloud integration tests."""
-
from collections.abc import Callable
from dataclasses import dataclass, field
from http import HTTPStatus
diff --git a/tests/fixtures/dashboards.py b/tests/fixtures/dashboards.py
new file mode 100644
index 0000000000..087ea1667d
--- /dev/null
+++ b/tests/fixtures/dashboards.py
@@ -0,0 +1,36 @@
+from collections.abc import Callable
+from http import HTTPStatus
+
+import pytest
+import requests
+
+from fixtures import types
+
+DASHBOARDS_BASE_URL = "/api/v2/dashboards"
+# MaxListLimit caps a single list page, so wiping a shared DB has to drain pages
+# until the list comes back empty.
+MAX_LIST_LIMIT = 200
+
+
[email protected](name="wipe_all_dashboards", scope="function")
+def wipe_all_dashboards(signoz: types.SigNoz) -> Callable[[str], None]:
+ def _wipe_all_dashboards(token: str) -> None:
+ while True:
+ response = requests.get(
+ signoz.self.host_configs["8080"].get(f"{DASHBOARDS_BASE_URL}?limit={MAX_LIST_LIMIT}"),
+ headers={"Authorization": f"Bearer {token}"},
+ timeout=5,
+ )
+ assert response.status_code == HTTPStatus.OK, response.text
+ dashboards = response.json()["data"]["dashboards"]
+ if not dashboards:
+ return
+ for dashboard in dashboards:
+ del_res = requests.delete(
+ signoz.self.host_configs["8080"].get(f"{DASHBOARDS_BASE_URL}/{dashboard['id']}"),
+ headers={"Authorization": f"Bearer {token}"},
+ timeout=5,
+ )
+ assert del_res.status_code == HTTPStatus.NO_CONTENT, del_res.text
+
+ return _wipe_all_dashboards
diff --git a/tests/fixtures/http.py b/tests/fixtures/http.py
index 65e7048b19..5c19f7b8fb 100644
--- a/tests/fixtures/http.py
+++ b/tests/fixtures/http.py
@@ -24,9 +24,6 @@ def zeus(
request: pytest.FixtureRequest,
pytestconfig: pytest.Config,
) -> types.TestContainerDocker:
- """
- Package-scoped fixture for running zeus
- """
def create() -> types.TestContainerDocker:
container = WireMockContainer(image="wiremock/wiremock:2.35.1-1", secure=False)
@@ -76,9 +73,6 @@ def gateway(
request: pytest.FixtureRequest,
pytestconfig: pytest.Config,
) -> types.TestContainerDocker:
- """
- Package-scoped fixture for running gateway
- """
def create() -> types.TestContainerDocker:
container = WireMockContainer(image="wiremock/wiremock:2.35.1-1", secure=False)
diff --git a/tests/fixtures/idp.py b/tests/fixtures/idp.py
index b0a2fbfb5b..9a6e926634 100644
--- a/tests/fixtures/idp.py
+++ b/tests/fixtures/idp.py
@@ -381,7 +381,6 @@ def idp_login(driver: webdriver.Chrome) -> Callable[[str, str], None]:
@pytest.fixture(name="create_group_idp", scope="function")
def create_group_idp(idp: types.TestContainerIDP) -> Callable[[str], str]:
- """Creates a group in Keycloak IDP."""
client = KeycloakAdmin(
server_url=idp.container.host_configs["6060"].base(),
username=IDP_ROOT_USERNAME,
@@ -410,7 +409,6 @@ def create_user_idp_with_groups(
idp: types.TestContainerIDP,
create_group_idp: Callable[[str], str], # pylint: disable=redefined-outer-name
) -> Callable[[str, str, bool, list[str]], None]:
- """Creates a user in Keycloak IDP with specified groups."""
client = KeycloakAdmin(
server_url=idp.container.host_configs["6060"].base(),
username=IDP_ROOT_USERNAME,
@@ -458,7 +456,6 @@ def add_user_to_group(
idp: types.TestContainerIDP,
create_group_idp: Callable[[str], str], # pylint: disable=redefined-outer-name
) -> Callable[[str, str], None]:
- """Adds an existing user to a group."""
client = KeycloakAdmin(
server_url=idp.container.host_configs["6060"].base(),
username=IDP_ROOT_USERNAME,
@@ -479,7 +476,6 @@ def create_user_idp_with_role(
idp: types.TestContainerIDP,
create_group_idp: Callable[[str], str], # pylint: disable=redefined-outer-name
) -> Callable[[str, str, bool, str, list[str]], None]:
- """Creates a user in Keycloak IDP with a custom role attribute and optional groups."""
client = KeycloakAdmin(
server_url=idp.container.host_configs["6060"].base(),
username=IDP_ROOT_USERNAME,
@@ -527,7 +523,6 @@ def create_user_idp_with_role(
@pytest.fixture(name="setup_user_profile", scope="package")
def setup_user_profile(idp: types.TestContainerIDP) -> Callable[[], None]:
- """Setup Keycloak User Profile with signoz_role attribute."""
def _setup_user_profile() -> None:
client = KeycloakAdmin(
@@ -568,7 +563,6 @@ def setup_user_profile(idp: types.TestContainerIDP) -> Callable[[], None]:
def _ensure_groups_client_scope(client: KeycloakAdmin) -> None:
- """Create 'groups' client scope if it doesn't exist."""
# Check if groups scope exists
scopes = client.get_client_scopes()
groups_scope_exists = any(s.get("name") == "groups" for s in scopes)
@@ -619,7 +613,6 @@ def _ensure_groups_client_scope(client: KeycloakAdmin) -> None:
def get_oidc_domain(signoz: types.SigNoz, admin_token: str) -> dict:
- """Helper to get the OIDC domain."""
response = requests.get(
signoz.self.host_configs["8080"].get("/api/v1/domains"),
headers={"Authorization": f"Bearer {admin_token}"},
@@ -632,7 +625,6 @@ def get_oidc_domain(signoz: types.SigNoz, admin_token: str) -> dict:
def get_user_by_email(signoz: types.SigNoz, admin_token: str, email: str) -> dict:
- """Helper to get a user by email."""
response = requests.get(
signoz.self.host_configs["8080"].get("/api/v1/user"),
timeout=2,
@@ -653,7 +645,6 @@ def perform_oidc_login(
email: str,
password: str,
) -> None:
- """Helper to perform OIDC login flow."""
session_context = get_session_context(email)
url = session_context["orgs"][0]["authNSupport"]["callback"][0]["url"]
parsed_url = urlparse(url)
diff --git a/tests/fixtures/inframonitoring.py b/tests/fixtures/inframonitoring.py
index 638b3161f7..18f9ecb47f 100644
--- a/tests/fixtures/inframonitoring.py
+++ b/tests/fixtures/inframonitoring.py
@@ -1,4 +1,14 @@
-"""Shared constants/helpers for v2 infra-monitoring pod-status tests."""
+import json
+from collections.abc import Callable
+from datetime import datetime
+
+import pytest
+
+from fixtures.fs import get_testdata_file_path
+from fixtures.metrics import Metrics
+from fixtures.time import parse_timestamp
+
+START_TIME_PLACEHOLDER = "__START_TIME__"
# All 18 PodCountsByStatus buckets (camelCase, matches inframonitoringtypes.PodCountsByStatus / the API response).
STATUS_BUCKETS = (
@@ -50,3 +60,45 @@ def expected_status_counts(**nonzero: int) -> dict:
counts = {bucket: 0 for bucket in STATUS_BUCKETS}
counts.update(nonzero)
return counts
+
+
[email protected](name="load_pods_metrics", scope="function")
+def load_pods_metrics() -> Callable[..., list[Metrics]]:
+ """Load pod metrics JSONL with optional k8s.pod.start_time substitution.
+
+ Mirrors Metrics.load_from_file's base_time rebase logic but adds a hook
+ for the start_time label. Lines carrying ``k8s.pod.start_time =
+ __START_TIME__`` get rewritten to ``start_time.isoformat()`` before
+ construction, ensuring podAge is deterministic across runs.
+ """
+
+ def _load_pods_metrics(
+ file_relpath: str,
+ base_time: datetime,
+ start_time: datetime | None = None,
+ ) -> list[Metrics]:
+ path = get_testdata_file_path(file_relpath)
+ start_time_iso = start_time.isoformat() if start_time else None
+ rows = []
+ with open(path, encoding="utf-8") as f:
+ for line in f:
+ line = line.strip()
+ if not line:
+ continue
+ data = json.loads(line)
+ labels = data.get("labels", {})
+ if start_time_iso and labels.get("k8s.pod.start_time") == START_TIME_PLACEHOLDER:
+ labels["k8s.pod.start_time"] = start_time_iso
+ rows.append(data)
+ if not rows:
+ return []
+ earliest = min(parse_timestamp(r["timestamp"]) for r in rows)
+ offset = base_time - earliest
+ metrics = []
+ for r in rows:
+ ts = parse_timestamp(r["timestamp"]) + offset
+ r["timestamp"] = ts.isoformat()
+ metrics.append(Metrics.from_dict(r))
+ return metrics
+
+ return _load_pods_metrics
diff --git a/tests/fixtures/jsontypes.py b/tests/fixtures/jsontypes.py
index d7d97ad092..12faa99c66 100644
--- a/tests/fixtures/jsontypes.py
+++ b/tests/fixtures/jsontypes.py
@@ -1,9 +1,3 @@
-"""
-Simpler version of metadataexporter for exporting jsontypes for test fixtures.
-This exports JSON type metadata to the path_types table by parsing JSON bodies
-and extracting all paths with their types, similar to how the real metadataexporter works.
-"""
-
import datetime
import json
from abc import ABC
@@ -21,8 +15,6 @@ from fixtures import types
class JSONPathType(ABC):
- """Represents a JSON path with its type information"""
-
field_name: str
field_data_type: str
last_seen: np.uint64
@@ -44,7 +36,6 @@ class JSONPathType(ABC):
self.last_seen = np.uint64(int(last_seen.timestamp() * 1e9))
def np_arr(self) -> np.array:
- """Return path type data as numpy array for database insertion"""
return np.array([self.signal, self.field_context, self.field_name, self.field_data_type, self.last_seen])
@@ -145,7 +136,7 @@ def _python_type_to_clickhouse_type(value: Any) -> str:
elif isinstance(value, dict):
return "json"
else:
- return "string" # Default fallback
+ return "string"
def _extract_json_paths(
@@ -154,19 +145,7 @@ def _extract_json_paths(
path_types: dict[str, set[str]] | None = None,
level: int = 0,
) -> dict[str, set[str]]:
- """
- Recursively extract all paths and their types from a JSON object.
- Matches metadataexporter's analyzePValue logic.
-
- Args:
- obj: The JSON object to traverse
- current_path: Current path being built (e.g., "user.name")
- path_types: Dictionary mapping paths to sets of types found
- level: Current nesting level (for depth limiting)
-
- Returns:
- Dictionary mapping paths to sets of type strings
- """
+ """Matches metadataexporter's analyzePValue logic."""
if path_types is None:
path_types = {}
@@ -179,17 +158,14 @@ def _extract_json_paths(
# Matches Go walkMap which recurses without calling ta.record on the map node.
for key, value in obj.items():
- # Build the path for this key
if current_path:
new_path = f"{current_path}.{key}"
else:
new_path = key
- # Recurse into the value
_extract_json_paths(value, new_path, path_types, level + 1)
elif isinstance(obj, list):
- # Skip empty arrays
if len(obj) == 0:
return path_types
@@ -246,17 +222,6 @@ def _parse_json_bodies_and_extract_paths(
json_bodies: list[str],
timestamp: datetime.datetime | None = None,
) -> list[JSONPathType]:
- """
- Parse JSON bodies and extract all paths with their types.
- This mimics the behavior of metadataexporter.
-
- Args:
- json_bodies: List of JSON body strings to parse
- timestamp: Timestamp to use for last_seen (defaults to now)
-
- Returns:
- List of JSONPathType objects with all discovered paths and types
- """
if timestamp is None:
timestamp = datetime.datetime.now()
@@ -268,11 +233,9 @@ def _parse_json_bodies_and_extract_paths(
parsed = json.loads(json_body)
_extract_json_paths(parsed, "", all_path_types, level=0)
except (json.JSONDecodeError, TypeError):
- # Skip invalid JSON
continue
- # Convert to list of JSONPathType objects
- # Each path can have multiple types, so we create one JSONPathType per type
+ # Each path can have multiple types -> one JSONPathType per type
path_type_objects: list[JSONPathType] = []
for path, types_set in all_path_types.items():
for type_str in types_set:
@@ -285,64 +248,34 @@ def _parse_json_bodies_and_extract_paths(
def export_json_types(
clickhouse: types.TestContainerClickhouse,
) -> Generator[Callable[[list[JSONPathType] | list[str] | list[Any]], None], Any]:
- """
- Fixture for exporting JSON type metadata to the path_types table.
- This is a simpler version of metadataexporter for test fixtures.
-
- The function can accept:
- 1. List of JSONPathType objects (manual specification)
- 2. List of JSON body strings (auto-extract paths)
- 3. List of Logs objects (extract from body_json field)
-
- Usage examples:
- # Manual specification
- export_json_types([
- JSONPathType(field_name="user.name", field_data_type="string"),
- JSONPathType(field_name="user.age", field_data_type="int64"),
- ])
-
- # Auto-extract from JSON strings
- export_json_types([
- '{"user": {"name": "alice", "age": 25}}',
- '{"user": {"name": "bob", "age": 30}}',
- ])
-
- # Auto-extract from Logs objects
- export_json_types(logs_list)
+ """Write JSON path/type metadata the way the real metadataexporter would.
+
+ Accepts JSONPathType objects (manual specification), raw JSON body strings,
+ or Logs objects (paths auto-extracted from the JSON body).
"""
def _export_json_types(
data: list[JSONPathType] | list[str] | list[Any], # List[Logs] but avoiding circular import
) -> None:
- """
- Export JSON type metadata to signoz_metadata.distributed_field_keys table.
- This table stores signal, context, path, and type information for body JSON fields.
- """
path_types: list[JSONPathType] = []
if len(data) == 0:
return
- # Determine input type and convert to JSONPathType list
first_item = data[0]
if isinstance(first_item, JSONPathType):
- # Already JSONPathType objects
path_types = data # type: ignore
elif isinstance(first_item, str):
- # List of JSON strings - parse and extract paths
path_types = _parse_json_bodies_and_extract_paths(data) # type: ignore
else:
# Assume it's a list of Logs objects - extract body_v2
json_bodies: list[str] = []
for log in data: # type: ignore
- # Try to get body_v2 attribute
if hasattr(log, "body_v2") and log.body_v2:
json_bodies.append(log.body_v2)
elif hasattr(log, "body") and log.body:
- # Fallback to body if body_v2 not available
try:
- # Try to parse as JSON
json.loads(log.body)
json_bodies.append(log.body)
except (json.JSONDecodeError, TypeError):
@@ -369,7 +302,6 @@ def export_json_types(
yield _export_json_types
- # Cleanup - truncate the local table after tests (following pattern from logs fixture)
clickhouse.conn.query(f"TRUNCATE TABLE signoz_metadata.field_keys ON CLUSTER '{clickhouse.env['SIGNOZ_TELEMETRYSTORE_CLICKHOUSE_CLUSTER']}' SYNC")
diff --git a/tests/fixtures/keeper.py b/tests/fixtures/keeper.py
index 43c9e20ef5..e32a394d57 100644
--- a/tests/fixtures/keeper.py
+++ b/tests/fixtures/keeper.py
@@ -109,9 +109,6 @@ def keeper(
request: pytest.FixtureRequest,
pytestconfig: pytest.Config,
) -> types.TestContainerDocker:
- """
- Package-scoped fixture for ClickHouse Keeper TestContainer.
- """
return create_clickhouse_keeper(
tmpfs=tmpfs,
network=network,
diff --git a/tests/fixtures/keycloak.py b/tests/fixtures/keycloak.py
index 9ad15b5235..562bbab1cd 100644
--- a/tests/fixtures/keycloak.py
+++ b/tests/fixtures/keycloak.py
@@ -19,9 +19,6 @@ def idp(
request: pytest.FixtureRequest,
pytestconfig: pytest.Config,
) -> types.TestContainerIDP:
- """
- Package-scoped fixture for running an idp for SSO/SAML
- """
def create() -> types.TestContainerIDP:
container = KeycloakContainer(
diff --git a/tests/fixtures/logs.py b/tests/fixtures/logs.py
index cff6f55d37..9e66a8aff3 100644
--- a/tests/fixtures/logs.py
+++ b/tests/fixtures/logs.py
@@ -311,7 +311,6 @@ class Logs(ABC):
self.attribute_keys.append(LogsResourceOrAttributeKeys(name="severity_number", datatype="float64"))
def _get_severity_number(self, severity_text: str) -> np.uint8:
- """Convert severity text to numeric value"""
severity_map = {
"TRACE": 1,
"DEBUG": 5,
@@ -324,7 +323,6 @@ class Logs(ABC):
return np.uint8(severity_map.get(severity_text.upper(), 9)) # Default to INFO
def np_arr(self) -> np.array:
- """Return log data as numpy array for database insertion"""
return np.array(
[
self.ts_bucket_start,
@@ -356,7 +354,6 @@ class Logs(ABC):
cls,
data: dict,
) -> "Logs":
- """Create a Logs instance from a dict."""
# parse timestamp from iso format
timestamp = parse_timestamp(data["timestamp"])
return cls(
diff --git a/tests/fixtures/migrator.py b/tests/fixtures/migrator.py
index 64870f5e6c..9c012aac4d 100644
--- a/tests/fixtures/migrator.py
+++ b/tests/fixtures/migrator.py
@@ -92,9 +92,6 @@ def migrator(
request: pytest.FixtureRequest,
pytestconfig: pytest.Config,
) -> types.Operation:
- """
- Package-scoped fixture for running schema migrations.
- """
return create_migrator(
network=network,
clickhouse=clickhouse,
diff --git a/tests/fixtures/network.py b/tests/fixtures/network.py
index 6d7f08f241..cc36f01876 100644
--- a/tests/fixtures/network.py
+++ b/tests/fixtures/network.py
@@ -13,9 +13,6 @@ logger = setup_logger(__name__)
@pytest.fixture(name="network", scope="package")
def network(request: pytest.FixtureRequest, pytestconfig: pytest.Config) -> types.Network:
- """
- Package-Scoped fixture for creating a network
- """
def create() -> types.Network:
nw = Network()
diff --git a/tests/fixtures/postgres.py b/tests/fixtures/postgres.py
index 1b1f2256be..7277f65456 100644
--- a/tests/fixtures/postgres.py
+++ b/tests/fixtures/postgres.py
@@ -13,9 +13,6 @@ logger = setup_logger(__name__)
@pytest.fixture(name="postgres", scope="package")
def postgres(network: Network, request: pytest.FixtureRequest, pytestconfig: pytest.Config) -> types.TestContainerSQL:
- """
- Package-scoped fixture for PostgreSQL TestContainer.
- """
def create() -> types.TestContainerSQL:
version = request.config.getoption("--postgres-version")
diff --git a/tests/fixtures/querier.py b/tests/fixtures/querier.py
index 1fafa781b2..d690bd8881 100644
--- a/tests/fixtures/querier.py
+++ b/tests/fixtures/querier.py
@@ -1,8 +1,10 @@
+from collections.abc import Callable
from dataclasses import dataclass
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
from typing import Any
+import pytest
import requests
from fixtures import types
@@ -1109,3 +1111,51 @@ def make_scalar_query_request(
"formatOptions": {"formatTableResultForUI": True, "fillGaps": False},
},
)
+
+
[email protected](name="run_query_case", scope="function")
+def run_query_case(signoz: types.SigNoz) -> Callable[[str, datetime, dict[str, Any]], None]:
+ def _run_query_case(token: str, now: datetime, case: dict[str, Any]) -> None:
+ start_ms = case.get("startMs", int((now - timedelta(seconds=10)).timestamp() * 1000))
+ end_ms = case.get("endMs", int(now.timestamp() * 1000))
+
+ if case["requestType"] == "raw":
+ query = build_raw_query(
+ name=case["name"],
+ signal="logs",
+ filter_expression=case.get("expression"),
+ order=case.get("order") or [build_order_by("timestamp", "desc")],
+ limit=case.get("limit", 100),
+ step_interval=case.get("stepInterval") or 60,
+ )
+ else:
+ aggregation = case.get("aggregation")
+ if aggregation and not isinstance(aggregation, list):
+ aggregations = [build_aggregation(aggregation)]
+ elif aggregation:
+ aggregations = aggregation
+ else:
+ aggregations = []
+ query = build_scalar_query(
+ name=case["name"],
+ signal="logs",
+ aggregations=aggregations,
+ group_by=case.get("groupBy"),
+ order=case.get("order"),
+ limit=case.get("limit", 100),
+ filter_expression=case.get("expression"),
+ step_interval=case.get("stepInterval") or 60,
+ )
+
+ response = make_query_request(
+ signoz=signoz,
+ token=token,
+ start_ms=start_ms,
+ end_ms=end_ms,
+ queries=[query],
+ request_type=case["requestType"],
+ )
+ assert response.status_code == 200, f"HTTP {response.status_code} for case '{case['name']}': {response.text}"
+ assert case["validate"](response), f"Validation failed for case '{case['name']}': {response.json()}"
+
+ return _run_query_case
diff --git a/tests/fixtures/querierai.py b/tests/fixtures/querierai.py
index 4562d105aa..07d80cb2a5 100644
--- a/tests/fixtures/querierai.py
+++ b/tests/fixtures/querierai.py
@@ -1,8 +1,3 @@
-"""
-Trace builders for the querierai suite. Every builder pins its spans a few seconds
-before the given `now` so `query_window(now)` covers them.
-"""
-
from datetime import datetime, timedelta
from fixtures.traces import TraceIdGenerator, Traces, TracesKind, TracesStatusCode
diff --git a/tests/fixtures/reuse.py b/tests/fixtures/reuse.py
index 4532af0960..803e9b874d 100644
--- a/tests/fixtures/reuse.py
+++ b/tests/fixtures/reuse.py
@@ -19,17 +19,14 @@ def teardown(request: pytest.FixtureRequest) -> bool:
def get_cached_resource(pytestconfig: pytest.Config, key: str):
- """Get a resource from pytest cache by key."""
return pytestconfig.cache.get(key, None)
def set_cached_resource(pytestconfig: pytest.Config, key: str, value):
- """Set a resource in pytest cache by key."""
pytestconfig.cache.set(key, value)
def remove_cached_resource(pytestconfig: pytest.Config, key: str):
- """Remove a resource from pytest cache by key (set to None)."""
pytestconfig.cache.set(key, None)
diff --git a/tests/fixtures/role.py b/tests/fixtures/role.py
index 41bd7c0473..6f3835bfff 100644
--- a/tests/fixtures/role.py
+++ b/tests/fixtures/role.py
@@ -1,5 +1,3 @@
-"""Fixtures and helpers for role tests."""
-
import json
from collections.abc import Callable
from http import HTTPStatus
diff --git a/tests/fixtures/seed_golden_dataset.py b/tests/fixtures/seed_golden_dataset.py
index 2ad5dc30d4..68c0140c7d 100644
--- a/tests/fixtures/seed_golden_dataset.py
+++ b/tests/fixtures/seed_golden_dataset.py
@@ -1,11 +1,3 @@
-"""Golden dataset fixture — seeds OTel-demo-shaped metrics, traces, and
-logs into ClickHouse via the seeder on every test_setup invocation.
-
-Timestamps are rebased to `now` so panels with default time windows
-always find data. To refresh the dataset shape on disk, run
-`uv run python -m fixtures.seed_golden_dataset regenerate`.
-"""
-
from __future__ import annotations
import datetime
diff --git a/tests/fixtures/serviceaccount.py b/tests/fixtures/serviceaccount.py
index 44ac6e5c8a..5d253aae44 100644
--- a/tests/fixtures/serviceaccount.py
+++ b/tests/fixtures/serviceaccount.py
@@ -1,5 +1,3 @@
-"""Fixtures and helpers for service account tests."""
-
from http import HTTPStatus
import requests
diff --git a/tests/fixtures/signoz.py b/tests/fixtures/signoz.py
index 2793ae5fe6..86f24b112f 100644
--- a/tests/fixtures/signoz.py
+++ b/tests/fixtures/signoz.py
@@ -225,9 +225,6 @@ def signoz( # pylint: disable=too-many-arguments,too-many-positional-arguments
request: pytest.FixtureRequest,
pytestconfig: pytest.Config,
) -> types.SigNoz:
- """
- Package-scoped fixture for setting up SigNoz.
- """
return create_signoz(
network=network,
zeus=zeus,
diff --git a/tests/fixtures/sql.py b/tests/fixtures/sql.py
index 792b79d309..d8666ab40e 100644
--- a/tests/fixtures/sql.py
+++ b/tests/fixtures/sql.py
@@ -7,9 +7,6 @@ from fixtures import types
def sqlstore(
request: pytest.FixtureRequest,
) -> types.TestContainerSQL:
- """
- Packaged-scoped fixture for creating sql store.
- """
provider = request.config.getoption("--sqlstore-provider")
if provider == "postgres":
diff --git a/tests/fixtures/sqlite.py b/tests/fixtures/sqlite.py
index 23ac6cedc9..5378057b7a 100644
--- a/tests/fixtures/sqlite.py
+++ b/tests/fixtures/sqlite.py
@@ -16,9 +16,6 @@ def sqlite(
request: pytest.FixtureRequest,
pytestconfig: pytest.Config,
) -> types.TestContainerSQL:
- """
- Package-scoped fixture for SQLite.
- """
def create() -> types.TestContainerSQL:
tmpdir = tmpfs("sqlite")
diff --git a/tests/fixtures/thirdpartyapi.py b/tests/fixtures/thirdpartyapi.py
index 95912ae2ab..67aa4c6a78 100644
--- a/tests/fixtures/thirdpartyapi.py
+++ b/tests/fixtures/thirdpartyapi.py
@@ -1,9 +1,3 @@
-"""Shared helpers for the third-party (external) API monitoring domain list.
-
-A translator over v5 builder queries that answers with a UI-formatted scalar table, so the
-response is read by column rather than by series.
-"""
-
from typing import Any
import requests
@@ -49,7 +43,9 @@ def make_third_party_apis_request(
def scalar_result(response: requests.Response) -> dict:
- """The single scalar table from a third-party-apis response."""
+ """The single scalar table from a third-party-apis response. The endpoint is a
+ translator over v5 builder queries answering with a UI-formatted scalar table,
+ so the response is read by column rather than by series."""
return response.json()["data"]["data"]["results"][0]
diff --git a/tests/fixtures/time.py b/tests/fixtures/time.py
index 54e9cedba9..91e1816ed1 100644
--- a/tests/fixtures/time.py
+++ b/tests/fixtures/time.py
@@ -6,9 +6,6 @@ import isodate
# parses the given timestamp string from ISO format to datetime.datetime
def parse_timestamp(ts_str: str) -> datetime.datetime:
- """
- Parse a timestamp string from ISO format.
- """
if ts_str.endswith("Z"):
ts_str = ts_str[:-1] + "+00:00"
return datetime.datetime.fromisoformat(ts_str)
@@ -16,9 +13,6 @@ def parse_timestamp(ts_str: str) -> datetime.datetime:
# parses the given duration to datetime.timedelta
def parse_duration(duration: Any) -> datetime.timedelta:
- """
- Parse a duration string from ISO format.
- """
# if it's string then parse it as iso format
if isinstance(duration, str):
return isodate.parse_duration(duration)
diff --git a/tests/fixtures/traces.py b/tests/fixtures/traces.py
index f4314158ae..0572ab4e59 100644
--- a/tests/fixtures/traces.py
+++ b/tests/fixtures/traces.py
@@ -625,7 +625,6 @@ class Traces(ABC):
self.response_status_code = str_value
def np_arr(self) -> np.array:
- """Return span data as numpy array for database insertion"""
return np.array(
[
self.ts_bucket_start,
@@ -669,7 +668,6 @@ class Traces(ABC):
cls,
data: dict,
) -> "Traces":
- """Create a Traces instance from a dict."""
# parse timestamp from iso format
timestamp = parse_timestamp(data["timestamp"])
duration = parse_duration(data.get("duration", "PT1S"))
diff --git a/tests/integration/tests/alerts/01_notification_channel.py b/tests/integration/tests/alerts/01_notification_channel.py
index 7755d4407c..29b89e3de5 100644
--- a/tests/integration/tests/alerts/01_notification_channel.py
+++ b/tests/integration/tests/alerts/01_notification_channel.py
@@ -20,9 +20,6 @@ def test_webhook_notification_channel(
make_http_mocks: Callable[[types.TestContainerDocker, list[Mapping]], None],
create_webhook_notification_channel: Callable[[str, str, dict, bool], str],
) -> None:
- """
- Tests the creation and delivery of test alerts on the created notification channel
- """
logger.info("Setting up notification channel")
# Prepare notification channel name and webhook endpoint
diff --git a/tests/integration/tests/callbackauthn/01_domain.py b/tests/integration/tests/callbackauthn/01_domain.py
index 2a8207b37a..7f140f0527 100644
--- a/tests/integration/tests/callbackauthn/01_domain.py
+++ b/tests/integration/tests/callbackauthn/01_domain.py
@@ -176,7 +176,6 @@ def test_create_invalid_role_mapping(
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
):
- """Test that invalid role mappings are rejected."""
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
# Create domain with invalid defaultRole
diff --git a/tests/integration/tests/callbackauthn/02_saml.py b/tests/integration/tests/callbackauthn/02_saml.py
index 45049f21d6..fca49bea5d 100644
--- a/tests/integration/tests/callbackauthn/02_saml.py
+++ b/tests/integration/tests/callbackauthn/02_saml.py
@@ -216,9 +216,6 @@ def test_saml_role_mapping_single_group_admin(
get_token: Callable[[str, str], str],
get_session_context: Callable[[str], str],
) -> None:
- """
- Test: User in 'signoz-admins' group gets ADMIN role.
- """
create_user_idp_with_groups(email, "password", True, ["signoz-admins"])
@@ -239,9 +236,6 @@ def test_saml_role_mapping_single_group_editor(
get_token: Callable[[str, str], str],
get_session_context: Callable[[str], str],
) -> None:
- """
- Test: User in 'signoz-editors' group gets EDITOR role.
- """
create_user_idp_with_groups(email, "password", True, ["signoz-editors"])
@@ -311,9 +305,6 @@ def test_saml_role_mapping_unmapped_group_uses_default(
get_token: Callable[[str, str], str],
get_session_context: Callable[[str], str],
) -> None:
- """
- Test: User in unmapped group falls back to default role (VIEWER).
- """
create_user_idp_with_groups(email, "password", True, ["some-other-group"])
@@ -462,7 +453,6 @@ def test_saml_name_mapping(
get_token: Callable[[str, str], str],
get_session_context: Callable[[str], str],
) -> None:
- """Test that user's display name is mapped from SAML displayName attribute."""
create_user_idp(email, "password", True, "Jane", "Smith")
@@ -485,7 +475,6 @@ def test_saml_empty_name_fallback(
get_token: Callable[[str, str], str],
get_session_context: Callable[[str], str],
) -> None:
- """Test that user without displayName in IDP still gets created."""
create_user_idp(email, "password", True)
diff --git a/tests/integration/tests/callbackauthn/03_oidc.py b/tests/integration/tests/callbackauthn/03_oidc.py
index f01bbff6bc..ae1590ad99 100644
--- a/tests/integration/tests/callbackauthn/03_oidc.py
+++ b/tests/integration/tests/callbackauthn/03_oidc.py
@@ -26,9 +26,6 @@ def test_apply_license(
make_http_mocks: Callable[[TestContainerDocker, list[Mapping]], None],
get_token: Callable[[str, str], str],
) -> None:
- """
- This applies a license to the signoz instance.
- """
add_license(signoz, make_http_mocks, get_token)
@@ -40,9 +37,6 @@ def test_create_auth_domain(
create_user_admin: Callable[[], None], # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
) -> None:
- """
- This creates an OIDC auth domain in signoz.
- """
client_id = f"oidc.integration.test.{signoz.self.host_configs['8080'].address}:{signoz.self.host_configs['8080'].port}"
# Create a saml client in the idp.
create_oidc_client(client_id, "/api/v1/complete/oidc")
@@ -121,9 +115,6 @@ def test_oidc_update_domain_with_group_mappings(
get_token: Callable[[str, str], str],
get_oidc_settings: Callable[[str], dict],
) -> None:
- """
- Updates OIDC domain to add role mapping with group mappings and claim mapping.
- """
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
domain = get_oidc_domain(signoz, admin_token)
client_id = f"oidc.integration.test.{signoz.self.host_configs['8080'].address}:{signoz.self.host_configs['8080'].port}"
@@ -175,9 +166,6 @@ def test_oidc_role_mapping_single_group_admin(
get_token: Callable[[str, str], str],
get_session_context: Callable[[str], str],
) -> None:
- """
- Test: OIDC user in 'signoz-admins' group gets ADMIN role.
- """
create_user_idp_with_groups(email, "password123", True, ["signoz-admins"])
@@ -198,9 +186,6 @@ def test_oidc_role_mapping_single_group_editor(
get_token: Callable[[str, str], str],
get_session_context: Callable[[str], str],
) -> None:
- """
- Test: OIDC user in 'signoz-editors' group gets EDITOR role.
- """
create_user_idp_with_groups(email, "password123", True, ["signoz-editors"])
@@ -270,9 +255,6 @@ def test_oidc_role_mapping_unmapped_group_uses_default(
get_token: Callable[[str, str], str],
get_session_context: Callable[[str], str],
) -> None:
- """
- Test: OIDC user in unmapped group falls back to default role.
- """
create_user_idp_with_groups(email, "password123", True, ["some-other-group"])
@@ -290,9 +272,6 @@ def test_oidc_update_domain_with_use_role_claim(
get_token: Callable[[str, str], str],
get_oidc_settings: Callable[[str], dict],
) -> None:
- """
- Updates OIDC domain to enable useRoleClaim.
- """
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
domain = get_oidc_domain(signoz, admin_token)
client_id = f"oidc.integration.test.{signoz.self.host_configs['8080'].address}:{signoz.self.host_configs['8080'].port}"
@@ -424,7 +403,6 @@ def test_oidc_name_mapping(
get_token: Callable[[str, str], str],
get_session_context: Callable[[str], dict],
) -> None:
- """Test that user's display name is mapped from IDP name claim."""
# Create user with explicit first/last name
@@ -449,7 +427,6 @@ def test_oidc_empty_name_uses_fallback(
get_token: Callable[[str, str], str],
get_session_context: Callable[[str], dict],
) -> None:
- """Test that user without name in IDP still gets created (may have empty displayName)."""
# Create user without first/last name
diff --git a/tests/integration/tests/cloudintegrations/02_create_account.py b/tests/integration/tests/cloudintegrations/02_create_account.py
index 97c01ddd5d..522448a729 100644
--- a/tests/integration/tests/cloudintegrations/02_create_account.py
+++ b/tests/integration/tests/cloudintegrations/02_create_account.py
@@ -25,7 +25,6 @@ def test_create_account(
get_token: Callable[[str, str], str],
create_cloud_integration_account: Callable,
) -> None:
- """Test creating a new cloud integration account for AWS."""
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
cloud_provider = "aws"
@@ -54,7 +53,6 @@ def test_create_account_unsupported_provider(
create_user_admin: types.Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
) -> None:
- """Test that creating an account with an unsupported cloud provider returns 400."""
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
cloud_provider = "unknown"
endpoint = f"/api/v1/cloud_integrations/{cloud_provider}/accounts"
diff --git a/tests/integration/tests/cloudintegrations/03_agent_check_in.py b/tests/integration/tests/cloudintegrations/03_agent_check_in.py
index 7b5e513b5c..ab1a146da5 100644
--- a/tests/integration/tests/cloudintegrations/03_agent_check_in.py
+++ b/tests/integration/tests/cloudintegrations/03_agent_check_in.py
@@ -28,7 +28,6 @@ def test_agent_check_in(
get_token: Callable[[str, str], str],
create_cloud_integration_account: Callable,
) -> None:
- """Test agent check-in with new camelCase fields returns 200 with expected response shape."""
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
account = create_cloud_integration_account(admin_token, CLOUD_PROVIDER, regions=["us-east-1"])
@@ -71,7 +70,6 @@ def test_agent_check_in_account_not_found(
create_user_admin: types.Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
) -> None:
- """Test that check-in with an unknown cloudIntegrationId returns 404."""
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
fake_id = str(uuid.uuid4())
diff --git a/tests/integration/tests/dashboard/01_dashboard.py b/tests/integration/tests/dashboard/01_dashboard.py
index b0f8735ac1..c042de36a9 100644
--- a/tests/integration/tests/dashboard/01_dashboard.py
+++ b/tests/integration/tests/dashboard/01_dashboard.py
@@ -18,9 +18,6 @@ def test_apply_license(
make_http_mocks: Callable[[TestContainerDocker, list[Mapping]], None],
get_token: Callable[[str, str], str],
) -> None:
- """
- This applies a license to the signoz instance.
- """
add_license(signoz, make_http_mocks, get_token)
diff --git a/tests/integration/tests/dashboard/02_public_dashboard.py b/tests/integration/tests/dashboard/02_public_dashboard.py
index 34bb4f164b..b2d603261e 100644
--- a/tests/integration/tests/dashboard/02_public_dashboard.py
+++ b/tests/integration/tests/dashboard/02_public_dashboard.py
@@ -16,9 +16,6 @@ def test_apply_license(
make_http_mocks: Callable[[TestContainerDocker, list[Mapping]], None],
get_token: Callable[[str, str], str],
) -> None:
- """
- This applies a license to the signoz instance.
- """
add_license(signoz, make_http_mocks, get_token)
diff --git a/tests/integration/tests/dashboard/03_v2_dashboard.py b/tests/integration/tests/dashboard/03_v2_dashboard.py
index 20d8eb38c6..d7a3c39a0f 100644
--- a/tests/integration/tests/dashboard/03_v2_dashboard.py
+++ b/tests/integration/tests/dashboard/03_v2_dashboard.py
@@ -10,29 +10,6 @@ from fixtures.metrics import Metrics
from fixtures.types import Operation, SigNoz
BASE_URL = "/api/v2/dashboards"
-# MaxListLimit caps a single list page, so wiping a shared DB has to drain pages
-# until the list comes back empty.
-MAX_LIST_LIMIT = 200
-
-
-def _wipe_all_dashboards(signoz: SigNoz, token: str) -> None:
- while True:
- response = requests.get(
- signoz.self.host_configs["8080"].get(f"{BASE_URL}?limit={MAX_LIST_LIMIT}"),
- headers={"Authorization": f"Bearer {token}"},
- timeout=5,
- )
- assert response.status_code == HTTPStatus.OK, response.text
- dashboards = response.json()["data"]["dashboards"]
- if not dashboards:
- return
- for dashboard in dashboards:
- del_res = requests.delete(
- signoz.self.host_configs["8080"].get(f"{BASE_URL}/{dashboard['id']}"),
- headers={"Authorization": f"Bearer {token}"},
- timeout=5,
- )
- assert del_res.status_code == HTTPStatus.NO_CONTENT, del_res.text
# ─── failure cases (create no dashboards) ────────────────────────────────────
@@ -625,6 +602,7 @@ def test_dashboard_v2_lifecycle( # pylint: disable=too-many-locals,too-many-sta
signoz: SigNoz,
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
+ wipe_all_dashboards: Callable[[str], None],
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
@@ -632,7 +610,7 @@ def test_dashboard_v2_lifecycle( # pylint: disable=too-many-locals,too-many-sta
# runs, so start from a clean slate: delete every dashboard (which also clears
# pins via the delete cascade). This test then owns the whole dashboard space
# and asserts on global counts.
- _wipe_all_dashboards(signoz, token)
+ wipe_all_dashboards(token)
dashboard_requests = [
(
@@ -1269,6 +1247,7 @@ def test_dashboard_v2_pin_limit(
signoz: SigNoz,
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
+ wipe_all_dashboards: Callable[[str], None],
):
max_pinned = 10
@@ -1276,7 +1255,7 @@ def test_dashboard_v2_pin_limit(
# Wipe the dashboard space (see lifecycle) so the per-user pin cap this test
# asserts against starts empty — deleting dashboards clears their pins.
- _wipe_all_dashboards(signoz, token)
+ wipe_all_dashboards(token)
ids: list[str] = []
for i in range(max_pinned + 1):
@@ -1364,12 +1343,13 @@ def test_dashboard_v2_like_escaping(
signoz: SigNoz,
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
+ wipe_all_dashboards: Callable[[str], None],
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
# Wipe the dashboard space (see lifecycle) so the filter assertions run
# against only the dashboards this test creates.
- _wipe_all_dashboards(signoz, token)
+ wipe_all_dashboards(token)
dashboard_requests = [
("esc-pct", "Cost 50% Report"),
@@ -1440,6 +1420,7 @@ def test_dashboard_v2_get_by_metric_name(
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
insert_metrics: Callable[[list[Metrics]], None],
+ wipe_all_dashboards: Callable[[str], None],
) -> None:
"""The v3 endpoint shortlists dashboards via a coarse data prefilter, then
confirms matches by parsing the typed v2 panels. It must find the metric in
@@ -1447,7 +1428,7 @@ def test_dashboard_v2_get_by_metric_name(
the metric appears only in panel names (the prefilter matches but the parse
rejects it)."""
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- _wipe_all_dashboards(signoz, token)
+ wipe_all_dashboards(token)
target_metric = "system.network.dropped"
decoy_metric = "system.network.io"
diff --git a/tests/integration/tests/inframonitoring/01_hosts.py b/tests/integration/tests/inframonitoring/01_hosts.py
index 014355fb0b..f533f3caf8 100644
--- a/tests/integration/tests/inframonitoring/01_hosts.py
+++ b/tests/integration/tests/inframonitoring/01_hosts.py
@@ -1,5 +1,3 @@
-"""Integration tests for v2 infra-monitoring host endpoints."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/inframonitoring/02_pods.py b/tests/integration/tests/inframonitoring/02_pods.py
index 7cfa11e0cc..21838afbed 100644
--- a/tests/integration/tests/inframonitoring/02_pods.py
+++ b/tests/integration/tests/inframonitoring/02_pods.py
@@ -1,5 +1,3 @@
-"""Integration tests for v2 infra-monitoring pod endpoints."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
@@ -11,51 +9,11 @@ from fixtures import types
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
from fixtures.fs import get_testdata_file_path
from fixtures.inframonitoring import STATUS_BUCKETS, STATUS_TO_BUCKET
-from fixtures.metrics import Metrics
from fixtures.querier import compare_values, get_all_warnings
-from fixtures.time import parse_timestamp
ENDPOINT = "/api/v2/infra_monitoring/pods"
# Placeholder in JSONL labels that gets substituted with a runtime ISO string.
-START_TIME_PLACEHOLDER = "__START_TIME__"
-
-
-def _load_pods_metrics(
- file_relpath: str,
- base_time: datetime,
- start_time: datetime | None = None,
-) -> list[Metrics]:
- """Load pod metrics JSONL with optional k8s.pod.start_time substitution.
-
- Mirrors Metrics.load_from_file's base_time rebase logic but adds a hook
- for the start_time label. Lines carrying ``k8s.pod.start_time =
- __START_TIME__`` get rewritten to ``start_time.isoformat()`` before
- construction, ensuring podAge is deterministic across runs.
- """
- path = get_testdata_file_path(file_relpath)
- start_time_iso = start_time.isoformat() if start_time else None
- rows = []
- with open(path, encoding="utf-8") as f:
- for line in f:
- line = line.strip()
- if not line:
- continue
- data = json.loads(line)
- labels = data.get("labels", {})
- if start_time_iso and labels.get("k8s.pod.start_time") == START_TIME_PLACEHOLDER:
- labels["k8s.pod.start_time"] = start_time_iso
- rows.append(data)
- if not rows:
- return []
- earliest = min(parse_timestamp(r["timestamp"]) for r in rows)
- offset = base_time - earliest
- metrics = []
- for r in rows:
- ts = parse_timestamp(r["timestamp"]) + offset
- r["timestamp"] = ts.isoformat()
- metrics.append(Metrics.from_dict(r))
- return metrics
def test_pods_accuracy(
@@ -63,6 +21,7 @@ def test_pods_accuracy(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
) -> None:
"""Seed 2 pods x 7 metrics; assert response shape/contract + exact per-pod
metric values, podAge, and podCountsByStatus against precomputed expected
@@ -70,7 +29,7 @@ def test_pods_accuracy(
now = datetime.now(tz=UTC).replace(microsecond=0)
start_time = now - timedelta(minutes=10)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_value_accuracy.jsonl",
base_time=now - timedelta(minutes=4),
start_time=start_time,
@@ -191,6 +150,7 @@ def test_pods_warnings(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
case: dict,
) -> None:
"""A never-ingested metric surfaces a non-blocking warning (200 + data), not a
@@ -200,7 +160,7 @@ def test_pods_warnings(
once, for hosts, in 01_hosts.py.)"""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
f"inframonitoring/{case['dataset']}",
base_time=now - timedelta(minutes=4),
)
@@ -289,6 +249,7 @@ def test_pods_filter(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
expression: str,
expected_pods: set,
) -> None:
@@ -308,7 +269,7 @@ def test_pods_filter(
}
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_filter_dataset.jsonl",
base_time=now - timedelta(minutes=4),
)
@@ -349,6 +310,7 @@ def test_pods_filter_invalid(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
expression: str,
err_substr,
) -> None:
@@ -356,7 +318,7 @@ def test_pods_filter_invalid(
400 invalid_input with structured errors."""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_filter_dataset.jsonl",
base_time=now - timedelta(minutes=4),
)
@@ -395,6 +357,7 @@ def test_pods_groupby(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
group_key: str,
expected_groups: set,
) -> None:
@@ -404,7 +367,7 @@ def test_pods_groupby(
"""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_groupby.jsonl",
base_time=now - timedelta(minutes=4),
)
@@ -449,13 +412,14 @@ def test_pods_pagination(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
) -> None:
"""Pagination: per-page len matches min(limit, total-offset), total invariant,
pages cover the full set with no overlap. The final offset is beyond total:
it returns empty records while total still reflects dataset size."""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_pagination.jsonl",
base_time=now - timedelta(minutes=4),
)
@@ -511,6 +475,7 @@ def test_pods_orderby( # pylint: disable=too-many-arguments,too-many-positional
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
column: str,
record_field,
direction: str,
@@ -519,7 +484,7 @@ def test_pods_orderby( # pylint: disable=too-many-arguments,too-many-positional
sort) and records come back sorted by the requested column."""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_orderby.jsonl",
base_time=now - timedelta(minutes=4),
)
@@ -645,6 +610,7 @@ def test_pods_status_list_mode(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
pod_name: str,
expected_status: str,
) -> None:
@@ -665,7 +631,7 @@ def test_pods_status_list_mode(
"""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_phases.jsonl",
base_time=now - timedelta(minutes=4),
)
@@ -713,6 +679,7 @@ def test_pods_restarts_list_mode(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
pod_name: str,
expected_restarts: int,
) -> None:
@@ -721,7 +688,7 @@ def test_pods_restarts_list_mode(
series -> -1 no-data sentinel (kubectl would show 0)."""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_phases.jsonl",
base_time=now - timedelta(minutes=4),
)
@@ -752,6 +719,7 @@ def test_pods_status_latest_wins(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
) -> None:
"""A stale container reason from an old incarnation must not win. trans-p's
first incarnation (container.id=aaa) reported CrashLoopBackOff, then it
@@ -760,7 +728,7 @@ def test_pods_status_latest_wins(
ignored via argMax-by-latest-timestamp per (pod, container, reason)."""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_phases_transition.jsonl",
base_time=now - timedelta(minutes=8),
)
@@ -790,6 +758,7 @@ def test_pods_restarts_latest_wins(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
) -> None:
"""restartCount is cumulative per container. Across incarnations
(container.id=aaa reported 1, then container.id=bbb reported 5) podRestarts
@@ -797,7 +766,7 @@ def test_pods_restarts_latest_wins(
not be double-counted."""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_phases_transition.jsonl",
base_time=now - timedelta(minutes=8),
)
@@ -827,6 +796,7 @@ def test_pods_status_grouped_mode(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
) -> None:
"""groupBy=[k8s.namespace.name] aggregates each pod's display status across
ns-mixed. podStatus is no-data (no single pod identifies the group). Seeded
@@ -834,7 +804,7 @@ def test_pods_status_grouped_mode(
g-fail-1 Error, g-fail-2 Evicted, g-pend-1 Pending."""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_phases_grouped.jsonl",
base_time=now - timedelta(minutes=4),
)
@@ -883,12 +853,13 @@ def test_pods_restarts_grouped_mode(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
) -> None:
"""Grouped podRestarts is the sum of restarts across all pods in the group.
In ns-mixed only g-run-2 has restarts (3); all others 0 -> group total 3."""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_phases_grouped.jsonl",
base_time=now - timedelta(minutes=4),
)
@@ -925,6 +896,7 @@ def test_pods_status_missing_metric_warning(
create_user_admin: None, # pylint: disable=unused-argument
get_token,
insert_metrics,
+ load_pods_metrics,
) -> None:
"""When the status metrics were never ingested, the status query is gated
off: a warning naming the missing metric(s) is surfaced, podStatus is the
@@ -932,7 +904,7 @@ def test_pods_status_missing_metric_warning(
seeds only k8s.pod.cpu.usage.)"""
now = datetime.now(tz=UTC).replace(microsecond=0)
insert_metrics(
- _load_pods_metrics(
+ load_pods_metrics(
"inframonitoring/pods_missing_metrics.jsonl",
base_time=now - timedelta(minutes=4),
)
diff --git a/tests/integration/tests/inframonitoring/03_nodes.py b/tests/integration/tests/inframonitoring/03_nodes.py
index a93a5ab1d8..3b814e2a70 100644
--- a/tests/integration/tests/inframonitoring/03_nodes.py
+++ b/tests/integration/tests/inframonitoring/03_nodes.py
@@ -1,5 +1,3 @@
-"""Integration tests for v2 infra-monitoring node endpoints."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/inframonitoring/04_namespaces.py b/tests/integration/tests/inframonitoring/04_namespaces.py
index 3724bfe078..598e90d149 100644
--- a/tests/integration/tests/inframonitoring/04_namespaces.py
+++ b/tests/integration/tests/inframonitoring/04_namespaces.py
@@ -1,5 +1,3 @@
-"""Integration tests for v2 infra-monitoring namespace endpoints."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/inframonitoring/05_clusters.py b/tests/integration/tests/inframonitoring/05_clusters.py
index c4e0a17179..403afaff08 100644
--- a/tests/integration/tests/inframonitoring/05_clusters.py
+++ b/tests/integration/tests/inframonitoring/05_clusters.py
@@ -1,5 +1,3 @@
-"""Integration tests for v2 infra-monitoring cluster endpoints."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/inframonitoring/06_volumes.py b/tests/integration/tests/inframonitoring/06_volumes.py
index 6728054b95..4707839a24 100644
--- a/tests/integration/tests/inframonitoring/06_volumes.py
+++ b/tests/integration/tests/inframonitoring/06_volumes.py
@@ -1,5 +1,3 @@
-"""Integration tests for v2 infra-monitoring volumes (pvcs) endpoints."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/inframonitoring/07_deployments.py b/tests/integration/tests/inframonitoring/07_deployments.py
index 131acb20ba..40eaad3b85 100644
--- a/tests/integration/tests/inframonitoring/07_deployments.py
+++ b/tests/integration/tests/inframonitoring/07_deployments.py
@@ -1,5 +1,3 @@
-"""Integration tests for v2 infra-monitoring deployments endpoint."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/inframonitoring/08_statefulsets.py b/tests/integration/tests/inframonitoring/08_statefulsets.py
index fc748c3069..6d1c83ae65 100644
--- a/tests/integration/tests/inframonitoring/08_statefulsets.py
+++ b/tests/integration/tests/inframonitoring/08_statefulsets.py
@@ -1,5 +1,3 @@
-"""Integration tests for v2 infra-monitoring statefulsets endpoint."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/inframonitoring/09_jobs.py b/tests/integration/tests/inframonitoring/09_jobs.py
index 6d3f63a1cd..2bd8f86ced 100644
--- a/tests/integration/tests/inframonitoring/09_jobs.py
+++ b/tests/integration/tests/inframonitoring/09_jobs.py
@@ -1,5 +1,3 @@
-"""Integration tests for v2 infra-monitoring jobs endpoint."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/inframonitoring/10_daemonsets.py b/tests/integration/tests/inframonitoring/10_daemonsets.py
index 9a4c92a25e..a2baa47dfe 100644
--- a/tests/integration/tests/inframonitoring/10_daemonsets.py
+++ b/tests/integration/tests/inframonitoring/10_daemonsets.py
@@ -1,5 +1,3 @@
-"""Integration tests for v2 infra-monitoring daemonsets endpoint."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/inframonitoring/11_checks.py b/tests/integration/tests/inframonitoring/11_checks.py
index 5bbb9b1bb3..fd2ef184eb 100644
--- a/tests/integration/tests/inframonitoring/11_checks.py
+++ b/tests/integration/tests/inframonitoring/11_checks.py
@@ -1,22 +1,3 @@
-"""Integration tests for the v2 infra-monitoring checks endpoint.
-
-GET /api/v2/infra_monitoring/checks?type=<t> reports per-tab readiness:
-for each collector component it lists which required/optional metrics and
-required attributes are present vs missing. `ready` is true iff every missing
-list is empty (optional gaps DO block).
-
-Presence is checked against distributed_metadata with NO time window
-(pkg/modules/inframonitoring/implinframonitoring/helpers.go:423,:479): a metric
-is present iff it was ever ingested; an attribute is present iff it appears as a
-label on any of that type's spec metrics. So seeding here is purely "make these
-(metric, label) rows exist" — no start/end, no value math. insert_metrics is
-function-scoped and truncates metadata on teardown, so (serial suite) each test
-sees only its own seeds.
-
-SPECS mirrors pkg/modules/inframonitoring/implinframonitoring/checks_constants.go
-and is the contract lock: if a Go spec changes, the matching assertion fails.
-"""
-
from datetime import UTC, datetime
from http import HTTPStatus
@@ -27,6 +8,10 @@ from fixtures import types
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
from fixtures.metrics import Metrics
+# GET /api/v2/infra_monitoring/checks?type=<t> reports per-tab readiness: for each
+# collector component it lists which required/optional metrics and required
+# attributes are present vs missing. `ready` is true iff every missing list is
+# empty (optional gaps DO block).
ENDPOINT = "/api/v2/infra_monitoring/checks"
# Component names (checks_constants.go:9-15) + their type + docs link.
@@ -53,6 +38,8 @@ _POD_STATUS_OPT = [
]
# Mirror of checkSpecs: type -> {default|optional: {component: [metrics]}, attrs: {component: [attrs]}}.
+# Mirrors pkg/modules/inframonitoring/implinframonitoring/checks_constants.go and is
+# the contract lock: if a Go spec changes, the matching assertion fails.
SPECS = {
"hosts": {
"default": {HMR: ["system.cpu.time", "system.memory.usage", "system.cpu.load_average.15m", "system.filesystem.usage"]},
@@ -124,68 +111,19 @@ SPECS = {
ALL_TYPES = list(SPECS.keys())
-
-# --- helpers ---
-
-
-def _all(d: dict) -> list:
- """Flatten a {component: [items]} map to a flat list."""
- return [x for items in d.values() for x in items]
-
-
-def _all_metrics(t: str) -> list:
- return _all(SPECS[t]["default"]) + _all(SPECS[t]["optional"])
-
-
-def _attr_labels(t: str, drop: str | None = None) -> dict:
- """Labels carrying every required attr (so they resolve present), minus `drop`."""
- return {a: f"v-{a}" for a in _all(SPECS[t]["attrs"]) if a != drop}
-
-
# Marker label so every seeded metric registers in distributed_metadata even when
# `labels` is empty (insert_metrics writes a metadata row per label). Non-spec, so it
# is never counted as a present required attribute.
+#
+# Presence is checked against distributed_metadata with NO time window
+# (pkg/modules/inframonitoring/implinframonitoring/helpers.go:423,:479): a metric is
+# present iff it was ever ingested; an attribute is present iff it appears as a label
+# on any of that type's spec metrics. So seeding is purely "make these (metric, label)
+# rows exist" — no start/end, no value math. insert_metrics is function-scoped and
+# truncates metadata on teardown, so (serial suite) each test sees only its own seeds.
_SEED_MARKER = {"test.seed.marker": "1"}
-def _seed(insert_metrics, metric_names: list, labels: dict) -> None:
- now = datetime.now(tz=UTC).replace(microsecond=0)
- insert_metrics([Metrics(metric_name=m, labels={**_SEED_MARKER, **labels}, timestamp=now, value=1.0) for m in metric_names])
-
-
-def _request(signoz: types.SigNoz, token: str, type_: str | None):
- params = {} if type_ is None else {"type": type_}
- return requests.get(
- signoz.self.host_configs["8080"].get(ENDPOINT),
- headers={"authorization": f"Bearer {token}"},
- params=params,
- timeout=5,
- )
-
-
-def _grouped(entries: list, field: str) -> dict:
- """{component_name: set(items)} from a present/missing entry list; also asserts
- each entry's associatedComponent.type matches the known component type."""
- out: dict = {}
- for e in entries:
- comp = e["associatedComponent"]
- assert comp["type"] == COMPONENT_TYPE[comp["name"]], f"wrong type for {comp!r}"
- out.setdefault(comp["name"], set()).update(e[field])
- return out
-
-
-def _exp(d: dict) -> dict:
- return {comp: set(items) for comp, items in d.items()}
-
-
-def _check_missing_entries(entries: list) -> None:
- """Every missing entry carries a non-empty message + a non-empty docs link
- (exact link not asserted — links are subject to change)."""
- for e in entries:
- assert e["message"], f"empty message: {e!r}"
- assert e["documentationLink"], f"empty doc link: {e!r}"
-
-
# Parametrize cases derived from SPECS.
_DEFAULT_CASES = [ # one representative dropped default metric per type
pytest.param(t, comp, ms[0], id=f"{t}-{ms[0]}") for t in ALL_TYPES for comp, ms in [next(iter(SPECS[t]["default"].items()))]
@@ -212,7 +150,13 @@ def test_checks_validation_errors(
) -> None:
"""Missing/unknown `type` query param → 400 invalid_input."""
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- response = _request(signoz, token, type_)
+ response = requests.get(
+ signoz.self.host_configs["8080"].get(ENDPOINT),
+ headers={"authorization": f"Bearer {token}"},
+ params={} if type_ is None else {"type": type_},
+ timeout=5,
+ )
+
assert response.status_code == HTTPStatus.BAD_REQUEST, response.text
error = response.json()["error"]
assert error["code"] == "invalid_input"
@@ -229,18 +173,47 @@ def test_checks_empty_backend(
"""No data ingested → not ready; every default metric + required attr reported
missing (bucketed by component, with message + docs link); present lists empty."""
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- data = _request(signoz, token, type_).json()["data"]
+ response = requests.get(
+ signoz.self.host_configs["8080"].get(ENDPOINT),
+ headers={"authorization": f"Bearer {token}"},
+ params={"type": type_},
+ timeout=5,
+ )
+ data = response.json()["data"]
assert data["ready"] is False
assert data["presentDefaultEnabledMetrics"] == []
assert data["presentOptionalMetrics"] == []
assert data["presentRequiredAttributes"] == []
- assert _grouped(data["missingDefaultEnabledMetrics"], "metrics") == _exp(SPECS[type_]["default"])
- assert _grouped(data["missingOptionalMetrics"], "metrics") == _exp(SPECS[type_]["optional"])
- assert _grouped(data["missingRequiredAttributes"], "attributes") == _exp(SPECS[type_]["attrs"])
- _check_missing_entries(data["missingDefaultEnabledMetrics"])
- _check_missing_entries(data["missingOptionalMetrics"])
- _check_missing_entries(data["missingRequiredAttributes"])
+
+ # Every missing entry carries a non-empty message + a non-empty docs link
+ # (exact link not asserted — links are subject to change).
+ missing_default: dict = {}
+ for e in data["missingDefaultEnabledMetrics"]:
+ comp = e["associatedComponent"]
+ assert comp["type"] == COMPONENT_TYPE[comp["name"]], f"wrong type for {comp!r}"
+ assert e["message"], f"empty message: {e!r}"
+ assert e["documentationLink"], f"empty doc link: {e!r}"
+ missing_default.setdefault(comp["name"], set()).update(e["metrics"])
+ assert missing_default == {comp: set(ms) for comp, ms in SPECS[type_]["default"].items()}
+
+ missing_optional: dict = {}
+ for e in data["missingOptionalMetrics"]:
+ comp = e["associatedComponent"]
+ assert comp["type"] == COMPONENT_TYPE[comp["name"]], f"wrong type for {comp!r}"
+ assert e["message"], f"empty message: {e!r}"
+ assert e["documentationLink"], f"empty doc link: {e!r}"
+ missing_optional.setdefault(comp["name"], set()).update(e["metrics"])
+ assert missing_optional == {comp: set(ms) for comp, ms in SPECS[type_]["optional"].items()}
+
+ missing_attrs: dict = {}
+ for e in data["missingRequiredAttributes"]:
+ comp = e["associatedComponent"]
+ assert comp["type"] == COMPONENT_TYPE[comp["name"]], f"wrong type for {comp!r}"
+ assert e["message"], f"empty message: {e!r}"
+ assert e["documentationLink"], f"empty doc link: {e!r}"
+ missing_attrs.setdefault(comp["name"], set()).update(e["attributes"])
+ assert missing_attrs == {comp: set(attrs) for comp, attrs in SPECS[type_]["attrs"].items()}
@pytest.mark.parametrize("type_", ALL_TYPES)
@@ -253,19 +226,47 @@ def test_checks_all_present_ready(
) -> None:
"""Every default+optional metric seeded carrying all required attrs → ready;
present buckets exactly match the spec, all missing lists empty."""
- _seed(insert_metrics, _all_metrics(type_), _attr_labels(type_))
+ # Labels carrying every required attr (so they resolve present).
+ labels = {a: f"v-{a}" for attrs in SPECS[type_]["attrs"].values() for a in attrs}
+ metric_names = [m for ms in SPECS[type_]["default"].values() for m in ms] + [m for ms in SPECS[type_]["optional"].values() for m in ms]
+ now = datetime.now(tz=UTC).replace(microsecond=0)
+ insert_metrics([Metrics(metric_name=m, labels={**_SEED_MARKER, **labels}, timestamp=now, value=1.0) for m in metric_names])
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- data = _request(signoz, token, type_).json()["data"]
+ response = requests.get(
+ signoz.self.host_configs["8080"].get(ENDPOINT),
+ headers={"authorization": f"Bearer {token}"},
+ params={"type": type_},
+ timeout=5,
+ )
+ data = response.json()["data"]
assert data["type"] == type_
assert data["ready"] is True
assert data["missingDefaultEnabledMetrics"] == []
assert data["missingOptionalMetrics"] == []
assert data["missingRequiredAttributes"] == []
- assert _grouped(data["presentDefaultEnabledMetrics"], "metrics") == _exp(SPECS[type_]["default"])
- assert _grouped(data["presentOptionalMetrics"], "metrics") == _exp(SPECS[type_]["optional"])
- assert _grouped(data["presentRequiredAttributes"], "attributes") == _exp(SPECS[type_]["attrs"])
+
+ present_default: dict = {}
+ for e in data["presentDefaultEnabledMetrics"]:
+ comp = e["associatedComponent"]
+ assert comp["type"] == COMPONENT_TYPE[comp["name"]], f"wrong type for {comp!r}"
+ present_default.setdefault(comp["name"], set()).update(e["metrics"])
+ assert present_default == {comp: set(ms) for comp, ms in SPECS[type_]["default"].items()}
+
+ present_optional: dict = {}
+ for e in data["presentOptionalMetrics"]:
+ comp = e["associatedComponent"]
+ assert comp["type"] == COMPONENT_TYPE[comp["name"]], f"wrong type for {comp!r}"
+ present_optional.setdefault(comp["name"], set()).update(e["metrics"])
+ assert present_optional == {comp: set(ms) for comp, ms in SPECS[type_]["optional"].items()}
+
+ present_attrs: dict = {}
+ for e in data["presentRequiredAttributes"]:
+ comp = e["associatedComponent"]
+ assert comp["type"] == COMPONENT_TYPE[comp["name"]], f"wrong type for {comp!r}"
+ present_attrs.setdefault(comp["name"], set()).update(e["attributes"])
+ assert present_attrs == {comp: set(attrs) for comp, attrs in SPECS[type_]["attrs"].items()}
@pytest.mark.parametrize("type_,component,metric", _DEFAULT_CASES)
@@ -280,17 +281,33 @@ def test_checks_missing_default_metric(
) -> None:
"""One default metric never ingested (everything else present) → that metric is
in missingDefaultEnabledMetrics under its component; not ready."""
- seed = [m for m in _all_metrics(type_) if m != metric]
- _seed(insert_metrics, seed, _attr_labels(type_))
+ labels = {a: f"v-{a}" for attrs in SPECS[type_]["attrs"].values() for a in attrs}
+ all_metrics = [m for ms in SPECS[type_]["default"].values() for m in ms] + [m for ms in SPECS[type_]["optional"].values() for m in ms]
+ seed = [m for m in all_metrics if m != metric]
+ now = datetime.now(tz=UTC).replace(microsecond=0)
+ insert_metrics([Metrics(metric_name=m, labels={**_SEED_MARKER, **labels}, timestamp=now, value=1.0) for m in seed])
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- data = _request(signoz, token, type_).json()["data"]
+ response = requests.get(
+ signoz.self.host_configs["8080"].get(ENDPOINT),
+ headers={"authorization": f"Bearer {token}"},
+ params={"type": type_},
+ timeout=5,
+ )
+ data = response.json()["data"]
assert data["ready"] is False
- assert metric in _grouped(data["missingDefaultEnabledMetrics"], "metrics").get(component, set())
+
+ missing_default: dict = {}
+ for e in data["missingDefaultEnabledMetrics"]:
+ comp = e["associatedComponent"]
+ assert comp["type"] == COMPONENT_TYPE[comp["name"]], f"wrong type for {comp!r}"
+ assert e["message"], f"empty message: {e!r}"
+ assert e["documentationLink"], f"empty doc link: {e!r}"
+ missing_default.setdefault(comp["name"], set()).update(e["metrics"])
+ assert metric in missing_default.get(component, set())
assert data["missingOptionalMetrics"] == []
assert data["missingRequiredAttributes"] == []
- _check_missing_entries(data["missingDefaultEnabledMetrics"])
@pytest.mark.parametrize("type_,component,metric", _OPTIONAL_CASES)
@@ -305,17 +322,33 @@ def test_checks_missing_optional_metric(
) -> None:
"""One optional metric missing → reported in missingOptionalMetrics and (locked
decision) NOT ready, even though all default metrics + attrs are present."""
- seed = [m for m in _all_metrics(type_) if m != metric]
- _seed(insert_metrics, seed, _attr_labels(type_))
+ labels = {a: f"v-{a}" for attrs in SPECS[type_]["attrs"].values() for a in attrs}
+ all_metrics = [m for ms in SPECS[type_]["default"].values() for m in ms] + [m for ms in SPECS[type_]["optional"].values() for m in ms]
+ seed = [m for m in all_metrics if m != metric]
+ now = datetime.now(tz=UTC).replace(microsecond=0)
+ insert_metrics([Metrics(metric_name=m, labels={**_SEED_MARKER, **labels}, timestamp=now, value=1.0) for m in seed])
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- data = _request(signoz, token, type_).json()["data"]
+ response = requests.get(
+ signoz.self.host_configs["8080"].get(ENDPOINT),
+ headers={"authorization": f"Bearer {token}"},
+ params={"type": type_},
+ timeout=5,
+ )
+ data = response.json()["data"]
assert data["ready"] is False
- assert metric in _grouped(data["missingOptionalMetrics"], "metrics").get(component, set())
+
+ missing_optional: dict = {}
+ for e in data["missingOptionalMetrics"]:
+ comp = e["associatedComponent"]
+ assert comp["type"] == COMPONENT_TYPE[comp["name"]], f"wrong type for {comp!r}"
+ assert e["message"], f"empty message: {e!r}"
+ assert e["documentationLink"], f"empty doc link: {e!r}"
+ missing_optional.setdefault(comp["name"], set()).update(e["metrics"])
+ assert metric in missing_optional.get(component, set())
assert data["missingDefaultEnabledMetrics"] == []
assert data["missingRequiredAttributes"] == []
- _check_missing_entries(data["missingOptionalMetrics"])
@pytest.mark.parametrize("type_,component,attr", _ATTR_CASES)
@@ -330,13 +363,29 @@ def test_checks_missing_required_attribute(
) -> None:
"""All metrics present but one required attr never seen on any of them → that
attr is in missingRequiredAttributes under its component; not ready."""
- _seed(insert_metrics, _all_metrics(type_), _attr_labels(type_, drop=attr))
+ labels = {a: f"v-{a}" for attrs in SPECS[type_]["attrs"].values() for a in attrs if a != attr}
+ metric_names = [m for ms in SPECS[type_]["default"].values() for m in ms] + [m for ms in SPECS[type_]["optional"].values() for m in ms]
+ now = datetime.now(tz=UTC).replace(microsecond=0)
+ insert_metrics([Metrics(metric_name=m, labels={**_SEED_MARKER, **labels}, timestamp=now, value=1.0) for m in metric_names])
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- data = _request(signoz, token, type_).json()["data"]
+ response = requests.get(
+ signoz.self.host_configs["8080"].get(ENDPOINT),
+ headers={"authorization": f"Bearer {token}"},
+ params={"type": type_},
+ timeout=5,
+ )
+ data = response.json()["data"]
assert data["ready"] is False
- assert attr in _grouped(data["missingRequiredAttributes"], "attributes").get(component, set())
+
+ missing_attrs: dict = {}
+ for e in data["missingRequiredAttributes"]:
+ comp = e["associatedComponent"]
+ assert comp["type"] == COMPONENT_TYPE[comp["name"]], f"wrong type for {comp!r}"
+ assert e["message"], f"empty message: {e!r}"
+ assert e["documentationLink"], f"empty doc link: {e!r}"
+ missing_attrs.setdefault(comp["name"], set()).update(e["attributes"])
+ assert attr in missing_attrs.get(component, set())
assert data["missingDefaultEnabledMetrics"] == []
assert data["missingOptionalMetrics"] == []
- _check_missing_entries(data["missingRequiredAttributes"])
diff --git a/tests/integration/tests/inframonitoring/12_kube_containers.py b/tests/integration/tests/inframonitoring/12_kube_containers.py
index 460d9d1d28..fe606927b5 100644
--- a/tests/integration/tests/inframonitoring/12_kube_containers.py
+++ b/tests/integration/tests/inframonitoring/12_kube_containers.py
@@ -1,5 +1,3 @@
-"""Integration tests for the v2 infra-monitoring kube_containers endpoint."""
-
import json
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/logspipelines/01_logs_pipelines.py b/tests/integration/tests/logspipelines/01_logs_pipelines.py
index 74307995f5..db8c11fbac 100644
--- a/tests/integration/tests/logspipelines/01_logs_pipelines.py
+++ b/tests/integration/tests/logspipelines/01_logs_pipelines.py
@@ -1,10 +1,3 @@
-"""
-Summary:
-This test file contains integration tests for log parsing pipelines in SigNoz's query service.
-It verifies the correct behavior of log pipeline CRUD operations, versioning, preview functionality,
-and pipeline processing.
-"""
-
from collections.abc import Callable
from http import HTTPStatus
diff --git a/tests/integration/tests/metricreduction/05_inframonitoring.py b/tests/integration/tests/metricreduction/05_inframonitoring.py
index df370f6dd6..d10f995352 100644
--- a/tests/integration/tests/metricreduction/05_inframonitoring.py
+++ b/tests/integration/tests/metricreduction/05_inframonitoring.py
@@ -1,13 +1,3 @@
-"""Infra-monitoring v2 list endpoints on the metrics-reduction path.
-
-With reduction enabled, every list endpoint unions raw and reduced series and
-restricts each side with a fingerprint IN (samples) subquery. Those subqueries
-must read local tables: a distributed subquery inside the distributed outer
-query is rejected by ClickHouse with error 288 (distributed_product_mode =
-'deny'), which only ever fires on a multi-shard cluster — exactly what this
-package's fixtures provide. Seed raw-only and reduced-only entities and assert
-each endpoint returns the union of both."""
-
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
@@ -102,7 +92,9 @@ def test_list_merges_raw_and_reduced_entities( # pylint: disable=too-many-argum
"""One set of entities exists only in the raw tables, another only in the
reduced tables. The list response must contain both sets: pre-fix, the
reduced branch's fingerprint subquery on distributed tables made every one
- of these endpoints fail with ClickHouse error 288."""
+ of these endpoints fail with ClickHouse error 288 (distributed_product_mode =
+ 'deny') — which only ever fires on a multi-shard cluster, exactly what this
+ package's fixtures provide."""
base_epoch = aligned_epoch(timedelta(hours=30), step_seconds=300)
raw_names = [f"{prefix}-raw-{i}" for i in range(COUNT_PER_SOURCE)]
reduced_names = [f"{prefix}-red-{i}" for i in range(COUNT_PER_SOURCE)]
diff --git a/tests/integration/tests/passwordauthn/01_register.py b/tests/integration/tests/passwordauthn/01_register.py
index 4fa2f17963..cc03af7733 100644
--- a/tests/integration/tests/passwordauthn/01_register.py
+++ b/tests/integration/tests/passwordauthn/01_register.py
@@ -20,11 +20,6 @@ logger = setup_logger(__name__)
def test_register_with_invalid_input(signoz: types.SigNoz) -> None:
- """
- Test the register endpoint with invalid input.
- 1. Invalid Password
- 2. Invalid Email
- """
response = requests.post(
signoz.self.host_configs["8080"].get("/api/v1/register"),
json={
diff --git a/tests/integration/tests/passwordauthn/03_password.py b/tests/integration/tests/passwordauthn/03_password.py
index 80a946e066..935ec9a9c3 100644
--- a/tests/integration/tests/passwordauthn/03_password.py
+++ b/tests/integration/tests/passwordauthn/03_password.py
@@ -306,9 +306,6 @@ def test_forgot_password_creates_reset_token(signoz: types.SigNoz, get_token: Ca
def test_reset_password_with_expired_token(signoz: types.SigNoz, get_token: Callable[[str, str], str]) -> None:
- """
- Test that resetting password with an expired token fails.
- """
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
forgot_email = "[email protected]"
diff --git a/tests/integration/tests/promqlconformance/01_upstream_corpus.py b/tests/integration/tests/promqlconformance/01_upstream_corpus.py
index d733f210ec..5311c3b97e 100644
--- a/tests/integration/tests/promqlconformance/01_upstream_corpus.py
+++ b/tests/integration/tests/promqlconformance/01_upstream_corpus.py
@@ -1,35 +1,3 @@
-"""
-Upstream promqltest conformance: replay the frozen corpus extracted from
-Prometheus' own promql/promqltest testdata and assert our API returns the
-reference engine's answers.
-
-Unlike live-vs-live parity suites, the oracle here is a committed file
-(tests/integration/testdata/promqltestcorpus/corpus.json), generated by
-scripts/promqltestcorpus from upstream's load scripts and the vendored
-reference engine. It therefore keeps working when the serving path itself is
-the thing being changed — the one situation where comparing two live paths
-against each other is blind.
-
-Every case replays on both serving paths — the default provider, and the
-clickhousev2 provider pinned via the flag-gated X-SigNoz-PromQL-Provider
-header (see conftest.py) — and each leg is asserted against the same frozen
-expectations, each leg against its own known-divergences ledger. The legs
-are deliberately never asserted against each other: both can sit within one
-rounding quantum of the expected value yet differ from each other by up to
-two quanta when a true value straddles a rounding boundary, so a leg-vs-leg
-equality check would reintroduce exactly the boundary noise the quantum
-tolerance exists to absorb. Because both legs anchor to the same oracle over
-the same ingested bytes, a case failing on one leg while passing on the
-other already localizes the defect to that provider — and the printed
-DIVERGED lines for both legs are the side-by-side view for triage.
-
-Datasets are placed on disjoint time windows (2h isolation gaps, far beyond
-the 5m lookback) so one bulk ingest serves every case without cross-talk.
-Expected values carry the API's 3-significant-decimal rounding, mirrored by
-the generator; comparison allows one rounding quantum for ULP-at-boundary
-noise between storage iteration orders.
-"""
-
import json
import math
import os
@@ -43,6 +11,11 @@ from fixtures.metrics import Metrics
from fixtures.querier import get_all_series, make_query_request
TESTDATA_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "testdata")
+# Frozen corpus extracted from Prometheus' own promql/promqltest testdata by
+# scripts/promqltestcorpus (upstream load scripts + the vendored reference engine).
+# Unlike live-vs-live parity suites, the oracle is this committed file, so the suite
+# keeps working when the serving path itself is the thing being changed — the one
+# situation where comparing two live paths against each other is blind.
CORPUS_FILE = os.path.join(TESTDATA_DIR, "promqltestcorpus", "corpus.json")
# One ledger per leg, enforced exactly in both directions. The default leg's
@@ -53,121 +26,26 @@ LEDGER_FILES = {
"clickhousev2": os.path.join(TESTDATA_DIR, "promqltestcorpus", "known_divergences_v2.json"),
}
+# Every case replays on both legs, each asserted against the same frozen
+# expectations and its own ledger — deliberately never against each other: both
+# legs can sit within one rounding quantum of the expected value yet differ from
+# each other by up to two quanta when a true value straddles a rounding boundary,
+# so a leg-vs-leg equality check would reintroduce exactly the boundary noise the
+# quantum tolerance absorbs. A case failing on one leg while passing on the other
+# already localizes the defect to that provider; the printed DIVERGED lines for
+# both legs are the side-by-side triage view. The clickhousev2 header is
+# flag-gated (see conftest.py).
LEGS: list[tuple[str, dict | None]] = [
("default", None),
("clickhousev2", {"X-SigNoz-PromQL-Provider": "clickhousev2"}),
]
+# Datasets sit on disjoint time windows (2h gaps, far beyond the 5m lookback) so
+# one bulk ingest serves every case without cross-talk.
ISOLATION_GAP_MS = 2 * 3600 * 1000
SPECIALS = {"NaN": math.nan, "Inf": math.inf, "-Inf": -math.inf}
-def _decode(v: float | str) -> float:
- if isinstance(v, str):
- return SPECIALS[v]
- return float(v)
-
-
-def _values_close(a: float, b: float) -> bool:
- if math.isnan(a) or math.isnan(b):
- return math.isnan(a) and math.isnan(b)
- if math.isinf(a) or math.isinf(b):
- return a == b
- if a == b:
- return True
- # Both sides carry the API's rounding (>=1: three decimal places; <1:
- # three significant digits). A true value sitting exactly on a rounding
- # boundary can round either way when the two computations differ at ULP
- # level (float aggregation order over series is storage-iteration
- # dependent), so allow one rounding quantum.
- scale = max(abs(a), abs(b))
- if scale >= 1:
- # Values too large to round pass through unrounded; give those an
- # ULP-class relative grace on top of the rounding quantum.
- quantum = max(1e-3, scale * 1e-9)
- else:
- quantum = 10 ** (math.floor(math.log10(scale)) - 2)
- return abs(a - b) <= quantum + 1e-12
-
-
-def _labelset(labels: dict[str, str]) -> tuple:
- return tuple(sorted(labels.items()))
-
-
-def _response_series(data: dict) -> tuple[dict[tuple, dict[int, float]], list[tuple]]:
- """Returns (series map, duplicate labelsets). A response carrying several
- series with identical visible labels is itself a defect signal (e.g. a
- hidden grouping label stripped on the way out) and must not be silently
- collapsed into one entry."""
- out: dict[tuple, dict[int, float]] = {}
- duplicates: list[tuple] = []
- # Empty results serialize with null aggregations/series/values fields.
- for series in get_all_series(data, "A") or []:
- lbls = {l["key"]["name"]: str(l["value"]) for l in series.get("labels") or []}
- points = {int(v["timestamp"]): _decode(v["value"]) for v in series.get("values") or []}
- key = _labelset(lbls)
- if key in out:
- duplicates.append(key)
- out[key] = points
- return out, duplicates
-
-
-def _case_failure(
- signoz: types.SigNoz,
- token: str,
- case: dict,
- base: int,
- headers: dict | None,
-) -> str | None:
- """Replays one corpus case on one leg; returns a failure line or None."""
- start_ms = base + case["start_ms"]
- end_ms = base + case["end_ms"]
- step_s = max(1, case["step_ms"] // 1000)
- req_start_ms = start_ms
- if case["instant"]:
- # The API rejects start == end; ask for one extra step backward
- # and compare only at the instant timestamp. Nudging the start
- # earlier instead of the end later keeps every window that the
- # expected values were computed from untouched.
- req_start_ms = start_ms - step_s * 1000
- query = {
- "type": "promql",
- "spec": {"name": "A", "query": case["expr"], "step": step_s},
- }
-
- case_id = f"{case['source']}[{case['variant']}]"
- response = make_query_request(signoz, token, req_start_ms, end_ms, [query], headers=headers)
- if response.status_code != HTTPStatus.OK:
- return f"{case_id}: HTTP {response.status_code} for {case['expr']!r}: {response.text[:200]}"
-
- actual, duplicates = _response_series(response.json())
- if duplicates:
- return f"{case_id}: response carries multiple series with identical labels for {case['expr']!r}: {[dict(d) for d in duplicates[:3]]}"
- if case["instant"]:
- # Keep only the instant point; the extra grid step is a request
- # encoding byproduct, not part of the assertion.
- actual = {lset: {ts: v for ts, v in pts.items() if ts == end_ms} for lset, pts in actual.items()}
- actual = {lset: pts for lset, pts in actual.items() if pts}
- expected: dict[tuple, dict[int, float]] = {}
- for res in case["expected"]:
- points = {base + off_ms: _decode(v) for off_ms, v in res["points"]}
- expected[_labelset(res["labels"])] = points
-
- if set(actual) != set(expected):
- missing = set(expected) - set(actual)
- extra = set(actual) - set(expected)
- return f"{case_id}: series mismatch for {case['expr']!r} (missing={sorted(missing)[:3]} extra={sorted(extra)[:3]}) actual={[(dict(k), {t - base: v for t, v in pts.items()}) for k, pts in actual.items()]}"
-
- for lset, exp_points in expected.items():
- act_points = actual[lset]
- if set(act_points) != set(exp_points):
- return f"{case_id}: timestamp mismatch for {case['expr']!r} series {dict(lset)} (expected {len(exp_points)} points, got {len(act_points)})"
- for ts, exp_v in exp_points.items():
- if not _values_close(act_points[ts], exp_v):
- return f"{case_id}: value mismatch for {case['expr']!r} series {dict(lset)} at {ts}: expected {exp_v}, got {act_points[ts]}"
- return None
-
-
def test_upstream_promqltest_corpus(
signoz: types.SigNoz,
create_user_admin: None, # pylint: disable=unused-argument
@@ -212,7 +90,7 @@ def test_upstream_promqltest_corpus(
metric_name=metric_name,
labels=labels,
timestamp=datetime.fromtimestamp((cursor + off_ms) / 1000, tz=UTC),
- value=0.0 if stale else _decode(raw),
+ value=0.0 if stale else (SPECIALS[raw] if isinstance(raw, str) else float(raw)),
flags=1 if stale else 0,
)
)
@@ -223,10 +101,97 @@ def test_upstream_promqltest_corpus(
failures: dict[str, list[str]] = {leg: [] for leg, _ in LEGS}
for case in corpus["cases"]:
+ base = bases[case["dataset"]]
+ start_ms = base + case["start_ms"]
+ end_ms = base + case["end_ms"]
+ step_s = max(1, case["step_ms"] // 1000)
+ req_start_ms = start_ms
+ if case["instant"]:
+ # The API rejects start == end; ask for one extra step backward
+ # and compare only at the instant timestamp. Nudging the start
+ # earlier instead of the end later keeps every window that the
+ # expected values were computed from untouched.
+ req_start_ms = start_ms - step_s * 1000
+ query = {
+ "type": "promql",
+ "spec": {"name": "A", "query": case["expr"], "step": step_s},
+ }
+ case_id = f"{case['source']}[{case['variant']}]"
+
for leg, headers in LEGS:
- f_line = _case_failure(signoz, token, case, bases[case["dataset"]], headers)
- if f_line:
- failures[leg].append(f_line)
+ response = make_query_request(signoz, token, req_start_ms, end_ms, [query], headers=headers)
+ if response.status_code != HTTPStatus.OK:
+ failures[leg].append(f"{case_id}: HTTP {response.status_code} for {case['expr']!r}: {response.text[:200]}")
+ continue
+
+ # A response carrying several series with identical visible labels
+ # is itself a defect signal (e.g. a hidden grouping label stripped
+ # on the way out) and must not be silently collapsed into one entry.
+ actual: dict[tuple, dict[int, float]] = {}
+ duplicates: list[tuple] = []
+ # Empty results serialize with null aggregations/series/values fields.
+ for series in get_all_series(response.json(), "A") or []:
+ lbls = {l["key"]["name"]: str(l["value"]) for l in series.get("labels") or []}
+ points = {int(v["timestamp"]): SPECIALS[v["value"]] if isinstance(v["value"], str) else float(v["value"]) for v in series.get("values") or []}
+ key = tuple(sorted(lbls.items()))
+ if key in actual:
+ duplicates.append(key)
+ actual[key] = points
+ if duplicates:
+ failures[leg].append(f"{case_id}: response carries multiple series with identical labels for {case['expr']!r}: {[dict(d) for d in duplicates[:3]]}")
+ continue
+
+ if case["instant"]:
+ # Keep only the instant point; the extra grid step is a request
+ # encoding byproduct, not part of the assertion.
+ actual = {lset: {ts: v for ts, v in pts.items() if ts == end_ms} for lset, pts in actual.items()}
+ actual = {lset: pts for lset, pts in actual.items() if pts}
+ expected: dict[tuple, dict[int, float]] = {}
+ for res in case["expected"]:
+ points = {base + off_ms: SPECIALS[v] if isinstance(v, str) else float(v) for off_ms, v in res["points"]}
+ expected[tuple(sorted(res["labels"].items()))] = points
+
+ if set(actual) != set(expected):
+ missing = set(expected) - set(actual)
+ extra = set(actual) - set(expected)
+ failures[leg].append(f"{case_id}: series mismatch for {case['expr']!r} (missing={sorted(missing)[:3]} extra={sorted(extra)[:3]}) actual={[(dict(k), {t - base: v for t, v in pts.items()}) for k, pts in actual.items()]}")
+ continue
+
+ mismatch = None
+ for lset, exp_points in expected.items():
+ act_points = actual[lset]
+ if set(act_points) != set(exp_points):
+ mismatch = f"{case_id}: timestamp mismatch for {case['expr']!r} series {dict(lset)} (expected {len(exp_points)} points, got {len(act_points)})"
+ break
+ for ts, exp_v in exp_points.items():
+ act_v = act_points[ts]
+ if math.isnan(act_v) or math.isnan(exp_v):
+ close = math.isnan(act_v) and math.isnan(exp_v)
+ elif math.isinf(act_v) or math.isinf(exp_v):
+ close = act_v == exp_v
+ elif act_v == exp_v:
+ close = True
+ else:
+ # Both sides carry the API's rounding (>=1: three decimal places; <1:
+ # three significant digits). A true value sitting exactly on a rounding
+ # boundary can round either way when the two computations differ at ULP
+ # level (float aggregation order over series is storage-iteration
+ # dependent), so allow one rounding quantum.
+ scale = max(abs(act_v), abs(exp_v))
+ if scale >= 1:
+ # Values too large to round pass through unrounded; give those an
+ # ULP-class relative grace on top of the rounding quantum.
+ quantum = max(1e-3, scale * 1e-9)
+ else:
+ quantum = 10 ** (math.floor(math.log10(scale)) - 2)
+ close = abs(act_v - exp_v) <= quantum + 1e-12
+ if not close:
+ mismatch = f"{case_id}: value mismatch for {case['expr']!r} series {dict(lset)} at {ts}: expected {exp_v}, got {act_v}"
+ break
+ if mismatch:
+ break
+ if mismatch:
+ failures[leg].append(mismatch)
for leg, _ in LEGS:
for f_line in failures[leg]:
diff --git a/tests/integration/tests/promqlconformance/02_fingerprint_probe.py b/tests/integration/tests/promqlconformance/02_fingerprint_probe.py
index 8167835c86..d0f5eed5f3 100644
--- a/tests/integration/tests/promqlconformance/02_fingerprint_probe.py
+++ b/tests/integration/tests/promqlconformance/02_fingerprint_probe.py
@@ -1,18 +1,3 @@
-"""
-Regression tests for series identity in the PromQL serving path (PR #8563).
-
-#8563 fixed a real duplicate-labelset collision by injecting a synthetic
-per-series "fingerprint" label, which silently broke without() grouping and
-unaggregated vector matching; the adapter now merges fingerprints sharing a
-labelset instead. Pinned here:
-
- 1. Clean data: without() yields exactly the grouped series with correct
- sums; "fingerprint" behaves as any absent label.
- 2. The #8563 incident: one series under two fingerprints (empty-valued vs
- absent label). Both must come back as ONE merged series — not a
- "duplicate series" error, not duplicate identical-labeled output.
-"""
-
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
@@ -26,13 +11,14 @@ METRIC = "probe_requests"
EVOLVED_METRIC = "probe_schema_evolution"
-def _value_at(view_entry: tuple[dict, list], ts_ms: int) -> float:
- for ts, v in view_entry[1]:
- if ts == ts_ms:
- return float(v)
- raise AssertionError(f"no point at {ts_ms} in {view_entry}")
-
-
+# PR #8563 fixed a real duplicate-labelset collision by injecting a synthetic
+# per-series "fingerprint" label, which silently broke without() grouping and
+# unaggregated vector matching; the adapter now merges fingerprints sharing a
+# labelset. Pinned here: on clean data, without() yields exactly the grouped
+# series with correct sums and "fingerprint" behaves as any absent label; and the
+# #8563 incident shape — one series under two fingerprints (empty-valued vs absent
+# label) — comes back as ONE merged series, not a "duplicate series" error, not
+# duplicate identical-labeled output.
def test_identical_labelsets_merge_and_grouping(
signoz: types.SigNoz,
create_user_admin: None, # pylint: disable=unused-argument
@@ -106,12 +92,12 @@ def test_identical_labelsets_merge_and_grouping(
assert not any("fingerprint" in l for l, _ in raw), "no synthetic fingerprint label may appear in results"
count = run(f"count({METRIC})", start_ms, end_ms)
- assert count and _value_at(count[0], end_ms) == 4
+ assert count and next(float(v) for ts, v in count[0][1] if ts == end_ms) == 4
# without(instance): exactly one series per group, with the group sums —
# not per-fingerprint groups collapsing into duplicate labelsets.
without = run(f"sum without (instance) ({METRIC})", start_ms, end_ms)
- assert [(l.get("group"), _value_at((l, v), end_ms)) for l, v in without] == [
+ assert [(l.get("group"), next(float(v) for ts, v in vals if ts == end_ms)) for l, vals in without] == [
("canary", 304.0),
("production", 704.0),
], f"without(instance) must yield 2 correctly-summed groups: {without}"
@@ -119,13 +105,13 @@ def test_identical_labelsets_merge_and_grouping(
# "fingerprint" is now just an absent label: adding it to without() must
# not change the result, and grouping by it collapses everything.
healed = run(f"sum without (instance, fingerprint) ({METRIC})", start_ms, end_ms)
- assert [(l.get("group"), _value_at((l, v), end_ms)) for l, v in healed] == [
+ assert [(l.get("group"), next(float(v) for ts, v in vals if ts == end_ms)) for l, vals in healed] == [
("canary", 304.0),
("production", 704.0),
], f"without(instance, fingerprint) must equal without(instance): {healed}"
by_fp = run(f"sum by (fingerprint) ({METRIC})", start_ms, end_ms)
- assert len(by_fp) == 1 and _value_at(by_fp[0], end_ms) == 304.0 + 704.0, f"by(fingerprint) must collapse to one group (label absent): {by_fp}"
+ assert len(by_fp) == 1 and next(float(v) for ts, v in by_fp[0][1] if ts == end_ms) == 304.0 + 704.0, f"by(fingerprint) must collapse to one group (label absent): {by_fp}"
assert "fingerprint" not in by_fp[0][0] or by_fp[0][0] == {}, by_fp
# Scenario 2: both fingerprints must come back as ONE merged series
@@ -137,5 +123,5 @@ def test_identical_labelsets_merge_and_grouping(
assert len(evolved) == 1, f"label-evolution fingerprints must merge into one series: {evolved}"
lbls, _ = evolved[0]
assert lbls == {"__name__": EVOLVED_METRIC, "job": "api"}, evolved
- got = [_value_at(evolved[0], evo_start_ms + m * 60_000) for m in range(6)]
+ got = [next(float(v) for ts, v in evolved[0][1] if ts == evo_start_ms + m * 60_000) for m in range(6)]
assert got == [1.0, 2.0, 3.0, 4.0, 5.0, 6.0], f"merged series must carry both fingerprints' samples in order: {got}"
diff --git a/tests/integration/tests/querier_json_body/01_logs_json_body_new_qb.py b/tests/integration/tests/querier_json_body/01_logs_json_body_new_qb.py
index 31315c32db..b5e2c83f7a 100644
--- a/tests/integration/tests/querier_json_body/01_logs_json_body_new_qb.py
+++ b/tests/integration/tests/querier_json_body/01_logs_json_body_new_qb.py
@@ -9,65 +9,14 @@ from fixtures import types
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
from fixtures.logs import Logs
from fixtures.querier import (
- build_aggregation,
build_order_by,
build_raw_query,
- build_scalar_query,
get_column_data_from_response,
get_rows,
get_scalar_table_data,
make_query_request,
)
-
-def _get_bodies(response: requests.Response) -> list[dict[str, Any]]:
- return [row["data"]["body"] for row in get_rows(response)]
-
-
-def _run_query_case(signoz: types.SigNoz, token: str, now: datetime, case: dict[str, Any]) -> None:
- start_ms = case.get("startMs", int((now - timedelta(seconds=10)).timestamp() * 1000))
- end_ms = case.get("endMs", int(now.timestamp() * 1000))
-
- if case["requestType"] == "raw":
- query = build_raw_query(
- name=case["name"],
- signal="logs",
- filter_expression=case.get("expression"),
- order=case.get("order") or [build_order_by("timestamp", "desc")],
- limit=case.get("limit", 100),
- step_interval=case.get("stepInterval") or 60,
- )
- else:
- aggregation = case.get("aggregation")
- if aggregation and not isinstance(aggregation, list):
- aggregations = [build_aggregation(aggregation)]
- elif aggregation:
- aggregations = aggregation
- else:
- aggregations = []
- query = build_scalar_query(
- name=case["name"],
- signal="logs",
- aggregations=aggregations,
- group_by=case.get("groupBy"),
- order=case.get("order"),
- limit=case.get("limit", 100),
- filter_expression=case.get("expression"),
- step_interval=case.get("stepInterval") or 60,
- )
-
- response = make_query_request(
- signoz=signoz,
- token=token,
- start_ms=start_ms,
- end_ms=end_ms,
- queries=[query],
- request_type=case["requestType"],
- )
- assert response.status_code == 200, f"HTTP {response.status_code} for case '{case['name']}': {response.text}"
- assert case["validate"](response), f"Validation failed for case '{case['name']}': {response.json()}"
-
-
# ============================================================================
# Primitive path operations
# ============================================================================
@@ -88,11 +37,11 @@ def _run_query_case(signoz: types.SigNoz, token: str, now: datetime, case: dict[
def test_primitive_path_operations(
- signoz: types.SigNoz,
create_user_admin: None, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
export_json_types: Callable[[list[Logs]], None],
+ run_query_case: Callable[[str, datetime, dict[str, Any]], None],
) -> None:
now = datetime.now(tz=UTC)
@@ -227,7 +176,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": 'user.name = "alice"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and _get_bodies(r)[0]["user"]["name"] == "alice",
+ "validate": lambda r: len(get_rows(r)) == 1 and [row["data"]["body"] for row in get_rows(r)][0]["user"]["name"] == "alice",
},
# log1,log3,log4 have status=200 — log4 is flat with no user object
{
@@ -235,7 +184,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "status = 200",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 3 and all(b["status"] == 200 for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 3 and all(b["status"] == 200 for b in [row["data"]["body"] for row in get_rows(r)]),
},
# height only exists in log1,log3 — tests comparison on sparse field
{
@@ -243,7 +192,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "user.height > 5.8",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and _get_bodies(r)[0]["user"]["height"] == 6.1,
+ "validate": lambda r: len(get_rows(r)) == 1 and [row["data"]["body"] for row in get_rows(r)][0]["user"]["height"] == 6.1,
},
# user.age: Int64 in log1, String "28" in log5, Int64 0 in log6 — type ambiguity.
# Matches: log1 (25 < 30), log5 ("28" via type ambiguity), log6 (0 < 30) → 3 results.
@@ -260,7 +209,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "user.active = true",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 3 and {b["user"]["name"] for b in _get_bodies(r)} == {"alice", "charlie", "diana"},
+ "validate": lambda r: len(get_rows(r)) == 3 and {b["user"]["name"] for b in [row["data"]["body"] for row in get_rows(r)]} == {"alice", "charlie", "diana"},
},
# CONTAINS uses ILIKE — distinct from =
{
@@ -268,7 +217,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": 'user.name CONTAINS "ali"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and _get_bodies(r)[0]["user"]["name"] == "alice",
+ "validate": lambda r: len(get_rows(r)) == 1 and [row["data"]["body"] for row in get_rows(r)][0]["user"]["name"] == "alice",
},
# CONTAINS on Float uses toString() wrapping — distinct code path
{
@@ -276,7 +225,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "user.height Contains 5.4",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and _get_bodies(r)[0]["user"]["height"] == 5.4,
+ "validate": lambda r: len(get_rows(r)) == 1 and [row["data"]["body"] for row in get_rows(r)][0]["user"]["height"] == 5.4,
},
# LIKE — distinct operator (sb.Like)
{
@@ -284,7 +233,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "user.name LIKE '%li%'",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and {b["user"]["name"] for b in _get_bodies(r)} == {"alice", "charlie"},
+ "validate": lambda r: len(get_rows(r)) == 2 and {b["user"]["name"] for b in [row["data"]["body"] for row in get_rows(r)]} == {"alice", "charlie"},
},
# REGEXP — distinct operator (match() function)
{
@@ -292,7 +241,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "user.name REGEXP '^[a-b].*'",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and {b["user"]["name"] for b in _get_bodies(r)} == {"alice", "bob"},
+ "validate": lambda r: len(get_rows(r)) == 2 and {b["user"]["name"] for b in [row["data"]["body"] for row in get_rows(r)]} == {"alice", "bob"},
},
# IN — distinct operator (sb.In)
{
@@ -300,7 +249,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "user.name IN ['alice', 'diana']",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and {b["user"]["name"] for b in _get_bodies(r)} == {"alice", "diana"},
+ "validate": lambda r: len(get_rows(r)) == 2 and {b["user"]["name"] for b in [row["data"]["body"] for row in get_rows(r)]} == {"alice", "diana"},
},
# BETWEEN — distinct operator + type ambiguity (log5 "28" included)
{
@@ -308,7 +257,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "user.age BETWEEN 25 AND 30",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 3 and {b["user"]["age"] for b in _get_bodies(r)} == {25, 30, "28"},
+ "validate": lambda r: len(get_rows(r)) == 3 and {b["user"]["age"] for b in [row["data"]["body"] for row in get_rows(r)]} == {25, 30, "28"},
},
# EXISTS on sparse field — only log1 has email
{
@@ -316,7 +265,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "user.email EXISTS",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and _get_bodies(r)[0]["user"]["email"] == "[email protected]",
+ "validate": lambda r: len(get_rows(r)) == 1 and [row["data"]["body"] for row in get_rows(r)][0]["user"]["email"] == "[email protected]",
},
# Deep non-array nesting (a.b.c)
{
@@ -324,7 +273,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "user.address.zip = 110001",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and _get_bodies(r)[0]["user"]["address"]["zip"] == 110001,
+ "validate": lambda r: len(get_rows(r)) == 1 and [row["data"]["body"] for row in get_rows(r)][0]["user"]["address"]["zip"] == 110001,
},
# Hyphen in key name — special character path escaping
{
@@ -332,7 +281,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "http-status = 200",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all(b["http-status"] == 200 for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 2 and all(b["http-status"] == 200 for b in [row["data"]["body"] for row in get_rows(r)]),
},
# ── negative operators ─────────────────────────────────────────────
# != uses assumeNotNull wrapping
@@ -341,7 +290,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": 'user.name != "alice"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) >= 3 and all(b.get("user", {}).get("name") != "alice" for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) >= 3 and all(b.get("user", {}).get("name") != "alice" for b in [row["data"]["body"] for row in get_rows(r)]),
},
# NOT CONTAINS uses NOT ILIKE — distinct from !=
{
@@ -349,7 +298,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": 'user.name NOT CONTAINS "ali"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) >= 3 and all("ali" not in b.get("user", {}).get("name", "") for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) >= 3 and all("ali" not in b.get("user", {}).get("name", "") for b in [row["data"]["body"] for row in get_rows(r)]),
},
# NOT EXISTS — IS NULL
{
@@ -357,7 +306,7 @@ def test_primitive_path_operations(
"requestType": "raw",
"expression": "user.email NOT EXISTS",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) >= 2 and all("email" not in b.get("user", {}) for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) >= 2 and all("email" not in b.get("user", {}) for b in [row["data"]["body"] for row in get_rows(r)]),
},
# NOT IN — complement of prim.string_in
{
@@ -367,14 +316,14 @@ def test_primitive_path_operations(
"aggregation": "count()",
# log1(alice) and log3(charlie) are excluded
# bob, diana, "" (log6), healthcheck (no user) are included
- "validate": lambda r: len(get_rows(r)) >= 2 and all(b.get("user", {}).get("name") not in ("alice", "charlie") for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) >= 2 and all(b.get("user", {}).get("name") not in ("alice", "charlie") for b in [row["data"]["body"] for row in get_rows(r)]),
},
]
for case in cases:
case.setdefault("groupBy", None)
case.setdefault("stepInterval", None)
- _run_query_case(signoz, token, now, case)
+ run_query_case(token, now, case)
# ============================================================================
@@ -386,13 +335,13 @@ def test_primitive_path_operations(
def test_indexed_paths(
- signoz: types.SigNoz,
create_user_admin: None, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
export_json_types: Callable[[list[Logs]], None],
create_json_index: Callable[[str, list[dict[str, Any]]], None],
check_query_log: Callable[[datetime, str, Callable[[str], bool]], None],
+ run_query_case: Callable[[str, datetime, dict[str, Any]], None],
) -> None:
now = datetime.now(tz=UTC)
@@ -488,7 +437,7 @@ def test_indexed_paths(
"requestType": "raw",
"expression": "user.raw-data.name EXISTS",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 5 and any(b.get("user", {}).get("raw-data", {}).get("name") == "" for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 5 and any(b.get("user", {}).get("raw-data", {}).get("name") == "" for b in [row["data"]["body"] for row in get_rows(r)]),
"check_query": lambda q: "IS NOT NULL" in q and "assumeNotNull" not in q,
},
# Int64 minmax index on body.user.age: EXISTS skips the indexed path.
@@ -500,7 +449,7 @@ def test_indexed_paths(
"requestType": "raw",
"expression": "user.raw-data.age EXISTS",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 5 and any(b.get("user", {}).get("raw-data", {}).get("age") == 0 for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 5 and any(b.get("user", {}).get("raw-data", {}).get("age") == 0 for b in [row["data"]["body"] for row in get_rows(r)]),
"check_query": lambda q: "IS NOT NULL" in q and "assumeNotNull" not in q,
},
# body.user.name = "": `assumeNotNull(dynamicElement(..., 'String')) = ''
@@ -514,7 +463,7 @@ def test_indexed_paths(
"requestType": "raw",
"expression": 'user.raw-data.name = ""',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and _get_bodies(r)[0]["user"]["raw-data"]["name"] == "",
+ "validate": lambda r: len(get_rows(r)) == 1 and [row["data"]["body"] for row in get_rows(r)][0]["user"]["raw-data"]["name"] == "",
"check_query": lambda q: "assumeNotNull" in q and "IS NOT NULL" in q,
},
# ── Non-EXISTS, non-zero value: indexed condition is self-contained ──────────────
@@ -525,7 +474,7 @@ def test_indexed_paths(
"requestType": "raw",
"expression": "user.raw-data.age = 25",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and _get_bodies(r)[0]["user"]["raw-data"]["age"] == 25,
+ "validate": lambda r: len(get_rows(r)) == 1 and [row["data"]["body"] for row in get_rows(r)][0]["user"]["raw-data"]["age"] == 25,
"check_query": lambda q: "assumeNotNull" in q and "IS NOT NULL" not in q,
},
# body.user.name = "alice": `assumeNotNull(dynamicElement(..., 'String')) = 'alice'`
@@ -536,7 +485,7 @@ def test_indexed_paths(
"requestType": "raw",
"expression": 'user.raw-data.name = "alice"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and _get_bodies(r)[0]["user"]["raw-data"]["name"] == "alice",
+ "validate": lambda r: len(get_rows(r)) == 1 and [row["data"]["body"] for row in get_rows(r)][0]["user"]["raw-data"]["name"] == "alice",
"check_query": lambda q: "assumeNotNull" in q and "IS NOT NULL" not in q,
},
]
@@ -545,7 +494,7 @@ def test_indexed_paths(
case.setdefault("groupBy", None)
case.setdefault("stepInterval", None)
before = datetime.now(tz=UTC)
- _run_query_case(signoz, token, now, case)
+ run_query_case(token, now, case)
if "check_query" in case:
check_query_log(
before,
@@ -716,11 +665,11 @@ def test_select_order_by(
def test_array_path_operations(
- signoz: types.SigNoz,
create_user_admin: None, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
export_json_types: Callable[[list[Logs]], None],
+ run_query_case: Callable[[str, datetime, dict[str, Any]], None],
) -> None:
now = datetime.now(tz=UTC)
@@ -877,14 +826,14 @@ def test_array_path_operations(
"requestType": "raw",
"expression": "education[].name EXISTS",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 3 and all(all("name" in e for e in b["education"]) for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 3 and all(all("name" in e for e in b["education"]) for b in [row["data"]["body"] for row in get_rows(r)]),
},
{
"name": "arr.single_string_equal",
"requestType": "raw",
"expression": 'education[].name = "IIT"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and any(e["name"] == "IIT" for e in _get_bodies(r)[0]["education"]),
+ "validate": lambda r: len(get_rows(r)) == 1 and any(e["name"] == "IIT" for e in [row["data"]["body"] for row in get_rows(r)][0]["education"]),
},
# education[].type: "engineering" (string) in log1[0], 10001 (int!) in log1[1],
# absent in log2, "research" in log3 — type ambiguity
@@ -893,7 +842,7 @@ def test_array_path_operations(
"requestType": "raw",
"expression": 'education[].type = "engineering"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and any(e.get("type") == "engineering" for e in _get_bodies(r)[0]["education"]),
+ "validate": lambda r: len(get_rows(r)) == 1 and any(e.get("type") == "engineering" for e in [row["data"]["body"] for row in get_rows(r)][0]["education"]),
},
# Terminal Array(Float64) + Array(Dynamic) dual branch traversal
{
@@ -901,7 +850,7 @@ def test_array_path_operations(
"requestType": "raw",
"expression": "education[].parameters CONTAINS 1.65",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all(any(1.65 in e.get("parameters", []) for e in b["education"]) for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 2 and all(any(1.65 in e.get("parameters", []) for e in b["education"]) for b in [row["data"]["body"] for row in get_rows(r)]),
},
# IN on terminal Array(Int64)
{
@@ -909,7 +858,7 @@ def test_array_path_operations(
"requestType": "raw",
"expression": "education[].scores IN [90, 95]",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all(any(set(e.get("scores", [])) & {90, 95} for e in b["education"]) for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 2 and all(any(set(e.get("scores", [])) & {90, 95} for e in b["education"]) for b in [row["data"]["body"] for row in get_rows(r)]),
},
# ── single-hop negative ────────────────────────────────────────────
# != wraps NOT at outer arrayExists level
@@ -918,7 +867,7 @@ def test_array_path_operations(
"requestType": "raw",
"expression": 'education[].name != "IIT"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 3 and all(not any(e.get("name") == "IIT" for e in b.get("education", [])) for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 3 and all(not any(e.get("name") == "IIT" for e in b.get("education", [])) for b in [row["data"]["body"] for row in get_rows(r)]),
},
# NOT EXISTS on array path — log4 has no education at all
{
@@ -926,7 +875,7 @@ def test_array_path_operations(
"requestType": "raw",
"expression": "education[].name NOT EXISTS",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and all("education" not in b for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 1 and all("education" not in b for b in [row["data"]["body"] for row in get_rows(r)]),
},
# NOT CONTAINS 1.65: log1 (has 1.65 → excluded), log2 (has 1.65 → excluded).
# Matches: log3 (params [7.0, 8.0]), log4 (no education — passes NOT CONTAINS).
@@ -936,7 +885,7 @@ def test_array_path_operations(
"requestType": "raw",
"expression": "education[].parameters NOT CONTAINS 1.65",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all(not any(1.65 in e.get("parameters", []) for e in b.get("education", [])) for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 2 and all(not any(1.65 in e.get("parameters", []) for e in b.get("education", [])) for b in [row["data"]["body"] for row in get_rows(r)]),
},
# ── double-hop: education[].awards[].field ─────────────────────────
# Only log1 and log3 have awards; log2 has no awards (sparse)
@@ -945,7 +894,7 @@ def test_array_path_operations(
"requestType": "raw",
"expression": "education[].awards[].name EXISTS",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all(any(any("name" in a for a in e.get("awards", [])) for e in b["education"]) for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 2 and all(any(any("name" in a for a in e.get("awards", [])) for e in b["education"]) for b in [row["data"]["body"] for row in get_rows(r)]),
},
# Array(JSON) + Array(Dynamic) dual branch at awards[] hop
{
@@ -953,7 +902,7 @@ def test_array_path_operations(
"requestType": "raw",
"expression": 'education[].awards[].name = "Iron Award"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and any(any(a.get("name") == "Iron Award" for a in e.get("awards", [])) for e in _get_bodies(r)[0]["education"]),
+ "validate": lambda r: len(get_rows(r)) == 1 and any(any(a.get("name") == "Iron Award" for a in e.get("awards", [])) for e in [row["data"]["body"] for row in get_rows(r)][0]["education"]),
},
# ── multi-hop: 4+ hops deep (participated[].team[].branch) ────────
{
@@ -961,7 +910,7 @@ def test_array_path_operations(
"requestType": "raw",
"expression": 'education[].awards[].participated[].team[].branch Contains "Civil"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all(any(any(any(any("Civil" in t.get("branch", "") for t in p.get("team", [])) for p in a.get("participated", [])) for a in e.get("awards", [])) for e in b["education"]) for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 2 and all(any(any(any(any("Civil" in t.get("branch", "") for t in p.get("team", [])) for p in a.get("participated", [])) for a in e.get("awards", [])) for e in b["education"]) for b in [row["data"]["body"] for row in get_rows(r)]),
},
# ── non-array intermediate: http-events[].request-info.host ────────
{
@@ -969,7 +918,7 @@ def test_array_path_operations(
"requestType": "raw",
"expression": 'http-events[].request-info.host = "example.com"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and any(e["request-info"]["host"] == "example.com" for e in _get_bodies(r)[0]["http-events"]),
+ "validate": lambda r: len(get_rows(r)) == 1 and any(e["request-info"]["host"] == "example.com" for e in [row["data"]["body"] for row in get_rows(r)][0]["http-events"]),
},
# ── super deep: 6-hop interests[]...ratings ────────────────────────
{
@@ -979,7 +928,10 @@ def test_array_path_operations(
"aggregation": "count()",
"validate": lambda r: (
len(get_rows(r)) == 1
- and any(any(any(any(any(any(4 in pos.get("ratings", []) for pos in meta.get("positions", [])) for meta in entry.get("metadata", [])) for entry in rev.get("entries", [])) for rev in ent.get("reviews", [])) for ent in interest.get("entities", [])) for interest in _get_bodies(r)[0]["interests"])
+ and any(
+ any(any(any(any(any(4 in pos.get("ratings", []) for pos in meta.get("positions", [])) for meta in entry.get("metadata", [])) for entry in rev.get("entries", [])) for rev in ent.get("reviews", [])) for ent in interest.get("entities", []))
+ for interest in [row["data"]["body"] for row in get_rows(r)][0]["interests"]
+ )
),
},
]
@@ -987,7 +939,7 @@ def test_array_path_operations(
for case in cases:
case.setdefault("groupBy", None)
case.setdefault("stepInterval", None)
- _run_query_case(signoz, token, now, case)
+ run_query_case(token, now, case)
# ============================================================================
@@ -996,11 +948,11 @@ def test_array_path_operations(
def test_array_membership_operations(
- signoz: types.SigNoz,
create_user_admin: None, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
export_json_types: Callable[[list[Logs]], None],
+ run_query_case: Callable[[str, datetime, dict[str, Any]], None],
) -> None:
now = datetime.now(tz=UTC)
@@ -1096,7 +1048,7 @@ def test_array_membership_operations(
"requestType": "raw",
"expression": 'has(tags, "production")',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all("production" in b["tags"] for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 2 and all("production" in b["tags"] for b in [row["data"]["body"] for row in get_rows(r)]),
},
# has(flags, true): only log1 (log2 has [false], log3/log4 have no flags)
{
@@ -1104,7 +1056,7 @@ def test_array_membership_operations(
"requestType": "raw",
"expression": "has(flags, true)",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and True in _get_bodies(r)[0]["flags"],
+ "validate": lambda r: len(get_rows(r)) == 1 and True in [row["data"]["body"] for row in get_rows(r)][0]["flags"],
},
# has() on nested array terminal: parameters contains 1.65 → log1 only
{
@@ -1112,28 +1064,28 @@ def test_array_membership_operations(
"requestType": "raw",
"expression": "has(education[].parameters, 1.65)",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and any(1.65 in e.get("parameters", []) for e in _get_bodies(r)[0]["education"]),
+ "validate": lambda r: len(get_rows(r)) == 1 and any(1.65 in e.get("parameters", []) for e in [row["data"]["body"] for row in get_rows(r)][0]["education"]),
},
{
"name": "membership.hasall_permissions",
"requestType": "raw",
"expression": "hasAll(user.permissions, ['read', 'write'])",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all({"read", "write"}.issubset(set(b["user"]["permissions"])) for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 2 and all({"read", "write"}.issubset(set(b["user"]["permissions"])) for b in [row["data"]["body"] for row in get_rows(r)]),
},
{
"name": "membership.hasany_deep_members",
"requestType": "raw",
"expression": "hasAny(education[].awards[].participated[].members, ['Piyush', 'Tushar'])",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all(any(any(any({"Piyush", "Tushar"} & set(p.get("members", [])) for p in a.get("participated", [])) for a in e.get("awards", [])) for e in b["education"]) for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 2 and all(any(any(any({"Piyush", "Tushar"} & set(p.get("members", [])) for p in a.get("participated", [])) for a in e.get("awards", [])) for e in b["education"]) for b in [row["data"]["body"] for row in get_rows(r)]),
},
]
for case in cases:
case.setdefault("groupBy", None)
case.setdefault("stepInterval", None)
- _run_query_case(signoz, token, now, case)
+ run_query_case(token, now, case)
# ============================================================================
@@ -1142,11 +1094,11 @@ def test_array_membership_operations(
def test_message_searches(
- signoz: types.SigNoz,
create_user_admin: None, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
export_json_types: Callable[[list[Logs]], None],
+ run_query_case: Callable[[str, datetime, dict[str, Any]], None],
) -> None:
now = datetime.now(tz=UTC)
@@ -1223,7 +1175,7 @@ def test_message_searches(
"requestType": "raw",
"expression": '"Payment"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all("Payment" in b.get("message", "") for b in _get_bodies(r)) and r.json().get("data", {}).get("warning") is not None,
+ "validate": lambda r: len(get_rows(r)) == 2 and all("Payment" in b.get("message", "") for b in [row["data"]["body"] for row in get_rows(r)]) and r.json().get("data", {}).get("warning") is not None,
},
# FTS — bare keyword
{
@@ -1231,7 +1183,7 @@ def test_message_searches(
"requestType": "raw",
"expression": "Payment",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 2 and all("Payment" in b.get("message", "") for b in _get_bodies(r)) and r.json().get("data", {}).get("warning") is not None,
+ "validate": lambda r: len(get_rows(r)) == 2 and all("Payment" in b.get("message", "") for b in [row["data"]["body"] for row in get_rows(r)]) and r.json().get("data", {}).get("warning") is not None,
},
# = operator via body.message — tests exact match path
{
@@ -1247,7 +1199,7 @@ def test_message_searches(
"requestType": "raw",
"expression": "message EXISTS",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 3 and all("message" in b for b in _get_bodies(r)),
+ "validate": lambda r: len(get_rows(r)) == 3 and all("message" in b for b in [row["data"]["body"] for row in get_rows(r)]),
},
# ── negative ──────────────────────────────────────────────────────
# NOT CONTAINS "Payment": control_log and no_msg_log
@@ -1263,7 +1215,7 @@ def test_message_searches(
for case in cases:
case.setdefault("groupBy", None)
case.setdefault("stepInterval", None)
- _run_query_case(signoz, token, now, case)
+ run_query_case(token, now, case)
# ============================================================================
@@ -1272,11 +1224,11 @@ def test_message_searches(
def test_polluted_data(
- signoz: types.SigNoz,
create_user_admin: None, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
export_json_types: Callable[[list[Logs]], None],
+ run_query_case: Callable[[str, datetime, dict[str, Any]], None],
) -> None:
now = datetime.now(tz=UTC)
@@ -1360,7 +1312,7 @@ def test_polluted_data(
"requestType": "raw",
"expression": 'user.name = "alice"',
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 1 and _get_bodies(r)[0]["user"]["name"] == "alice",
+ "validate": lambda r: len(get_rows(r)) == 1 and [row["data"]["body"] for row in get_rows(r)][0]["user"]["name"] == "alice",
},
# EXISTS with an ambiguous key uses OR across contexts:
# body-EXISTS: log_clean(alice), log_body_attr_clash(shadow), log_flat_attr(charlie) → 3
@@ -1372,7 +1324,7 @@ def test_polluted_data(
"requestType": "raw",
"expression": "user.name EXISTS",
"aggregation": "count()",
- "validate": lambda r: len(get_rows(r)) == 3 and {b.get("user", {}).get("name") for b in _get_bodies(r)} == {"alice", "shadow", "charlie"},
+ "validate": lambda r: len(get_rows(r)) == 3 and {b.get("user", {}).get("name") for b in [row["data"]["body"] for row in get_rows(r)]} == {"alice", "shadow", "charlie"},
},
# ── new: OR match across body AND attribute in the same query ──────────
# "shadow" exists in body (log_body_attr_clash: body.user.name="shadow") AND
@@ -1390,7 +1342,7 @@ def test_polluted_data(
for case in cases:
case.setdefault("groupBy", None)
case.setdefault("stepInterval", None)
- _run_query_case(signoz, token, now, case)
+ run_query_case(token, now, case)
# ============================================================================
@@ -1413,11 +1365,11 @@ def test_polluted_data(
def test_groupby_scalar(
- signoz: types.SigNoz,
create_user_admin: None, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
export_json_types: Callable[[list[Logs]], None],
+ run_query_case: Callable[[str, datetime, dict[str, Any]], None],
) -> None:
now = datetime.now(tz=UTC)
@@ -1477,4 +1429,4 @@ def test_groupby_scalar(
]
for case in cases:
- _run_query_case(signoz, token, now, case)
+ run_query_case(token, now, case)
diff --git a/tests/integration/tests/querier_json_body/02_non_body_fields.py b/tests/integration/tests/querier_json_body/02_non_body_fields.py
index 798a106a60..1e8b3a274b 100644
--- a/tests/integration/tests/querier_json_body/02_non_body_fields.py
+++ b/tests/integration/tests/querier_json_body/02_non_body_fields.py
@@ -1,9 +1,6 @@
import json
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
-from typing import Any
-
-import requests
from fixtures import types
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
@@ -19,85 +16,6 @@ from fixtures.querier import (
make_query_request,
)
-
-def _raw(
- signoz: types.SigNoz,
- token: str,
- start_ms: int,
- end_ms: int,
- name: str,
- *,
- expression: str | None = None,
- order: list[dict] | None = None,
- limit: int = 100,
-) -> requests.Response:
- q = build_raw_query(
- name=name,
- signal="logs",
- filter_expression=expression,
- order=order or [build_order_by("timestamp", "desc")],
- limit=limit,
- step_interval=60,
- )
- r = make_query_request(signoz, token, start_ms, end_ms, queries=[q], request_type="raw")
- assert r.status_code == 200, f"HTTP {r.status_code} for '{name}': {r.text}"
- return r
-
-
-def _scalar(
- signoz: types.SigNoz,
- token: str,
- start_ms: int,
- end_ms: int,
- name: str,
- aggregation: str,
- *,
- expression: str | None = None,
- group_by: list[dict] | None = None,
-) -> requests.Response:
- q = build_scalar_query(
- name=name,
- signal="logs",
- aggregations=[build_aggregation(aggregation)],
- filter_expression=expression,
- group_by=group_by,
- step_interval=60,
- )
- r = make_query_request(signoz, token, start_ms, end_ms, queries=[q], request_type="scalar")
- assert r.status_code == 200, f"HTTP {r.status_code} for '{name}': {r.text}"
- return r
-
-
-def _body_users(response: requests.Response) -> set[str | None]:
- return {row["data"]["body"].get("user") for row in get_rows(response)}
-
-
-def _body_scores(response: requests.Response) -> list[int | None]:
- return [row["data"]["body"].get("score") for row in get_rows(response)]
-
-
-def _services(response: requests.Response) -> list[str]:
- return [row["data"]["resources_string"].get("service.name", "") for row in get_rows(response)]
-
-
-def _counts(response: requests.Response) -> dict[str, Any]:
- return {str(row[0]): row[-1] for row in get_scalar_table_data(response.json()) if row}
-
-
-def _run_case(
- signoz: types.SigNoz,
- token: str,
- start_ms: int,
- end_ms: int,
- case: dict[str, Any],
-) -> None:
- if case["requestType"] == "raw":
- response = _raw(signoz, token, start_ms, end_ms, case["name"], expression=case.get("expression"), order=case.get("order"))
- else:
- response = _scalar(signoz, token, start_ms, end_ms, case["name"], case["aggregation"], expression=case.get("expression"), group_by=case.get("groupBy"))
- assert case["validate"](response), f"Validation failed for '{case['name']}': {response.json()}"
-
-
# ============================================================================
# Filter · GroupBy · Aggregation — non-body fields across all three contexts
#
@@ -158,7 +76,7 @@ def test_non_body_filter_groupby_aggregation(
"name": "filter.cross_context",
"requestType": "raw",
"expression": 'service.name = "auth-svc" AND http.method = "GET" AND severity_text = "INFO"',
- "validate": lambda r: len(get_rows(r)) == 2 and _body_users(r) == {"alice", "carol"},
+ "validate": lambda r: len(get_rows(r)) == 2 and {row["data"]["body"].get("user") for row in get_rows(r)} == {"alice", "carol"},
},
# 2. GroupBy — resource × top-level multi-key, no filter
# Proves both contexts resolve correctly as simultaneous GROUP BY keys.
@@ -179,7 +97,7 @@ def test_non_body_filter_groupby_aggregation(
"expression": None,
"groupBy": [{"name": "severity_text"}],
"aggregation": "count_distinct(http.method)",
- "validate": lambda r: (rows := _counts(r)) and int(rows["INFO"]) == 1 and int(rows["ERROR"]) == 2 and int(rows["WARN"]) == 1,
+ "validate": lambda r: (rows := {str(row[0]): row[-1] for row in get_scalar_table_data(r.json()) if row}) and int(rows["INFO"]) == 1 and int(rows["ERROR"]) == 2 and int(rows["WARN"]) == 1,
},
# 4. Aggregation + body filter — count by resource WHERE body score >= 80
# Body field gates the logs; non-body field drives the GROUP BY.
@@ -190,7 +108,7 @@ def test_non_body_filter_groupby_aggregation(
"groupBy": [build_group_by_field("service.name")],
"aggregation": "count()",
# score>=80: alice(80), bob(90), eve(100) → auth-svc: 2, worker: 1; api-gw excluded
- "validate": lambda r: (rows := _counts(r)) and int(rows["auth-svc"]) == 2 and int(rows["worker"]) == 1 and "api-gw" not in rows,
+ "validate": lambda r: (rows := {str(row[0]): row[-1] for row in get_scalar_table_data(r.json()) if row}) and int(rows["auth-svc"]) == 2 and int(rows["worker"]) == 1 and "api-gw" not in rows,
},
# 5. Aggregation + top-level filter — count_distinct(resource) grouped by log attr
# Aggregates a resource attr, groups by a log attr, filtered by a top-level field.
@@ -201,13 +119,35 @@ def test_non_body_filter_groupby_aggregation(
"groupBy": [{"name": "http.method"}],
"aggregation": "count_distinct(service.name)",
# INFO/WARN logs: GET(auth-svc×2, api-gw) → 2 distinct svcs; POST/DELETE excluded
- "validate": lambda r: (rows := _counts(r)) and int(rows["GET"]) == 2 and "POST" not in rows and "DELETE" not in rows,
+ "validate": lambda r: (rows := {str(row[0]): row[-1] for row in get_scalar_table_data(r.json()) if row}) and int(rows["GET"]) == 2 and "POST" not in rows and "DELETE" not in rows,
},
]
for case in cases:
case.setdefault("groupBy", None)
- _run_case(signoz, token, start_ms, end_ms, case)
+
+ if case["requestType"] == "raw":
+ query = build_raw_query(
+ name=case["name"],
+ signal="logs",
+ filter_expression=case.get("expression"),
+ order=case.get("order") or [build_order_by("timestamp", "desc")],
+ limit=100,
+ step_interval=60,
+ )
+ else:
+ query = build_scalar_query(
+ name=case["name"],
+ signal="logs",
+ aggregations=[build_aggregation(case["aggregation"])],
+ filter_expression=case.get("expression"),
+ group_by=case.get("groupBy"),
+ step_interval=60,
+ )
+
+ response = make_query_request(signoz, token, start_ms, end_ms, queries=[query], request_type=case["requestType"])
+ assert response.status_code == 200, f"HTTP {response.status_code} for '{case['name']}': {response.text}"
+ assert case["validate"](response), f"Validation failed for '{case['name']}': {response.json()}"
# ============================================================================
@@ -254,21 +194,21 @@ def test_non_body_orderby(
"name": "orderby.service_asc",
"requestType": "raw",
"order": [build_order_by("service.name", "asc")],
- "validate": lambda r: len(get_rows(r)) == 4 and _services(r)[:2] == ["svc-a", "svc-a"] and _services(r)[2:] == ["svc-b", "svc-b"],
+ "validate": lambda r: len(get_rows(r)) == 4 and (svcs := [row["data"]["resources_string"].get("service.name", "") for row in get_rows(r)])[:2] == ["svc-a", "svc-a"] and svcs[2:] == ["svc-b", "svc-b"],
},
# top-level timestamp DESC: ts-1s(svc-b/70), ts-2s(svc-b/60), ts-3s(svc-a/90), ts-4s(svc-a/80)
{
"name": "orderby.timestamp_desc",
"requestType": "raw",
"order": [build_order_by("timestamp", "desc")],
- "validate": lambda r: len(get_rows(r)) == 4 and _body_scores(r) == [70, 60, 90, 80] and _services(r) == ["svc-b", "svc-b", "svc-a", "svc-a"],
+ "validate": lambda r: len(get_rows(r)) == 4 and [row["data"]["body"].get("score") for row in get_rows(r)] == [70, 60, 90, 80] and [row["data"]["resources_string"].get("service.name", "") for row in get_rows(r)] == ["svc-b", "svc-b", "svc-a", "svc-a"],
},
# top-level severity_text ASC: INFO(svc-a×2) before WARN(svc-b×2)
{
"name": "orderby.severity_asc",
"requestType": "raw",
"order": [build_order_by("severity_text", "asc")],
- "validate": lambda r: len(get_rows(r)) == 4 and _services(r)[:2] == ["svc-a", "svc-a"] and _services(r)[2:] == ["svc-b", "svc-b"],
+ "validate": lambda r: len(get_rows(r)) == 4 and (svcs := [row["data"]["resources_string"].get("service.name", "") for row in get_rows(r)])[:2] == ["svc-a", "svc-a"] and svcs[2:] == ["svc-b", "svc-b"],
},
# multi-key: http.method ASC then score ASC — DELETE(70), GET(60,80), POST(90)
{
@@ -276,10 +216,32 @@ def test_non_body_orderby(
"requestType": "raw",
"order": [build_order_by("http.method", "asc"), build_order_by("score", "asc")],
# DELETE < GET < POST alphabetically; within GET scores go 60→80
- "validate": lambda r: len(get_rows(r)) == 4 and _body_scores(r) == [70, 60, 80, 90],
+ "validate": lambda r: len(get_rows(r)) == 4 and [row["data"]["body"].get("score") for row in get_rows(r)] == [70, 60, 80, 90],
},
]
for case in cases:
case.setdefault("groupBy", None)
- _run_case(signoz, token, start_ms, end_ms, case)
+
+ if case["requestType"] == "raw":
+ query = build_raw_query(
+ name=case["name"],
+ signal="logs",
+ filter_expression=case.get("expression"),
+ order=case.get("order") or [build_order_by("timestamp", "desc")],
+ limit=100,
+ step_interval=60,
+ )
+ else:
+ query = build_scalar_query(
+ name=case["name"],
+ signal="logs",
+ aggregations=[build_aggregation(case["aggregation"])],
+ filter_expression=case.get("expression"),
+ group_by=case.get("groupBy"),
+ step_interval=60,
+ )
+
+ response = make_query_request(signoz, token, start_ms, end_ms, queries=[query], request_type=case["requestType"])
+ assert response.status_code == 200, f"HTTP {response.status_code} for '{case['name']}': {response.text}"
+ assert case["validate"](response), f"Validation failed for '{case['name']}': {response.json()}"
diff --git a/tests/integration/tests/querier_skip_resource_fingerprint/01_skip_resource_fingerprint.py b/tests/integration/tests/querier_skip_resource_fingerprint/01_skip_resource_fingerprint.py
index 5c2c7ff553..c92d4943dc 100644
--- a/tests/integration/tests/querier_skip_resource_fingerprint/01_skip_resource_fingerprint.py
+++ b/tests/integration/tests/querier_skip_resource_fingerprint/01_skip_resource_fingerprint.py
@@ -1,14 +1,3 @@
-"""
-Transparency check for the skip_resource_fingerprint optimization (traces and logs).
-
-At or above the configured fingerprint threshold the optimization pushes resource
-conditions onto the main spans/logs table instead of the fingerprint CTE. That
-rewrite must change ClickHouse performance, never the rows: each test runs the same
-query against the primary instance (optimization on, threshold=2) and
-`signoz_fingerprint` (optimization off) and asserts the responses are identical, then
-diffs the rendered SQL to prove the two really did take different paths.
-"""
-
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
@@ -33,6 +22,12 @@ from fixtures.traces import Traces
FINGERPRINT_CTE_FILTER = "resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter)"
+# At or above the configured fingerprint threshold the optimization pushes resource
+# conditions onto the main spans/logs table instead of the fingerprint CTE. That
+# rewrite must change performance, never rows: each test runs the same query against
+# the primary instance (optimization on, threshold=2) and `signoz_fingerprint`
+# (optimization off), asserts identical responses, then diffs the rendered SQL to
+# prove the two really did take different paths.
def test_skip_resource_fingerprint_traces_fallback_matches_fingerprint(
signoz: types.SigNoz,
signoz_fingerprint: types.SigNoz,
diff --git a/tests/integration/tests/querierai/01_ai_traces.py b/tests/integration/tests/querierai/01_ai_traces.py
index 1d9938dce8..3d9a7997ac 100644
--- a/tests/integration/tests/querierai/01_ai_traces.py
+++ b/tests/integration/tests/querierai/01_ai_traces.py
@@ -1,10 +1,3 @@
-"""
-Integration tests for query_type="builder_ai_query" over the traces signal.
-
-Each test tags its spans with a unique service.name and filters on it, so tests do
-not interfere with each other's data. Shared builders live in fixtures/querierai.py.
-"""
-
import json
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
@@ -30,6 +23,8 @@ from fixtures.querierai import (
from fixtures.traces import TraceIdGenerator, Traces, TracesKind, TracesStatusCode
+# Each test tags its spans with a unique service.name and filters on it, so tests
+# do not interfere with each other's data.
def test_ai_list_excludes_non_ai(
signoz: types.SigNoz,
create_user_admin: None, # pylint: disable=unused-argument
diff --git a/tests/integration/tests/queriercommon/03_clickhouse_queries.py b/tests/integration/tests/queriercommon/03_clickhouse_queries.py
index 8237225f06..039e3df4e9 100644
--- a/tests/integration/tests/queriercommon/03_clickhouse_queries.py
+++ b/tests/integration/tests/queriercommon/03_clickhouse_queries.py
@@ -1,7 +1,3 @@
-"""
-Integration tests for raw ClickHouse SQL queries in the querier.
-"""
-
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/querierlogs/03_fill.py b/tests/integration/tests/querierlogs/03_fill.py
index 000763e7e1..4001db0968 100644
--- a/tests/integration/tests/querierlogs/03_fill.py
+++ b/tests/integration/tests/querierlogs/03_fill.py
@@ -20,9 +20,6 @@ def test_logs_fill_gaps(
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
) -> None:
- """
- Test fillGaps for logs without groupBy.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
logs: list[Logs] = [
Logs(
@@ -106,9 +103,6 @@ def test_logs_fill_gaps_with_group_by(
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
) -> None:
- """
- Test fillGaps for logs with groupBy.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
logs: list[Logs] = [
Logs(
@@ -207,9 +201,6 @@ def test_logs_fill_gaps_formula(
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
) -> None:
- """
- Test fillGaps for logs with formula.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
logs: list[Logs] = [
Logs(
@@ -314,9 +305,6 @@ def test_logs_fill_gaps_formula_with_group_by(
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
) -> None:
- """
- Test fillGaps for logs with formula and groupBy.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
logs: list[Logs] = [
Logs(
@@ -442,9 +430,6 @@ def test_logs_fill_zero(
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
) -> None:
- """
- Test fillZero function for logs without groupBy.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
logs: list[Logs] = [
Logs(
@@ -518,9 +503,6 @@ def test_logs_fill_zero_with_group_by(
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
) -> None:
- """
- Test fillZero function for logs with groupBy.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
logs: list[Logs] = [
Logs(
@@ -618,9 +600,6 @@ def test_logs_fill_zero_formula(
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
) -> None:
- """
- Test fillZero function for logs with formula.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
logs: list[Logs] = [
Logs(
@@ -726,9 +705,6 @@ def test_logs_fill_zero_formula_with_group_by(
get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
) -> None:
- """
- Test fillZero function for logs with formula and groupBy.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
logs: list[Logs] = [
Logs(
diff --git a/tests/integration/tests/querierlogs/07_list_expectations.py b/tests/integration/tests/querierlogs/07_list_expectations.py
index a516591dd0..03bbf1ce8a 100644
--- a/tests/integration/tests/querierlogs/07_list_expectations.py
+++ b/tests/integration/tests/querierlogs/07_list_expectations.py
@@ -26,7 +26,23 @@ from fixtures.querier import (
# name="A",
# limit=1,
# ),
- # lambda x: _flatten_log(x[2]),
+ # lambda x: [
+ # x[2].attributes_bool,
+ # x[2].attributes_number,
+ # x[2].attributes_string,
+ # x[2].body,
+ # x[2].id,
+ # x[2].resources_string,
+ # x[2].scope_name,
+ # x[2].scope_string,
+ # x[2].scope_version,
+ # x[2].severity_number,
+ # x[2].severity_text,
+ # x[2].span_id,
+ # x[2].timestamp,
+ # x[2].trace_flags,
+ # x[2].trace_id,
+ # ],
# id="no-select-no-order",
# # Behaviour:
# # Empty order results in consistent random order
@@ -141,7 +157,23 @@ from fixtures.querier import (
limit=1,
order=[OrderBy(TelemetryFieldKey("timestamp"), "desc")],
),
- lambda x: _flatten_log(x[3]),
+ lambda x: [
+ x[3].attributes_bool,
+ x[3].attributes_number,
+ x[3].attributes_string,
+ x[3].body,
+ x[3].id,
+ x[3].resources_string,
+ x[3].scope_name,
+ x[3].scope_string,
+ x[3].scope_version,
+ x[3].severity_number,
+ x[3].severity_text,
+ x[3].span_id,
+ x[3].timestamp,
+ x[3].trace_flags,
+ x[3].trace_id,
+ ],
id="no-select-order-timestamp-desc",
# Behaviour:
# AdjustKeys no-op
@@ -259,7 +291,23 @@ from fixtures.querier import (
limit=1,
order=[OrderBy(TelemetryFieldKey("attribute.timestamp"), "desc")],
),
- lambda x: _flatten_log(x[0]),
+ lambda x: [
+ x[0].attributes_bool,
+ x[0].attributes_number,
+ x[0].attributes_string,
+ x[0].body,
+ x[0].id,
+ x[0].resources_string,
+ x[0].scope_name,
+ x[0].scope_string,
+ x[0].scope_version,
+ x[0].severity_number,
+ x[0].severity_text,
+ x[0].span_id,
+ x[0].timestamp,
+ x[0].trace_flags,
+ x[0].trace_id,
+ ],
id="no-select-order-attr-timestamp-desc",
# Behaviour:
# Order by attribute.timestamp resolves to attributes_string['timestamp'].
@@ -521,10 +569,24 @@ def test_logs_list_query_timestamp_expectations(
order=[OrderBy(TelemetryFieldKey("trace_id"), "desc")],
),
lambda x: [
- _flatten_log(x[0]),
- _flatten_log(x[2]),
- _flatten_log(x[1]),
- _flatten_log(x[3]),
+ [
+ log.attributes_bool,
+ log.attributes_number,
+ log.attributes_string,
+ log.body,
+ log.id,
+ log.resources_string,
+ log.scope_name,
+ log.scope_string,
+ log.scope_version,
+ log.severity_number,
+ log.severity_text,
+ log.span_id,
+ log.timestamp,
+ log.trace_flags,
+ log.trace_id,
+ ]
+ for log in (x[0], x[2], x[1], x[3])
],
id="no-select-trace-id-order",
# Justification (expected values and row order):
@@ -541,10 +603,24 @@ def test_logs_list_query_timestamp_expectations(
order=[OrderBy(TelemetryFieldKey("attribute.trace_id"), "desc")],
),
lambda x: [
- _flatten_log(x[1]),
- _flatten_log(x[2]),
- _flatten_log(x[0]),
- _flatten_log(x[3]),
+ [
+ log.attributes_bool,
+ log.attributes_number,
+ log.attributes_string,
+ log.body,
+ log.id,
+ log.resources_string,
+ log.scope_name,
+ log.scope_string,
+ log.scope_version,
+ log.severity_number,
+ log.severity_text,
+ log.span_id,
+ log.timestamp,
+ log.trace_flags,
+ log.trace_id,
+ ]
+ for log in (x[1], x[2], x[0], x[3])
],
id="no-select-attribute-trace-id-order",
# Justification (expected values and row order):
@@ -740,23 +816,3 @@ def test_logs_list_query_trace_id_expectations(
keys = list(data.keys())
for i, expected_value in enumerate(expected_row):
assert data[keys[i]] == expected_value, f"Row mismatch at key '{keys[i]}': expected {expected_value}, got {data[keys[i]]}"
-
-
-def _flatten_log(log: Logs) -> list[Any]:
- return [
- log.attributes_bool,
- log.attributes_number,
- log.attributes_string,
- log.body,
- log.id,
- log.resources_string,
- log.scope_name,
- log.scope_string,
- log.scope_version,
- log.severity_number,
- log.severity_text,
- log.span_id,
- log.timestamp,
- log.trace_flags,
- log.trace_id,
- ]
diff --git a/tests/integration/tests/querierlogs/08_resource_evolution.py b/tests/integration/tests/querierlogs/08_resource_evolution.py
index 32ef8d964a..902ac461a7 100644
--- a/tests/integration/tests/querierlogs/08_resource_evolution.py
+++ b/tests/integration/tests/querierlogs/08_resource_evolution.py
@@ -1,7 +1,9 @@
from collections.abc import Callable
-from datetime import datetime, timedelta
+from datetime import timedelta
from http import HTTPStatus
+import pytest
+
from fixtures import types
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
from fixtures.logs import Logs
@@ -15,73 +17,20 @@ from fixtures.querier import (
)
-# Logs with timestamps before the evolution time will have resources written only to resources_string.
-# Logs with timestamps at or after the evolution time will have resources written to both resources_string and resource_json.
-def _build_evolved_log(
- timestamp: datetime,
- evolution_time: datetime,
- service_name: str,
- body: str,
-) -> Logs:
- resource_write_mode = "legacy_only" if timestamp < evolution_time else "dual_write"
- return Logs(
- timestamp=timestamp,
- resources={
- "service.name": service_name,
- "deployment.environment": "integration",
- },
- body=body,
- severity_text="INFO",
- resource_write_mode=resource_write_mode,
- )
-
-
-def _query_grouped_log_series(
- signoz: types.SigNoz,
- token: str,
- start: datetime,
- end: datetime,
- group_by: str = "service.name",
- aggregation: str = "count()",
-) -> dict[str, list[dict]]:
- response = make_query_request(
- signoz,
- token,
- start_ms=int(start.timestamp() * 1000),
- end_ms=int(end.timestamp() * 1000),
- request_type="time_series",
- queries=[
- {
- "type": "builder_query",
- "spec": {
- "name": "A",
- "signal": "logs",
- "stepInterval": 60,
- "disabled": False,
- "groupBy": [build_group_by_field(group_by)],
- "having": {"expression": ""},
- "aggregations": [build_aggregation(aggregation)],
- },
- }
- ],
- )
-
- assert response.status_code == HTTPStatus.OK
- assert response.json()["status"] == "success"
-
- results = response.json()["data"]["data"]["results"]
- assert len(results) == 1
-
- aggregations = results[0]["aggregations"]
- assert len(aggregations) == 1
-
- return index_series_by_label(aggregations[0]["series"], group_by)
-
-
-def _test_logs_resource_evolution(
+ "materialize_service_name",
+ [
+ pytest.param(False, id="map_resource_fields"),
+ pytest.param(True, id="materialized_resource_field"),
+ ],
+)
+def test_logs_resource_evolution(
signoz: types.SigNoz,
- token: str,
+ create_user_admin: None, # pylint: disable=unused-argument
+ get_token: Callable[[str, str], str],
insert_logs: Callable[[list[Logs]], None],
+ materialize_log_field: Callable[[str, str, str, str], None],
+ materialize_service_name: bool,
) -> None:
"""
# 1. Get the evolution time.
@@ -91,6 +40,10 @@ def _test_logs_resource_evolution(
# 5. Query the logs after the evolution time.
# Both aggregation and group by should be checked.
"""
+ token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
+ if materialize_service_name:
+ materialize_log_field(token, "service.name", "string", "resources")
+
evolution_time = get_resource_evolution_time(signoz, "logs")
evolution_time = evolution_time.replace(second=0, microsecond=0)
@@ -99,119 +52,150 @@ def _test_logs_resource_evolution(
after_1 = evolution_time + timedelta(minutes=5)
after_2 = evolution_time + timedelta(minutes=10)
+ # Logs with timestamps before the evolution time will have resources written only to resources_string.
+ # Logs with timestamps at or after the evolution time will have resources written to both resources_string and resource_json.
insert_logs(
[
- _build_evolved_log(
+ Logs(
timestamp=before_2,
- evolution_time=evolution_time,
- service_name="svc-before-2",
+ resources={
+ "service.name": "svc-before-2",
+ "deployment.environment": "integration",
+ },
body="log before evolution 2",
+ severity_text="INFO",
+ resource_write_mode="legacy_only",
),
- _build_evolved_log(
+ Logs(
timestamp=before_1,
- evolution_time=evolution_time,
- service_name="svc-before-1",
+ resources={
+ "service.name": "svc-before-1",
+ "deployment.environment": "integration",
+ },
body="log before evolution 1",
+ severity_text="INFO",
+ resource_write_mode="legacy_only",
),
- _build_evolved_log(
+ Logs(
timestamp=after_1,
- evolution_time=evolution_time,
- service_name="svc-after-1",
+ resources={
+ "service.name": "svc-after-1",
+ "deployment.environment": "integration",
+ },
body="log after evolution 1",
+ severity_text="INFO",
+ resource_write_mode="dual_write",
),
- _build_evolved_log(
+ Logs(
timestamp=after_2,
- evolution_time=evolution_time,
- service_name="svc-after-2",
+ resources={
+ "service.name": "svc-after-2",
+ "deployment.environment": "integration",
+ },
body="log after evolution 2",
+ severity_text="INFO",
+ resource_write_mode="dual_write",
),
]
)
- before_series = _query_grouped_log_series(signoz, token, before_2 - timedelta(minutes=1), before_1 + timedelta(minutes=1))
- assert_grouped_series(
- before_series,
- expected_values_by_group={
- "svc-before-2": {
- int(before_2.timestamp() * 1000): 1,
- },
- "svc-before-1": {
- int(before_1.timestamp() * 1000): 1,
- },
- },
- )
-
- after_series = _query_grouped_log_series(signoz, token, after_1 - timedelta(minutes=1), after_2 + timedelta(minutes=1))
- assert_grouped_series(
- after_series,
- expected_values_by_group={
- "svc-after-1": {
- int(after_1.timestamp() * 1000): 1,
- },
- "svc-after-2": {
- int(after_2.timestamp() * 1000): 1,
- },
- },
- )
-
- spanning_series = _query_grouped_log_series(signoz, token, before_2, after_2 + timedelta(minutes=1))
- assert_grouped_series(
- spanning_series,
- expected_values_by_group={
- "svc-before-2": {
- int(before_2.timestamp() * 1000): 1,
- },
- "svc-before-1": {
- int(before_1.timestamp() * 1000): 1,
+ for start, end, group_by, aggregation, expected_values_by_group in [
+ (
+ before_2 - timedelta(minutes=1),
+ before_1 + timedelta(minutes=1),
+ "service.name",
+ "count()",
+ {
+ "svc-before-2": {
+ int(before_2.timestamp() * 1000): 1,
+ },
+ "svc-before-1": {
+ int(before_1.timestamp() * 1000): 1,
+ },
},
- "svc-after-1": {
- int(after_1.timestamp() * 1000): 1,
+ ),
+ (
+ after_1 - timedelta(minutes=1),
+ after_2 + timedelta(minutes=1),
+ "service.name",
+ "count()",
+ {
+ "svc-after-1": {
+ int(after_1.timestamp() * 1000): 1,
+ },
+ "svc-after-2": {
+ int(after_2.timestamp() * 1000): 1,
+ },
},
- "svc-after-2": {
- int(after_2.timestamp() * 1000): 1,
+ ),
+ (
+ before_2,
+ after_2 + timedelta(minutes=1),
+ "service.name",
+ "count()",
+ {
+ "svc-before-2": {
+ int(before_2.timestamp() * 1000): 1,
+ },
+ "svc-before-1": {
+ int(before_1.timestamp() * 1000): 1,
+ },
+ "svc-after-1": {
+ int(after_1.timestamp() * 1000): 1,
+ },
+ "svc-after-2": {
+ int(after_2.timestamp() * 1000): 1,
+ },
},
- },
- )
-
- # query to check aggregation on the resource field like count_distinct(service.name)
- aggregation_series = _query_grouped_log_series(
- signoz,
- token,
- before_2,
- after_2 + timedelta(minutes=1),
- group_by="deployment.environment",
- aggregation="count_distinct(service.name)",
- )
- assert_grouped_series(
- aggregation_series,
- expected_values_by_group={
- "integration": {
- int(before_2.timestamp() * 1000): 1,
- int(before_1.timestamp() * 1000): 1,
- int(after_1.timestamp() * 1000): 1,
- int(after_2.timestamp() * 1000): 1,
+ ),
+ # query to check aggregation on the resource field like count_distinct(service.name)
+ (
+ before_2,
+ after_2 + timedelta(minutes=1),
+ "deployment.environment",
+ "count_distinct(service.name)",
+ {
+ "integration": {
+ int(before_2.timestamp() * 1000): 1,
+ int(before_1.timestamp() * 1000): 1,
+ int(after_1.timestamp() * 1000): 1,
+ int(after_2.timestamp() * 1000): 1,
+ },
},
- },
- )
-
-
-def test_logs_resource_evolution(
- signoz: types.SigNoz,
- create_user_admin: None, # pylint: disable=unused-argument
- get_token: Callable[[str, str], str],
- insert_logs: Callable[[list[Logs]], None],
-) -> None:
- token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- _test_logs_resource_evolution(signoz, token, insert_logs)
-
-
-def test_logs_materialized_resource_evolution(
- signoz: types.SigNoz,
- create_user_admin: None, # pylint: disable=unused-argument
- get_token: Callable[[str, str], str],
- insert_logs: Callable[[list[Logs]], None],
- materialize_log_field: Callable[[str, str, str, str], None],
-) -> None:
- token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- materialize_log_field(token, "service.name", "string", "resources")
- _test_logs_resource_evolution(signoz, token, insert_logs)
+ ),
+ ]:
+ response = make_query_request(
+ signoz,
+ token,
+ start_ms=int(start.timestamp() * 1000),
+ end_ms=int(end.timestamp() * 1000),
+ request_type="time_series",
+ queries=[
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "logs",
+ "stepInterval": 60,
+ "disabled": False,
+ "groupBy": [build_group_by_field(group_by)],
+ "having": {"expression": ""},
+ "aggregations": [build_aggregation(aggregation)],
+ },
+ }
+ ],
+ )
+
+ assert response.status_code == HTTPStatus.OK
+ assert response.json()["status"] == "success"
+
+ results = response.json()["data"]["data"]["results"]
+ assert len(results) == 1
+
+ aggregations = results[0]["aggregations"]
+ assert len(aggregations) == 1
+
+ assert_grouped_series(
+ index_series_by_label(aggregations[0]["series"], group_by),
+ expected_values_by_group=expected_values_by_group,
+ )
diff --git a/tests/integration/tests/queriermetrics/01_fill.py b/tests/integration/tests/queriermetrics/01_fill.py
index bc6b508cb7..b84dbc2a33 100644
--- a/tests/integration/tests/queriermetrics/01_fill.py
+++ b/tests/integration/tests/queriermetrics/01_fill.py
@@ -19,30 +19,7 @@ FILL_GAPS = "fillGaps"
FILL_ZERO = "fillZero"
-def _build_format_options(fill_mode: str) -> dict[str, Any]:
- return {
- "formatTableResultForUI": False,
- "fillGaps": fill_mode == FILL_GAPS,
- }
-
-
-def _maybe_add_functions(spec: dict[str, Any], fill_mode: str, is_formula: bool = False) -> None:
- """Add fillZero function to the spec when using fillZero mode.
-
- For builder_query: functions go on the query spec.
- For builder_formula: functions go on the formula spec.
- fillGaps mode uses formatOptions instead, so nothing is added.
- """
- if fill_mode == FILL_ZERO and not is_formula:
- spec["functions"] = [{"name": "fillZero"}]
-
-
-def _maybe_add_formula_functions(spec: dict[str, Any], fill_mode: str) -> None:
- if fill_mode == FILL_ZERO:
- spec["functions"] = [{"name": "fillZero"}]
-
-
[email protected]("fill_mode", [FILL_GAPS, FILL_ZERO], ids=["fillGaps", "fillZero"])
[email protected]("fill_mode", [FILL_GAPS, FILL_ZERO], ids=["fill_gaps", "fill_zero"])
def test_metrics_fill_no_group_by(
fill_mode: str,
signoz: types.SigNoz,
@@ -50,9 +27,6 @@ def test_metrics_fill_no_group_by(
get_token: Callable[[str, str], str],
insert_metrics: Callable[[list[Metrics]], None],
) -> None:
- """
- Test that gaps in time series are filled with zeros (no groupBy).
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
metric_name = f"test_{fill_mode}_metric"
@@ -97,7 +71,9 @@ def test_metrics_fill_no_group_by(
"stepInterval": 60,
"disabled": False,
}
- _maybe_add_functions(query_spec, fill_mode)
+ # fillZero goes on the query spec as a function; fillGaps uses formatOptions instead.
+ if fill_mode == FILL_ZERO:
+ query_spec["functions"] = [{"name": "fillZero"}]
response = requests.post(
signoz.self.host_configs["8080"].get("/api/v5/query_range"),
@@ -109,7 +85,10 @@ def test_metrics_fill_no_group_by(
"end": end_ms,
"requestType": "time_series",
"compositeQuery": {"queries": [{"type": "builder_query", "spec": query_spec}]},
- "formatOptions": _build_format_options(fill_mode),
+ "formatOptions": {
+ "formatTableResultForUI": False,
+ "fillGaps": fill_mode == FILL_GAPS,
+ },
},
)
@@ -133,7 +112,7 @@ def test_metrics_fill_no_group_by(
)
[email protected]("fill_mode", [FILL_GAPS, FILL_ZERO], ids=["fillGaps", "fillZero"])
[email protected]("fill_mode", [FILL_GAPS, FILL_ZERO], ids=["fill_gaps", "fill_zero"])
def test_metrics_fill_with_group_by(
fill_mode: str,
signoz: types.SigNoz,
@@ -141,9 +120,6 @@ def test_metrics_fill_with_group_by(
get_token: Callable[[str, str], str],
insert_metrics: Callable[[list[Metrics]], None],
) -> None:
- """
- Test that gaps are filled per group when using groupBy.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
metric_name = f"test_{fill_mode}_grouped_metric"
@@ -204,7 +180,9 @@ def test_metrics_fill_with_group_by(
}
],
}
- _maybe_add_functions(query_spec, fill_mode)
+ # fillZero goes on the query spec as a function; fillGaps uses formatOptions instead.
+ if fill_mode == FILL_ZERO:
+ query_spec["functions"] = [{"name": "fillZero"}]
response = requests.post(
signoz.self.host_configs["8080"].get("/api/v5/query_range"),
@@ -216,7 +194,10 @@ def test_metrics_fill_with_group_by(
"end": end_ms,
"requestType": "time_series",
"compositeQuery": {"queries": [{"type": "builder_query", "spec": query_spec}]},
- "formatOptions": _build_format_options(fill_mode),
+ "formatOptions": {
+ "formatTableResultForUI": False,
+ "fillGaps": fill_mode == FILL_GAPS,
+ },
},
)
@@ -251,7 +232,7 @@ def test_metrics_fill_with_group_by(
)
[email protected]("fill_mode", [FILL_GAPS, FILL_ZERO], ids=["fillGaps", "fillZero"])
[email protected]("fill_mode", [FILL_GAPS, FILL_ZERO], ids=["fill_gaps", "fill_zero"])
def test_metrics_fill_formula(
fill_mode: str,
signoz: types.SigNoz,
@@ -259,9 +240,6 @@ def test_metrics_fill_formula(
get_token: Callable[[str, str], str],
insert_metrics: Callable[[list[Metrics]], None],
) -> None:
- """
- Test that formula results have gaps filled.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
metric_name_a = f"test_{fill_mode}_formula_a"
metric_name_b = f"test_{fill_mode}_formula_b"
@@ -307,7 +285,9 @@ def test_metrics_fill_formula(
"expression": "A + B",
"disabled": False,
}
- _maybe_add_formula_functions(formula_spec, fill_mode)
+ # fillZero goes on the formula spec as a function; fillGaps uses formatOptions instead.
+ if fill_mode == FILL_ZERO:
+ formula_spec["functions"] = [{"name": "fillZero"}]
response = requests.post(
signoz.self.host_configs["8080"].get("/api/v5/query_range"),
@@ -357,7 +337,10 @@ def test_metrics_fill_formula(
{"type": "builder_formula", "spec": formula_spec},
]
},
- "formatOptions": _build_format_options(fill_mode),
+ "formatOptions": {
+ "formatTableResultForUI": False,
+ "fillGaps": fill_mode == FILL_GAPS,
+ },
},
)
@@ -386,7 +369,7 @@ def test_metrics_fill_formula(
)
[email protected]("fill_mode", [FILL_GAPS, FILL_ZERO], ids=["fillGaps", "fillZero"])
[email protected]("fill_mode", [FILL_GAPS, FILL_ZERO], ids=["fill_gaps", "fill_zero"])
def test_metrics_fill_formula_with_group_by(
fill_mode: str,
signoz: types.SigNoz,
@@ -394,9 +377,6 @@ def test_metrics_fill_formula_with_group_by(
get_token: Callable[[str, str], str],
insert_metrics: Callable[[list[Metrics]], None],
) -> None:
- """
- Test that formula results with groupBy have gaps filled per group.
- """
now = datetime.now(tz=UTC).replace(second=0, microsecond=0)
metric_name_a = f"test_{fill_mode}_formula_grp_a"
metric_name_b = f"test_{fill_mode}_formula_grp_b"
@@ -478,7 +458,9 @@ def test_metrics_fill_formula_with_group_by(
"expression": "A + B",
"disabled": False,
}
- _maybe_add_formula_functions(formula_spec, fill_mode)
+ # fillZero goes on the formula spec as a function; fillGaps uses formatOptions instead.
+ if fill_mode == FILL_ZERO:
+ formula_spec["functions"] = [{"name": "fillZero"}]
response = requests.post(
signoz.self.host_configs["8080"].get("/api/v5/query_range"),
@@ -530,7 +512,10 @@ def test_metrics_fill_formula_with_group_by(
{"type": "builder_formula", "spec": formula_spec},
]
},
- "formatOptions": _build_format_options(fill_mode),
+ "formatOptions": {
+ "formatTableResultForUI": False,
+ "fillGaps": fill_mode == FILL_GAPS,
+ },
},
)
diff --git a/tests/integration/tests/queriermetrics/04_histogram.py b/tests/integration/tests/queriermetrics/04_histogram.py
index e74e14e5e6..b44d55d5eb 100644
--- a/tests/integration/tests/queriermetrics/04_histogram.py
+++ b/tests/integration/tests/queriermetrics/04_histogram.py
@@ -1,7 +1,3 @@
-"""
-Look at the histogram_data_1h.jsonl file for the relevant data
-"""
-
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
diff --git a/tests/integration/tests/queriermetrics/05_multi_temporality.py b/tests/integration/tests/queriermetrics/05_multi_temporality.py
index 0bcaf845f9..5c7a4c28af 100644
--- a/tests/integration/tests/queriermetrics/05_multi_temporality.py
+++ b/tests/integration/tests/queriermetrics/05_multi_temporality.py
@@ -1,7 +1,3 @@
-"""
-Look at the multi_temporality_counters_1h.jsonl file for the relevant data
-"""
-
import random
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
diff --git a/tests/integration/tests/queriermetrics/07_rate_cumulative.py b/tests/integration/tests/queriermetrics/07_rate_cumulative.py
index c30c369173..92582e175a 100644
--- a/tests/integration/tests/queriermetrics/07_rate_cumulative.py
+++ b/tests/integration/tests/queriermetrics/07_rate_cumulative.py
@@ -1,7 +1,3 @@
-"""
-Look at the cumulative_counters_1h.jsonl file for the relevant data
-"""
-
import os
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
diff --git a/tests/integration/tests/queriermetrics/08_rate_delta.py b/tests/integration/tests/queriermetrics/08_rate_delta.py
index c8274a68af..78e846f111 100644
--- a/tests/integration/tests/queriermetrics/08_rate_delta.py
+++ b/tests/integration/tests/queriermetrics/08_rate_delta.py
@@ -1,7 +1,3 @@
-"""
-Look at the delta_counters_1h.jsonl file for the relevant data
-"""
-
import os
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
diff --git a/tests/integration/tests/queriertraces/01_list.py b/tests/integration/tests/queriertraces/01_list.py
index 416c201c03..fa501bd670 100644
--- a/tests/integration/tests/queriertraces/01_list.py
+++ b/tests/integration/tests/queriertraces/01_list.py
@@ -36,54 +36,6 @@ from fixtures.traces import (
# collision-robustness check.
-def _query_window(now: datetime) -> tuple[int, int]:
- """[now-1min, now+1s) in epoch millis — the default window for list tests
- that seed spans a few seconds in the past."""
- return (
- int((now - timedelta(minutes=1)).timestamp() * 1000),
- int((now + timedelta(seconds=1)).timestamp() * 1000),
- )
-
-
-def _expected_list_row(span: Traces) -> dict[str, Any]:
- """The full empty-selectFields list row the API returns for `span`: every
- intrinsic + calculated column (mirroring the fixture's OTel-derived
- computation), the merged `attributes` map (the union of the typed attribute
- dicts) and the `resource` map. Deriving it from the span object lets list
- responses be asserted as an exact round-trip of the inserted span — which
- holds for clean and corrupt spans alike, since the corrupt values live only
- inside the `attributes` map."""
- return {
- "timestamp": format_timestamp(span.timestamp),
- "trace_id": span.trace_id,
- "span_id": span.span_id,
- "trace_state": span.trace_state,
- "parent_span_id": span.parent_span_id,
- "flags": int(span.flags),
- "name": span.name,
- "kind": int(span.kind),
- "kind_string": span.kind_string,
- "duration_nano": int(span.duration_nano),
- "status_code": int(span.status_code),
- "status_message": span.status_message,
- "status_code_string": span.status_code_string,
- "events": span.events,
- "links": span.links,
- "response_status_code": span.response_status_code,
- "external_http_url": span.external_http_url,
- "http_url": span.http_url,
- "external_http_method": span.external_http_method,
- "http_method": span.http_method,
- "http_host": span.http_host,
- "db_name": span.db_name,
- "db_operation": span.db_operation,
- "has_error": span.has_error,
- "is_remote": span.is_remote,
- "attributes": {**span.attribute_string, **span.attributes_number, **span.attributes_bool},
- "resource": span.resources_string,
- }
-
-
# ============================================================================
# Basic list & row shape
# ============================================================================
@@ -251,31 +203,14 @@ def test_traces_list(
assert rows[1]["data"]["service.name"] == post_span.service_name
-def _verify_events_links_full(rows: list[dict], traces: list[Traces]) -> None:
- """Empty-selectFields case: events/links arrive parsed into structured objects.
- Every row's events/links should match the fixture's stored parsed shape
- (the fixture's `.events`/`.links` mirror the API response shape directly).
- """
- for row, trace in zip(rows, traces, strict=True):
- assert row["data"]["events"] == trace.events
- assert row["data"]["links"] == trace.links
- # Jaeger-era `refType` is dropped at the consume layer.
- for link in row["data"]["links"]:
- assert "refType" not in link
-
-
-def _verify_events_links_skip(rows: list[dict], traces: list[Traces]) -> None:
- """Projected-selectFields case: nothing to verify beyond the key set."""
-
-
@pytest.mark.parametrize(
- "select_fields,expected_keys,verify_values",
+ "select_fields,expected_keys,events_links",
[
- pytest.param([], ALL_SELECT_FIELDS, _verify_events_links_full, id="empty_returns_all_fields"),
+ pytest.param([], ALL_SELECT_FIELDS, "full", id="empty_returns_all_fields"),
pytest.param(
[TelemetryFieldKey("service.name")],
["timestamp", "trace_id", "span_id", "service.name"],
- _verify_events_links_skip,
+ "skip",
id="projected_subset",
),
],
@@ -289,7 +224,7 @@ def test_traces_list_select_fields(
noise: str,
select_fields: list[TelemetryFieldKey],
expected_keys: list[str],
- verify_values: Callable[[list[dict], list[Traces]], None],
+ events_links: str,
) -> None:
"""
Setup:
@@ -386,7 +321,17 @@ def test_traces_list_select_fields(
for row in rows:
assert set(row["data"].keys()) == set(expected_keys)
- verify_values(rows, traces)
+ # Empty-selectFields case: events/links arrive parsed into structured objects.
+ # Every row's events/links should match the fixture's stored parsed shape
+ # (the fixture's `.events`/`.links` mirror the API response shape directly).
+ # Projected-selectFields case: nothing to verify beyond the key set.
+ if events_links == "full":
+ for row, trace in zip(rows, traces, strict=True):
+ assert row["data"]["events"] == trace.events
+ assert row["data"]["links"] == trace.links
+ # Jaeger-era `refType` is dropped at the consume layer.
+ for link in row["data"]["links"]:
+ assert "refType" not in link
@pytest.mark.parametrize(
@@ -439,7 +384,8 @@ def test_traces_list_select_field_types(
insert_traces([span])
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
response = make_query_request(
signoz,
@@ -491,7 +437,8 @@ def test_traces_list_select_field_dedup(
insert_traces([span])
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
response = make_query_request(
signoz,
@@ -555,7 +502,8 @@ def test_traces_list_select_calculated_field_collision(
insert_traces([span])
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
response = make_query_request(
signoz,
@@ -624,12 +572,14 @@ def test_traces_list_response_shape_values(
insert_traces(spans)
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
# Each span's full empty-selectFields row is derived from the span object:
# intrinsic + calculated columns come from the fixture's own OTel-mirroring
# computation, and the merged `attributes` map is exactly the union of the
- # typed attribute dicts. This holds identically for clean and corrupt spans.
+ # typed attribute dicts. This holds identically for clean and corrupt spans,
+ # since the corrupt values live only inside the `attributes` map.
for span_obj in spans:
marker = span_obj.attribute_string["marker"]
response = make_query_request(
@@ -644,7 +594,35 @@ def test_traces_list_response_shape_values(
rows = get_rows(response)
assert len(rows) == 1
data = rows[0]["data"]
- assert data == _expected_list_row(span_obj)
+ assert data == {
+ "timestamp": format_timestamp(span_obj.timestamp),
+ "trace_id": span_obj.trace_id,
+ "span_id": span_obj.span_id,
+ "trace_state": span_obj.trace_state,
+ "parent_span_id": span_obj.parent_span_id,
+ "flags": int(span_obj.flags),
+ "name": span_obj.name,
+ "kind": int(span_obj.kind),
+ "kind_string": span_obj.kind_string,
+ "duration_nano": int(span_obj.duration_nano),
+ "status_code": int(span_obj.status_code),
+ "status_message": span_obj.status_message,
+ "status_code_string": span_obj.status_code_string,
+ "events": span_obj.events,
+ "links": span_obj.links,
+ "response_status_code": span_obj.response_status_code,
+ "external_http_url": span_obj.external_http_url,
+ "http_url": span_obj.http_url,
+ "external_http_method": span_obj.external_http_method,
+ "http_method": span_obj.http_method,
+ "http_host": span_obj.http_host,
+ "db_name": span_obj.db_name,
+ "db_operation": span_obj.db_operation,
+ "has_error": span_obj.has_error,
+ "is_remote": span_obj.is_remote,
+ "attributes": {**span_obj.attribute_string, **span_obj.attributes_number, **span_obj.attributes_bool},
+ "resource": span_obj.resources_string,
+ }
# `==` treats True/1 and 7.5/7.5 as equal regardless of type, so pin the
# string/number/bool type preservation for the error span explicitly.
if marker == "error":
@@ -719,7 +697,8 @@ def test_traces_list_ordering(
)
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
expected = [m["marker"] for m in sorted(metas, key=sort_value, reverse=(direction == "desc"))]
@@ -780,7 +759,8 @@ def test_traces_list_order_multi_key_tiebreak(
by_duration_secs = {1: spans[0].span_id, 2: spans[1].span_id, 3: spans[2].span_id}
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
def query(duration_direction: str) -> list[str]:
response = make_query_request(
@@ -837,7 +817,8 @@ def test_traces_list_no_default_order(
insert_traces(spans)
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
response = make_query_request(
signoz,
@@ -904,7 +885,8 @@ def test_traces_list_pagination(
insert_traces(spans)
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
# timestamp desc => newest span (i=4) first
ordered_span_ids = [span.span_id for span in reversed(spans)]
@@ -1018,7 +1000,8 @@ def test_traces_list_empty_result(
)
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
# Filter matches nothing.
response = make_query_request(
@@ -1109,7 +1092,8 @@ def test_traces_list_span_scope(
insert_top_level_operations([("op-entry", "scope-svc")])
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
def query_scope(expression: str) -> list[str]:
response = make_query_request(
@@ -1137,11 +1121,40 @@ def test_traces_list_span_scope(
[
# Case 1: order by timestamp; empty selectFields returns the full
# response shape (all intrinsic + calculated columns plus the merged
- # `attributes` and `resource` maps). x[3] (topic-service) is latest.
+ # `attributes` and `resource` maps, every value derived from the inserted
+ # span object). x[3] (topic-service) is latest.
pytest.param(
BuilderQuery(signal="traces", name="A", order=[OrderBy(TelemetryFieldKey("timestamp"), "desc")], limit=1),
HTTPStatus.OK,
- lambda x: _expected_list_row(x[3]),
+ lambda x: {
+ "timestamp": format_timestamp(x[3].timestamp),
+ "trace_id": x[3].trace_id,
+ "span_id": x[3].span_id,
+ "trace_state": x[3].trace_state,
+ "parent_span_id": x[3].parent_span_id,
+ "flags": int(x[3].flags),
+ "name": x[3].name,
+ "kind": int(x[3].kind),
+ "kind_string": x[3].kind_string,
+ "duration_nano": int(x[3].duration_nano),
+ "status_code": int(x[3].status_code),
+ "status_message": x[3].status_message,
+ "status_code_string": x[3].status_code_string,
+ "events": x[3].events,
+ "links": x[3].links,
+ "response_status_code": x[3].response_status_code,
+ "external_http_url": x[3].external_http_url,
+ "http_url": x[3].http_url,
+ "external_http_method": x[3].external_http_method,
+ "http_method": x[3].http_method,
+ "http_host": x[3].http_host,
+ "db_name": x[3].db_name,
+ "db_operation": x[3].db_operation,
+ "has_error": x[3].has_error,
+ "is_remote": x[3].is_remote,
+ "attributes": {**x[3].attribute_string, **x[3].attributes_number, **x[3].attributes_bool},
+ "resource": x[3].resources_string,
+ },
id="order_timestamp_full_shape",
),
# Case 2: order by attribute.timestamp. The key resolves to the intrinsic
@@ -1150,7 +1163,35 @@ def test_traces_list_span_scope(
pytest.param(
BuilderQuery(signal="traces", name="A", order=[OrderBy(TelemetryFieldKey("attribute.timestamp"), "desc")], limit=1),
HTTPStatus.OK,
- lambda x: _expected_list_row(x[3]),
+ lambda x: {
+ "timestamp": format_timestamp(x[3].timestamp),
+ "trace_id": x[3].trace_id,
+ "span_id": x[3].span_id,
+ "trace_state": x[3].trace_state,
+ "parent_span_id": x[3].parent_span_id,
+ "flags": int(x[3].flags),
+ "name": x[3].name,
+ "kind": int(x[3].kind),
+ "kind_string": x[3].kind_string,
+ "duration_nano": int(x[3].duration_nano),
+ "status_code": int(x[3].status_code),
+ "status_message": x[3].status_message,
+ "status_code_string": x[3].status_code_string,
+ "events": x[3].events,
+ "links": x[3].links,
+ "response_status_code": x[3].response_status_code,
+ "external_http_url": x[3].external_http_url,
+ "http_url": x[3].http_url,
+ "external_http_method": x[3].external_http_method,
+ "http_method": x[3].http_method,
+ "http_host": x[3].http_host,
+ "db_name": x[3].db_name,
+ "db_operation": x[3].db_operation,
+ "has_error": x[3].has_error,
+ "is_remote": x[3].is_remote,
+ "attributes": {**x[3].attribute_string, **x[3].attributes_number, **x[3].attributes_bool},
+ "resource": x[3].resources_string,
+ },
id="order_attribute_timestamp_full_shape",
),
# Case 3: select timestamp with empty order by.
@@ -1275,7 +1316,8 @@ def test_traces_list_unknown_span_context_synthesizes(
insert_traces([span])
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
key = "span.does_not_exist"
svc = "resource.service.name = 'forgiving-ctx-service'"
@@ -1346,7 +1388,8 @@ def test_traces_list_unknown_other_context_synthesizes(
insert_traces(spans)
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
key = f"{context}.does_not_exist"
svc = "resource.service.name = 'synth-service'"
@@ -1409,7 +1452,8 @@ def test_traces_list_order_unknown_key_synthesizes(
insert_traces(spans)
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- start_ms, end_ms = _query_window(now)
+ start_ms = int((now - timedelta(minutes=1)).timestamp() * 1000)
+ end_ms = int((now + timedelta(seconds=1)).timestamp() * 1000)
response = make_query_request(
signoz,
diff --git a/tests/integration/tests/queriertraces/03_fill.py b/tests/integration/tests/queriertraces/03_fill.py
index b0404f3d0e..d5fc8faf42 100644
--- a/tests/integration/tests/queriertraces/03_fill.py
+++ b/tests/integration/tests/queriertraces/03_fill.py
@@ -29,11 +29,6 @@ from fixtures.traces import TraceIdGenerator, Traces, TracesKind, TracesStatusCo
FILL_MODES = ["fillGaps", "fillZero"]
-def _bucket_ms(span: Traces) -> int:
- """The minutely bucket (epoch millis) a seeded span lands in."""
- return int(span.timestamp.timestamp() * 1000)
-
-
@pytest.mark.parametrize("fill_mode", FILL_MODES)
@pytest.mark.parametrize("noise", ["clean", "corrupt"])
def test_traces_fill_plain(
@@ -84,7 +79,8 @@ def test_traces_fill_plain(
assert response.status_code == HTTPStatus.OK, response.text
series = get_all_series(response.json(), "A")
assert len(series) >= 1
- assert_minutely_bucket_values(series[0]["values"], now, expected_by_ts={_bucket_ms(span): 1}, context=f"traces/{fill_mode}")
+ # int(span.timestamp.timestamp() * 1000) is the minutely bucket (epoch millis) the seeded span lands in.
+ assert_minutely_bucket_values(series[0]["values"], now, expected_by_ts={int(span.timestamp.timestamp() * 1000): 1}, context=f"traces/{fill_mode}")
@pytest.mark.parametrize("fill_mode", FILL_MODES)
@@ -157,8 +153,8 @@ def test_traces_fill_group_by(
by_service = index_series_by_label(series, "service.name")
assert set(by_service) == {"service-a", "service-b"}
- assert_minutely_bucket_values(by_service["service-a"]["values"], now, expected_by_ts={_bucket_ms(span_a): 1}, context=f"traces/{fill_mode}/service-a")
- assert_minutely_bucket_values(by_service["service-b"]["values"], now, expected_by_ts={_bucket_ms(span_b): 1}, context=f"traces/{fill_mode}/service-b")
+ assert_minutely_bucket_values(by_service["service-a"]["values"], now, expected_by_ts={int(span_a.timestamp.timestamp() * 1000): 1}, context=f"traces/{fill_mode}/service-a")
+ assert_minutely_bucket_values(by_service["service-b"]["values"], now, expected_by_ts={int(span_b.timestamp.timestamp() * 1000): 1}, context=f"traces/{fill_mode}/service-b")
@pytest.mark.parametrize("fill_mode", FILL_MODES)
@@ -228,7 +224,7 @@ def test_traces_fill_formula(
assert f1 is not None
series = f1["aggregations"][0]["series"]
assert len(series) >= 1
- assert_minutely_bucket_values(series[0]["values"], now, expected_by_ts={_bucket_ms(span_test): 1, _bucket_ms(span_other): 1}, context=f"traces/{fill_mode}/F1")
+ assert_minutely_bucket_values(series[0]["values"], now, expected_by_ts={int(span_test.timestamp.timestamp() * 1000): 1, int(span_other.timestamp.timestamp() * 1000): 1}, context=f"traces/{fill_mode}/F1")
@pytest.mark.parametrize("fill_mode", FILL_MODES)
@@ -303,5 +299,5 @@ def test_traces_fill_formula_group_by(
by_service = index_series_by_label(series, "service.name")
assert set(by_service) == {"group1", "group2"}
- assert_minutely_bucket_values(by_service["group1"]["values"], now, expected_by_ts={_bucket_ms(span_g1): 2}, context=f"traces/{fill_mode}/F1/group1")
- assert_minutely_bucket_values(by_service["group2"]["values"], now, expected_by_ts={_bucket_ms(span_g2): 2}, context=f"traces/{fill_mode}/F1/group2")
+ assert_minutely_bucket_values(by_service["group1"]["values"], now, expected_by_ts={int(span_g1.timestamp.timestamp() * 1000): 2}, context=f"traces/{fill_mode}/F1/group1")
+ assert_minutely_bucket_values(by_service["group2"]["values"], now, expected_by_ts={int(span_g2.timestamp.timestamp() * 1000): 2}, context=f"traces/{fill_mode}/F1/group2")
diff --git a/tests/integration/tests/queriertraces/05_resource_evolution.py b/tests/integration/tests/queriertraces/05_resource_evolution.py
index 81d8c0ee83..d62ef6a8b3 100644
--- a/tests/integration/tests/queriertraces/05_resource_evolution.py
+++ b/tests/integration/tests/queriertraces/05_resource_evolution.py
@@ -1,5 +1,5 @@
from collections.abc import Callable
-from datetime import datetime, timedelta
+from datetime import timedelta
from http import HTTPStatus
from fixtures import types
@@ -17,65 +17,10 @@ from fixtures.querier import (
from fixtures.traces import TraceIdGenerator, Traces
-# Spans with timestamps before the evolution time will have resources written only to resources_string.
-# Spans with timestamps at or after the evolution time will have resources written to both resources_string and resource (JSON).
-def _build_evolved_span(
- timestamp: datetime,
- evolution_time: datetime,
- service_name: str,
- name: str,
-) -> Traces:
- resource_write_mode = "legacy_only" if timestamp < evolution_time else "dual_write"
- return Traces(
- timestamp=timestamp,
- trace_id=TraceIdGenerator.trace_id(),
- span_id=TraceIdGenerator.span_id(),
- name=name,
- resources={
- "service.name": service_name,
- "deployment.environment": "integration",
- },
- resource_write_mode=resource_write_mode,
- )
-
-
-def _query_grouped_trace_series(
- signoz: types.SigNoz,
- token: str,
- start: datetime,
- end: datetime,
- group_by: str = "service.name",
- aggregation: str = "count()",
-) -> dict[str, list[dict]]:
- response = make_query_request(
- signoz,
- token,
- start_ms=int(start.timestamp() * 1000),
- end_ms=int(end.timestamp() * 1000),
- request_type=RequestType.TIME_SERIES,
- queries=[
- build_traces_scalar_query(
- aggregations=[build_aggregation(aggregation)],
- group_by=[build_group_by_field(group_by)],
- )
- ],
- )
-
- assert response.status_code == HTTPStatus.OK
- assert response.json()["status"] == "success"
-
- results = response.json()["data"]["data"]["results"]
- assert len(results) == 1
-
- aggregations = results[0]["aggregations"]
- assert len(aggregations) == 1
-
- return index_series_by_label(aggregations[0]["series"], group_by)
-
-
-def _test_traces_resource_evolution(
+def test_traces_resource_evolution(
signoz: types.SigNoz,
- token: str,
+ create_user_admin: None, # pylint: disable=unused-argument
+ get_token: Callable[[str, str], str],
insert_traces: Callable[[list[Traces]], None],
) -> None:
"""
@@ -86,6 +31,8 @@ def _test_traces_resource_evolution(
# 5. Query the spans after the evolution time.
# Both aggregation and group by should be checked.
"""
+ token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
+
evolution_time = get_resource_evolution_time(signoz, "traces")
evolution_time = evolution_time.replace(second=0, microsecond=0)
@@ -94,36 +41,77 @@ def _test_traces_resource_evolution(
after_1 = evolution_time + timedelta(minutes=5)
after_2 = evolution_time + timedelta(minutes=10)
+ # Spans with timestamps before the evolution time will have resources written only to resources_string.
+ # Spans with timestamps at or after the evolution time will have resources written to both resources_string and resource (JSON).
insert_traces(
[
- _build_evolved_span(
+ Traces(
timestamp=before_2,
- evolution_time=evolution_time,
- service_name="svc-before-2",
+ trace_id=TraceIdGenerator.trace_id(),
+ span_id=TraceIdGenerator.span_id(),
name="span before evolution 2",
+ resources={
+ "service.name": "svc-before-2",
+ "deployment.environment": "integration",
+ },
+ resource_write_mode="legacy_only",
),
- _build_evolved_span(
+ Traces(
timestamp=before_1,
- evolution_time=evolution_time,
- service_name="svc-before-1",
+ trace_id=TraceIdGenerator.trace_id(),
+ span_id=TraceIdGenerator.span_id(),
name="span before evolution 1",
+ resources={
+ "service.name": "svc-before-1",
+ "deployment.environment": "integration",
+ },
+ resource_write_mode="legacy_only",
),
- _build_evolved_span(
+ Traces(
timestamp=after_1,
- evolution_time=evolution_time,
- service_name="svc-after-1",
+ trace_id=TraceIdGenerator.trace_id(),
+ span_id=TraceIdGenerator.span_id(),
name="span after evolution 1",
+ resources={
+ "service.name": "svc-after-1",
+ "deployment.environment": "integration",
+ },
+ resource_write_mode="dual_write",
),
- _build_evolved_span(
+ Traces(
timestamp=after_2,
- evolution_time=evolution_time,
- service_name="svc-after-2",
+ trace_id=TraceIdGenerator.trace_id(),
+ span_id=TraceIdGenerator.span_id(),
name="span after evolution 2",
+ resources={
+ "service.name": "svc-after-2",
+ "deployment.environment": "integration",
+ },
+ resource_write_mode="dual_write",
),
]
)
- before_series = _query_grouped_trace_series(signoz, token, before_2 - timedelta(minutes=1), before_1 + timedelta(minutes=1))
+ response = make_query_request(
+ signoz,
+ token,
+ start_ms=int((before_2 - timedelta(minutes=1)).timestamp() * 1000),
+ end_ms=int((before_1 + timedelta(minutes=1)).timestamp() * 1000),
+ request_type=RequestType.TIME_SERIES,
+ queries=[
+ build_traces_scalar_query(
+ aggregations=[build_aggregation("count()")],
+ group_by=[build_group_by_field("service.name")],
+ )
+ ],
+ )
+ assert response.status_code == HTTPStatus.OK
+ assert response.json()["status"] == "success"
+ results = response.json()["data"]["data"]["results"]
+ assert len(results) == 1
+ aggregations = results[0]["aggregations"]
+ assert len(aggregations) == 1
+ before_series = index_series_by_label(aggregations[0]["series"], "service.name")
assert_grouped_series(
before_series,
expected_values_by_group={
@@ -136,7 +124,26 @@ def _test_traces_resource_evolution(
},
)
- after_series = _query_grouped_trace_series(signoz, token, after_1 - timedelta(minutes=1), after_2 + timedelta(minutes=1))
+ response = make_query_request(
+ signoz,
+ token,
+ start_ms=int((after_1 - timedelta(minutes=1)).timestamp() * 1000),
+ end_ms=int((after_2 + timedelta(minutes=1)).timestamp() * 1000),
+ request_type=RequestType.TIME_SERIES,
+ queries=[
+ build_traces_scalar_query(
+ aggregations=[build_aggregation("count()")],
+ group_by=[build_group_by_field("service.name")],
+ )
+ ],
+ )
+ assert response.status_code == HTTPStatus.OK
+ assert response.json()["status"] == "success"
+ results = response.json()["data"]["data"]["results"]
+ assert len(results) == 1
+ aggregations = results[0]["aggregations"]
+ assert len(aggregations) == 1
+ after_series = index_series_by_label(aggregations[0]["series"], "service.name")
assert_grouped_series(
after_series,
expected_values_by_group={
@@ -149,7 +156,26 @@ def _test_traces_resource_evolution(
},
)
- spanning_series = _query_grouped_trace_series(signoz, token, before_2, after_2 + timedelta(minutes=1))
+ response = make_query_request(
+ signoz,
+ token,
+ start_ms=int(before_2.timestamp() * 1000),
+ end_ms=int((after_2 + timedelta(minutes=1)).timestamp() * 1000),
+ request_type=RequestType.TIME_SERIES,
+ queries=[
+ build_traces_scalar_query(
+ aggregations=[build_aggregation("count()")],
+ group_by=[build_group_by_field("service.name")],
+ )
+ ],
+ )
+ assert response.status_code == HTTPStatus.OK
+ assert response.json()["status"] == "success"
+ results = response.json()["data"]["data"]["results"]
+ assert len(results) == 1
+ aggregations = results[0]["aggregations"]
+ assert len(aggregations) == 1
+ spanning_series = index_series_by_label(aggregations[0]["series"], "service.name")
assert_grouped_series(
spanning_series,
expected_values_by_group={
@@ -169,14 +195,26 @@ def _test_traces_resource_evolution(
)
# query to check aggregation on the resource field like count_distinct(service.name)
- aggregation_series = _query_grouped_trace_series(
+ response = make_query_request(
signoz,
token,
- before_2,
- after_2 + timedelta(minutes=1),
- group_by="deployment.environment",
- aggregation="count_distinct(service.name)",
+ start_ms=int(before_2.timestamp() * 1000),
+ end_ms=int((after_2 + timedelta(minutes=1)).timestamp() * 1000),
+ request_type=RequestType.TIME_SERIES,
+ queries=[
+ build_traces_scalar_query(
+ aggregations=[build_aggregation("count_distinct(service.name)")],
+ group_by=[build_group_by_field("deployment.environment")],
+ )
+ ],
)
+ assert response.status_code == HTTPStatus.OK
+ assert response.json()["status"] == "success"
+ results = response.json()["data"]["data"]["results"]
+ assert len(results) == 1
+ aggregations = results[0]["aggregations"]
+ assert len(aggregations) == 1
+ aggregation_series = index_series_by_label(aggregations[0]["series"], "deployment.environment")
assert_grouped_series(
aggregation_series,
expected_values_by_group={
@@ -188,13 +226,3 @@ def _test_traces_resource_evolution(
},
},
)
-
-
-def test_traces_resource_evolution(
- signoz: types.SigNoz,
- create_user_admin: None, # pylint: disable=unused-argument
- get_token: Callable[[str, str], str],
- insert_traces: Callable[[list[Traces]], None],
-) -> None:
- token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- _test_traces_resource_evolution(signoz, token, insert_traces)
diff --git a/tests/integration/tests/queriertraces/06_trace_operator.py b/tests/integration/tests/queriertraces/06_trace_operator.py
index c81c9de37a..6a75b96b20 100644
--- a/tests/integration/tests/queriertraces/06_trace_operator.py
+++ b/tests/integration/tests/queriertraces/06_trace_operator.py
@@ -1,27 +1,3 @@
-"""
-Integration tests for TraceOperatorQuery (builder_trace_operator) through the
-/api/v5/query_range endpoint.
-
-Covers:
-1. Order-by variants (A -> B, A => B) with returnSpansFrom="A".
- Guards against the NOT_FOUND_COLUMN_IN_BLOCK regression where ordering by a
- column absent from an outer SELECT caused a query failure.
-2. Expression operators (=>, ->, &&, ||, A NOT B) with and without returnSpansFrom.
-
-returnSpansFrom semantics
---------------------------
-returnSpansFrom="" (default)
- The final rows come from the expression's root CTE. Only spans that
- directly satisfy the structural predicate are returned.
-
-returnSpansFrom="A"
- The expression is still evaluated in full (the structural relationship
- must hold), but the final rows are drawn from the A sub-query CTE,
- filtered to traces that appeared in the expression result. Concretely:
- the query returns every A span whose trace_id belongs to a trace that
- matched the expression.
-"""
-
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
@@ -54,11 +30,6 @@ from fixtures.traces import (
TracesStatusCode,
)
-
-def _names(response: requests.Response) -> set:
- return {r["data"]["name"] for r in get_rows(response)}
-
-
# ============================================================================
# Dataset — 4 traces using real OTel semantic-convention attributes
#
@@ -90,7 +61,9 @@ def _names(response: requests.Response) -> set:
# A || B A=http.method EXISTS B=messaging.system='kafka' T1✓ T2✓ T3✓ T4✓
# A NOT B A=http.method EXISTS B=db.system='redis' T1✗ T2✗ T3✓ T4✗
#
-# Order-by cases (all use returnSpansFrom=A, 3 rows expected):
+# Order-by cases (all use returnSpansFrom=A, 3 rows expected). Guards against the
+# NOT_FOUND_COLUMN_IN_BLOCK regression: ordering by a column absent from an outer
+# SELECT caused a query failure.
# ob.indirect A->B order http.method DESC → POST(checkout+proxy), GET(catalog)
# ob.duration A=>B order duration_nano DESC → POST/checkout(5s), api-proxy(3s), GET/catalog(1s)
# ob.select A=>B order http.method DESC → POST, POST, GET
@@ -159,7 +132,7 @@ def _names(response: requests.Response) -> set:
"filter_b": "db.system = 'redis'",
"expression": "A => B",
"return_spans_from": "",
- "validate": lambda r: len(get_rows(r)) == 2 and _names(r) == {"POST /checkout", "GET /catalog"},
+ "validate": lambda r: len(get_rows(r)) == 2 and {row["data"]["name"] for row in get_rows(r)} == {"POST /checkout", "GET /catalog"},
},
id="ex.direct_child.default",
),
@@ -171,7 +144,7 @@ def _names(response: requests.Response) -> set:
"filter_b": "db.system = 'redis'",
"expression": "A => B",
"return_spans_from": "A",
- "validate": lambda r: len(get_rows(r)) == 3 and _names(r) == {"POST /checkout", "GET /catalog", "api-proxy"},
+ "validate": lambda r: len(get_rows(r)) == 3 and {row["data"]["name"] for row in get_rows(r)} == {"POST /checkout", "GET /catalog", "api-proxy"},
},
id="ex.direct_child.return_A",
),
@@ -184,7 +157,7 @@ def _names(response: requests.Response) -> set:
"filter_b": "db.system = 'postgresql'",
"expression": "A -> B",
"return_spans_from": "",
- "validate": lambda r: len(get_rows(r)) == 2 and _names(r) == {"POST /checkout", "GET /catalog"},
+ "validate": lambda r: len(get_rows(r)) == 2 and {row["data"]["name"] for row in get_rows(r)} == {"POST /checkout", "GET /catalog"},
},
id="ex.indirect_descendant.default",
),
@@ -196,7 +169,7 @@ def _names(response: requests.Response) -> set:
"filter_b": "db.system = 'postgresql'",
"expression": "A -> B",
"return_spans_from": "A",
- "validate": lambda r: len(get_rows(r)) == 3 and _names(r) == {"POST /checkout", "GET /catalog", "api-proxy"},
+ "validate": lambda r: len(get_rows(r)) == 3 and {row["data"]["name"] for row in get_rows(r)} == {"POST /checkout", "GET /catalog", "api-proxy"},
},
id="ex.indirect_descendant.return_A",
),
@@ -211,7 +184,7 @@ def _names(response: requests.Response) -> set:
"filter_b": "db.system = 'redis'",
"expression": "A && B",
"return_spans_from": "",
- "validate": lambda r: len(get_rows(r)) == 3 and _names(r) == {"POST /checkout", "GET /catalog", "api-proxy"},
+ "validate": lambda r: len(get_rows(r)) == 3 and {row["data"]["name"] for row in get_rows(r)} == {"POST /checkout", "GET /catalog", "api-proxy"},
},
id="ex.and.default",
),
@@ -224,7 +197,7 @@ def _names(response: requests.Response) -> set:
"filter_b": "messaging.system = 'kafka'",
"expression": "A || B",
"return_spans_from": "",
- "validate": lambda r: len(get_rows(r)) == 5 and _names(r) == {"POST /checkout", "GET /catalog", "api-proxy", "standalone-server", "isolated-worker"},
+ "validate": lambda r: len(get_rows(r)) == 5 and {row["data"]["name"] for row in get_rows(r)} == {"POST /checkout", "GET /catalog", "api-proxy", "standalone-server", "isolated-worker"},
},
id="ex.or.default",
),
@@ -237,7 +210,7 @@ def _names(response: requests.Response) -> set:
"filter_b": "messaging.system = 'kafka'",
"expression": "A || B",
"return_spans_from": "A",
- "validate": lambda r: len(get_rows(r)) == 4 and _names(r) == {"POST /checkout", "GET /catalog", "api-proxy", "standalone-server"},
+ "validate": lambda r: len(get_rows(r)) == 4 and {row["data"]["name"] for row in get_rows(r)} == {"POST /checkout", "GET /catalog", "api-proxy", "standalone-server"},
},
id="ex.or.return_A",
),
@@ -252,7 +225,7 @@ def _names(response: requests.Response) -> set:
"filter_b": "db.system = 'redis'",
"expression": "A NOT B",
"return_spans_from": "",
- "validate": lambda r: len(get_rows(r)) == 1 and _names(r) == {"standalone-server"},
+ "validate": lambda r: len(get_rows(r)) == 1 and {row["data"]["name"] for row in get_rows(r)} == {"standalone-server"},
},
id="ex.not.default",
),
@@ -449,17 +422,6 @@ def test_trace_operator(
assert case["validate"](response), f"validation failed: {response.json()}"
-def _expected_trace_subset(trace: Traces) -> dict[str, Any]:
- return {
- "duration_nano": trace.duration_nano,
- "name": trace.name,
- "parent_span_id": trace.parent_span_id,
- "span_id": trace.span_id,
- "timestamp": format_timestamp(trace.timestamp),
- "trace_id": trace.trace_id,
- }
-
-
@pytest.mark.parametrize(
"payload_factory,request_type,assert_result",
[
@@ -492,7 +454,18 @@ def _expected_trace_subset(trace: Traces) -> dict[str, Any]:
},
],
RequestType.RAW,
- lambda response, traces: assert_raw_row_subset(response, "C", _expected_trace_subset(traces[0])),
+ lambda response, traces: assert_raw_row_subset(
+ response,
+ "C",
+ {
+ "duration_nano": traces[0].duration_nano,
+ "name": traces[0].name,
+ "parent_span_id": traces[0].parent_span_id,
+ "span_id": traces[0].span_id,
+ "timestamp": format_timestamp(traces[0].timestamp),
+ "trace_id": traces[0].trace_id,
+ },
+ ),
id="deprecated-intrinsic-filter",
),
# Case 2: CTE filter uses the deprecated calculated field `responseStatusCode`.
@@ -524,7 +497,18 @@ def _expected_trace_subset(trace: Traces) -> dict[str, Any]:
},
],
RequestType.RAW,
- lambda response, traces: assert_raw_row_subset(response, "C", _expected_trace_subset(traces[0])),
+ lambda response, traces: assert_raw_row_subset(
+ response,
+ "C",
+ {
+ "duration_nano": traces[0].duration_nano,
+ "name": traces[0].name,
+ "parent_span_id": traces[0].parent_span_id,
+ "span_id": traces[0].span_id,
+ "timestamp": format_timestamp(traces[0].timestamp),
+ "trace_id": traces[0].trace_id,
+ },
+ ),
id="deprecated-calculated-filter",
),
# Case 3: order by uses `count_` with fieldContext `span`, which has
@@ -631,38 +615,13 @@ TRACE_OPERATOR_CORE_FIELDS = [
]
-def _verify_full_expansion(rows: list[dict], parent_trace: Traces) -> None:
- """Empty-selectFields case: every column from the builder_query parity set
- arrives, and events/links are parsed into structured form (refType is
- dropped at the consume layer).
- """
- assert len(rows) == 1
- parent_row = rows[0]["data"]
- assert set(parent_row.keys()) == set(ALL_SELECT_FIELDS)
- assert parent_row["events"] == parent_trace.events
- assert parent_row["links"] == parent_trace.links
- for link in parent_row["links"]:
- assert "refType" not in link
-
-
-def _verify_explicit_projection(rows: list[dict], parent_trace: Traces) -> None: # pylint: disable=unused-argument
- """Explicit-selectFields case: only the 6 hardcoded core fields plus the
- user-supplied resource.service.name come back. Contextual columns
- (events/links/attributes/resource) and the rest of the intrinsics never
- appear because the consume-layer merge isn't triggered.
- """
- assert len(rows) == 1
- parent_row = rows[0]["data"]
- assert set(parent_row.keys()) == set(TRACE_OPERATOR_CORE_FIELDS + ["service.name"])
-
-
@pytest.mark.parametrize(
- "select_fields,verify_values",
+ "select_fields,expansion",
[
- pytest.param([], _verify_full_expansion, id="empty-select-fields"),
+ pytest.param([], "full", id="empty-select-fields"),
pytest.param(
[{"name": "service.name", "fieldContext": "resource"}],
- _verify_explicit_projection,
+ "explicit",
id="explicit-service-name",
),
],
@@ -673,7 +632,7 @@ def test_trace_operator_select_fields(
get_token: Callable[[str, str], str],
insert_traces: Callable[[list[Traces]], None],
select_fields: list[dict[str, Any]],
- verify_values: Callable[[list[dict], Traces], None],
+ expansion: str,
) -> None:
"""
Setup:
@@ -792,4 +751,21 @@ def test_trace_operator_select_fields(
trace_operator_result = find_named_result(results, "C")
assert trace_operator_result is not None, "trace_operator result C not found"
rows = trace_operator_result["rows"]
- verify_values(rows, parent_trace)
+
+ assert len(rows) == 1
+ parent_row = rows[0]["data"]
+ if expansion == "full":
+ # Empty-selectFields case: every column from the builder_query parity set
+ # arrives, and events/links are parsed into structured form (refType is
+ # dropped at the consume layer).
+ assert set(parent_row.keys()) == set(ALL_SELECT_FIELDS)
+ assert parent_row["events"] == parent_trace.events
+ assert parent_row["links"] == parent_trace.links
+ for link in parent_row["links"]:
+ assert "refType" not in link
+ else:
+ # Explicit-selectFields case: only the 6 hardcoded core fields plus the
+ # user-supplied resource.service.name come back. Contextual columns
+ # (events/links/attributes/resource) and the rest of the intrinsics never
+ # appear because the consume-layer merge isn't triggered.
+ assert set(parent_row.keys()) == set(TRACE_OPERATOR_CORE_FIELDS + ["service.name"])
diff --git a/tests/integration/tests/queriertraces/12_timestamp_aggregations.py b/tests/integration/tests/queriertraces/12_timestamp_aggregations.py
index fcbc8c7aa5..7280537ea8 100644
--- a/tests/integration/tests/queriertraces/12_timestamp_aggregations.py
+++ b/tests/integration/tests/queriertraces/12_timestamp_aggregations.py
@@ -1,9 +1,3 @@
-"""Aggregations over the intrinsic `timestamp` column.
-
-`timestamp` is DateTime64(9), so a numeric coercion rescales it to seconds — the #5824
-regression. Order-based aggregations answer with an instant; sum/avg have no time meaning.
-"""
-
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
@@ -61,6 +55,9 @@ def query_timestamp_aggregation(signoz: types.SigNoz, token: str, expression: st
)
+# `timestamp` is DateTime64(9), so a numeric coercion rescales it to seconds — the
+# #5824 regression. Order-based aggregations answer with an instant; sum/avg have
+# no time meaning.
@pytest.mark.parametrize("expression,bound", [("max(timestamp)", "newest"), ("min(timestamp)", "oldest")])
def test_timestamp_order_aggregations_return_the_instant(
signoz: types.SigNoz,
diff --git a/tests/integration/tests/savedview/01_saved_view.py b/tests/integration/tests/savedview/01_saved_view.py
index e4d1c6b390..ac2f58f8b6 100644
--- a/tests/integration/tests/savedview/01_saved_view.py
+++ b/tests/integration/tests/savedview/01_saved_view.py
@@ -10,55 +10,6 @@ from fixtures.types import Operation, SigNoz
BASE_URL = "/api/v2/saved_views"
-def _query(*, disabled: bool = False, legend: str = "") -> dict:
- return {
- "type": "builder_query",
- "spec": {
- "name": "A",
- "signal": "logs",
- "aggregations": [{"expression": "count()"}],
- "disabled": disabled,
- "legend": legend,
- },
- }
-
-
-def _data(
- *,
- display_name: str = "My View",
- panel_type: str = "table",
- max_lines: int = 0,
- font_size: str = "",
- fmt: str = "",
- color: str = "",
- selected_fields: list | None = None,
- disabled: bool = False,
- legend: str = "",
-) -> dict:
- return {
- "schemaVersion": "v2",
- "spec": {
- "displayName": display_name,
- "panelType": panel_type,
- "queries": [_query(disabled=disabled, legend=legend)],
- "selectedFields": [] if selected_fields is None else selected_fields,
- "display": {"maxLines": max_lines, "fontSize": font_size, "format": fmt, "color": color},
- },
- }
-
-
-def _create_body(*, name: str = "my-view", generate_name: bool = False, display_name: str = "My View", source: str = "logs", **data_kwargs) -> dict:
- """name is the immutable slug. Pass generate_name=True (and leave name
- empty) to have the server generate one from display_name instead."""
- return {"name": name, "generateName": generate_name, "source": source, "data": _data(display_name=display_name, **data_kwargs)}
-
-
-def _update_body(*, display_name: str = "My View", source: str = "logs", **data_kwargs) -> dict:
- """Deliberately has no name field at all -- name is immutable and not
- part of the update payload."""
- return {"source": source, "data": _data(display_name=display_name, **data_kwargs)}
-
-
# ─── failure cases (create no saved views) ───────────────────────────────────
@@ -69,11 +20,23 @@ def test_create_rejects_wrong_schema_version(
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- body = _create_body()
- body["data"]["schemaVersion"] = "v9"
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=body,
+ json={
+ "name": "my-view",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v9",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
@@ -90,11 +53,23 @@ def test_create_rejects_invalid_panel_type(
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- body = _create_body()
- body["data"]["spec"]["panelType"] = "bogus"
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=body,
+ json={
+ "name": "my-view",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "bogus",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
@@ -110,11 +85,23 @@ def test_create_rejects_empty_queries(
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- body = _create_body()
- body["data"]["spec"]["queries"] = []
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=body,
+ json={
+ "name": "my-view",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "table",
+ "queries": [],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
@@ -134,11 +121,23 @@ def test_create_rejects_empty_display_name(
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- body = _create_body()
- body["data"]["spec"]["displayName"] = ""
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=body,
+ json={
+ "name": "my-view",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
@@ -155,11 +154,23 @@ def test_create_rejects_invalid_source(
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- body = _create_body()
- body["source"] = "bogus"
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=body,
+ json={
+ "name": "my-view",
+ "generateName": False,
+ "source": "bogus",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
@@ -175,10 +186,23 @@ def test_create_rejects_invalid_name(
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- body = _create_body(name="Not A Valid Slug")
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=body,
+ json={
+ "name": "Not A Valid Slug",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
@@ -196,10 +220,23 @@ def test_create_rejects_empty_name_without_generate_name(
generate one -- generateName has to be explicitly set."""
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- body = _create_body(name="")
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=body,
+ json={
+ "name": "",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
@@ -216,10 +253,25 @@ def test_create_rejects_name_when_generate_name_is_true(
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
- body = _create_body(name="explicit-name", generate_name=True)
+ # name is the immutable slug. Pass generateName=true (and leave name empty)
+ # to have the server generate one from displayName instead.
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=body,
+ json={
+ "name": "explicit-name",
+ "generateName": True,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
@@ -240,11 +292,24 @@ def test_create_rejects_unknown_field(
# that rewraps this as its own dashboard_invalid_input code), PostableSavedView
# relies solely on binding.WithDisallowUnknownFields, so this surfaces as the
# generic invalid_input code rather than saved_view_invalid_input.
- body = _create_body()
- body["unknownfield"] = "boom"
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=body,
+ json={
+ "name": "my-view",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ "unknownfield": "boom",
+ },
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
@@ -299,7 +364,19 @@ def test_update_missing_view_returns_not_found(
response = requests.put(
signoz.self.host_configs["8080"].get(f"{BASE_URL}/{uuid.uuid4()}"),
- json=_update_body(),
+ json={
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
@@ -321,7 +398,21 @@ def test_update_rejects_name_field(
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=_create_body(name="update-rejects-name-field"),
+ json={
+ "name": "update-rejects-name-field",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers=headers,
timeout=5,
)
@@ -329,11 +420,22 @@ def test_update_rejects_name_field(
view_id = response.json()["data"]["id"]
try:
- body = _update_body()
- body["name"] = "update-rejects-name-field"
response = requests.put(
signoz.self.host_configs["8080"].get(f"{BASE_URL}/{view_id}"),
- json=body,
+ json={
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My View",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ "name": "update-rejects-name-field",
+ },
headers=headers,
timeout=5,
)
@@ -379,7 +481,21 @@ def test_saved_view_lifecycle(
# ── create ────────────────────────────────────────────────────────────────
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=_create_body(name="lc-logs-overview", display_name="lc-logs-overview", source="logs"),
+ json={
+ "name": "lc-logs-overview",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "lc-logs-overview",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers=headers,
timeout=5,
)
@@ -388,7 +504,21 @@ def test_saved_view_lifecycle(
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=_create_body(name="lc-traces-overview", display_name="lc-traces-overview", source="traces"),
+ json={
+ "name": "lc-traces-overview",
+ "generateName": False,
+ "source": "traces",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "lc-traces-overview",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers=headers,
timeout=5,
)
@@ -432,7 +562,19 @@ def test_saved_view_lifecycle(
# since it isn't even part of the update payload ─────────────────
response = requests.put(
signoz.self.host_configs["8080"].get(f"{BASE_URL}/{view_id}"),
- json=_update_body(display_name="lc-logs-overview-renamed", source="metrics", panel_type="graph"),
+ json={
+ "source": "metrics",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "lc-logs-overview-renamed",
+ "panelType": "graph",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers=headers,
timeout=5,
)
@@ -475,7 +617,21 @@ def test_empty_name_derives_a_slug_from_display_name(
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=_create_body(name="", generate_name=True, display_name="My Generated View!"),
+ json={
+ "name": "",
+ "generateName": True,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "My Generated View!",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers=headers,
timeout=5,
)
@@ -521,17 +677,21 @@ def test_create_roundtrip_preserves_zero_values(
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=_create_body(
- name="create-zero-values",
- display_name="create-zero-values",
- max_lines=0,
- font_size="",
- fmt="",
- color="",
- selected_fields=[],
- disabled=False,
- legend="",
- ),
+ json={
+ "name": "create-zero-values",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "create-zero-values",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers=headers,
timeout=5,
)
@@ -575,11 +735,22 @@ def test_selected_fields_omitted_on_create_reads_back_as_empty_list_not_null(
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
headers = {"Authorization": f"Bearer {token}"}
- body = _create_body(name="omitted-selected-fields", display_name="omitted-selected-fields")
- del body["data"]["spec"]["selectedFields"]
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=body,
+ json={
+ "name": "omitted-selected-fields",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "omitted-selected-fields",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers=headers,
timeout=5,
)
@@ -618,17 +789,21 @@ def test_update_does_not_corrupt_zero_values(
# ── create with deliberately non-zero values everywhere ──────────────────
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
- json=_create_body(
- name="update-zero-values",
- display_name="update-zero-values",
- max_lines=25,
- font_size="large",
- fmt="table",
- color="blue",
- selected_fields=[{"name": "service.name"}],
- disabled=True,
- legend="Custom Legend",
- ),
+ json={
+ "name": "update-zero-values",
+ "generateName": False,
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "update-zero-values",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": True, "legend": "Custom Legend"}}],
+ "selectedFields": [{"name": "service.name"}],
+ "display": {"maxLines": 25, "fontSize": "large", "format": "table", "color": "blue"},
+ },
+ },
+ },
headers=headers,
timeout=5,
)
@@ -653,16 +828,19 @@ def test_update_does_not_corrupt_zero_values(
# ── update overwrites every one of those fields down to its zero value ──
response = requests.put(
signoz.self.host_configs["8080"].get(f"{BASE_URL}/{view_id}"),
- json=_update_body(
- display_name="update-zero-values",
- max_lines=0,
- font_size="",
- fmt="",
- color="",
- selected_fields=[],
- disabled=False,
- legend="",
- ),
+ json={
+ "source": "logs",
+ "data": {
+ "schemaVersion": "v2",
+ "spec": {
+ "displayName": "update-zero-values",
+ "panelType": "table",
+ "queries": [{"type": "builder_query", "spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}], "disabled": False, "legend": ""}}],
+ "selectedFields": [],
+ "display": {"maxLines": 0, "fontSize": "", "format": "", "color": ""},
+ },
+ },
+ },
headers=headers,
timeout=5,
)
diff --git a/tests/integration/tests/serviceaccount/01_crud.py b/tests/integration/tests/serviceaccount/01_crud.py
index 601c52c5ff..8c4edbb1aa 100644
--- a/tests/integration/tests/serviceaccount/01_crud.py
+++ b/tests/integration/tests/serviceaccount/01_crud.py
@@ -59,7 +59,6 @@ def test_create_service_account_missing_name(
create_user_admin: types.Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
):
- """Creating a service account with an empty name should be rejected."""
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
response = requests.post(
@@ -213,7 +212,6 @@ def test_delete_already_deleted_service_account(
create_user_admin: types.Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
):
- """Deleting an already-deleted service account should be handled gracefully."""
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
service_account_id = create_service_account(signoz, token, "sa-double-delete")
diff --git a/tests/integration/tests/thirdpartyapi/01_domain_list.py b/tests/integration/tests/thirdpartyapi/01_domain_list.py
index 38ee44baff..e3d38899a2 100644
--- a/tests/integration/tests/thirdpartyapi/01_domain_list.py
+++ b/tests/integration/tests/thirdpartyapi/01_domain_list.py
@@ -1,9 +1,3 @@
-"""Integration tests for the third-party (external) API monitoring domain list.
-
-A translator over v5 builder queries, so these cover the contract it exposes (columns,
-grouping, base filter, IP masking) plus the `max(timestamp)` Last Seen from #5824.
-"""
-
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
@@ -40,7 +34,7 @@ def test_domain_list_last_seen_is_the_span_instant(
Two client spans to api.stripe.com, 3 and 1 minutes ago.
Tests:
- Last Seen resolves to the newer span's instant. A numeric coercion of the
+ Last Seen resolves to the newer span's instant (#5824). A numeric coercion of the
DateTime64 column would yield seconds since epoch (~1.7e9), which lands in
January 1970 once read as milliseconds.
"""
diff --git a/tests/integration/tests/ttl/01_ttl.py b/tests/integration/tests/ttl/01_ttl.py
index ef5c69fc45..6cf3c0f9e2 100644
--- a/tests/integration/tests/ttl/01_ttl.py
+++ b/tests/integration/tests/ttl/01_ttl.py
@@ -1,11 +1,3 @@
-"""
-Summary:
-This test file contains integration tests for Time-To-Live (TTL) and custom retention policies
-in SigNoz's query service. It verifies the correct behavior of TTL settings for traces, metrics,
-and logs, including support for cold storage, custom retention conditions, error handling for
-invalid configurations, and retrieval of TTL settings.
-"""
-
import time
from collections.abc import Callable
from http import HTTPStatus
@@ -94,7 +86,6 @@ def test_set_ttl_traces_success(
get_token: Callable[[str, str], str],
remove_traces_ttl_and_storage_settings, # pylint: disable=unused-argument
):
- """Test setting TTL for traces with new ttlConfig structure."""
test_duration_hours = 3601 # 3601 hours
@@ -139,7 +130,6 @@ def test_set_ttl_traces_with_cold_storage(
get_token: Callable[[str, str], str],
remove_traces_ttl_and_storage_settings, # pylint: disable=unused-argument
):
- """Test setting TTL for traces with cold storage configuration."""
test_duration_hours = 91 * 24 # 91 days in hours
test_cold_duration_hours = 32 * 24 # 32 days in hours
@@ -200,7 +190,6 @@ def test_set_ttl_metrics_success(
get_token: Callable[[str, str], str],
remove_metrics_ttl_and_storage_settings, # pylint: disable=unused-argument
):
- """Test setting TTL for metrics using the new setTTLMetrics method."""
test_duration_hours = 92 * 24 # 92 days in hours
@@ -249,7 +238,6 @@ def test_set_ttl_metrics_with_cold_storage(
get_token: Callable[[str, str], str],
remove_metrics_ttl_and_storage_settings, # pylint: disable=unused-argument
):
- """Test setting TTL for metrics with cold storage configuration."""
test_duration_hours = 91 * 24 # 91 days in hours
test_cold_duration_hours = 21 * 24 # 21 days in hours
@@ -314,7 +302,6 @@ def test_set_ttl_metrics_with_cold_storage(
def test_set_ttl_invalid_type(signoz: types.SigNoz, get_token: Callable[[str, str], str]):
- """Test setting TTL with invalid type returns error."""
payload = {
"type": "invalid_type",
"duration": f"{90 * 24}h",
@@ -340,7 +327,6 @@ def test_set_custom_retention_ttl_basic(
insert_logs,
remove_logs_ttl_settings, # pylint: disable=unused-argument
):
- """Test setting custom retention TTL with basic configuration."""
test_retention_days = 103 # 103 days
@@ -399,7 +385,6 @@ def test_set_custom_retention_ttl_basic_with_cold_storage(
insert_logs,
remove_logs_ttl_settings, # pylint: disable=unused-argument
):
- """Test setting custom retention TTL with basic configuration."""
test_retention_days = 104 # 104 days
test_retention_days_cold = 27 # 27 days
@@ -466,7 +451,6 @@ def test_set_custom_retention_ttl_basic_fallback(
ttl_legacy_logs_v2_table_setup, # pylint: disable=unused-argument
ttl_legacy_logs_v2_resource_table_setup, # pylint: disable=unused-argument,
):
- """Test setting TTL for logs using the new setTTLLogs method."""
test_retention_days = 101 # 101 days
test_retention_days_cold = 17 # 17 days
@@ -569,7 +553,6 @@ def test_set_custom_retention_ttl_with_conditions(
insert_logs,
remove_logs_ttl_settings, # pylint: disable=unused-argument
):
- """Test setting custom retention TTL with filter conditions."""
test_retention_days = 30 # 30 days
test_retention_days_condition = 60 # 60 days
@@ -677,7 +660,6 @@ def test_set_custom_retention_ttl_with_invalid_cold_storage(
insert_logs,
remove_logs_ttl_settings, # pylint: disable=unused-argument
):
- """Test setting custom retention TTL with cold storage configuration."""
payload = {
"type": "logs",
"defaultTTLDays": 60,
@@ -714,7 +696,6 @@ def test_set_custom_retention_ttl_with_invalid_cold_storage(
def test_set_custom_retention_ttl_duplicate_conditions(signoz: types.SigNoz, get_token: Callable[[str, str], str]):
- """Test that duplicate TTL conditions are rejected."""
payload = {
"type": "logs",
"defaultTTLDays": 30,
@@ -784,7 +765,6 @@ def test_set_custom_retention_ttl_invalid_condition(signoz: types.SigNoz, get_to
def test_get_custom_retention_ttl(signoz: types.SigNoz, get_token: Callable[[str, str], str], insert_logs):
- """Test getting custom retention TTL configuration."""
# First set a custom retention TTL
set_payload = {
"type": "logs",
@@ -844,7 +824,6 @@ def test_set_ttl_logs_success(
ttl_legacy_logs_v2_table_setup, # pylint: disable=unused-argument
ttl_legacy_logs_v2_resource_table_setup, # pylint: disable=unused-argument
):
- """Test setting TTL for logs using the new setTTLLogs method."""
test_retention_days = 150 # 150 days
payload = {
@@ -881,7 +860,6 @@ def test_set_ttl_logs_success(
def test_get_ttl_traces_success(signoz: types.SigNoz, get_token: Callable[[str, str], str]):
- """Test getting TTL for traces."""
# First set a TTL configuration for traces
test_retention_days = 33 # 33 days
@@ -929,7 +907,6 @@ def test_large_ttl_conditions_list(
insert_logs,
remove_logs_ttl_settings, # pylint: disable=unused-argument
):
- """Test custom retention TTL with many conditions."""
# Create a list of many TTL conditions to test performance and limits
conditions = []
for i in range(10): # Test with 10 conditions
diff --git a/tests/seeder/server.py b/tests/seeder/server.py
index 20bab38771..36367ed1fe 100644
--- a/tests/seeder/server.py
+++ b/tests/seeder/server.py
@@ -1,13 +1,3 @@
-"""HTTP seeder — single entrypoint for e2e/integration telemetry.
-
-POST /telemetry/{metrics,logs,traces} insert into ClickHouse via
-fixtures.{metrics,logs,traces}. DELETE truncates the signal tables.
-
-Parallel-safe: every seeded row is tagged `seeder=true`. Tests share
-the seeded baseline; per-test mutations live in their own dashboards.
-Only test_teardown should call DELETE — workers must finish first.
-"""
-
import os
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
@@ -37,6 +27,8 @@ CH_USER = os.environ["CH_USER"]
CH_PASSWORD = os.environ["CH_PASSWORD"]
CH_CLUSTER = os.environ["CH_CLUSTER"]
+# Every seeded row carries this tag so parallel tests can share the seeded
+# baseline; per-test mutations live in their own dashboards.
SEEDER_MARKER = {"seeder": "true"}
@@ -96,6 +88,8 @@ def post_traces(payload: list[dict[str, Any]]) -> dict[str, Any]:
raise HTTPException(status_code=500, detail=str(e)) from e
+# The DELETE endpoints truncate the signal tables. Only test_teardown should
+# call them — workers must finish first.
@app.delete("/telemetry/traces", status_code=status.HTTP_204_NO_CONTENT)
def delete_traces() -> Response:
try: