Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metric-alerts): Adds subscription consumer for metrics [INGEST-623] #2222

Merged
merged 4 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions snuba/cli/devserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,45 @@ def devserver(*, bootstrap: bool, workers: bool) -> None:
],
),
]
if settings.ENABLE_METRICS_SUBSCRIPTIONS:
daemons += [
(
"subscriptions-consumer-metrics-counters",
[
"snuba",
"subscriptions",
"--auto-offset-reset=latest",
"--log-level=debug",
"--max-batch-size=1",
"--consumer-group=snuba-metrics-subscriptions-consumers",
"--dataset=metrics",
"--entity=metrics_counters",
"--commit-log-topic=snuba-metrics-commit-log",
"--commit-log-group=metrics_group",
"--delay-seconds=1",
"--schedule-ttl=10",
"--max-query-workers=1",
],
),
(
"subscriptions-consumer-metrics-sets",
[
"snuba",
"subscriptions",
"--auto-offset-reset=latest",
"--log-level=debug",
"--max-batch-size=1",
"--consumer-group=snuba-metrics-subscriptions-consumers",
"--dataset=metrics",
"--entity=metrics_sets",
"--commit-log-topic=snuba-metrics-commit-log",
"--commit-log-group=metrics_group",
"--delay-seconds=1",
"--schedule-ttl=10",
"--max-query-workers=1",
],
),
]

if settings.ENABLE_SESSIONS_SUBSCRIPTIONS:
daemons += [
Expand Down
16 changes: 13 additions & 3 deletions snuba/datasets/storages/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from snuba.query.processors.arrayjoin_keyvalue_optimizer import (
ArrayJoinKeyValueOptimizer,
)
from snuba.subscriptions.utils import SchedulingWatermarkMode
from snuba.utils.streams.topics import Topic

PRE_VALUE_COLUMNS: Sequence[Column[SchemaModifiers]] = [
Expand Down Expand Up @@ -58,11 +59,15 @@
),
query_processors=[],
stream_loader=build_kafka_stream_loader_from_settings(
processor=SetsMetricsProcessor(), default_topic=Topic.METRICS,
processor=SetsMetricsProcessor(),
default_topic=Topic.METRICS,
commit_log_topic=Topic.METRICS_COMMIT_LOG,
subscription_scheduler_mode=SchedulingWatermarkMode.GLOBAL,
subscription_scheduled_topic=Topic.SUBSCRIPTION_SCHEDULED_METRICS,
subscription_result_topic=Topic.SUBSCRIPTION_RESULTS_METRICS,
),
)


counters_buckets = WritableTableStorage(
storage_key=StorageKey.METRICS_COUNTERS_BUCKETS,
storage_set_key=StorageSetKey.METRICS,
Expand All @@ -76,7 +81,12 @@
),
query_processors=[],
stream_loader=build_kafka_stream_loader_from_settings(
processor=CounterMetricsProcessor(), default_topic=Topic.METRICS,
processor=CounterMetricsProcessor(),
ahmedetefy marked this conversation as resolved.
Show resolved Hide resolved
default_topic=Topic.METRICS,
commit_log_topic=Topic.METRICS_COMMIT_LOG,
subscription_scheduler_mode=SchedulingWatermarkMode.GLOBAL,
subscription_scheduled_topic=Topic.SUBSCRIPTION_SCHEDULED_METRICS,
subscription_result_topic=Topic.SUBSCRIPTION_RESULTS_METRICS,
),
)

Expand Down
1 change: 1 addition & 0 deletions snuba/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@

# Metric Alerts Subscription Options
ENABLE_SESSIONS_SUBSCRIPTIONS = os.environ.get("ENABLE_SESSIONS_SUBSCRIPTIONS", False)
ENABLE_METRICS_SUBSCRIPTIONS = os.environ.get("ENABLE_METRICS_SUBSCRIPTIONS", False)

# Subscriptions scheduler buffer size
SUBSCRIPTIONS_DEFAULT_BUFFER_SIZE = 10000
Expand Down