Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mongo] use queryPlanner verbosity when explaining long running queries #19232

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lu-zhengda
Copy link
Contributor

What does this PR do?

This PR updates the mongo integration to use the queryPlanner verbosity mode when collecting explain plans for queries with a duration longer than the configured timeout (default: 30s). This change avoids re-executing long-running queries on the monitored database, improving performance and reducing resource contention.

Motivation

https://datadoghq.atlassian.net/browse/DBMON-4823
Currently, the MongoDB integration collects explain plans using the executionStats verbosity mode, which executes the winning plan to completion for detailed execution statistics. This approach introduces two significant issues for long-running queries:

  • Timeouts: Explaining long-running queries often results in timeouts, especially for operations exceeding the configured timeout.
    • Before Agent 7.59, timeouts occurred only on the client side, but the query continued to run on the server side.
  • Performance Impact: The integration re-executes the long-running query during explain collection, creating additional resource-intensive operations against the monitored database.
    Switching to the queryPlanner mode resolves these issues by running the MongoDB query optimizer to determine the winning plan without executing the query to completion. This change reduces overhead and improves stability for monitoring.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 77.41935% with 7 lines in your changes missing coverage. Please review.

Project coverage is 87.26%. Comparing base (c42d9ec) to head (87c93cd).
Report is 10 commits behind head on master.

Additional details and impacted files
Flag Coverage Δ
activemq ?
cassandra ?
hive ?
hivemq ?
hudi ?
ignite ?
jboss_wildfly ?
kafka ?
mongo 92.84% <77.41%> (-0.97%) ⬇️
presto ?
solr ?

Flags with carried forward coverage won't be shown. Click here to find out more.

@lu-zhengda lu-zhengda marked this pull request as ready for review December 9, 2024 22:10
@lu-zhengda lu-zhengda requested review from a team as code owners December 9, 2024 22:10
nenadnoveljic
nenadnoveljic previously approved these changes Dec 10, 2024
@@ -229,6 +229,9 @@ def is_collection_sharded(self, db_name, coll_name):
self._log.warning("Could not determine if collection %s.%s is sharded: %s", db_name, coll_name, e)
return False

def explain_command(self, db_name, command, verbosity="executionStats", session=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add typing to the function's arguments and return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will do it in a separate pr because the entire api.py does not have type hint

mongo/datadog_checks/mongo/dbm/operation_samples.py Outdated Show resolved Hide resolved
mongo/datadog_checks/mongo/dbm/slow_operations.py Outdated Show resolved Hide resolved
mongo/datadog_checks/mongo/dbm/utils.py Show resolved Hide resolved
@lu-zhengda lu-zhengda added this pull request to the merge queue Dec 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants