|
@@ -1,6 +1,6 @@
|
|
|
from dataclasses import dataclass
|
|
|
from enum import Enum
|
|
|
-from typing import Any, Mapping, MutableMapping, Optional
|
|
|
+from typing import Any, Mapping, MutableMapping, Optional, Tuple
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
@@ -15,10 +15,20 @@ class UseCaseKey(Enum):
|
|
|
# backwards compatibility
|
|
|
RELEASE_HEALTH_PG_NAMESPACE = "releasehealth"
|
|
|
PERFORMANCE_PG_NAMESPACE = "performance"
|
|
|
+RELEASE_HEALTH_CS_NAMESPACE = "releasehealth.cs"
|
|
|
+PERFORMANCE_CS_NAMESPACE = "performance.cs"
|
|
|
+
|
|
|
+
|
|
|
+class IndexerStorage(Enum):
|
|
|
+ CLOUDSPANNER = "cloudspanner"
|
|
|
+ POSTGRES = "postgres"
|
|
|
+ MOCK = "mock"
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
class MetricsIngestConfiguration:
|
|
|
+ db_backend: IndexerStorage
|
|
|
+ db_backend_options: Mapping[str, Any]
|
|
|
input_topic: str
|
|
|
output_topic: str
|
|
|
use_case_id: UseCaseKey
|
|
@@ -27,17 +37,23 @@ class MetricsIngestConfiguration:
|
|
|
writes_limiter_namespace: str
|
|
|
|
|
|
|
|
|
-_METRICS_INGEST_CONFIG_BY_USE_CASE: MutableMapping[UseCaseKey, MetricsIngestConfiguration] = dict()
|
|
|
+_METRICS_INGEST_CONFIG_BY_USE_CASE: MutableMapping[
|
|
|
+ Tuple[UseCaseKey, IndexerStorage], MetricsIngestConfiguration
|
|
|
+] = dict()
|
|
|
|
|
|
|
|
|
def _register_ingest_config(config: MetricsIngestConfiguration) -> None:
|
|
|
- _METRICS_INGEST_CONFIG_BY_USE_CASE[config.use_case_id] = config
|
|
|
+ _METRICS_INGEST_CONFIG_BY_USE_CASE[(config.use_case_id, config.db_backend)] = config
|
|
|
|
|
|
|
|
|
-def get_ingest_config(use_case_key: UseCaseKey) -> MetricsIngestConfiguration:
|
|
|
+def get_ingest_config(
|
|
|
+ use_case_key: UseCaseKey, db_backend: IndexerStorage
|
|
|
+) -> MetricsIngestConfiguration:
|
|
|
if len(_METRICS_INGEST_CONFIG_BY_USE_CASE) == 0:
|
|
|
_register_ingest_config(
|
|
|
MetricsIngestConfiguration(
|
|
|
+ db_backend=IndexerStorage.POSTGRES,
|
|
|
+ db_backend_options={},
|
|
|
input_topic=settings.KAFKA_INGEST_METRICS,
|
|
|
output_topic=settings.KAFKA_SNUBA_METRICS,
|
|
|
use_case_id=UseCaseKey.RELEASE_HEALTH,
|
|
@@ -46,8 +62,11 @@ def get_ingest_config(use_case_key: UseCaseKey) -> MetricsIngestConfiguration:
|
|
|
writes_limiter_namespace=RELEASE_HEALTH_PG_NAMESPACE,
|
|
|
)
|
|
|
)
|
|
|
+
|
|
|
_register_ingest_config(
|
|
|
MetricsIngestConfiguration(
|
|
|
+ db_backend=IndexerStorage.POSTGRES,
|
|
|
+ db_backend_options={},
|
|
|
input_topic=settings.KAFKA_INGEST_PERFORMANCE_METRICS,
|
|
|
output_topic=settings.KAFKA_SNUBA_GENERIC_METRICS,
|
|
|
use_case_id=UseCaseKey.PERFORMANCE,
|
|
@@ -57,4 +76,46 @@ def get_ingest_config(use_case_key: UseCaseKey) -> MetricsIngestConfiguration:
|
|
|
)
|
|
|
)
|
|
|
|
|
|
- return _METRICS_INGEST_CONFIG_BY_USE_CASE[use_case_key]
|
|
|
+ _register_ingest_config(
|
|
|
+ MetricsIngestConfiguration(
|
|
|
+ db_backend=IndexerStorage.CLOUDSPANNER,
|
|
|
+ # todo: set cloudspanner options of db and instance ids
|
|
|
+ db_backend_options=settings.SENTRY_METRICS_INDEXER_SPANNER_OPTIONS,
|
|
|
+ input_topic=settings.KAFKA_INGEST_METRICS,
|
|
|
+ output_topic=settings.KAFKA_SNUBA_GENERICS_METRICS_CS,
|
|
|
+ use_case_id=UseCaseKey.RELEASE_HEALTH,
|
|
|
+ internal_metrics_tag="release-health-spanner",
|
|
|
+ writes_limiter_cluster_options=settings.SENTRY_METRICS_INDEXER_WRITES_LIMITER_OPTIONS,
|
|
|
+ writes_limiter_namespace=RELEASE_HEALTH_CS_NAMESPACE,
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ _register_ingest_config(
|
|
|
+ MetricsIngestConfiguration(
|
|
|
+ db_backend=IndexerStorage.CLOUDSPANNER,
|
|
|
+ # todo: set cloudspanner options of db and instance ids
|
|
|
+ db_backend_options=settings.SENTRY_METRICS_INDEXER_SPANNER_OPTIONS,
|
|
|
+ input_topic=settings.KAFKA_INGEST_PERFORMANCE_METRICS,
|
|
|
+ output_topic=settings.KAFKA_SNUBA_GENERICS_METRICS_CS,
|
|
|
+ use_case_id=UseCaseKey.PERFORMANCE,
|
|
|
+ internal_metrics_tag="perf-spanner",
|
|
|
+ writes_limiter_cluster_options=settings.SENTRY_METRICS_INDEXER_WRITES_LIMITER_OPTIONS_PERFORMANCE,
|
|
|
+ writes_limiter_namespace=PERFORMANCE_CS_NAMESPACE,
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ if db_backend == IndexerStorage.MOCK:
|
|
|
+ _register_ingest_config(
|
|
|
+ MetricsIngestConfiguration(
|
|
|
+ db_backend=IndexerStorage.MOCK,
|
|
|
+ db_backend_options={},
|
|
|
+ input_topic="topic",
|
|
|
+ output_topic="output-topic",
|
|
|
+ use_case_id=use_case_key,
|
|
|
+ internal_metrics_tag="release-health",
|
|
|
+ writes_limiter_cluster_options={},
|
|
|
+ writes_limiter_namespace="test-namespace",
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ return _METRICS_INGEST_CONFIG_BY_USE_CASE[(use_case_key, db_backend)]
|