Skip to content

Add _get_package_dir utility method to AgentCheck#22749

Open
AAraKKe wants to merge 3 commits intomasterfrom
aarakke/phase-0-get-package-dir
Open

Add _get_package_dir utility method to AgentCheck#22749
AAraKKe wants to merge 3 commits intomasterfrom
aarakke/phase-0-get-package-dir

Conversation

@AAraKKe
Copy link
Contributor

@AAraKKe AAraKKe commented Feb 27, 2026

Stacked PR 1/4 — This is part of a series to enable file-based YAML metrics loading for OpenMetrics V2 checks, eliminating the need for Python metrics.py modules when the only purpose is simple metric name mapping.

  • Stack 1: PR-22749 _get_package_dir utility on AgentCheck <-- you are here
  • Stack 2: PR-22750 File-based YAML metrics loading infrastructure + composable predicates
  • Stack 3: PR-22751 Krakend migration (proof of concept)
  • Stack 4: PR-22773 Developer documentation for file-based metrics loading

What does this PR do?

Adds a _get_package_dir() method to AgentCheck that resolves the filesystem path of the concrete check subclass's package directory (e.g., datadog_checks/krakend/). This enables base class methods to locate data files shipped alongside integration code.

The method follows the same __module__ + importlib pattern already used by the check_version property.

Motivation

Currently, every OpenMetrics V2 integration defines metric name mappings in a Python metrics.py file, even when the mapping is a simple dict of {"prometheus_name": "dd_name"}. This requires Python code for what is essentially a data declaration.

This PR adds the foundational utility needed to resolve file paths relative to an integration's package directory, which the file-based metrics loading system (PR 2) will use to find and load YAML metric files at runtime.

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.

Add a _get_package_dir() method to AgentCheck that resolves the filesystem
path of the concrete check subclass's package directory. This enables base
class methods to locate data files shipped alongside integration code.

The method follows the same __module__ + importlib pattern already used by
the check_version property.
@AAraKKe AAraKKe added the qa/skip-qa Automatically skip this PR for the next QA label Feb 27, 2026
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 95.23810% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.53%. Comparing base (497171f) to head (f6ae1fd).
⚠️ Report is 13 commits behind head on master.

Additional details and impacted files
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Cache result in self._package_dir to avoid repeated computation
- Use self.__module__ for consistency with check_version
- Fall back to package.__path__[0] for namespace packages
- Raise RuntimeError with descriptive message when neither
  __file__ nor __path__ is available
- Add 4 unit tests covering: return type, caching, namespace
  package fallback, and error case
@AAraKKe AAraKKe marked this pull request as ready for review February 27, 2026 14:52
@AAraKKe AAraKKe requested a review from a team as a code owner February 27, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

base_package qa/skip-qa Automatically skip this PR for the next QA team/agent-integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants