Add get_agent_embedded_path helper to base check#23644
Conversation
Resolve paths under the agent's `embedded` directory by reading `run_path` from the agent config instead of assuming the install sits at `/opt/datadog-agent`. Works for both standard installs and Remote-Management installs at `/opt/datadog-packages/datadog-agent/<ver>`. Returns `None` when `run_path` is unset so callers can decide whether the miss is fatal (raise) or skip a fallback. Refs: AI-5681 Follow-up to #20574 which inlined this lookup in glusterfs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
✨ Fix all issues with BitsAI or with Cursor
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files🚀 New features to boost your workflow:
|
… tests Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Use os.path.join when building expected values so backslash path separators on Windows runners no longer break assertions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: acd83145c7
ℹ️ 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".
| install_path = run_path[:-4] if run_path.endswith('/run') else run_path | ||
| return os.path.join(install_path, 'embedded', *parts) |
There was a problem hiding this comment.
Handle Windows embedded paths separately
When this helper is used from a Windows Agent, run_path is the writable cache directory (%ProgramData%\\Datadog\\run, as documented in datadog_checks_base/datadog_checks/base/checks/base.py), not the install directory, and the embedded runtime lives under C:\\Program Files\\Datadog\\Datadog Agent\\embedded3 (the existing FIPS helper switches to embedded3 for os.name == 'nt'). Since this line only strips a literal /run and then appends embedded, it would return a path like %ProgramData%\\Datadog\\run\\embedded\\..., so Windows checks that adopt the new helper will fail to find their bundled certs or binaries.
Useful? React with 👍 / 👎.
On Windows the agent's `run_path` is `%ProgramData%\Datadog\run`, a writable cache directory unrelated to the install directory, so the prior logic of stripping `/run` from `run_path` would have returned a nonsense path. Derive the install directory from `sys.executable` on Windows (the agent's embedded Python lives under the install dir), and use the `embedded3` directory name, matching the existing FIPS helper. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Validation ReportAll 20 validations passed. Show details
|
What does this PR do?
Adds
get_agent_embedded_path(*parts)todatadog_checks_base.utils.agent.common. Readsrun_pathfrom the agent config, strips a trailing/run, and joinsembedded/.... ReturnsNonewhenrun_pathis unset.Motivation
Remote-Management installs live at
/opt/datadog-packages/datadog-agent/<version>/, so hardcoded/opt/datadog-agentpaths silently miss. #20574 fixed this inline forglusterfs; this extracts the logic for reuse acrossglusterfs,kafka_consumer,kafka_actions, andnfsstatin follow-up commits.Jira: AI-5681
Review checklist (to be filled by reviewers)
qa/skip-qalabel if the PR doesn't need to be tested during QA.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged