Skip to content

Commit

Permalink
[Update] Misc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarksdale committed Jun 23, 2021
1 parent 47ba7d1 commit 5e1edd5
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions mysql/datadog_checks/mysql/statement_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,11 @@ def _collect_plan_for_statement(self, row):

collection_errors = []
if explain_errors:
for e in explain_errors:
strategy, explain_err_code, explain_err = e
for strategy, explain_err_code, explain_err in explain_errors:
collection_errors.append(
{
'strategy': strategy if strategy else None,
'code': explain_err_code.value,
'code': explain_err_code.value if explain_err_code else None,
'message': '{}'.format(type(explain_err)) if explain_err else None,
}
)
Expand Down Expand Up @@ -711,9 +710,9 @@ def _explain_statement(self, cursor, statement, schema, obfuscated_statement):
self._log.debug('Skipping statement which cannot be explained: %s', obfuscated_statement)
return None, [(None, DBExplainError.no_plans_possible, None)]

strategy_cache = self._collection_strategy_cache.get(strategy_cache_key)
if strategy_cache:
_, explain_err_code, _ = strategy_cache[0] # (strategy, explain_err_code, explain_err)
cached_strategy = self._collection_strategy_cache.get(strategy_cache_key)
if cached_strategy:
_, explain_err_code, _ = cached_strategy[0] # (strategy, explain_err_code, explain_err)
if explain_err_code:
self._log.debug('Skipping statement due to cached collection failure: %s', obfuscated_statement)
return None, None
Expand Down Expand Up @@ -744,9 +743,9 @@ def _explain_statement(self, cursor, statement, schema, obfuscated_statement):

# Use a cached strategy for the schema, if any, or try each strategy to collect plans
strategies = list(self._preferred_explain_strategies)
strategy_cache = self._collection_strategy_cache.get(strategy_cache_key)
if strategy_cache:
strategy, _, _ = strategy_cache[0] # (strategy, explain_err_code, explain_err)
cached_strategy = self._collection_strategy_cache.get(strategy_cache_key)
if cached_strategy:
strategy, _, _ = cached_strategy[0] # (strategy, explain_err_code, explain_err)
strategies.remove(strategy)
strategies.insert(0, strategy)

Expand Down

0 comments on commit 5e1edd5

Please sign in to comment.