Пример #1
0
def create_snuba_subscription(project, subscription_type, snuba_query,
                              aggregation):
    """
    Creates a subscription to a snuba query.

    :param project: The project we're applying the query to
    :param subscription_type: Text identifier for the subscription type this is. Used
    to identify the registered callback associated with this subscription.
    :param snuba_query: A `SnubaQuery` instance to subscribe the project to.
    :param aggregation: An aggregation to calculate over the time window. This will be
    removed soon, once we're relying entirely on `snuba_query`.
    :return: The QuerySubscription representing the subscription
    """
    subscription = QuerySubscription.objects.create(
        status=QuerySubscription.Status.CREATING.value,
        project=project,
        snuba_query=snuba_query,
        type=subscription_type,
        dataset=snuba_query.dataset,
        query=snuba_query.query,
        aggregation=aggregation.value,
        time_window=snuba_query.time_window,
        resolution=snuba_query.resolution,
    )
    if snuba_query.environment:
        QuerySubscriptionEnvironment.objects.create(
            query_subscription=subscription,
            environment=snuba_query.environment)

    create_subscription_in_snuba.apply_async(
        kwargs={"query_subscription_id": subscription.id}, countdown=5)

    return subscription
Пример #2
0
def enable_snuba_subscription(subscription):
    """
    enables a subscription to a snuba query.
    :param subscription: The subscription to enable
    :return:
    """
    subscription.update(status=QuerySubscription.Status.CREATING.value)
    create_subscription_in_snuba.apply_async(
        kwargs={"query_subscription_id": subscription.id}, countdown=5)
Пример #3
0
def create_snuba_subscription(project, subscription_type, snuba_query):
    """
    Creates a subscription to a snuba query.

    :param project: The project we're applying the query to
    :param subscription_type: Text identifier for the subscription type this is. Used
    to identify the registered callback associated with this subscription.
    :param snuba_query: A `SnubaQuery` instance to subscribe the project to.
    :return: The QuerySubscription representing the subscription
    """
    subscription = QuerySubscription.objects.create(
        status=QuerySubscription.Status.CREATING.value,
        project=project,
        snuba_query=snuba_query,
        type=subscription_type,
    )
    create_subscription_in_snuba.apply_async(
        kwargs={"query_subscription_id": subscription.id}, countdown=5)

    return subscription
Пример #4
0
def create_snuba_subscription(project, subscription_type, dataset, query,
                              aggregation, time_window, resolution,
                              environments):
    """
    Creates a subscription to a snuba query.

    :param project: The project we're applying the query to
    :param subscription_type: Text identifier for the subscription type this is. Used
    to identify the registered callback associated with this subscription.
    :param dataset: The snuba dataset to query and aggregate over
    :param query: An event search query that we can parse and convert into a
    set of Snuba conditions
    :param aggregation: An aggregation to calculate over the time window
    :param time_window: The time window to aggregate over
    :param resolution: How often to receive updates/bucket size
    :param environments: List of environments to filter by
    :return: The QuerySubscription representing the subscription
    """
    subscription = QuerySubscription.objects.create(
        status=QuerySubscription.Status.CREATING.value,
        project=project,
        type=subscription_type,
        dataset=dataset.value,
        query=query,
        aggregation=aggregation.value,
        time_window=int(time_window.total_seconds()),
        resolution=int(resolution.total_seconds()),
    )
    sub_envs = [
        QuerySubscriptionEnvironment(query_subscription=subscription,
                                     environment=env) for env in environments
    ]
    QuerySubscriptionEnvironment.objects.bulk_create(sub_envs)

    create_subscription_in_snuba.apply_async(
        kwargs={"query_subscription_id": subscription.id}, countdown=5)

    return subscription