def select_storage( self, query: Query, request_settings: RequestSettings ) -> StorageAndMappers: granularity = extract_granularity_from_query(query, "started") or 3600 use_materialized_storage = granularity >= 3600 and (granularity % 3600) == 0 metrics.increment( "query.selector", tags={ "selected_storage": "materialized" if use_materialized_storage else "raw", }, ) allow_subhour_sessions = state.get_config("allow_subhour_sessions", 0) if not allow_subhour_sessions: use_materialized_storage = True if use_materialized_storage: return StorageAndMappers( self.materialized_storage, sessions_hourly_translators ) else: return StorageAndMappers(self.raw_storage, sessions_raw_translators)
def select_storage(self, query: Query, request_settings: RequestSettings) -> StorageAndMappers: use_readonly_storage = (state.get_config( "enable_events_readonly_table", False) and not request_settings.get_consistent()) storage = (self.__events_ro_table if use_readonly_storage else self.__events_table) return StorageAndMappers(storage, event_translator)
def select_storage(self, query: Query, query_settings: QuerySettings) -> StorageAndMappers: readonly_referrer = ( query_settings.referrer in settings.TRANSACTIONS_DIRECT_TO_READONLY_REFERRERS) use_readonly_storage = readonly_referrer or state.get_config( "enable_transactions_readonly_table", False) storage = (self.__transactions_ro_table if use_readonly_storage else self.__transactions_table) return StorageAndMappers(storage, self.__mappers)
def select_storage(self, query: Query, request_settings: RequestSettings) -> StorageAndMappers: table = detect_table( query, self.__abstract_events_columns, self.__abstract_transactions_columns, True, ) if table == TRANSACTIONS: return StorageAndMappers(self.__transactions_table, self.__transaction_translator) else: use_readonly_storage = (state.get_config( "enable_events_readonly_table", False) and not request_settings.get_consistent()) return (StorageAndMappers(self.__events_ro_table, self.__event_translator) if use_readonly_storage else StorageAndMappers( self.__events_table, self.__event_translator))
def select_storage(self, query: Query, query_settings: QuerySettings) -> StorageAndMappers: # If the passed in `query_settings` arg is an instance of `SubscriptionQuerySettings`, # then it is a crash rate alert subscription, and hence we decide on whether to use the # materialized storage or the raw storage by examining the time_window. # If the `time_window` <=1h, then select the raw storage otherwise select materialized # storage # NOTE: If we were to support other types of subscriptions over the sessions dataset that # do not follow this method used to identify which storage to use, we would need to # find a different way to distinguish them. if isinstance(query_settings, SubscriptionQuerySettings): from_date, to_date = get_time_range(query, "started") if from_date and to_date: use_materialized_storage = to_date - from_date > timedelta( hours=1) else: use_materialized_storage = True else: granularity = extract_granularity_from_query(query, "started") or 3600 use_materialized_storage = granularity >= 3600 and (granularity % 3600) == 0 metrics.increment( "query.selector", tags={ "selected_storage": "materialized" if use_materialized_storage else "raw", }, ) if use_materialized_storage: return StorageAndMappers(self.materialized_storage, sessions_hourly_translators) else: return StorageAndMappers(self.raw_storage, sessions_raw_translators)