Add _get_package_dir utility method to AgentCheck#22749
Open
Add _get_package_dir utility method to AgentCheck#22749
Conversation
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.
This was referenced Feb 27, 2026
Codecov Report❌ Patch coverage is Additional details and impacted files🚀 New features to boost your workflow:
|
- 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
iliakur
approved these changes
Feb 27, 2026
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a
_get_package_dir()method toAgentCheckthat 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__+importlibpattern already used by thecheck_versionproperty.Motivation
Currently, every OpenMetrics V2 integration defines metric name mappings in a Python
metrics.pyfile, 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)
qa/skip-qalabel if the PR doesn't need to be tested during QA.