Browse Source

ref: Only expose tagstore, tsdb or search API through service wrapper (#7825)

ted kaemming 7 years ago
parent
commit
e7bea4d8bf

+ 1 - 2
bin/load-mocks

@@ -17,7 +17,7 @@ from django.utils import timezone
 from loremipsum import Generator
 from pytz import utc
 
-from sentry import buffer, roles
+from sentry import buffer, roles, tsdb
 from sentry.event_manager import HashDiscarded
 from sentry.models import (
     Activity, Broadcast, Commit, CommitAuthor, CommitFileChange, Deploy,
@@ -28,7 +28,6 @@ from sentry.models import (
 )
 from sentry.signals import mocks_loaded
 from sentry.similarity import features
-from sentry.tsdb import backend as tsdb
 from sentry.utils.hashlib import md5_text
 from sentry.utils.samples import create_sample_event as _create_sample_event
 from sentry.utils.samples import generate_user

+ 2 - 2
src/sentry/app.py

@@ -23,15 +23,15 @@ class State(local):
 
 env = State()
 
+
 # COMPAT
+from sentry import search, tsdb  # NOQA
 from .buffer import backend as buffer  # NOQA
 from .digests import backend as digests  # NOQA
 from .newsletter import backend as newsletter  # NOQA
 from .nodestore import backend as nodestore  # NOQA
 from .quotas import backend as quotas  # NOQA
 from .ratelimits import backend as ratelimiter  # NOQA
-from .search import backend as search  # NOQA
-from .tsdb import backend as tsdb  # NOQA
 
 raven = client
 

+ 1 - 3
src/sentry/event_manager.py

@@ -20,9 +20,7 @@ from django.utils.encoding import force_bytes, force_text
 from hashlib import md5
 from uuid import uuid4
 
-from sentry import eventtypes, features, buffer
-# we need a bunch of unexposed functions from tsdb
-from sentry.tsdb import backend as tsdb
+from sentry import buffer, eventtypes, features, tsdb
 from sentry.constants import (
     CLIENT_RESERVED_ATTRS, LOG_LEVELS, LOG_LEVELS_MAP, DEFAULT_LOG_LEVEL,
     DEFAULT_LOGGER_NAME, MAX_CULPRIT_LENGTH, VALID_PLATFORMS

+ 2 - 2
src/sentry/models/groupsnooze.py

@@ -71,7 +71,7 @@ class GroupSnooze(Model):
         return True
 
     def test_frequency_rates(self):
-        from sentry.tsdb import backend as tsdb
+        from sentry import tsdb
 
         end = timezone.now()
         start = end - timedelta(minutes=self.window)
@@ -88,7 +88,7 @@ class GroupSnooze(Model):
         return True
 
     def test_user_rates(self):
-        from sentry.tsdb import backend as tsdb
+        from sentry import tsdb
 
         end = timezone.now()
         start = end - timedelta(minutes=self.user_window)

+ 1 - 1
src/sentry/rules/conditions/event_frequency.py

@@ -12,7 +12,7 @@ from datetime import timedelta
 from django import forms
 from django.utils import timezone
 
-from sentry.tsdb import backend as tsdb
+from sentry import tsdb
 from sentry.rules.conditions.base import EventCondition
 
 intervals = {

+ 5 - 2
src/sentry/search/__init__.py

@@ -6,5 +6,8 @@ from sentry.utils.services import LazyServiceWrapper
 
 from .base import SearchBackend  # NOQA
 
-backend = LazyServiceWrapper(SearchBackend, settings.SENTRY_SEARCH, settings.SENTRY_SEARCH_OPTIONS)
-backend.expose(locals())
+LazyServiceWrapper(
+    SearchBackend,
+    settings.SENTRY_SEARCH,
+    settings.SENTRY_SEARCH_OPTIONS,
+).expose(locals())

+ 3 - 1
src/sentry/search/base.py

@@ -15,7 +15,9 @@ EMPTY = object()
 
 
 class SearchBackend(Service):
-    __all__ = ('query', 'validate')
+    __all__ = frozenset([
+        'query',
+    ])
 
     def __init__(self, **options):
         pass

+ 5 - 4
src/sentry/tagstore/__init__.py

@@ -7,7 +7,8 @@ from sentry.utils.services import LazyServiceWrapper
 from .base import TagStorage, TagKeyStatus  # NOQA
 from .exceptions import *  # NOQA
 
-backend = LazyServiceWrapper(
-    TagStorage, settings.SENTRY_TAGSTORE, settings.SENTRY_TAGSTORE_OPTIONS
-)
-backend.expose(locals())
+LazyServiceWrapper(
+    TagStorage,
+    settings.SENTRY_TAGSTORE,
+    settings.SENTRY_TAGSTORE_OPTIONS,
+).expose(locals())

+ 6 - 4
src/sentry/tsdb/__init__.py

@@ -7,7 +7,9 @@ from sentry.utils.services import LazyServiceWrapper
 from .base import BaseTSDB  # NOQA
 from .dummy import DummyTSDB
 
-backend = LazyServiceWrapper(
-    BaseTSDB, settings.SENTRY_TSDB, settings.SENTRY_TSDB_OPTIONS, (DummyTSDB, )
-)
-backend.expose(locals())
+LazyServiceWrapper(
+    BaseTSDB,
+    settings.SENTRY_TSDB,
+    settings.SENTRY_TSDB_OPTIONS,
+    dangerous=[DummyTSDB],
+).expose(locals())

+ 38 - 4
src/sentry/tsdb/base.py

@@ -101,10 +101,38 @@ class TSDBModel(Enum):
 
 
 class BaseTSDB(Service):
-    __all__ = (
-        'models', 'incr', 'incr_multi', 'get_range', 'get_rollups', 'get_sums', 'rollup',
-        'validate', 'make_series',
-    )
+    __all__ = frozenset([
+        'get_earliest_timestamp',
+        'get_optimal_rollup_series',
+        'get_rollups',
+        'make_series',
+        'models',
+        'models_with_environment_support',
+        'rollup',
+
+        'get_range',
+        'get_sums',
+        'get_distinct_counts_series',
+        'get_distinct_counts_totals',
+        'get_distinct_counts_union',
+        'get_most_frequent',
+        'get_most_frequent_series',
+        'get_frequency_series',
+        'get_frequency_totals',
+
+        'incr',
+        'incr_multi',
+        'merge',
+        'delete',
+        'record',
+        'record_multi',
+        'merge_distinct_counts',
+        'delete_distinct_counts',
+        'record_frequency_multi',
+        'merge_frequencies',
+        'delete_frequencies',
+        'flush',
+    ])
 
     models = TSDBModel
 
@@ -458,3 +486,9 @@ class BaseTSDB(Service):
         Delete all frequency tables.
         """
         raise NotImplementedError
+
+    def flush(self):
+        """
+        Delete all data.
+        """
+        raise NotImplementedError

Some files were not shown because too many files changed in this diff