(self)
return strategy
Decides on the plan collection strategy:
        - which events_statement_history-* table are we using
        - how long should the rate and time limits be
        :return: (table, rate_limit)
Decides on the plan collection strategy:
        - which events_statement_history-* table are we using
        - how long should the rate and time limits be
        :return: (table, rate_limit)
Decides on the plan collection strategy : - which events_statement_history - * table are we using - how long should the rate and time limits be : return : ( table rate_limit )
def _get_sample_collection_strategy(self):
        """
        Decides on the plan collection strategy:
        - which events_statement_history-* table are we using
        - how long should the rate and time limits be
        :return: (table, rate_limit)
        """
        cached_strategy = self._collection_strategy_cache.get("events_statements_strategy")
        if cached_strategy:
            self._log.debug("Using cached events_statements_strategy: %s", cached_strategy)
            return cached_strategy

        enabled_consumers = self._get_enabled_performance_schema_consumers()
        if len(enabled_consumers) < 3:
            self._enable_events_statements_consumers()
            enabled_consumers = self._get_enabled_performance_schema_consumers()

        if not enabled_consumers:
            self._log.warning(
                "Cannot collect statement samples as there are no enabled performance_schema.events_statements_* "
                "consumers. Enable performance_schema and at least one events_statements consumer in order to collect "
                "statement samples."
            )
            self._check.count(
                "dd.mysql.query_samples.error",
                1,
                tags=self._tags + ["error:no-enabled-events-statements-consumers"] + self._check._get_debug_tags(),
                hostname=self._check.resolved_hostname,
            )
            return None, None
        self._log.debug("Found enabled performance_schema statements consumers: %s", enabled_consumers)

        events_statements_table = None
        for table in self._preferred_events_statements_tables:
            if table not in enabled_consumers:
                continue
            rows = self._get_new_events_statements(table, 1)
            if not rows:
                self._log.debug("No statements found in %s table. checking next one.", table)
                continue
            events_statements_table = table
            break
        if not events_statements_table:
            self._log.warning(
                "Cannot collect statement samples as all enabled events_statements_consumers %s are empty.",
                enabled_consumers,
            )
            return None, None

        collection_interval = self._configured_collection_interval
        if collection_interval < 0:
            collection_interval = DEFAULT_EVENTS_STATEMENTS_COLLECTION_INTERVAL[events_statements_table]

        # cache only successful strategies
        # should be short enough that we'll reflect updates relatively quickly
        # i.e., an aurora replica becomes a master (or vice versa).
        strategy = (events_statements_table, collection_interval)
        self._log.debug(
            "Chose plan collection strategy: events_statements_table=%s, collection_interval=%s",
            events_statements_table,
            collection_interval,
        )
        self._collection_strategy_cache["events_statements_strategy"] = strategy
        return strategy
def _get_sample_collection_strategy ( self ) : cached_strategy = self . _collection_strategy_cache . get ( "events_statements_strategy" ) if cached_strategy : self . _log . debug ( "Using cached events_statements_strategy: %s" , cached_strategy ) return cached_strategy enabled_consumers = self . _get_enabled_performance_schema_consumers ( ) if len ( enabled_consumers ) < 3 : self . _enable_events_statements_consumers ( ) enabled_consumers = self . _get_enabled_performance_schema_consumers ( ) if not enabled_consumers : self . _log . warning ( "Cannot collect statement samples as there are no enabled performance_schema.events_statements_* " "consumers. Enable performance_schema and at least one events_statements consumer in order to collect " "statement samples." ) self . _check . count ( "dd.mysql.query_samples.error" , 1 , tags = self . _tags + [ "error:no-enabled-events-statements-consumers" ] + self . _check . _get_debug_tags ( ) , hostname = self . _check . resolved_hostname , ) return None , None self . _log . debug ( "Found enabled performance_schema statements consumers: %s" , enabled_consumers ) events_statements_table = None for table in self . _preferred_events_statements_tables : if table not in enabled_consumers : continue rows = self . _get_new_events_statements ( table , 1 ) if not rows : self . _log . debug ( "No statements found in %s table. checking next one." , table ) continue events_statements_table = table break if not events_statements_table : self . _log . warning ( "Cannot collect statement samples as all enabled events_statements_consumers %s are empty." , enabled_consumers , ) return None , None collection_interval = self . _configured_collection_interval if collection_interval < 0 : collection_interval = DEFAULT_EVENTS_STATEMENTS_COLLECTION_INTERVAL [ events_statements_table ] # cache only successful strategies # should be short enough that we'll reflect updates relatively quickly # i.e., an aurora replica becomes a master (or vice versa). strategy = ( events_statements_table , collection_interval ) self . _log . debug ( "Chose plan collection strategy: events_statements_table=%s, collection_interval=%s" , events_statements_table , collection_interval , ) self . _collection_strategy_cache [ "events_statements_strategy" ] = strategy return strategy