-
Notifications
You must be signed in to change notification settings - Fork 617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persist container exit code in agent state file #1125
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I missed this in my comments. Can you please add a changelog entry as well? Example: 6527d7d#diff-4ac32a78649ca5bdd8e0ba38b7006a1eR4 |
Container exit code needs to be persisted in the agent state file so that api.Container structs can be rebuilt after agent restarts. Go's default JSON encoder marshals only public fields. Rename and export KnownExitCodeUnsafe with proper JSON marking. Add test to ensure exit code is persisted and catch any regressions. Fix existing test panics caused by continuing after fatal nil checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ship it.
// the JSON body while saving the state. | ||
// NOTE: Do not access KnownExitCodeUnsafe directly. Instead, use `GetKnownExitCode` | ||
// and `SetKnownExitCode`. | ||
KnownExitCodeUnsafe *int `json:"KnownExitCode"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may also bump the state file version here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the KnownExitCode was part of the state file since the beginning. It was recently accidentally removed, this change is just putting it back in. So I thought I shouldn't bump the version?
Summary
Container exit code needs to be persisted in the agent state file so
that api.Container structs can be rebuilt after agent restarts. Go's
default JSON encoder marshals only public fields. This PR renames
and exports that field, updates access functions and adds a test case
for exercising the new logic.
Future work: We should write a custom marshaler for container class
so that we don't have to expose internal state. Since this improvement
is not specific to exit code, I chose to fix it first, and implement the
custom marshaler in a later commit.
Implementation details
Testing
make release
)go build -out amazon-ecs-agent.exe ./agent
)make test
) passgo test -timeout=25s ./agent/...
) passmake run-integ-tests
) pass.\scripts\run-integ-tests.ps1
) passmake run-functional-tests
) pass.\scripts\run-functional-tests.ps1
) passNew tests cover the changes: yes
Description for the changelog
Bug - Persist container exit code in agent state file
Licensing
This contribution is under the terms of the Apache 2.0 License: yes
Fixes #986