Repository navigation
fix(profiles): check that the agent stays up without NRestarts or --value - #805
Open
fedeghiglio wants to merge 1 commit into
Open
fedeghiglio wants to merge 1 commit into
fedeghiglio wants to merge 1 commit into
Conversation
…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.
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.
Description of the issue
otel_collect_linux_profiles_testfails on every run on AL2 (amd64 and arm64), although the agent stays up.ProfilesCap_AgentStaysUpreads the agent unit withsystemctl show -p MainPID -p NRestarts -p ActiveState amazon-cloudwatch-agent. The systemd on AL2 (219) has noNRestartsproperty, so the command printsMainPID=<pid>andActiveState=activeand then exits 1, and the check fails withsystemctl 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
agent_process.gowith onereadAgentProcessthat both checks use. It readsMainPIDandActiveState, which every supported systemd reports, and readsNRestartswith a separate query that may fail.MainPIDis the restart proof on every distro.ProfilesCap_AgentStaysUpcompares the restart count only when systemd reports it.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
TestReadAgentProcess,TestAgentPIDOnAL2andTestCheckAgentStaysUp(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_NRestartsandTestAgentPIDOnAL2fail.gofmtandgo vetare clean.ProfilesCap_AgentStaysUpisSuccessfulon both, and the other-signals check now reads the agent PID (pid 19555,pid 13695) instead of an empty one.