Skip to content

Fix Ping check on Linux with a non-English locale by running ping with LC_ALL=C - #3306

Open
JunShibata-Datadog wants to merge 2 commits into
masterfrom
jun.shibata/ping-force-c-locale
Open

JunShibata-Datadog wants to merge 2 commits into
masterfrom
jun.shibata/ping-force-c-locale

Conversation

@JunShibata-Datadog

Copy link
Copy Markdown

What does this PR do?

Runs ping with LC_ALL=C on Linux and macOS so its output is always untranslated.

get_subprocess_output is now given an env. The Agent replaces the child's whole environment when env is set (cmd.Env = subprocessEnv in pkg/collector/python/util.go), so the check copies os.environ and only overrides LC_ALL. The Agent's own environment is not modified. The Windows path (_exec_ping_windows) is unchanged.

Motivation

When the Agent runs with a non-English locale, ping (iputils) translates its output, including the ms unit. For example, with LANG=ja_JP.UTF-8 (systemd passes the system locale from /etc/locale.conf to datadog-agent.service):

64 バイト応答 送信元 127.0.0.1: icmp_seq=1 ttl=127 時間=0.019ミリ秒
rtt min/avg/max/mdev = 0.019/0.019/0.019/0.000 ms

Neither time[<=]... nor the [<=]\s*([\d.]+)\s*ms fallback added in #3075 matches, so the check raises No response time found and reports a reachable host as CRITICAL. The fallback works on Windows because Windows keeps ms untranslated; Linux does not.

Review checklist

  • PR has a meaningful title or PR has the no-changelog label attached
  • Feature or bugfix has tests
  • Git history is clean
  • If PR impacts documentation, docs team has been notified or an issue has been opened on the documentation repo
  • If this PR includes a log pipeline, please add a description describing the remappers and processors.

Additional Notes

  • Added test_unix_ping_runs_with_c_locale. It checks that ping gets LC_ALL=C with the rest of the environment kept, and that the Agent's environment is unchanged. It fails without the fix (KeyError: 'env').
  • Tested with real ping in an amazonlinux:2023 container with glibc-langpack-ja and LANG=ja_JP.UTF-8: test_integration_response_time fails without the fix and passes with it.
  • The changelog entry uses version 1.0.5, following Fix Ping check on non-English Windows by decoding with the OEM code page #3092. The version bump can follow in a separate PR, as with Bump ping version to 1.0.4 #3098.

🤖 Generated with Claude Code

…h LC_ALL=C

When the Agent runs with a non-English locale (for example LANG=ja_JP.UTF-8,
which systemd passes to the service from /etc/locale.conf), ping translates
its output, including the "ms" unit ("時間=0.019ミリ秒"). Neither response-time
regex matches, so the check fails with "No response time found" and reports
reachable hosts as down.

Run ping with LC_ALL=C on non-Windows platforms. The Agent replaces the whole
child environment when env is given, so copy os.environ first; the Agent's
own environment is not modified.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dd-octo-sts

dd-octo-sts Bot commented Nov 26, 2026

Copy link
Copy Markdown

Validation Report

All 11 validations passed.

Show details
Validation Description Status
ci Validate CI configuration and code coverage settings ✅
codeowners Validate every integration has a CODEOWNERS entry ✅
config Validate default configuration files against spec.yaml ✅
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 ✅
legacy-signature Validate no integration uses the legacy Agent check signature ✅
metadata Validate metadata.csv metric definitions ✅
models Validate configuration data models match spec.yaml ✅
package Validate Python package metadata, naming, and wheel contents ✅
readmes Validate README files have required sections ✅

View full run

@datadog-prod-us1-6

Copy link
Copy Markdown

Pipelines  Code Coverage

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 93.48% (+7.43%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 4c72d1d | Docs | Give us feedback!

@janine-c janine-c left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks awesome, just some minor writing suggestions (feel free to ignore if I introduced any inaccuracies!)

Comment thread ping/CHANGELOG.md

***Fixed***:

* Fix the Ping check reporting reachable hosts as down on Linux and macOS when the Agent runs with a non-English locale (for example ``LANG=ja_JP.UTF-8``). ping translated its output, including the ``ms`` unit, so no response time was found. The check now runs ping with ``LC_ALL=C`` ([#3306](https://github.com/DataDog/integrations-extras/pull/3306)).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Fix the Ping check reporting reachable hosts as down on Linux and macOS when the Agent runs with a non-English locale (for example ``LANG=ja_JP.UTF-8``). ping translated its output, including the ``ms`` unit, so no response time was found. The check now runs ping with ``LC_ALL=C`` ([#3306](https://github.com/DataDog/integrations-extras/pull/3306)).
* Fix the ping check so it reports reachable hosts as down on Linux and macOS when the Agent runs with a non-English locale (for example, ``LANG=ja_JP.UTF-8``). It translated the output, including the ``ms`` unit, so it didn't properly report a response time. The check now runs ping with ``LC_ALL=C`` ([#3306](https://github.com/DataDog/integrations-extras/pull/3306)).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants