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.

test(integration): alerts e2e test cases with basic rule manager alerts (#10163)

Abhishek Kumar Singh4bbe5ead07c3
diff --git a/tests/integration/fixtures/alertutils.py b/tests/integration/fixtures/alertutils.py
index 747afff4af..b1c97663d9 100644
--- a/tests/integration/fixtures/alertutils.py
+++ b/tests/integration/fixtures/alertutils.py
@@ -112,7 +112,7 @@ def verify_webhook_alert_expectation(
break
# wait for some time before checking again
- time.sleep(10)
+ time.sleep(1)
# We've waited but we didn't get the expected number of alerts
@@ -133,3 +133,15 @@ def verify_webhook_alert_expectation(
)
return True # should not reach here
+
+
+def update_rule_channel_name(rule_data: dict, channel_name: str):
+ """
+ updates the channel name in the thresholds
+ so alert notification are sent to the given channel
+ """
+ thresholds = rule_data["condition"]["thresholds"]
+ if "kind" in thresholds and thresholds["kind"] == "basic":
+ # loop over all the sepcs and update the channels
+ for spec in thresholds["spec"]:
+ spec["channels"] = [channel_name]
diff --git a/tests/integration/fixtures/cloudintegrations.py b/tests/integration/fixtures/cloudintegrations.py
index 14b49fbe24..9514890699 100644
--- a/tests/integration/fixtures/cloudintegrations.py
+++ b/tests/integration/fixtures/cloudintegrations.py
@@ -1,16 +1,18 @@
"""Fixtures for cloud integration tests."""
-from typing import Callable, Optional
+
from http import HTTPStatus
+from typing import Callable, Optional
import pytest
import requests
from fixtures import types
-from fixtures.logger import setup_logger
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
+from fixtures.logger import setup_logger
logger = setup_logger(__name__)
+
@pytest.fixture(scope="function")
def create_cloud_integration_account(
request: pytest.FixtureRequest,
@@ -24,9 +26,7 @@ def create_cloud_integration_account(
cloud_provider: str = "aws",
) -> dict:
nonlocal created_account_id, cloud_provider_used
- endpoint = (
- f"/api/v1/cloud-integrations/{cloud_provider}/accounts/generate-connection-url"
- )
+ endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/accounts/generate-connection-url"
request_payload = {
"account_config": {"regions": ["us-east-1"]},
@@ -59,9 +59,7 @@ def create_cloud_integration_account(
def _disconnect(admin_token: str, cloud_provider: str) -> requests.Response:
assert created_account_id
- disconnect_endpoint = (
- f"/api/v1/cloud-integrations/{cloud_provider}/accounts/{created_account_id}/disconnect"
- )
+ disconnect_endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/accounts/{created_account_id}/disconnect"
return requests.post(
signoz.self.host_configs["8080"].get(disconnect_endpoint),
headers={"Authorization": f"Bearer {admin_token}"},
diff --git a/tests/integration/fixtures/cloudintegrationsutils.py b/tests/integration/fixtures/cloudintegrationsutils.py
index 599ece3108..8b52897244 100644
--- a/tests/integration/fixtures/cloudintegrationsutils.py
+++ b/tests/integration/fixtures/cloudintegrationsutils.py
@@ -1,4 +1,5 @@
"""Fixtures for cloud integration tests."""
+
from http import HTTPStatus
import requests
diff --git a/tests/integration/fixtures/metrics.py b/tests/integration/fixtures/metrics.py
index 7973dabe75..a0d4b402fe 100644
--- a/tests/integration/fixtures/metrics.py
+++ b/tests/integration/fixtures/metrics.py
@@ -43,6 +43,10 @@ class MetricsTimeSeries(ABC):
resource_attrs: dict[str, str] = {},
scope_attrs: dict[str, str] = {},
) -> None:
+ # Create a copy of labels to avoid mutating the caller's dictionary
+ labels = dict(labels)
+ # Add metric_name to the labels to support promql queries
+ labels["__name__"] = metric_name
self.env = env
self.metric_name = metric_name
self.temporality = temporality
diff --git a/tests/integration/fixtures/signoz.py b/tests/integration/fixtures/signoz.py
index be3b0662af..bec1117093 100644
--- a/tests/integration/fixtures/signoz.py
+++ b/tests/integration/fixtures/signoz.py
@@ -69,6 +69,10 @@ def signoz( # pylint: disable=too-many-arguments,too-many-positional-arguments
"SIGNOZ_GLOBAL_INGESTION__URL": "https://ingest.test.signoz.cloud",
"SIGNOZ_USER_PASSWORD_RESET_ALLOW__SELF": True,
"SIGNOZ_USER_PASSWORD_RESET_MAX__TOKEN__LIFETIME": "6h",
+ "RULES_EVAL_DELAY": "0s",
+ "SIGNOZ_ALERTMANAGER_SIGNOZ_POLL__INTERVAL": "5s",
+ "SIGNOZ_ALERTMANAGER_SIGNOZ_ROUTE_GROUP__WAIT": "1s",
+ "SIGNOZ_ALERTMANAGER_SIGNOZ_ROUTE_GROUP__INTERVAL": "5s",
}
| sqlstore.env
| clickhouse.env
diff --git a/tests/integration/fixtures/types.py b/tests/integration/fixtures/types.py
index d7d399f836..d9e8fd980a 100644
--- a/tests/integration/fixtures/types.py
+++ b/tests/integration/fixtures/types.py
@@ -191,3 +191,15 @@ class AlertExpectation:
# seconds to wait for the alerts to be fired, if no
# alerts are fired in the expected time, the test will fail
wait_time_seconds: int
+
+
+@dataclass(frozen=True)
+class AlertTestCase:
+ # name of the test case
+ name: str
+ # path to the rule file in testdata directory
+ rule_path: str
+ # list of alert data that will be inserted into the database
+ alert_data: List[AlertData]
+ # list of alert expectations for the test case
+ alert_expectation: AlertExpectation
diff --git a/tests/integration/src/alerts/01_notification_channel.py b/tests/integration/src/alerts/01_notification_channel.py
index b5d48245ad..e7d5f93ddc 100644
--- a/tests/integration/src/alerts/01_notification_channel.py
+++ b/tests/integration/src/alerts/01_notification_channel.py
@@ -8,6 +8,9 @@ from wiremock.client import HttpMethods, Mapping, MappingRequest, MappingRespons
from fixtures import types
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
+from fixtures.logger import setup_logger
+
+logger = setup_logger(__name__)
def test_webhook_notification_channel(
@@ -20,6 +23,7 @@ def test_webhook_notification_channel(
"""
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
notification_channel_name = f"notification-channel-{uuid.uuid4()}"
@@ -55,10 +59,10 @@ def test_webhook_notification_channel(
)
# TODO: @abhishekhugetech # pylint: disable=W0511
- # Time required for Org to be registered
- # in the alertmanager, default 1m.
+ # Time required for newly created Org to be registered in the alertmanager is 5 seconds in signoz.py
# this will be fixed after [https://github.com/SigNoz/engineering-pod/issues/3800]
- time.sleep(65)
+ # 10 seconds safe time for org to be registered in the alertmanager
+ time.sleep(10)
# Call test API for the notification channel
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
diff --git a/tests/integration/src/alerts/02_basic_alert_conditions.py b/tests/integration/src/alerts/02_basic_alert_conditions.py
new file mode 100644
index 0000000000..ad4f767ab1
--- /dev/null
+++ b/tests/integration/src/alerts/02_basic_alert_conditions.py
@@ -0,0 +1,671 @@
+import json
+import uuid
+from datetime import datetime, timedelta, timezone
+from typing import Callable, List
+
+import pytest
+from wiremock.client import HttpMethods, Mapping, MappingRequest, MappingResponse
+
+from fixtures import types
+from fixtures.alertutils import (
+ update_rule_channel_name,
+ verify_webhook_alert_expectation,
+)
+from fixtures.logger import setup_logger
+from fixtures.utils import get_testdata_file_path
+
+# test cases for match type and compare operators have wait time of 30 seconds to verify the alert expectation.
+# we've poistioned the alert data to fire the alert on first eval of rule manager, the eval frequency
+# for most alert rules are set of 15s so considering this delay plus some delay from alert manager's
+# group_wait and group_interval, even in worst case most alerts should be triggered in about 30 seconds
+TEST_RULES_MATCH_TYPE_AND_COMPARE_OPERATORS = [
+ types.AlertTestCase(
+ name="test_threshold_above_at_least_once",
+ rule_path="alerts/test_scenarios/threshold_above_at_least_once/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_above_at_least_once/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_above_at_least_once",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_above_all_the_time",
+ rule_path="alerts/test_scenarios/threshold_above_all_the_time/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_above_all_the_time/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_above_all_the_time",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_above_in_total",
+ rule_path="alerts/test_scenarios/threshold_above_in_total/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_above_in_total/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_above_in_total",
+ "threshold.name": "critical",
+ "service": "server",
+ },
+ ),
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_above_in_total",
+ "threshold.name": "critical",
+ "service": "api",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_above_average",
+ rule_path="alerts/test_scenarios/threshold_above_average/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="traces",
+ data_path="alerts/test_scenarios/threshold_above_average/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_above_average",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ # TODO: @abhishekhugetech enable the test for matchType last, pylint: disable=W0511
+ # after the [issue](https://github.com/SigNoz/engineering-pod/issues/3801) with matchType last is fixed
+ # types.AlertTestCase(
+ # name="test_threshold_above_last",
+ # rule_path="alerts/test_scenarios/threshold_above_last/rule.json",
+ # alert_data=[
+ # types.AlertData(
+ # type="metrics",
+ # data_path="alerts/test_scenarios/threshold_above_last/alert_data.jsonl",
+ # ),
+ # ],
+ # alert_expectation=types.AlertExpectation(
+ # should_alert=True,
+ # wait_time_seconds=30,
+ # expected_alerts=[
+ # types.FiringAlert(
+ # labels={
+ # "alertname": "threshold_above_last",
+ # "threshold.name": "critical",
+ # }
+ # ),
+ # ],
+ # ),
+ # ),
+ types.AlertTestCase(
+ name="test_threshold_below_at_least_once",
+ rule_path="alerts/test_scenarios/threshold_below_at_least_once/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="logs",
+ data_path="alerts/test_scenarios/threshold_below_at_least_once/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_below_at_least_once",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_below_all_the_time",
+ rule_path="alerts/test_scenarios/threshold_below_all_the_time/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="logs",
+ data_path="alerts/test_scenarios/threshold_below_all_the_time/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_below_all_the_time",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_below_in_total",
+ rule_path="alerts/test_scenarios/threshold_below_in_total/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_below_in_total/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_below_in_total",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_below_average",
+ rule_path="alerts/test_scenarios/threshold_below_average/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_below_average/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_below_average",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ # TODO: @abhishekhugetech enable the test for matchType last,
+ # after the [issue](https://github.com/SigNoz/engineering-pod/issues/3801) with matchType last is fixed, pylint: disable=W0511
+ # types.AlertTestCase(
+ # name="test_threshold_below_last",
+ # rule_path="alerts/test_scenarios/threshold_below_last/rule.json",
+ # alert_data=[
+ # types.AlertData(
+ # type="metrics",
+ # data_path="alerts/test_scenarios/threshold_below_last/alert_data.jsonl",
+ # ),
+ # ],
+ # alert_expectation=types.AlertExpectation(
+ # should_alert=True,
+ # wait_time_seconds=30,
+ # expected_alerts=[
+ # types.FiringAlert(
+ # labels={
+ # "alertname": "threshold_below_last",
+ # "threshold.name": "critical",
+ # }
+ # ),
+ # ],
+ # ),
+ # ),
+ types.AlertTestCase(
+ name="test_threshold_equal_to_at_least_once",
+ rule_path="alerts/test_scenarios/threshold_equal_to_at_least_once/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_equal_to_at_least_once/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_equal_to_at_least_once",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_equal_to_all_the_time",
+ rule_path="alerts/test_scenarios/threshold_equal_to_all_the_time/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_equal_to_all_the_time/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_equal_to_all_the_time",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_equal_to_in_total",
+ rule_path="alerts/test_scenarios/threshold_equal_to_in_total/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_equal_to_in_total/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_equal_to_in_total",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_equal_to_average",
+ rule_path="alerts/test_scenarios/threshold_equal_to_average/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_equal_to_average/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_equal_to_average",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ # TODO: @abhishekhugetech enable the test for matchType last,
+ # after the [issue](https://github.com/SigNoz/engineering-pod/issues/3801) with matchType last is fixed, pylint: disable=W0511
+ # types.AlertTestCase(
+ # name="test_threshold_equal_to_last",
+ # rule_path="alerts/test_scenarios/threshold_equal_to_last/rule.json",
+ # alert_data=[
+ # types.AlertData(
+ # type="metrics",
+ # data_path="alerts/test_scenarios/threshold_equal_to_last/alert_data.jsonl",
+ # ),
+ # ],
+ # alert_expectation=types.AlertExpectation(
+ # should_alert=True,
+ # wait_time_seconds=30,
+ # expected_alerts=[
+ # types.FiringAlert(
+ # labels={
+ # "alertname": "threshold_equal_to_last",
+ # "threshold.name": "critical",
+ # }
+ # ),
+ # ],
+ # ),
+ # ),
+ types.AlertTestCase(
+ name="test_threshold_not_equal_to_at_least_once",
+ rule_path="alerts/test_scenarios/threshold_not_equal_to_at_least_once/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_not_equal_to_at_least_once/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_not_equal_to_at_least_once",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_not_equal_to_all_the_time",
+ rule_path="alerts/test_scenarios/threshold_not_equal_to_all_the_time/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_not_equal_to_all_the_time/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_not_equal_to_all_the_time",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_not_equal_to_in_total",
+ rule_path="alerts/test_scenarios/threshold_not_equal_to_in_total/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_not_equal_to_in_total/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_not_equal_to_in_total",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_threshold_not_equal_to_average",
+ rule_path="alerts/test_scenarios/threshold_not_equal_to_average/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/threshold_not_equal_to_average/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "threshold_not_equal_to_average",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ # TODO: @abhishekhugetech enable the test for matchType last,
+ # after the [issue](https://github.com/SigNoz/engineering-pod/issues/3801) with matchType last is fixed, pylint: disable=W0511
+ # types.AlertTestCase(
+ # name="test_threshold_not_equal_to_last",
+ # rule_path="alerts/test_scenarios/threshold_not_equal_to_last/rule.json",
+ # alert_data=[
+ # types.AlertData(
+ # type="metrics",
+ # data_path="alerts/test_scenarios/threshold_not_equal_to_last/alert_data.jsonl",
+ # ),
+ # ],
+ # alert_expectation=types.AlertExpectation(
+ # should_alert=True,
+ # wait_time_seconds=30,
+ # expected_alerts=[
+ # types.FiringAlert(
+ # labels={
+ # "alertname": "threshold_not_equal_to_last",
+ # "threshold.name": "critical",
+ # }
+ # ),
+ # ],
+ # ),
+ # ),
+]
+
+# test cases unit conversion
+TEST_RULES_UNIT_CONVERSION = [
+ types.AlertTestCase(
+ name="test_unit_conversion_bytes_to_mb",
+ rule_path="alerts/test_scenarios/unit_conversion_bytes_to_mb/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/unit_conversion_bytes_to_mb/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "unit_conversion_bytes_to_mb",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+ types.AlertTestCase(
+ name="test_unit_conversion_ms_to_second",
+ rule_path="alerts/test_scenarios/unit_conversion_ms_to_second/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/unit_conversion_ms_to_second/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "unit_conversion_ms_to_second",
+ "threshold.name": "critical",
+ }
+ ),
+ ],
+ ),
+ ),
+]
+
+# test cases miscellaneous cases, no data and multi threshold
+TEST_RULES_MISCELLANEOUS = [
+ types.AlertTestCase(
+ name="test_no_data_rule_test",
+ rule_path="alerts/test_scenarios/no_data_rule_test/rule.json",
+ alert_data=[
+ types.AlertData(
+ type="metrics",
+ data_path="alerts/test_scenarios/no_data_rule_test/alert_data.jsonl",
+ ),
+ ],
+ alert_expectation=types.AlertExpectation(
+ should_alert=True,
+ wait_time_seconds=30,
+ expected_alerts=[
+ types.FiringAlert(
+ labels={
+ "alertname": "[No data] no_data_rule_test",
+ "nodata": "true",
+ }
+ ),
+ ],
+ ),
+ ),
+ # TODO: @abhishekhugetech enable the test for multi threshold rule, pylint: disable=W0511
+ # after the [issue](https://github.com/SigNoz/engineering-pod/issues/3934) with alertManager is resolved
+ # types.AlertTestCase(
+ # name="test_multi_threshold_rule_test",
+ # rule_path="alerts/test_scenarios/multi_threshold_rule_test/rule.json",
+ # alert_data=[
+ # types.AlertData(
+ # type="metrics",
+ # data_path="alerts/test_scenarios/multi_threshold_rule_test/alert_data.jsonl",
+ # ),
+ # ],
+ # alert_expectation=types.AlertExpectation(
+ # should_alert=True,
+ # # the second alert will be fired with some delay from alert manager's group_interval
+ # # so taking this in consideration, the wait time is 90 seconds (30s + 30s for next alert + 30s buffer)
+ # wait_time_seconds=90,
+ # expected_alerts=[
+ # types.FiringAlert(
+ # labels={
+ # "alertname": "multi_threshold_rule_test",
+ # "threshold.name": "info",
+ # }
+ # ),
+ # types.FiringAlert(
+ # labels={
+ # "alertname": "multi_threshold_rule_test",
+ # "threshold.name": "warning",
+ # }
+ # ),
+ # ],
+ # ),
+ # ),
+]
+
+
+logger = setup_logger(__name__)
+
+
+ "alert_test_case",
+ TEST_RULES_MATCH_TYPE_AND_COMPARE_OPERATORS
+ + TEST_RULES_UNIT_CONVERSION
+ + TEST_RULES_MISCELLANEOUS,
+ ids=lambda alert_test_case: alert_test_case.name,
+)
+def test_basic_alert_rule_conditions(
+ # Notification channel related fixtures
+ notification_channel: types.TestContainerDocker,
+ make_http_mocks: Callable[[types.TestContainerDocker, List[Mapping]], None],
+ create_webhook_notification_channel: Callable[[str, str, dict, bool], str],
+ # Alert rule related fixtures
+ create_alert_rule: Callable[[dict], str],
+ # Alert data insertion related fixtures
+ insert_alert_data: Callable[[List[types.AlertData], datetime], None],
+ alert_test_case: types.AlertTestCase,
+):
+ # Prepare notification channel name and webhook endpoint
+ notification_channel_name = str(uuid.uuid4())
+ webhook_endpoint_path = f"/alert/{notification_channel_name}"
+ notification_url = notification_channel.container_configs["8080"].get(
+ webhook_endpoint_path
+ )
+
+ logger.info("notification_url: %s", {"notification_url": notification_url})
+
+ # register the mock endpoint in notification channel
+ make_http_mocks(
+ notification_channel,
+ [
+ Mapping(
+ request=MappingRequest(
+ method=HttpMethods.POST,
+ url=webhook_endpoint_path,
+ ),
+ response=MappingResponse(
+ status=200,
+ json_body={},
+ ),
+ persistent=False,
+ )
+ ],
+ )
+
+ # Create an alert channel using the given route
+ create_webhook_notification_channel(
+ channel_name=notification_channel_name,
+ webhook_url=notification_url,
+ http_config={},
+ send_resolved=False,
+ )
+
+ logger.info(
+ "alert channel created with name: %s",
+ {"notification_channel_name": notification_channel_name},
+ )
+
+ # Insert alert data
+ insert_alert_data(
+ alert_test_case.alert_data,
+ base_time=datetime.now(tz=timezone.utc) - timedelta(minutes=5),
+ )
+
+ # Create Alert Rule
+ rule_path = get_testdata_file_path(alert_test_case.rule_path)
+ with open(rule_path, "r", encoding="utf-8") as f:
+ rule_data = json.loads(f.read())
+ # Update the channel name in the rule data
+ update_rule_channel_name(rule_data, notification_channel_name)
+ rule_id = create_alert_rule(rule_data)
+ logger.info(
+ "rule created with id: %s",
+ {"rule_id": rule_id, "rule_name": rule_data["alert"]},
+ )
+
+ # Verify alert expectation
+ verify_webhook_alert_expectation(
+ notification_channel,
+ notification_channel_name,
+ alert_test_case.alert_expectation,
+ )
diff --git a/tests/integration/src/cloudintegrations/02_generate_connection_url.py b/tests/integration/src/cloudintegrations/02_generate_connection_url.py
index 1a25f1a01e..2471018649 100644
--- a/tests/integration/src/cloudintegrations/02_generate_connection_url.py
+++ b/tests/integration/src/cloudintegrations/02_generate_connection_url.py
@@ -1,7 +1,6 @@
from http import HTTPStatus
from typing import Callable
-import pytest
import requests
from fixtures import types
@@ -21,7 +20,9 @@ def test_generate_connection_url(
# Get authentication token for admin user
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
cloud_provider = "aws"
- endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/accounts/generate-connection-url"
+ endpoint = (
+ f"/api/v1/cloud-integrations/{cloud_provider}/accounts/generate-connection-url"
+ )
# Prepare request payload
request_payload = {
@@ -65,9 +66,7 @@ def test_generate_connection_url(
data = response_data["data"]
# Assert account_id is a valid UUID format
- assert (
- len(data["account_id"]) > 0
- ), "account_id should be a non-empty string (UUID)"
+ assert len(data["account_id"]) > 0, "account_id should be a non-empty string (UUID)"
# Assert connection_url contains expected CloudFormation parameters
connection_url = data["connection_url"]
@@ -111,7 +110,9 @@ def test_generate_connection_url_unsupported_provider(
# Try with GCP (unsupported)
cloud_provider = "gcp"
- endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/accounts/generate-connection-url"
+ endpoint = (
+ f"/api/v1/cloud-integrations/{cloud_provider}/accounts/generate-connection-url"
+ )
request_payload = {
"account_config": {"regions": ["us-central1"]},
diff --git a/tests/integration/src/cloudintegrations/03_accounts.py b/tests/integration/src/cloudintegrations/03_accounts.py
index 0838bf7ad9..f33cb2f006 100644
--- a/tests/integration/src/cloudintegrations/03_accounts.py
+++ b/tests/integration/src/cloudintegrations/03_accounts.py
@@ -1,17 +1,13 @@
+import uuid
from http import HTTPStatus
from typing import Callable
-import uuid
-import pytest
import requests
from fixtures import types
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
-from fixtures.logger import setup_logger
-from fixtures.cloudintegrations import (
- create_cloud_integration_account,
-)
from fixtures.cloudintegrationsutils import simulate_agent_checkin
+from fixtures.logger import setup_logger
logger = setup_logger(__name__)
@@ -40,8 +36,9 @@ def test_list_connected_accounts_empty(
data = response_data.get("data", response_data)
assert "accounts" in data, "Response should contain 'accounts' field"
assert isinstance(data["accounts"], list), "Accounts should be a list"
- assert len(data["accounts"]) == 0, "Accounts list should be empty when no accounts are connected"
-
+ assert (
+ len(data["accounts"]) == 0
+ ), "Accounts list should be empty when no accounts are connected"
def test_list_connected_accounts_with_account(
@@ -60,7 +57,9 @@ def test_list_connected_accounts_with_account(
# Simulate agent check-in to mark as connected
cloud_account_id = str(uuid.uuid4())
- simulate_agent_checkin(signoz, admin_token, cloud_provider, account_id, cloud_account_id)
+ simulate_agent_checkin(
+ signoz, admin_token, cloud_provider, account_id, cloud_account_id
+ )
# List accounts
endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/accounts"
@@ -87,7 +86,6 @@ def test_list_connected_accounts_with_account(
assert "status" in account, "Account should have status field"
-
def test_get_account_status(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -163,16 +161,16 @@ def test_update_account_config(
# Simulate agent check-in to mark as connected
cloud_account_id = str(uuid.uuid4())
- simulate_agent_checkin(signoz, admin_token, cloud_provider, account_id, cloud_account_id)
+ simulate_agent_checkin(
+ signoz, admin_token, cloud_provider, account_id, cloud_account_id
+ )
# Update account configuration
endpoint = (
f"/api/v1/cloud-integrations/{cloud_provider}/accounts/{account_id}/config"
)
- updated_config = {
- "config": {"regions": ["us-east-1", "us-west-2", "eu-west-1"]}
- }
+ updated_config = {"config": {"regions": ["us-east-1", "us-west-2", "eu-west-1"]}}
response = requests.post(
signoz.self.host_configs["8080"].get(endpoint),
@@ -198,7 +196,6 @@ def test_update_account_config(
timeout=10,
)
-
list_response_data = list_response.json()
list_data = list_response_data.get("data", list_response_data)
account = next((a for a in list_data["accounts"] if a["id"] == account_id), None)
@@ -213,7 +210,6 @@ def test_update_account_config(
}, "Regions should match updated config"
-
def test_disconnect_account(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -230,7 +226,9 @@ def test_disconnect_account(
# Simulate agent check-in to mark as connected
cloud_account_id = str(uuid.uuid4())
- simulate_agent_checkin(signoz, admin_token, cloud_provider, account_id, cloud_account_id)
+ simulate_agent_checkin(
+ signoz, admin_token, cloud_provider, account_id, cloud_account_id
+ )
# Disconnect the account
endpoint = (
@@ -262,8 +260,9 @@ def test_disconnect_account(
disconnected_account = next(
(a for a in list_data["accounts"] if a["id"] == account_id), None
)
- assert disconnected_account is None, f"Account {account_id} should be removed from connected accounts"
-
+ assert (
+ disconnected_account is None
+ ), f"Account {account_id} should be removed from connected accounts"
def test_disconnect_account_not_found(
@@ -277,9 +276,7 @@ def test_disconnect_account_not_found(
cloud_provider = "aws"
fake_account_id = "00000000-0000-0000-0000-000000000000"
- endpoint = (
- f"/api/v1/cloud-integrations/{cloud_provider}/accounts/{fake_account_id}/disconnect"
- )
+ endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/accounts/{fake_account_id}/disconnect"
response = requests.post(
signoz.self.host_configs["8080"].get(endpoint),
@@ -292,7 +289,6 @@ def test_disconnect_account_not_found(
), f"Expected 404, got {response.status_code}"
-
def test_list_accounts_unsupported_provider(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
diff --git a/tests/integration/src/cloudintegrations/04_services.py b/tests/integration/src/cloudintegrations/04_services.py
index 975ebed33d..2fe8810132 100644
--- a/tests/integration/src/cloudintegrations/04_services.py
+++ b/tests/integration/src/cloudintegrations/04_services.py
@@ -1,17 +1,13 @@
+import uuid
from http import HTTPStatus
from typing import Callable
-import uuid
-import pytest
import requests
from fixtures import types
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
-from fixtures.logger import setup_logger
-from fixtures.cloudintegrations import (
- create_cloud_integration_account,
-)
from fixtures.cloudintegrationsutils import simulate_agent_checkin
+from fixtures.logger import setup_logger
logger = setup_logger(__name__)
@@ -50,7 +46,6 @@ def test_list_services_without_account(
assert "icon" in service, "Service should have 'icon' field"
-
def test_list_services_with_account(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -66,7 +61,9 @@ def test_list_services_with_account(
account_id = account_data["account_id"]
cloud_account_id = str(uuid.uuid4())
- simulate_agent_checkin(signoz, admin_token, cloud_provider, account_id, cloud_account_id)
+ simulate_agent_checkin(
+ signoz, admin_token, cloud_provider, account_id, cloud_account_id
+ )
# List services for the account
endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/services?cloud_account_id={cloud_account_id}"
@@ -94,7 +91,6 @@ def test_list_services_with_account(
assert "icon" in service, "Service should have 'icon' field"
-
def test_get_service_details_without_account(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -141,7 +137,6 @@ def test_get_service_details_without_account(
assert isinstance(data["assets"], dict), "Assets should be a dictionary"
-
def test_get_service_details_with_account(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -157,7 +152,9 @@ def test_get_service_details_with_account(
account_id = account_data["account_id"]
cloud_account_id = str(uuid.uuid4())
- simulate_agent_checkin(signoz, admin_token, cloud_provider, account_id, cloud_account_id)
+ simulate_agent_checkin(
+ signoz, admin_token, cloud_provider, account_id, cloud_account_id
+ )
# Get list of services first
list_endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/services"
@@ -196,7 +193,6 @@ def test_get_service_details_with_account(
assert "status" in data, "Config should have 'status' field"
-
def test_get_service_details_invalid_service(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -220,7 +216,6 @@ def test_get_service_details_invalid_service(
), f"Expected 404, got {response.status_code}"
-
def test_list_services_unsupported_provider(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -243,7 +238,6 @@ def test_list_services_unsupported_provider(
), f"Expected 400, got {response.status_code}"
-
def test_update_service_config(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -259,7 +253,9 @@ def test_update_service_config(
account_id = account_data["account_id"]
cloud_account_id = str(uuid.uuid4())
- simulate_agent_checkin(signoz, admin_token, cloud_provider, account_id, cloud_account_id)
+ simulate_agent_checkin(
+ signoz, admin_token, cloud_provider, account_id, cloud_account_id
+ )
# Get list of services to pick a valid service ID
list_endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/services"
@@ -274,7 +270,9 @@ def test_update_service_config(
service_id = list_data["services"][0]["id"]
# Update service configuration
- endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/services/{service_id}/config"
+ endpoint = (
+ f"/api/v1/cloud-integrations/{cloud_provider}/services/{service_id}/config"
+ )
config_payload = {
"cloud_account_id": cloud_account_id,
@@ -306,7 +304,6 @@ def test_update_service_config(
assert "logs" in data["config"], "Config should contain 'logs' field"
-
def test_update_service_config_without_account(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -329,7 +326,9 @@ def test_update_service_config_without_account(
service_id = list_data["services"][0]["id"]
# Try to update config with non-existent account
- endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/services/{service_id}/config"
+ endpoint = (
+ f"/api/v1/cloud-integrations/{cloud_provider}/services/{service_id}/config"
+ )
fake_cloud_account_id = str(uuid.uuid4())
config_payload = {
@@ -351,7 +350,6 @@ def test_update_service_config_without_account(
), f"Expected 500 for non-existent account, got {response.status_code}"
-
def test_update_service_config_invalid_service(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -367,11 +365,15 @@ def test_update_service_config_invalid_service(
account_id = account_data["account_id"]
cloud_account_id = str(uuid.uuid4())
- simulate_agent_checkin(signoz, admin_token, cloud_provider, account_id, cloud_account_id)
+ simulate_agent_checkin(
+ signoz, admin_token, cloud_provider, account_id, cloud_account_id
+ )
# Try to update config for invalid service
fake_service_id = "non-existent-service"
- endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/services/{fake_service_id}/config"
+ endpoint = (
+ f"/api/v1/cloud-integrations/{cloud_provider}/services/{fake_service_id}/config"
+ )
config_payload = {
"cloud_account_id": cloud_account_id,
@@ -392,7 +394,6 @@ def test_update_service_config_invalid_service(
), f"Expected 404 for invalid service, got {response.status_code}"
-
def test_update_service_config_disable_service(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
@@ -408,7 +409,9 @@ def test_update_service_config_disable_service(
account_id = account_data["account_id"]
cloud_account_id = str(uuid.uuid4())
- simulate_agent_checkin(signoz, admin_token, cloud_provider, account_id, cloud_account_id)
+ simulate_agent_checkin(
+ signoz, admin_token, cloud_provider, account_id, cloud_account_id
+ )
# Get a valid service
list_endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/services"
@@ -422,7 +425,9 @@ def test_update_service_config_disable_service(
service_id = list_data["services"][0]["id"]
# First enable the service
- endpoint = f"/api/v1/cloud-integrations/{cloud_provider}/services/{service_id}/config"
+ endpoint = (
+ f"/api/v1/cloud-integrations/{cloud_provider}/services/{service_id}/config"
+ )
enable_payload = {
"cloud_account_id": cloud_account_id,
diff --git a/tests/integration/src/querier/07_metrics_multi_temporality.py b/tests/integration/src/querier/07_metrics_multi_temporality.py
index b3e36a2215..c39e6b616d 100644
--- a/tests/integration/src/querier/07_metrics_multi_temporality.py
+++ b/tests/integration/src/querier/07_metrics_multi_temporality.py
@@ -2,11 +2,11 @@
Look at the multi_temporality_counters_1h.jsonl file for the relevant data
"""
-import os
+import random
from datetime import datetime, timedelta, timezone
from http import HTTPStatus
-import random
-from typing import Any, Callable, List
+from typing import Callable, List
+
import pytest
from fixtures import types
@@ -21,8 +21,13 @@ from fixtures.querier import (
from fixtures.utils import get_testdata_file_path
MULTI_TEMPORALITY_FILE = get_testdata_file_path("multi_temporality_counters_1h.jsonl")
-MULTI_TEMPORALITY_FILE_10h = get_testdata_file_path("multi_temporality_counters_10h.jsonl")
-MULTI_TEMPORALITY_FILE_24h = get_testdata_file_path("multi_temporality_counters_24h.jsonl")
+MULTI_TEMPORALITY_FILE_10h = get_testdata_file_path(
+ "multi_temporality_counters_10h.jsonl"
+)
+MULTI_TEMPORALITY_FILE_24h = get_testdata_file_path(
+ "multi_temporality_counters_24h.jsonl"
+)
+
@pytest.mark.parametrize(
"time_aggregation, expected_value_at_31st_minute, expected_value_at_32nd_minute, steady_value",
@@ -39,7 +44,7 @@ def test_with_steady_values_and_reset(
time_aggregation: str,
expected_value_at_31st_minute: float,
expected_value_at_32nd_minute: float,
- steady_value: float
+ steady_value: float,
) -> None:
now = datetime.now(tz=timezone.utc).replace(second=0, microsecond=0)
start_ms = int((now - timedelta(minutes=65)).timestamp() * 1000)
@@ -69,22 +74,21 @@ def test_with_steady_values_and_reset(
result_values = sorted(get_series_values(data, "A"), key=lambda x: x["timestamp"])
assert len(result_values) >= 59
# the counter reset happened at 31st minute
- assert (
- result_values[30]["value"] == expected_value_at_31st_minute
- )
- assert (
- result_values[31]["value"] == expected_value_at_32nd_minute
- )
+ assert result_values[30]["value"] == expected_value_at_31st_minute
+ assert result_values[31]["value"] == expected_value_at_32nd_minute
assert (
result_values[39]["value"] == steady_value
- ) # 39th minute is when cumulative shifts to delta
+ ) # 39th minute is when cumulative shifts to delta
count_of_steady_rate = sum(1 for v in result_values if v["value"] == steady_value)
assert (
count_of_steady_rate >= 56
) # 59 - (1 reset + 1 high rate + 1 at the beginning)
# All rates should be non-negative (stale periods = 0 rate)
for v in result_values:
- assert v["value"] >= 0, f"{time_aggregation} should not be negative: {v['value']}"
+ assert (
+ v["value"] >= 0
+ ), f"{time_aggregation} should not be negative: {v['value']}"
+
@pytest.mark.parametrize(
"time_aggregation, stable_health_value, stable_products_value, stable_checkout_value, spike_checkout_value, stable_orders_value, spike_users_value",
@@ -161,20 +165,26 @@ def test_group_by_endpoint(
assert (
len(health_values) >= 58
), f"Expected >= 58 values for /health, got {len(health_values)}"
- count_steady_health = sum(1 for v in health_values if v["value"] == stable_health_value)
+ count_steady_health = sum(
+ 1 for v in health_values if v["value"] == stable_health_value
+ )
assert (
count_steady_health >= 57
), f"Expected >= 57 steady rate values ({stable_health_value}) for /health, got {count_steady_health}"
# all /health rates should be state except possibly first/last due to boundaries
for v in health_values[1:-1]:
- assert v["value"] == stable_health_value, f"Expected /health rate {stable_health_value}, got {v['value']}"
+ assert (
+ v["value"] == stable_health_value
+ ), f"Expected /health rate {stable_health_value}, got {v['value']}"
# /products: 51 data points with 10-minute gap (t20-t29 missing), steady +20/min
products_values = endpoint_values["/products"]
assert (
len(products_values) >= 49
), f"Expected >= 49 values for /products, got {len(products_values)}"
- count_steady_products = sum(1 for v in products_values if v["value"] == stable_products_value)
+ count_steady_products = sum(
+ 1 for v in products_values if v["value"] == stable_products_value
+ )
# most values should be stable, some boundary values differ due to 10-min gap
assert (
@@ -182,7 +192,9 @@ def test_group_by_endpoint(
), f"Expected >= 46 steady rate values ({stable_products_value}) for /products, got {count_steady_products}"
# check that non-stable values are due to gap averaging (should be lower)
- gap_boundary_values = [v["value"] for v in products_values if v["value"] != stable_products_value]
+ gap_boundary_values = [
+ v["value"] for v in products_values if v["value"] != stable_products_value
+ ]
for val in gap_boundary_values:
assert (
0 < val < stable_products_value
@@ -193,12 +205,16 @@ def test_group_by_endpoint(
assert (
len(checkout_values) >= 59
), f"Expected >= 59 values for /checkout, got {len(checkout_values)}"
- count_steady_checkout = sum(1 for v in checkout_values if v["value"] == stable_checkout_value)
+ count_steady_checkout = sum(
+ 1 for v in checkout_values if v["value"] == stable_checkout_value
+ )
assert (
count_steady_checkout >= 53
), f"Expected >= 53 steady {time_aggregation} values ({stable_checkout_value}) for /checkout, got {count_steady_checkout}"
# check that spike values exist (traffic spike +50/min at t40-t44)
- count_spike_checkout = sum(1 for v in checkout_values if v["value"] == spike_checkout_value)
+ count_spike_checkout = sum(
+ 1 for v in checkout_values if v["value"] == spike_checkout_value
+ )
assert (
count_spike_checkout >= 4
), f"Expected >= 4 spike {time_aggregation} values ({spike_checkout_value}) for /checkout, got {count_spike_checkout}"
@@ -220,12 +236,16 @@ def test_group_by_endpoint(
assert (
len(orders_values) >= 58
), f"Expected >= 58 values for /orders, got {len(orders_values)}"
- count_steady_orders = sum(1 for v in orders_values if v["value"] == stable_orders_value)
+ count_steady_orders = sum(
+ 1 for v in orders_values if v["value"] == stable_orders_value
+ )
assert (
count_steady_orders >= 55
), f"Expected >= 55 steady {time_aggregation} values ({stable_orders_value}) for /orders, got {count_steady_orders}"
# check for counter reset effects - there should be some non-standard values
- non_standard_orders = [v["value"] for v in orders_values if v["value"] != stable_orders_value]
+ non_standard_orders = [
+ v["value"] for v in orders_values if v["value"] != stable_orders_value
+ ]
assert (
len(non_standard_orders) >= 2
), f"Expected >= 2 non-standard values due to counter reset, got {non_standard_orders}"
@@ -252,6 +272,7 @@ def test_group_by_endpoint(
count_increment_rate >= 8
), f"Expected >= 8 increment {time_aggregation} values ({spike_users_value}) for /users, got {count_increment_rate}"
+
@pytest.mark.parametrize(
"time_aggregation, expected_value_at_30th_minute, expected_value_at_31st_minute, value_at_switch",
[
@@ -267,7 +288,7 @@ def test_for_service_with_switch(
time_aggregation: str,
expected_value_at_30th_minute: float,
expected_value_at_31st_minute: float,
- value_at_switch: float
+ value_at_switch: float,
) -> None:
now = datetime.now(tz=timezone.utc).replace(second=0, microsecond=0)
start_ms = int((now - timedelta(minutes=65)).timestamp() * 1000)
@@ -296,21 +317,18 @@ def test_for_service_with_switch(
data = response.json()
result_values = sorted(get_series_values(data, "A"), key=lambda x: x["timestamp"])
assert len(result_values) >= 60
+ assert result_values[30]["value"] == expected_value_at_30th_minute # 0.183
+ assert result_values[31]["value"] == expected_value_at_31st_minute # 0.183
+ assert result_values[38]["value"] == value_at_switch # 0.25
assert (
- result_values[30]["value"] == expected_value_at_30th_minute #0.183
- )
- assert (
- result_values[31]["value"] == expected_value_at_31st_minute # 0.183
- )
- assert (
- result_values[38]["value"] == value_at_switch # 0.25
- )
- assert (
- result_values[39]["value"] == value_at_switch # 0.25
- ) # 39th minute is when cumulative shifts to delta
+ result_values[39]["value"] == value_at_switch # 0.25
+ ) # 39th minute is when cumulative shifts to delta
# All rates should be non-negative (stale periods = 0 rate)
for v in result_values:
- assert v["value"] >= 0, f"{time_aggregation} should not be negative: {v['value']}"
+ assert (
+ v["value"] >= 0
+ ), f"{time_aggregation} should not be negative: {v['value']}"
+
@pytest.mark.parametrize(
"time_aggregation, expected_value",
@@ -355,6 +373,7 @@ def test_for_week_long_time_range(
for value in result_values[1:]:
assert value["value"] == expected_value
+
@pytest.mark.parametrize(
"time_aggregation, expected_value",
[
diff --git a/tests/integration/src/role/01_register.py b/tests/integration/src/role/01_register.py
index 9ef212fe96..a0fc2e0346 100644
--- a/tests/integration/src/role/01_register.py
+++ b/tests/integration/src/role/01_register.py
@@ -1,23 +1,23 @@
-import pytest
from http import HTTPStatus
from typing import Callable
+import pytest
import requests
from sqlalchemy import sql
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
from fixtures.types import Operation, SigNoz
-
ANONYMOUS_USER_ID = "00000000-0000-0000-0000-000000000000"
+
def test_managed_roles_create_on_register(
signoz: SigNoz,
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
):
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
-
+
# get the list of all roles.
response = requests.get(
signoz.self.host_configs["8080"].get("/api/v1/roles"),
@@ -32,18 +32,22 @@ def test_managed_roles_create_on_register(
# since this check happens immediately post registeration, all the managed roles should be present.
assert len(data) == 4
role_names = {role["name"] for role in data}
- expected_names = {"signoz-admin", "signoz-viewer", "signoz-editor", "signoz-anonymous"}
+ expected_names = {
+ "signoz-admin",
+ "signoz-viewer",
+ "signoz-editor",
+ "signoz-anonymous",
+ }
# do the set mapping as this is order insensitive, direct list match is order-sensitive.
assert set(role_names) == expected_names
-
def test_root_user_signoz_admin_assignment(
request: pytest.FixtureRequest,
signoz: SigNoz,
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
-):
+):
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
# Get the user from the /user/me endpoint and extract the id
@@ -64,14 +68,16 @@ def test_root_user_signoz_admin_assignment(
# this validates to some extent that the role assignment is complete under the assumption that middleware is functioning as expected.
assert response.status_code == HTTPStatus.OK
assert response.json()["status"] == "success"
-
+
# Loop over the roles and get the org_id and id for signoz-admin role
roles = response.json()["data"]
- admin_role_entry = next((role for role in roles if role["name"] == "signoz-admin"), None)
+ admin_role_entry = next(
+ (role for role in roles if role["name"] == "signoz-admin"), None
+ )
assert admin_role_entry is not None
org_id = admin_role_entry["orgId"]
- # to be super sure of authorization server, let's validate the tuples in DB as well.
+ # to be super sure of authorization server, let's validate the tuples in DB as well.
# todo[@vikrantgupta25]: replace this with role memebers handler once built.
with signoz.sqlstore.conn.connect() as conn:
# verify the entry present for role assignment
@@ -80,15 +86,14 @@ def test_root_user_signoz_admin_assignment(
sql.text("SELECT * FROM tuple WHERE object_id = :object_id"),
{"object_id": tuple_object_id},
)
-
+
tuple_row = tuple_result.mappings().fetchone()
assert tuple_row is not None
# check that the tuple if for role assignment
- assert tuple_row['object_type'] == "role"
- assert tuple_row['relation'] == "assignee"
+ assert tuple_row["object_type"] == "role"
+ assert tuple_row["relation"] == "assignee"
-
- if request.config.getoption("--sqlstore-provider") == 'sqlite':
+ if request.config.getoption("--sqlstore-provider") == "sqlite":
user_object_id = f"organization/{org_id}/user/{user_id}"
assert tuple_row["user_object_type"] == "user"
assert tuple_row["user_object_id"] == user_object_id
@@ -97,13 +102,13 @@ def test_root_user_signoz_admin_assignment(
assert tuple_row["user_type"] == "user"
assert tuple_row["_user"] == _user
-
+
def test_anonymous_user_signoz_anonymous_assignment(
request: pytest.FixtureRequest,
signoz: SigNoz,
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
-):
+):
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
response = requests.get(
@@ -115,14 +120,16 @@ def test_anonymous_user_signoz_anonymous_assignment(
# this validates to some extent that the role assignment is complete under the assumption that middleware is functioning as expected.
assert response.status_code == HTTPStatus.OK
assert response.json()["status"] == "success"
-
+
# Loop over the roles and get the org_id and id for signoz-admin role
roles = response.json()["data"]
- admin_role_entry = next((role for role in roles if role["name"] == "signoz-anonymous"), None)
+ admin_role_entry = next(
+ (role for role in roles if role["name"] == "signoz-anonymous"), None
+ )
assert admin_role_entry is not None
org_id = admin_role_entry["orgId"]
- # to be super sure of authorization server, let's validate the tuples in DB as well.
+ # to be super sure of authorization server, let's validate the tuples in DB as well.
# todo[@vikrantgupta25]: replace this with role memebers handler once built.
with signoz.sqlstore.conn.connect() as conn:
# verify the entry present for role assignment
@@ -131,15 +138,14 @@ def test_anonymous_user_signoz_anonymous_assignment(
sql.text("SELECT * FROM tuple WHERE object_id = :object_id"),
{"object_id": tuple_object_id},
)
-
+
tuple_row = tuple_result.mappings().fetchone()
assert tuple_row is not None
# check that the tuple if for role assignment
- assert tuple_row['object_type'] == "role"
- assert tuple_row['relation'] == "assignee"
+ assert tuple_row["object_type"] == "role"
+ assert tuple_row["relation"] == "assignee"
-
- if request.config.getoption("--sqlstore-provider") == 'sqlite':
+ if request.config.getoption("--sqlstore-provider") == "sqlite":
user_object_id = f"organization/{org_id}/anonymous/{ANONYMOUS_USER_ID}"
assert tuple_row["user_object_type"] == "anonymous"
assert tuple_row["user_object_id"] == user_object_id
@@ -147,5 +153,3 @@ def test_anonymous_user_signoz_anonymous_assignment(
_user = f"anonymous:organization/{org_id}/anonymous/{ANONYMOUS_USER_ID}"
assert tuple_row["user_type"] == "user"
assert tuple_row["_user"] == _user
-
-
\ No newline at end of file
diff --git a/tests/integration/src/role/02_user.py b/tests/integration/src/role/02_user.py
index 3100e5d182..20d2f8de40 100644
--- a/tests/integration/src/role/02_user.py
+++ b/tests/integration/src/role/02_user.py
@@ -1,11 +1,16 @@
-import pytest
from http import HTTPStatus
from typing import Callable
+import pytest
import requests
from sqlalchemy import sql
-from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD, USER_EDITOR_EMAIL, USER_EDITOR_PASSWORD
+from fixtures.auth import (
+ USER_ADMIN_EMAIL,
+ USER_ADMIN_PASSWORD,
+ USER_EDITOR_EMAIL,
+ USER_EDITOR_PASSWORD,
+)
from fixtures.types import Operation, SigNoz
@@ -16,7 +21,7 @@ def test_user_invite_accept_role_grant(
get_token: Callable[[str, str], str],
):
admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
-
+
# invite a user as editor
invite_payload = {
"email": USER_EDITOR_EMAIL,
@@ -30,7 +35,7 @@ def test_user_invite_accept_role_grant(
)
assert invite_response.status_code == HTTPStatus.CREATED
invite_token = invite_response.json()["data"]["token"]
-
+
# accept the invite for editor
accept_payload = {
"token": invite_token,
@@ -40,7 +45,7 @@ def test_user_invite_accept_role_grant(
signoz.self.host_configs["8080"].get("/api/v1/invite/accept"),
json=accept_payload,
timeout=2,
- )
+ )
assert accept_response.status_code == HTTPStatus.CREATED
# Login with editor email and password
@@ -53,7 +58,6 @@ def test_user_invite_accept_role_grant(
assert user_me_response.status_code == HTTPStatus.OK
editor_id = user_me_response.json()["data"]["id"]
-
# check the forbidden response for admin api for editor user
admin_roles_response = requests.get(
signoz.self.host_configs["8080"].get("/api/v1/roles"),
@@ -79,11 +83,11 @@ def test_user_invite_accept_role_grant(
)
tuple_row = tuple_result.mappings().fetchone()
assert tuple_row is not None
- assert tuple_row['object_type'] == "role"
- assert tuple_row['relation'] == "assignee"
+ assert tuple_row["object_type"] == "role"
+ assert tuple_row["relation"] == "assignee"
# verify the user tuple details depending on db provider
- if request.config.getoption("--sqlstore-provider") == 'sqlite':
+ if request.config.getoption("--sqlstore-provider") == "sqlite":
user_object_id = f"organization/{org_id}/user/{editor_id}"
assert tuple_row["user_object_type"] == "user"
assert tuple_row["user_object_id"] == user_object_id
@@ -93,7 +97,6 @@ def test_user_invite_accept_role_grant(
assert tuple_row["_user"] == _user
-
def test_user_update_role_grant(
request: pytest.FixtureRequest,
signoz: SigNoz,
@@ -122,9 +125,7 @@ def test_user_update_role_grant(
org_id = roles_data[0]["orgId"]
# Update the user's role to viewer
- update_payload = {
- "role": "VIEWER"
- }
+ update_payload = {"role": "VIEWER"}
update_response = requests.put(
signoz.self.host_configs["8080"].get(f"/api/v1/user/{editor_id}"),
json=update_payload,
@@ -139,7 +140,9 @@ def test_user_update_role_grant(
viewer_tuple_object_id = f"organization/{org_id}/role/signoz-viewer"
# Check there is no tuple for signoz-editor assignment
editor_tuple_result = conn.execute(
- sql.text("SELECT * FROM tuple WHERE object_id = :object_id AND relation = 'assignee'"),
+ sql.text(
+ "SELECT * FROM tuple WHERE object_id = :object_id AND relation = 'assignee'"
+ ),
{"object_id": editor_tuple_object_id},
)
for row in editor_tuple_result.mappings().fetchall():
@@ -152,13 +155,15 @@ def test_user_update_role_grant(
# Check that a tuple exists for signoz-viewer assignment
viewer_tuple_result = conn.execute(
- sql.text("SELECT * FROM tuple WHERE object_id = :object_id AND relation = 'assignee'"),
+ sql.text(
+ "SELECT * FROM tuple WHERE object_id = :object_id AND relation = 'assignee'"
+ ),
{"object_id": viewer_tuple_object_id},
)
row = viewer_tuple_result.mappings().fetchone()
assert row is not None
- assert row['object_type'] == "role"
- assert row['relation'] == "assignee"
+ assert row["object_type"] == "role"
+ assert row["relation"] == "assignee"
if request.config.getoption("--sqlstore-provider") == "sqlite":
user_object_id = f"organization/{org_id}/user/{editor_id}"
assert row["user_object_type"] == "user"
@@ -168,6 +173,7 @@ def test_user_update_role_grant(
assert row["user_type"] == "user"
assert row["_user"] == _user
+
def test_user_delete_role_revoke(
request: pytest.FixtureRequest,
signoz: SigNoz,
@@ -205,10 +211,12 @@ def test_user_delete_role_revoke(
with signoz.sqlstore.conn.connect() as conn:
tuple_result = conn.execute(
- sql.text("SELECT * FROM tuple WHERE object_id = :object_id AND relation = 'assignee'"),
+ sql.text(
+ "SELECT * FROM tuple WHERE object_id = :object_id AND relation = 'assignee'"
+ ),
{"object_id": tuple_object_id},
)
-
+
# there should NOT be any tuple for the current user assignment
tuple_rows = tuple_result.mappings().fetchall()
for row in tuple_rows:
@@ -217,4 +225,4 @@ def test_user_delete_role_revoke(
assert row["user_object_id"] != user_object_id
else:
_user = f"user:organization/{org_id}/user/{editor_id}"
- assert row["_user"] != _user
\ No newline at end of file
+ assert row["_user"] != _user
diff --git a/tests/integration/testdata/alerts/test_scenarios/multi_threshold_rule_test/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/multi_threshold_rule_test/alert_data.jsonl
new file mode 100644
index 0000000000..164e60c8c3
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/multi_threshold_rule_test/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:01:00+00:00","value":2,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:02:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:03:00+00:00","value":14,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:04:00+00:00","value":3,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:05:00+00:00","value":6,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:06:00+00:00","value":25,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:07:00+00:00","value":25,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:08:00+00:00","value":25,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:09:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:10:00+00:00","value":12,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:11:00+00:00","value":8,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_multi_threshold_rule_test","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:12:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/multi_threshold_rule_test/rule.json b/tests/integration/testdata/alerts/test_scenarios/multi_threshold_rule_test/rule.json
new file mode 100644
index 0000000000..b00ed4b78b
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/multi_threshold_rule_test/rule.json
@@ -0,0 +1,83 @@
+{
+ "alert": "multi_threshold_rule_test",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 30,
+ "matchType": "1",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ]
+ },
+ {
+ "name": "warning",
+ "target": 20,
+ "matchType": "1",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ]
+ },
+ {
+ "name": "info",
+ "target": 10,
+ "matchType": "1",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "cpu_percent_multi_threshold_rule_test",
+ "timeAggregation": "avg",
+ "spaceAggregation": "max"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/no_data_rule_test/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/no_data_rule_test/alert_data.jsonl
new file mode 100644
index 0000000000..4c77c846cc
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/no_data_rule_test/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:01:00+00:00","value":12,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:02:00+00:00","value":26,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:03:00+00:00","value":41,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:04:00+00:00","value":56,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:05:00+00:00","value":71,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:06:00+00:00","value":86,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:07:00+00:00","value":101,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:08:00+00:00","value":116,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:09:00+00:00","value":131,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:10:00+00:00","value":146,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:11:00+00:00","value":161,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_no_data_rule_test","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:12:00+00:00","value":176,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/no_data_rule_test/rule.json b/tests/integration/testdata/alerts/test_scenarios/no_data_rule_test/rule.json
new file mode 100644
index 0000000000..bc16f95357
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/no_data_rule_test/rule.json
@@ -0,0 +1,70 @@
+{
+ "alert": "no_data_rule_test",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "1",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "filter": {
+ "expression": "service = 'server'"
+ },
+ "aggregations": [
+ {
+ "metricName": "request_total_no_data_rule_test",
+ "timeAggregation": "rate",
+ "spaceAggregation": "sum"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A",
+ "alertOnAbsent": true,
+ "absentFor": 1
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_above_all_the_time/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_above_all_the_time/alert_data.jsonl
new file mode 100644
index 0000000000..cb8c392867
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_above_all_the_time/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:01:00+00:00","value":12,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:02:00+00:00","value":14,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:03:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:04:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:05:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:06:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:07:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:08:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:09:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:10:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:11:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_above_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:12:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_above_all_the_time/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_above_all_the_time/rule.json
new file mode 100644
index 0000000000..7bfcced756
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_above_all_the_time/rule.json
@@ -0,0 +1,58 @@
+{
+ "alert": "threshold_above_all_the_time",
+ "ruleType": "promql_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "2",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "promql",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "promql",
+ "spec": {
+ "name": "A",
+ "query": "{\"cpu_percent_threshold_above_all_the_time\"}"
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_above_at_least_once/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_above_at_least_once/alert_data.jsonl
new file mode 100644
index 0000000000..6653bb5c53
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_above_at_least_once/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:01:00+00:00","value":1,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:02:00+00:00","value":2,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:03:00+00:00","value":3,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:04:00+00:00","value":4,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:05:00+00:00","value":19,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:06:00+00:00","value":20,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:07:00+00:00","value":35,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:08:00+00:00","value":36,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:09:00+00:00","value":37,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:10:00+00:00","value":38,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:11:00+00:00","value":39,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:12:00+00:00","value":40,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_above_at_least_once/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_above_at_least_once/rule.json
new file mode 100644
index 0000000000..cb312082e7
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_above_at_least_once/rule.json
@@ -0,0 +1,58 @@
+{
+ "alert": "threshold_above_at_least_once",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "1",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "clickhouse_sql",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "clickhouse_sql",
+ "spec": {
+ "name": "A",
+ "query": "WITH __temporal_aggregation_cte AS (\n SELECT \n fingerprint, \n toStartOfInterval(toDateTime(intDiv(unix_milli, 1000)), toIntervalSecond(60)) AS ts, \n avg(value) AS per_series_value \n FROM signoz_metrics.distributed_samples_v4 AS points \n INNER JOIN (\n SELECT fingerprint \n FROM signoz_metrics.time_series_v4 \n WHERE metric_name IN ('request_total_threshold_above_at_least_once') \n AND LOWER(temporality) LIKE LOWER('cumulative') \n AND __normalized = false \n GROUP BY fingerprint\n ) AS filtered_time_series ON points.fingerprint = filtered_time_series.fingerprint \n WHERE metric_name IN ('request_total_threshold_above_at_least_once') \n AND unix_milli >= {{.start_timestamp_ms}} \n AND unix_milli < {{.end_timestamp_ms}} \n GROUP BY fingerprint, ts \n ORDER BY fingerprint, ts\n), \n__spatial_aggregation_cte AS (\n SELECT \n ts, \n avg(per_series_value) AS value \n FROM __temporal_aggregation_cte \n WHERE isNaN(per_series_value) = 0 \n GROUP BY ts\n) \nSELECT * FROM __spatial_aggregation_cte \nORDER BY ts"
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_above_average/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_above_average/alert_data.jsonl
new file mode 100644
index 0000000000..4671758d22
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_above_average/alert_data.jsonl
@@ -0,0 +1,20 @@
+{ "timestamp": "2026-01-29T10:00:00.000000Z", "duration": "PT0.8S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6a1", "span_id": "a1b2c3d4e5f6g7h8", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:00:30.000000Z", "duration": "PT1.2S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6a2", "span_id": "a2b3c4d5e6f7g8h9", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:01:00.000000Z", "duration": "PT0.9S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6a3", "span_id": "a3b4c5d6e7f8g9h0", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:01:30.000000Z", "duration": "PT1.5S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6a4", "span_id": "a4b5c6d7e8f9g0h1", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:02:00.000000Z", "duration": "PT1.1S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6a5", "span_id": "a5b6c7d8e9f0g1h2", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:02:30.000000Z", "duration": "PT0.7S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6a6", "span_id": "a6b7c8d9e0f1g2h3", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:03:00.000000Z", "duration": "PT1.8S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6a7", "span_id": "a7b8c9d0e1f2g3h4", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:03:30.000000Z", "duration": "PT1.3S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6a8", "span_id": "a8b9c0d1e2f3g4h5", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:04:00.000000Z", "duration": "PT0.6S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6a9", "span_id": "a9b0c1d2e3f4g5h6", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:04:30.000000Z", "duration": "PT1.4S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6b1", "span_id": "b1c2d3e4f5g6h7i8", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:05:00.000000Z", "duration": "PT1.6S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6b2", "span_id": "b2c3d4e5f6g7h8i9", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" },"attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:05:30.000000Z", "duration": "PT0.85S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6b3", "span_id": "b3c4d5e6f7g8h9i0", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:06:00.000000Z", "duration": "PT1.7S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6b4", "span_id": "b4c5d6e7f8g9h0i1", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:06:30.000000Z", "duration": "PT1.25S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6b5", "span_id": "b5c6d7e8f9g0h1i2", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:07:00.000000Z", "duration": "PT0.95S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6b6", "span_id": "b6c7d8e9f0g1h2i3", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:07:30.000000Z", "duration": "PT1.9S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6b7", "span_id": "b7c8d9e0f1g2h3i4", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:08:00.000000Z", "duration": "PT1.35S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6b8", "span_id": "b8c9d0e1f2g3h4i5", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:08:30.000000Z", "duration": "PT0.75S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6b9", "span_id": "b9c0d1e2f3g4h5i6", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:09:00.000000Z", "duration": "PT1.55S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6c1", "span_id": "c1d2e3f4g5h6i7j8", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
+{ "timestamp": "2026-01-29T10:10:00.000000Z", "duration": "PT1.65S", "trace_id": "491f6d3d6b0a1f9e8a71b2c3d4e5f6c2", "span_id": "c2d3e4f5g6h7i8j9", "parent_span_id": "", "name": "POST /order", "kind": 2, "status_code": 1, "status_message": "", "resources": { "deployment.environment": "production", "service.name": "order-service", "os.type": "linux", "host.name": "linux-000" }, "attributes": { "net.transport": "IP.TCP", "http.scheme": "http", "http.user_agent": "Integration Test", "http.request.method": "POST", "http.response.status_code": "200", "http.request.path": "/order" } }
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_above_average/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_above_average/rule.json
new file mode 100644
index 0000000000..1d5e2c8cfb
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_above_average/rule.json
@@ -0,0 +1,68 @@
+{
+ "alert": "threshold_above_average",
+ "ruleType": "threshold_rule",
+ "alertType": "TRACES_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 1,
+ "matchType": "3",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ],
+ "targetUnit": "s"
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "unit": "ns",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "traces",
+ "filter": {
+ "expression": "http.request.path = '/order'"
+ },
+ "aggregations": [
+ {
+ "expression": "p90(duration_nano)"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_above_in_total/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_above_in_total/alert_data.jsonl
new file mode 100644
index 0000000000..62eb204479
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_above_in_total/alert_data.jsonl
@@ -0,0 +1,24 @@
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:01:00+00:00","value":1,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:01:00+00:00","value":1,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:02:00+00:00","value":2,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:02:00+00:00","value":2,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:03:00+00:00","value":3,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:03:00+00:00","value":3,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:04:00+00:00","value":4,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:04:00+00:00","value":4,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:05:00+00:00","value":305,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:05:00+00:00","value":305,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:06:00+00:00","value":306,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:06:00+00:00","value":306,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:07:00+00:00","value":307,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:07:00+00:00","value":307,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:08:00+00:00","value":308,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:08:00+00:00","value":308,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:09:00+00:00","value":309,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:09:00+00:00","value":309,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:10:00+00:00","value":310,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:10:00+00:00","value":310,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:11:00+00:00","value":311,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:11:00+00:00","value":311,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:12:00+00:00","value":312,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_above_in_total","labels":{"service":"server","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:12:00+00:00","value":312,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_above_in_total/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_above_in_total/rule.json
new file mode 100644
index 0000000000..f18531ee1e
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_above_in_total/rule.json
@@ -0,0 +1,74 @@
+{
+ "alert": "threshold_above_in_total",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 5,
+ "matchType": "4",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "groupBy": [
+ {
+ "name": "service",
+ "fieldDataType": "",
+ "fieldContext": ""
+ }
+ ],
+ "aggregations": [
+ {
+ "metricName": "request_total_threshold_above_in_total",
+ "timeAggregation": "rate",
+ "spaceAggregation": "sum"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [
+ "service"
+ ],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_above_last/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_above_last/alert_data.jsonl
new file mode 100644
index 0000000000..521ea188cc
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_above_last/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:01:00+00:00","value":5,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:02:00+00:00","value":10,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:03:00+00:00","value":15,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:04:00+00:00","value":20,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:05:00+00:00","value":31,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:06:00+00:00","value":46,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:07:00+00:00","value":58,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:08:00+00:00","value":71,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:09:00+00:00","value":76,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:10:00+00:00","value":81,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:11:00+00:00","value":86,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_threshold_above_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:12:00+00:00","value":91,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_above_last/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_above_last/rule.json
new file mode 100644
index 0000000000..ed1c380e46
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_above_last/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_above_last",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "5",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "disk_usage_threshold_above_last",
+ "timeAggregation": "latest",
+ "spaceAggregation": "max"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_below_all_the_time/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_below_all_the_time/alert_data.jsonl
new file mode 100644
index 0000000000..916751ea03
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_below_all_the_time/alert_data.jsonl
@@ -0,0 +1,18 @@
+{ "timestamp": "2026-01-29T10:00:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:00:02.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:01:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Database connection established", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:01:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:02:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "API request received", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:02:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:03:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Request validation completed", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:03:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:04:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Cache updated successfully", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:04:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:05:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Rate limit check passed", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:05:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:06:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Authentication token validated", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:06:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:07:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Query executed successfully", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:08:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Response sent to client", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:09:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Metrics collected", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:10:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Background job started", "severity_text": "INFO" }
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_below_all_the_time/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_below_all_the_time/rule.json
new file mode 100644
index 0000000000..8d88f20ba6
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_below_all_the_time/rule.json
@@ -0,0 +1,66 @@
+{
+ "alert": "threshold_below_all_the_time",
+ "ruleType": "threshold_rule",
+ "alertType": "LOGS_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "2",
+ "op": "2",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "logs",
+ "filter": {
+ "expression": "body CONTAINS 'payment success'"
+ },
+ "aggregations": [
+ {
+ "expression": "count()"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_below_at_least_once/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_below_at_least_once/alert_data.jsonl
new file mode 100644
index 0000000000..df89b9a045
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_below_at_least_once/alert_data.jsonl
@@ -0,0 +1,20 @@
+{ "timestamp": "2026-01-29T10:00:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "User login successful", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:00:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:01:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:01:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Database connection established", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:02:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:02:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:03:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "API request received", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:03:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:04:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:04:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Cache updated successfully", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:05:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:05:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Request validation completed", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:06:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:06:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Authentication token validated", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:07:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "payment success", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:07:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Query executed successfully", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:08:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Response sent to client", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:08:30.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Health check endpoint called", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:09:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Metrics collected", "severity_text": "INFO" }
+{ "timestamp": "2026-01-29T10:10:00.000000Z", "resources": { "service.name": "payment-service" }, "attributes": { "code.file": "payment_handler.py" }, "body": "Background job started", "severity_text": "INFO" }
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_below_at_least_once/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_below_at_least_once/rule.json
new file mode 100644
index 0000000000..e680451ce6
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_below_at_least_once/rule.json
@@ -0,0 +1,66 @@
+{
+ "alert": "threshold_below_at_least_once",
+ "ruleType": "threshold_rule",
+ "alertType": "LOGS_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "1",
+ "op": "2",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "logs",
+ "filter": {
+ "expression": "body CONTAINS 'payment success'"
+ },
+ "aggregations": [
+ {
+ "expression": "count()"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_below_average/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_below_average/alert_data.jsonl
new file mode 100644
index 0000000000..abad5b3d26
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_below_average/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:01:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:02:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:03:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:04:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:05:00+00:00","value":2,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:06:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:07:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:08:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:09:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:10:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:11:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_below_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:12:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_below_average/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_below_average/rule.json
new file mode 100644
index 0000000000..034369a47f
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_below_average/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_below_average",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "3",
+ "op": "2",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "cpu_percent_threshold_below_average",
+ "timeAggregation": "avg",
+ "spaceAggregation": "max"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_below_in_total/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_below_in_total/alert_data.jsonl
new file mode 100644
index 0000000000..a2a8b62310
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_below_in_total/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:01:00+00:00","value":1,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:02:00+00:00","value":2,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:03:00+00:00","value":3,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:04:00+00:00","value":4,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:05:00+00:00","value":300,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:06:00+00:00","value":301,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:07:00+00:00","value":302,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:08:00+00:00","value":303,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:09:00+00:00","value":304,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:10:00+00:00","value":305,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:11:00+00:00","value":306,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_below_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:12:00+00:00","value":307,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_below_in_total/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_below_in_total/rule.json
new file mode 100644
index 0000000000..b49471a64f
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_below_in_total/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_below_in_total",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "4",
+ "op": "2",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "bytes_per_second_threshold_below_in_total",
+ "timeAggregation": "rate",
+ "spaceAggregation": "sum"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_below_last/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_below_last/alert_data.jsonl
new file mode 100644
index 0000000000..43ca484afa
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_below_last/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:01:00+00:00","value":100,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:02:00+00:00","value":95,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:03:00+00:00","value":90,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:04:00+00:00","value":85,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:05:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:06:00+00:00","value":3,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:07:00+00:00","value":2,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:08:00+00:00","value":78,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:09:00+00:00","value":72,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:10:00+00:00","value":80,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:11:00+00:00","value":76,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_left_threshold_below_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:12:00+00:00","value":82,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_below_last/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_below_last/rule.json
new file mode 100644
index 0000000000..fca793af60
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_below_last/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_below_last",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "5",
+ "op": "2",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "disk_usage_mb_left_threshold_below_last",
+ "timeAggregation": "latest",
+ "spaceAggregation": "min"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_all_the_time/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_all_the_time/alert_data.jsonl
new file mode 100644
index 0000000000..f1feb127fa
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_all_the_time/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:01:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:02:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:03:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:04:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:05:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:06:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:07:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:08:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:09:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:10:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:11:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:12:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_all_the_time/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_all_the_time/rule.json
new file mode 100644
index 0000000000..c85ff57aef
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_all_the_time/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_equal_to_all_the_time",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "2",
+ "op": "3",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "cpu_percent_threshold_equal_to_all_the_time",
+ "timeAggregation": "avg",
+ "spaceAggregation": "max"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_at_least_once/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_at_least_once/alert_data.jsonl
new file mode 100644
index 0000000000..0dbbcbd245
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_at_least_once/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:01:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:02:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:03:00+00:00","value":15,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:04:00+00:00","value":8,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:05:00+00:00","value":12,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:06:00+00:00","value":7,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:07:00+00:00","value":9,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:08:00+00:00","value":11,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:09:00+00:00","value":6,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:10:00+00:00","value":13,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:11:00+00:00","value":8,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_at_least_once","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:12:00+00:00","value":14,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_at_least_once/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_at_least_once/rule.json
new file mode 100644
index 0000000000..1388623b1a
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_at_least_once/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_equal_to_at_least_once",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "1",
+ "op": "3",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "cpu_percent_threshold_equal_to_at_least_once",
+ "timeAggregation": "avg",
+ "spaceAggregation": "max"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_average/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_average/alert_data.jsonl
new file mode 100644
index 0000000000..0d8b37d9e1
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_average/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:01:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:02:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:03:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:04:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:05:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:06:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:07:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:08:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:09:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:10:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:11:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:12:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_average/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_average/rule.json
new file mode 100644
index 0000000000..2e7acfc98a
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_average/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_equal_to_average",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "3",
+ "op": "3",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "cpu_percent_threshold_equal_to_average",
+ "timeAggregation": "avg",
+ "spaceAggregation": "max"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_in_total/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_in_total/alert_data.jsonl
new file mode 100644
index 0000000000..2b47274a4d
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_in_total/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:01:00+00:00","value":0,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:02:00+00:00","value":60,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:03:00+00:00","value":120,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:04:00+00:00","value":180,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:05:00+00:00","value":600,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:06:00+00:00","value":600,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:07:00+00:00","value":720,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:08:00+00:00","value":780,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:09:00+00:00","value":840,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:10:00+00:00","value":900,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:11:00+00:00","value":960,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:12:00+00:00","value":1020,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_in_total/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_in_total/rule.json
new file mode 100644
index 0000000000..3c2fd9795c
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_in_total/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_equal_to_in_total",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "4",
+ "op": "3",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "bytes_per_second_threshold_equal_to_in_total",
+ "timeAggregation": "rate",
+ "spaceAggregation": "sum"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_last/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_last/alert_data.jsonl
new file mode 100644
index 0000000000..d2a14705df
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_last/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:01:00+00:00","value":5,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:02:00+00:00","value":10,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:03:00+00:00","value":15,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:04:00+00:00","value":20,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:05:00+00:00","value":30,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:06:00+00:00","value":40,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:07:00+00:00","value":50,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:08:00+00:00","value":55,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:09:00+00:00","value":60,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:10:00+00:00","value":65,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:11:00+00:00","value":70,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_mb_threshold_equal_to_last","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:12:00+00:00","value":75,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_last/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_last/rule.json
new file mode 100644
index 0000000000..404151fd88
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_equal_to_last/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_equal_to_last",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "5",
+ "op": "3",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "disk_usage_mb_threshold_equal_to_last",
+ "timeAggregation": "latest",
+ "spaceAggregation": "max"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_all_the_time/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_all_the_time/alert_data.jsonl
new file mode 100644
index 0000000000..aeaddfdf01
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_all_the_time/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:01:00+00:00","value":2,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:02:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:03:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:04:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:05:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:06:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:07:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:08:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:09:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:10:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:11:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_all_the_time","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:12:00+00:00","value":5,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_all_the_time/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_all_the_time/rule.json
new file mode 100644
index 0000000000..9f890304f8
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_all_the_time/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_not_equal_to_all_the_time",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "2",
+ "op": "4",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "cpu_percent_threshold_not_equal_to_all_the_time",
+ "timeAggregation": "avg",
+ "spaceAggregation": "max"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_at_least_once/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_at_least_once/alert_data.jsonl
new file mode 100644
index 0000000000..a96cad6231
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_at_least_once/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:01:00+00:00","value":100,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:02:00+00:00","value":200,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:03:00+00:00","value":300,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:04:00+00:00","value":400,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:05:00+00:00","value":430,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:06:00+00:00","value":450,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:07:00+00:00","value":500,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:08:00+00:00","value":600,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:09:00+00:00","value":700,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:10:00+00:00","value":800,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:11:00+00:00","value":900,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"request_total_threshold_not_equal_to_at_least_once","labels":{"service":"api","endpoint":"/health","status_code":"200"},"timestamp":"2026-01-29T10:12:00+00:00","value":1000,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_at_least_once/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_at_least_once/rule.json
new file mode 100644
index 0000000000..09b932d3c0
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_at_least_once/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_not_equal_to_at_least_once",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 5,
+ "matchType": "1",
+ "op": "4",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "request_total_threshold_not_equal_to_at_least_once",
+ "timeAggregation": "rate",
+ "spaceAggregation": "sum"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_average/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_average/alert_data.jsonl
new file mode 100644
index 0000000000..88adada706
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_average/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:01:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:02:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:03:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:04:00+00:00","value":3,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:05:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:06:00+00:00","value":16,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:07:00+00:00","value":11,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:08:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:09:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:10:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:11:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"cpu_percent_threshold_not_equal_to_average","labels":{"host":"server-01","cpu":"cpu0"},"timestamp":"2026-01-29T10:12:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_average/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_average/rule.json
new file mode 100644
index 0000000000..7458be4cda
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_average/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_not_equal_to_average",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "3",
+ "op": "4",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "cpu_percent_threshold_not_equal_to_average",
+ "timeAggregation": "avg",
+ "spaceAggregation": "max"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_in_total/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_in_total/alert_data.jsonl
new file mode 100644
index 0000000000..4515f604b2
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_in_total/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:01:00+00:00","value":1,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:02:00+00:00","value":2,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:03:00+00:00","value":3,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:04:00+00:00","value":4,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:05:00+00:00","value":605,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:06:00+00:00","value":606,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:07:00+00:00","value":607,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:08:00+00:00","value":608,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:09:00+00:00","value":609,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:10:00+00:00","value":610,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:11:00+00:00","value":611,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"bytes_per_second_threshold_not_equal_to_in_total","labels":{"interface":"eth0","protocol":"tcp"},"timestamp":"2026-01-29T10:12:00+00:00","value":612,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_in_total/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_in_total/rule.json
new file mode 100644
index 0000000000..b689ab7536
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_in_total/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_not_equal_to_in_total",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "4",
+ "op": "4",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "bytes_per_second_threshold_not_equal_to_in_total",
+ "timeAggregation": "rate",
+ "spaceAggregation": "sum"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_last/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_last/alert_data.jsonl
new file mode 100644
index 0000000000..69831df03d
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_last/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:01:00+00:00","value":9,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:02:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:03:00+00:00","value":11,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:04:00+00:00","value":9,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:05:00+00:00","value":11,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:06:00+00:00","value":9,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:07:00+00:00","value":11,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:08:00+00:00","value":10,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:09:00+00:00","value":9,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:10:00+00:00","value":11,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:11:00+00:00","value":9,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"seats_left_threshold_not_equal_to_last","labels":{"venue":"conference_hall","section":"main"},"timestamp":"2026-01-29T10:12:00+00:00","value":11,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_last/rule.json b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_last/rule.json
new file mode 100644
index 0000000000..c497e619dd
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/threshold_not_equal_to_last/rule.json
@@ -0,0 +1,65 @@
+{
+ "alert": "threshold_not_equal_to_last",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 10,
+ "matchType": "5",
+ "op": "4",
+ "channels": [
+ "test channel"
+ ]
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "seats_left_threshold_not_equal_to_last",
+ "timeAggregation": "latest",
+ "spaceAggregation": "min"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/unit_conversion_bytes_to_mb/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/unit_conversion_bytes_to_mb/alert_data.jsonl
new file mode 100644
index 0000000000..269922484c
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/unit_conversion_bytes_to_mb/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:01:00+00:00","value":524288,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:02:00+00:00","value":1048576,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:03:00+00:00","value":1572864,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:04:00+00:00","value":2097152,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:05:00+00:00","value":3770016,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:06:00+00:00","value":5642880,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:07:00+00:00","value":10515744,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:08:00+00:00","value":11038632,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:09:00+00:00","value":11561520,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:10:00+00:00","value":12084408,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:11:00+00:00","value":12607296,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"disk_usage_unit_conversion_bytes_to_mb","labels":{"device":"/dev/sda1","mountpoint":"/"},"timestamp":"2026-01-29T10:12:00+00:00","value":13130184,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/unit_conversion_bytes_to_mb/rule.json b/tests/integration/testdata/alerts/test_scenarios/unit_conversion_bytes_to_mb/rule.json
new file mode 100644
index 0000000000..c53181398a
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/unit_conversion_bytes_to_mb/rule.json
@@ -0,0 +1,67 @@
+{
+ "alert": "unit_conversion_bytes_to_mb",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 1.5,
+ "matchType": "1",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ],
+ "targetUnit": "MBy"
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "unit": "By",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "disk_usage_unit_conversion_bytes_to_mb",
+ "timeAggregation": "latest",
+ "spaceAggregation": "max"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}
diff --git a/tests/integration/testdata/alerts/test_scenarios/unit_conversion_ms_to_second/alert_data.jsonl b/tests/integration/testdata/alerts/test_scenarios/unit_conversion_ms_to_second/alert_data.jsonl
new file mode 100644
index 0000000000..dd76d923f5
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/unit_conversion_ms_to_second/alert_data.jsonl
@@ -0,0 +1,12 @@
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:01:00+00:00","value":500,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:02:00+00:00","value":1000,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:03:00+00:00","value":1500,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:04:00+00:00","value":2000,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:05:00+00:00","value":182100,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:06:00+00:00","value":182200,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:07:00+00:00","value":182300,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:08:00+00:00","value":182400,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:09:00+00:00","value":182500,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:10:00+00:00","value":182600,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:11:00+00:00","value":182700,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
+{"metric_name":"duration_ms_unit_conversion_ms_to_second","labels":{"service":"api","endpoint":"/health","method":"GET","status_code":"200"},"timestamp":"2026-01-29T10:12:00+00:00","value":182800,"temporality":"Cumulative","type_":"Sum","is_monotonic":true,"flags":0,"description":"","unit":"","env":"default","resource_attrs":{},"scope_attrs":{}}
diff --git a/tests/integration/testdata/alerts/test_scenarios/unit_conversion_ms_to_second/rule.json b/tests/integration/testdata/alerts/test_scenarios/unit_conversion_ms_to_second/rule.json
new file mode 100644
index 0000000000..be86825047
--- /dev/null
+++ b/tests/integration/testdata/alerts/test_scenarios/unit_conversion_ms_to_second/rule.json
@@ -0,0 +1,67 @@
+{
+ "alert": "unit_conversion_ms_to_second",
+ "ruleType": "threshold_rule",
+ "alertType": "METRIC_BASED_ALERT",
+ "condition": {
+ "thresholds": {
+ "kind": "basic",
+ "spec": [
+ {
+ "name": "critical",
+ "target": 3,
+ "matchType": "1",
+ "op": "1",
+ "channels": [
+ "test channel"
+ ],
+ "targetUnit": "s"
+ }
+ ]
+ },
+ "compositeQuery": {
+ "queryType": "builder",
+ "panelType": "graph",
+ "unit": "ms",
+ "queries": [
+ {
+ "type": "builder_query",
+ "spec": {
+ "name": "A",
+ "signal": "metrics",
+ "aggregations": [
+ {
+ "metricName": "duration_ms_unit_conversion_ms_to_second",
+ "timeAggregation": "rate",
+ "spaceAggregation": "sum"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "selectedQueryName": "A"
+ },
+ "evaluation": {
+ "kind": "rolling",
+ "spec": {
+ "evalWindow": "5m0s",
+ "frequency": "15s"
+ }
+ },
+ "labels": {},
+ "annotations": {
+ "description": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})",
+ "summary": "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
+ },
+ "notificationSettings": {
+ "groupBy": [],
+ "usePolicy": false,
+ "renotify": {
+ "enabled": false,
+ "interval": "30m",
+ "alertStates": []
+ }
+ },
+ "version": "v5",
+ "schemaVersion": "v2alpha1"
+}