Skip to content

Add get_agent_embedded_path helper to base check#23644

Open
Kyle-Neale wants to merge 5 commits into
masterfrom
kyle.neale/agent-embedded-path
Open

Add get_agent_embedded_path helper to base check#23644
Kyle-Neale wants to merge 5 commits into
masterfrom
kyle.neale/agent-embedded-path

Conversation

@Kyle-Neale
Copy link
Copy Markdown
Contributor

@Kyle-Neale Kyle-Neale commented May 8, 2026

What does this PR do?

Adds get_agent_embedded_path(*parts) to datadog_checks_base.utils.agent.common. Reads run_path from the agent config, strips a trailing /run, and joins embedded/.... Returns None when run_path is unset.

Motivation

Remote-Management installs live at /opt/datadog-packages/datadog-agent/<version>/, so hardcoded /opt/datadog-agent paths silently miss. #20574 fixed this inline for glusterfs; this extracts the logic for reuse across glusterfs, kafka_consumer, kafka_actions, and nfsstat in follow-up commits.

Jira: AI-5681

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

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>
@datadog-prod-us1-4
Copy link
Copy Markdown
Contributor

datadog-prod-us1-4 Bot commented May 8, 2026

Tests

Fix all issues with BitsAI or with Cursor

⚠️ Warnings

🧪 4 Tests failed

❄️ Known flaky: test_e2e_core_vs_python_profile_f5_big_ip from test_e2e_core_vs_python.py   View in Datadog   (Fix with Cursor)
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 01-check-apikey.sh: executing... 
[cont-init.d] 01-check-apikey.sh: exited 0.
[cont-init.d] 50-ci.sh: executing... 
[cont-init.d] 50-ci.sh: exited 0.
[cont-init.d] 50-ecs-managed.sh: executing... 
...
test_e2e_profile_apc_ups_user from test_e2e_core_vs_python.py   View in Datadog   (Fix with Cursor)
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 01-check-apikey.sh: executing... 
[cont-init.d] 01-check-apikey.sh: exited 0.
[cont-init.d] 50-ci.sh: executing... 
[cont-init.d] 50-ci.sh: exited 0.
[cont-init.d] 50-ecs-managed.sh: executing... 
...
❄️ Known flaky: test_e2e_regex_match from test_e2e_core_vs_python.py   View in Datadog   (Fix with Cursor)
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 01-check-apikey.sh: executing... 
[cont-init.d] 01-check-apikey.sh: exited 0.
[cont-init.d] 50-ci.sh: executing... 
[cont-init.d] 50-ci.sh: exited 0.
[cont-init.d] 50-ecs-managed.sh: executing... 
...
test_check_hugging_face_tgi_e2e from test_e2e.py   View in Datadog   (Fix with Cursor)
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 01-check-apikey.sh: executing... 
[cont-init.d] 01-check-apikey.sh: exited 0.
[cont-init.d] 50-ci.sh: executing... 
[cont-init.d] 50-ci.sh: exited 0.
[cont-init.d] 50-ecs-managed.sh: executing... 
...
View all

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 87.38%

Useful? React with 👍 / 👎

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.90%. Comparing base (57b7286) to head (603a539).
⚠️ Report is 11 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.

@Kyle-Neale Kyle-Neale changed the title [base] Add get_agent_embedded_path helper Add get_agent_embedded_path helper to base check May 11, 2026
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>
@Kyle-Neale Kyle-Neale marked this pull request as ready for review May 12, 2026 13:36
@Kyle-Neale Kyle-Neale requested a review from a team as a code owner May 12, 2026 13:36
Copy link
Copy Markdown

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

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: 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".

Comment on lines +26 to +27
install_path = run_path[:-4] if run_path.endswith('/run') else run_path
return os.path.join(install_path, 'embedded', *parts)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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>
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 12, 2026

Validation Report

All 20 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and Codecov 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
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

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.

1 participant