Skip to content
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

Improve the error message when reserved memory is larger than the available memory #897

Merged
merged 2 commits into from
Jul 25, 2017

Conversation

richardpen
Copy link

@richardpen richardpen commented Jul 19, 2017

Summary

Fix #888

Implementation details

Check the value of memory trying to registered before calling ecs RegisterContainerInstance. And if the value is negative then just emit an error and exit the agent.

Testing

  • Builds on Linux (make release)
  • Builds on Windows (go build -out amazon-ecs-agent.exe ./agent)
  • Unit tests on Linux (make test) pass
  • Unit tests on Windows (go test -timeout=25s ./agent/...) pass
  • Integration tests on Linux (make run-integ-tests) pass
  • Integration tests on Windows (.\scripts\run-integ-tests.ps1) pass
  • Functional tests on Linux (make run-functional-tests) pass
  • Functional tests on Windows (.\scripts\run-functional-tests.ps1) pass

New tests cover the changes:
yes

Description for the changelog

Licensing

This contribution is under the terms of the Apache 2.0 License:
yes

mem = mem - int64(client.config.ReservedMemory)
registeredMem := mem - int64(client.config.ReservedMemory)
if registeredMem < 0 {
return "", fmt.Errorf("Resource memory is less than reserved, total memory: %d, reserved: %d", mem, client.config.ReservedMemory)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you modify the error string to be of the "context: message" format?

"api register-container-instance: reserved memory higher than available memory on the host ..."

Copy link
Contributor

@vsiddharth vsiddharth left a comment

Choose a reason for hiding this comment

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

I'm sorry for nitpicking but the commit message also has typos.

registeredMem := mem - int64(client.config.ReservedMemory)
if registeredMem < 0 {
return "", fmt.Errorf(
"api register-container-instance: reserved memory is higher than available memory on the hos, total memory: %d, reserved: %d",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: hos --> host

@richardpen richardpen force-pushed the fix-888 branch 3 times, most recently from c0c62ea to c9b51ac Compare July 19, 2017 22:58
Copy link
Contributor

@petderek petderek left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -172,7 +173,12 @@ func (client *APIECSClient) registerContainerInstance(clusterRef string, contain
integerStr := "INTEGER"

cpu, mem := getCpuAndMemory()
mem = mem - int64(client.config.ReservedMemory)
registeredMem := mem - int64(client.config.ReservedMemory)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would 'remainingMem' be more appropriate?

Copy link
Contributor

@aaithal aaithal left a comment

Choose a reason for hiding this comment

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

lgtm; i'd vote for modifying this as per petderek@'s comment before merging.

richardpen added 2 commits July 20, 2017 19:42
@aaithal aaithal merged commit 6fdad7e into aws:dev Jul 25, 2017
@jhaynes jhaynes mentioned this pull request Aug 22, 2017
@samuelkarp samuelkarp added this to the 1.14.4 milestone Aug 22, 2017
@richardpen richardpen deleted the fix-888 branch November 21, 2017 01:00
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.

5 participants