Exemplo n.º 1
0
    def test(self) -> None:
        creator = SubscriptionCreator(self.dataset, EntityKey.EVENTS)
        subscription = SubscriptionData(
            project_id=1,
            query="MATCH (events) SELECT count() AS count",
            time_window_sec=10 * 60,
            resolution_sec=60,
            entity_subscription=create_entity_subscription(),
        )
        identifier = creator.create(subscription, Timer("test"))
        assert (cast(
            List[Tuple[UUID, SubscriptionData]],
            RedisSubscriptionDataStore(
                redis_client,
                self.entity_key,
                identifier.partition,
            ).all(),
        )[0][1] == subscription)

        SubscriptionDeleter(self.entity_key,
                            identifier.partition).delete(identifier.uuid)
        assert (RedisSubscriptionDataStore(
            redis_client,
            self.entity_key,
            identifier.partition,
        ).all() == [])
Exemplo n.º 2
0
 def subscription(self) -> Sequence[SubscriptionData]:
     return [
         SubscriptionData(
             project_id=self.project_id,
             query="MATCH (events) SELECT count() WHERE in(platform, 'a')",
             time_window_sec=500 * 60,
             resolution_sec=60,
             entity_subscription=create_entity_subscription(),
         ),
         SubscriptionData(
             project_id=self.project_id,
             time_window_sec=500 * 60,
             resolution_sec=60,
             query="MATCH (events) SELECT count() WHERE in(platform, 'a')",
             entity_subscription=create_entity_subscription(),
         ),
     ]
Exemplo n.º 3
0
    def test_invalid_time_window(self) -> None:
        creator = SubscriptionCreator(self.dataset, EntityKey.EVENTS)
        with raises(InvalidSubscriptionError):
            creator.create(
                SubscriptionData(
                    project_id=123,
                    time_window_sec=0,
                    resolution_sec=60,
                    query=
                    "MATCH (events) SELECT count() AS count WHERE platfo IN tuple('a')",
                    entity_subscription=create_entity_subscription(),
                ),
                self.timer,
            )

        with raises(InvalidSubscriptionError):
            creator.create(
                SubscriptionData(
                    project_id=123,
                    query=("MATCH (events) "
                           "SELECT count() AS count BY time "
                           "WHERE "
                           "platform IN tuple('a') "),
                    time_window_sec=0,
                    resolution_sec=60,
                    entity_subscription=create_entity_subscription(),
                ),
                self.timer,
            )

        with raises(InvalidSubscriptionError):
            creator.create(
                SubscriptionData(
                    project_id=123,
                    time_window_sec=48 * 60 * 60,
                    resolution_sec=60,
                    query=
                    "MATCH (events) SELECT count() AS count WHERE platfo IN tuple('a')",
                    entity_subscription=create_entity_subscription(),
                ),
                self.timer,
            )
Exemplo n.º 4
0
 def build_subscription(self, resolution: timedelta) -> Subscription:
     return Subscription(
         SubscriptionIdentifier(self.partition_id, uuid.uuid4()),
         SubscriptionData(
             project_id=1,
             query="MATCH (events) SELECT count() AS count",
             time_window_sec=60,
             resolution_sec=int(resolution.total_seconds()),
             entity_subscription=create_entity_subscription(),
         ),
     )
Exemplo n.º 5
0
def build_snql_subscription_data(
    entity_key: EntityKey,
    organization: Optional[int] = None,
) -> SubscriptionData:

    return SubscriptionData(
        project_id=5,
        time_window_sec=500 * 60,
        resolution_sec=60,
        query="MATCH events SELECT count() WHERE in(platform, 'a')",
        entity_subscription=create_entity_subscription(entity_key,
                                                       organization),
    )
Exemplo n.º 6
0
 def test_invalid_aggregation(self) -> None:
     creator = SubscriptionCreator(self.dataset, EntityKey.EVENTS)
     with raises(QueryException):
         creator.create(
             SubscriptionData(
                 project_id=123,
                 time_window_sec=10 * 60,
                 resolution_sec=60,
                 query=
                 "MATCH (events) SELECT cout() AS count WHERE platform IN tuple('a')",
                 entity_subscription=create_entity_subscription(),
             ),
             self.timer,
         )
Exemplo n.º 7
0
from snuba.utils.metrics.timer import Timer
from snuba.web import QueryException
from tests.subscriptions import BaseSubscriptionTest
from tests.subscriptions.subscriptions_utils import create_entity_subscription

TESTS_CREATE = [
    pytest.param(
        SubscriptionData(
            project_id=123,
            query=("MATCH (events) "
                   "SELECT count() AS count "
                   "WHERE "
                   "platform IN tuple('a')"),
            time_window_sec=10 * 60,
            resolution_sec=60,
            entity_subscription=create_entity_subscription(),
        ),
        id="SnQL subscription",
    ),
]

TESTS_INVALID = [
    pytest.param(
        SubscriptionData(
            project_id=123,
            query=("MATCH (events) "
                   "SELECT count() AS count "
                   "WHERE "
                   "platfo IN tuple('a') "),
            time_window_sec=10 * 60,
            resolution_sec=60,
Exemplo n.º 8
0
from tests.subscriptions import BaseSubscriptionTest
from tests.subscriptions.subscriptions_utils import create_entity_subscription

TESTS = [
    pytest.param(
        SubscriptionData(
            project_id=1,
            query=(
                "MATCH (events) "
                "SELECT count() AS count "
                "WHERE "
                "platform IN tuple('a') "
            ),
            time_window_sec=500 * 60,
            resolution_sec=60,
            entity_subscription=create_entity_subscription(),
        ),
        None,
        id="SnQL subscription",
    ),
    pytest.param(
        SubscriptionData(
            project_id=1,
            query=(
                "MATCH (events) "
                "SELECT count() AS count, avg(timestamp) AS average_t "
                "WHERE "
                "platform IN tuple('a') "
            ),
            time_window_sec=500 * 60,
            resolution_sec=60,