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

Fix CPUPercent for windows and add functional test #1089

Merged
merged 2 commits into from
Nov 17, 2017

Conversation

richardpen
Copy link

@richardpen richardpen commented Nov 17, 2017

Summary

  • Fix CPUPercent for windows
  • Add functional test for cpu percent

Implementation details

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
  • Manual test on windows
    New tests cover the changes:
    yes

Description for the changelog

Licensing

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

Copy link
Contributor

@samuelkarp samuelkarp left a comment

Choose a reason for hiding this comment

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

Mostly looks good, some minor comments.

@@ -62,7 +62,12 @@ func getCanonicalPath(path string) string {
// passed to Docker API.
func (task *Task) platformHostConfigOverride(hostConfig *docker.HostConfig) error {
task.overrideDefaultMemorySwappiness(hostConfig)
hostConfig.CPUPercent = hostConfig.CPUShares / int64(cpuShareScaleFactor)
// Convert the CPUShares to CPUPercent
hostConfig.CPUPercent = hostConfig.CPUShares * 100 / int64(cpuShareScaleFactor)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the 100 here? Please make a named constant expressing what this is.

Copy link
Author

Choose a reason for hiding this comment

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

CPUPercent is the integer of percentage, this is the conversion: 25% -> 25

@@ -266,36 +266,36 @@ func DeleteCluster(t *testing.T, clusterName string) {

// VerifyMetrics whether the response is as expected
// the expected value can be 0 or positive
func VerifyMetrics(cwclient *cloudwatch.CloudWatch, params *cloudwatch.GetMetricStatisticsInput, idleCluster bool) error {
func VerifyMetrics(cwclient *cloudwatch.CloudWatch, params *cloudwatch.GetMetricStatisticsInput, idleCluster bool) (error, *cloudwatch.Datapoint) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please reorder the return to be (*cloudwatch.Datapoint, error).


tdOverrides := make(map[string]string)
// Set the container cpu percentage 25%
tdOverrides["$$$$CPUSHARE$$$$"] = strconv.Itoa(cpuNum * 1024 / 4)
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 * 0.25 instead of / 4 so that it's clearer with respect to your comment?

Can you add a constant for 1024? cpuSharesPerCore would be reasonable.

assert.NoError(t, err, "Task is running, verify metrics for CPU utilization failed")
// Also verify the cpu usage is around 25%
assert.True(t, *metrics.Average < 0.3)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use assert.InDelta.

assert.InDelta(t, 0.25, *metrics.Average, 0.05)

@@ -0,0 +1,24 @@
package main
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs the license header.

WORKDIR /gopath
COPY main.go .

CMD ["go", "run", "main.go", "-concurrency", "1000"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why compile it at runtime?

RUN go build main.go -o cpuhog
ENTRYPOINT ["./cpuhog"]
CMD ["-concurrency", "1000"]

@richardpen richardpen merged commit f00e273 into aws:windows Nov 17, 2017
@richardpen richardpen deleted the functional-test branch November 21, 2017 01:01
@samuelkarp samuelkarp mentioned this pull request Nov 22, 2017
8 tasks
@samuelkarp samuelkarp added this to the 1.16.0 milestone Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants