Skip to content

fix(profiles): check that the agent stays up without NRestarts or --value - #805

Open
fedeghiglio wants to merge 1 commit into
mainfrom
fix/profiles-al2-systemd
Open

fedeghiglio wants to merge 1 commit into
mainfrom
fix/profiles-al2-systemd

Conversation

@fedeghiglio

Copy link
Copy Markdown

Description of the issue

otel_collect_linux_profiles_test fails on every run on AL2 (amd64 and arm64), although the agent stays up.

ProfilesCap_AgentStaysUp reads the agent unit with systemctl show -p MainPID -p NRestarts -p ActiveState amazon-cloudwatch-agent. The systemd on AL2 (219) has no NRestarts property, so the command prints MainPID=<pid> and ActiveState=active and then exits 1, and the check fails with systemctl show amazon-cloudwatch-agent: exit status 1.

The other-signals check in the same package reads the PID with systemctl show -p MainPID --value, and AL2's systemctl rejects that flag (systemctl: unrecognized option '--value'). It gets an empty PID and silently skips its restart comparison, so on AL2 that check never ran.

Description of changes

  • Adds agent_process.go with one readAgentProcess that both checks use. It reads MainPID and ActiveState, which every supported systemd reports, and reads NRestarts with a separate query that may fail.
  • An unchanged MainPID is the restart proof on every distro. ProfilesCap_AgentStaysUp compares the restart count only when systemd reports it.
  • The other-signals check reads the PID through the same helper, so its restart comparison now runs on AL2 too.
  • Command execution goes through a package variable so unit tests can simulate AL2's systemctl.

No change to the checks on distros with a newer systemd.

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

  • New unit tests simulate AL2's systemctl: TestReadAgentProcess, TestAgentPIDOnAL2 and TestCheckAgentStaysUp (unchanged PID passes; a changed PID, a changed restart count or an inactive unit fails). With the previous commands put back, TestReadAgentProcess/AL2_systemd_without_NRestarts and TestAgentPIDOnAL2 fail.
  • All unit tests in the package pass, and gofmt and go vet are clean.
  • Integration run with this branch on AL2, filtered to this test (https://github.com/aws/amazon-cloudwatch-agent/actions/runs/42836848688): amd64 and arm64 both pass. ProfilesCap_AgentStaysUp is Successful on both, and the other-signals check now reads the agent PID (pid 19555, pid 13695) instead of an empty one.

…alue

The systemd on AL2 (219) has no NRestarts property and no `systemctl show
--value` flag. `systemctl show -p MainPID -p NRestarts -p ActiveState`
exits 1 there, so ProfilesCap_AgentStaysUp failed on AL2 amd64 and arm64
although the agent kept the same MainPID and stayed active. The other
signals check read the PID with `--value`, got an empty PID on AL2 and
silently skipped its restart comparison.

Read MainPID and ActiveState on their own, which every supported systemd
reports, and NRestarts with a separate query that may fail. An unchanged
MainPID stays the restart proof everywhere; the restart count is compared
only where systemd reports it. Both checks now share readAgentProcess.

Unit tests simulate AL2's systemctl and fail on the previous commands.
@fedeghiglio
fedeghiglio requested a review from a team as a code owner November 10, 2026 15:11
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.

1 participant