Skip to content

[DBMON-6812] Add async job registry to DatabaseCheck - #24442

Merged
eric-weaver merged 5 commits into
masterfrom
eric.weaver/DBMON-6812
Jul 14, 2026
Merged

[DBMON-6812] Add async job registry to DatabaseCheck#24442
eric-weaver merged 5 commits into
masterfrom
eric.weaver/DBMON-6812

Conversation

@eric-weaver

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds an async job registry to DatabaseCheck so DBM integrations can declare their
DBMAsyncJobs additively and manage them all through a single entry point instead of
wiring each job's lifecycle by hand.

DatabaseCheck gains:

  • register_async_job(job) — registers a job under its job_name, returns it unchanged,
    no-ops on None, replaces an existing job registered under the same name, and raises
    ValueError if the job has no name.
  • run_async_jobs(tags) — runs every registered job's loop, forwarding tags.
  • cancel_async_jobs() — signals every job to stop without waiting or releasing resources
    (safe to call while check() is running).
  • shutdown_async_jobs() — waits for each job's loop to finish, then runs its teardown.

DBMAsyncJob gains:

  • job_name property — public accessor used as the registry key.
  • wait_for_completion() — blocks until the loop finishes and clears its future, hiding the
    private future from callers.
  • shutdown() — a no-op teardown hook, called once on unschedule after the loop stops, for
    releasing lifetime-scoped resources (e.g. dedicated DB connections). Distinct from
    shutdown_callback, which runs on every loop exit and may be followed by a restart.

Motivation

DBM integrations each hand-roll registering, running, and stopping their async jobs, and
jobs reach into check config directly. Centralizing the registry in DatabaseCheck gives a
consistent, additive pattern for owning job lifecycles and a clear teardown seam, paving the
way to migrate individual integrations onto it.

Additional Notes

No behavior change for existing integrations; the registry is opt-in and unused until an
integration adopts it.

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 appropriate backport/ label.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog auto-retried 1 job - 1 passed on retry View in Datadog

🎯 Code Coverage (details)
Patch Coverage: 98.81%
Overall Coverage: 88.33% (-1.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b6d7453 | Docs | Datadog PR Page | Give us feedback!

@eric-weaver eric-weaver added the qa/skip-qa Automatically skip this PR for the next QA label Jul 8, 2026
@eric-weaver
eric-weaver marked this pull request as ready for review July 8, 2026 18:43
@eric-weaver
eric-weaver requested review from a team as code owners July 8, 2026 18:43

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f1633e741

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

self.tag_manager = TagManager()
#: Async jobs owned by this check, keyed by job name, populated via
#: :meth:`register_async_job`.
self._async_job_registry: Dict[str, "DBMAsyncJob"] = {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Rename the registry attribute without a leading underscore

The root AGENTS.md naming rule says variables may only use a leading underscore for Pydantic PrivateAttrs; this new DatabaseCheck instance attribute is not one of those exceptions. Please rename the registry storage (and the new test references to it) without the underscore so this generated code follows the repo-wide convention.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was an intentional decision in this case in order to help clarify internal properties for this shared class that will be used by other integrations that we want to discourage leaking logic from. We know it's a soft guard. This is already done across the repo and within this class. If this is new guidance we need to follow from agent integrations then I'm happy to change.

Comment thread datadog_checks_base/datadog_checks/base/checks/db.py Outdated
@dd-octo-sts

dd-octo-sts Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Validation Report

All 21 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and code coverage settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
qa-label Validate the pull request declares whether it needs QA for the next Agent release
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

@eric-weaver
eric-weaver added this pull request to the merge queue Jul 14, 2026
Merged via the queue into master with commit f2a39eb Jul 14, 2026
642 of 647 checks passed
@eric-weaver
eric-weaver deleted the eric.weaver/DBMON-6812 branch July 14, 2026 17:39
@dd-octo-sts dd-octo-sts Bot added this to the 7.83.0 milestone Jul 14, 2026
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.

3 participants