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

Set router skip clean to false #1844

Merged
merged 1 commit into from
Feb 14, 2019
Merged

Set router skip clean to false #1844

merged 1 commit into from
Feb 14, 2019

Conversation

suneyz
Copy link
Contributor

@suneyz suneyz commented Feb 13, 2019

Summary

This enables agent to handle request like "//v2/credential" correctly. This brings back the support for //path that agent version 1.20.3 or before
#1839

Implementation details

set router skip clean to false
doc for skip clean https://godoc.org/github.com/gorilla/mux#Router.SkipClean

Testing

New tests cover the changes:

yes,

unit test, functional test

Description for the changelog

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@suneyz suneyz requested a review from a team February 13, 2019 02:10
@samuelkarp
Copy link
Contributor

New tests cover the changes:

I don't see any tests in the pull request. Can you add a functional test covering this change?

@yhlee-aws
Copy link
Contributor

v3 tests are failing, is this causing different regression?
TestTaskHTTPEndpointErrorCode404 (0.02s)
TestTaskHTTPEndpointErrorCode404/Test_path:/v3///task/
TestTaskHTTPEndpointErrorCode400
TestTaskHTTPEndpointErrorCode400/Test_path:
/v3//stats
TestTaskHTTPEndpointErrorCode400/Test_path:/v3//task
TestTaskHTTPEndpointErrorCode400/Test_path:
/v3//task/stats

@suneyz
Copy link
Contributor Author

suneyz commented Feb 13, 2019

New tests cover the changes:

I don't see any tests in the pull request. Can you add a functional test covering this change?

Great call out! Added tests, there is actually unit tests that covers router

@samuelkarp
Copy link
Contributor

Can you add a functional test as well?

@suneyz
Copy link
Contributor Author

suneyz commented Feb 14, 2019

Can you add a functional test as well?

updated with functional tests

@@ -0,0 +1,7 @@
FROM ubuntu:latest
Copy link
Contributor

Choose a reason for hiding this comment

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

Locking this to a version would be a good idea. We are using 16.04 at other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense :)

@@ -1101,11 +1128,11 @@ func TestTaskHTTPEndpointErrorCode400(t *testing.T) {
"/v3/wrong-v3-endpoint-id",
"/v3/",
"/v3/wrong-v3-endpoint-id/stats",
"/v3//stats",
"/v3/stats",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this changed? Shouldn't "/v3//stats" work as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we handle double/muti slash with a redirect prior to 1.20.3 release. at 1.21.0 release we changed the router and added the behavior to not clean double/multi slash. This is the root cause of this issue #1839.

"networkMode": "host",
"containerDefinitions": [{
"image": "127.0.0.1:51670/amazon/task-server-endpoint-validator:latest",
"name": "container_1",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: rename this to a more descripritive one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you have a suggestion? i thought the task definition and image name is descriptive enough and i didn't want to introduce similar/same name to cause confusion as it is the only container in the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah what about something like task_server_endpoint_validator_container? 🤔

muxRouter.SkipClean(true)
// Set this to false so that for request like "//v3//metadata/task"
// to permanently redirect(301) to "/v3/metadata/task" handler
muxRouter.SkipClean(false)
Copy link
Member

@fierlion fierlion Feb 14, 2019

Choose a reason for hiding this comment

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

Since this defaults to false (from the docs: SkipClean defines the path cleaning behaviour for new routes. The initial value is false.) I initially wondered if we even need the explicit setting here.
But I like it here. It's deliberate.
I would make the comment clearer (like the one in the docs: When false, the path will be cleaned, so //v3//metadata/task will become /v3/metadata/task)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think a 301 redirect is more clear as it is not "becoming" the new url. it is a specific 301 redirect to the new url. let me know how you think

Copy link
Member

Choose a reason for hiding this comment

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

I see w.WriteHeader(http.StatusMovedPermanently) aka 301. Cool.

@@ -1427,3 +1427,45 @@ func TestElasticInferenceValidator(t *testing.T) {
exitCode, _ := task.ContainerExitcode("container_1")
assert.Equal(t, 42, exitCode, fmt.Sprintf("Expected exit code of 42 for container; got %d", exitCode))
}

// TestServerEndpointValidator tests the workflow of task server endpoint
func TestServerEndpointValidator(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a particular reason you hand-wrote this code instead of using the simpletests package? I would recommend using that instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it is for setting the task iam roles configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed with Sam offline, we might not need network mode setup for it to work.

But I'm thinking for now, let's keep test file as hand-written to release it today to solve our customers' issue. I will keep troubleshooting to see if I can make functional test work with simpletests file

Copy link
Contributor

Choose a reason for hiding this comment

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

Task IAM roles are supported with "host", "bridge", and "awsvpc" network modes, and we have existing functional tests that validate this. There should not be a dependency on using the "host" network mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Read some document, agree on this should not depend on host mode. I will dive deep to see if my host needs some config to make it functional test on other modes, and I will follow up with another pr to address it once i get it figured out.

@@ -0,0 +1,7 @@
FROM ubuntu:latest
Copy link
Contributor

Choose a reason for hiding this comment

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

If you use an image like busybox which already includes wget or an image like amazonlinux:2 which already includes curl, you can avoid having to construct a new image and instead can just override the command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

awesome! will change it to al2 image

@@ -45,7 +45,7 @@ mirror_local_image() {
docker rmi $2
}

for image in "amazon/amazon-ecs-netkitten" "amazon/amazon-ecs-volumes-test" "amazon/amazon-ecs-pid-namespace-test" "amazon/amazon-ecs-ipc-namespace-test" "amazon/squid" "amazon/awscli" "amazon/image-cleanup-test-image1" "amazon/image-cleanup-test-image2" "amazon/image-cleanup-test-image3" "amazon/fluentd" "amazon/amazon-ecs-agent-introspection-validator" "amazon/amazon-ecs-taskmetadata-validator" "amazon/amazon-ecs-v3-task-endpoint-validator" "amazon/amazon-ecs-container-metadata-file-validator" "amazon/amazon-ecs-elastic-inference-validator"; do
for image in "amazon/amazon-ecs-netkitten" "amazon/amazon-ecs-volumes-test" "amazon/amazon-ecs-pid-namespace-test" "amazon/amazon-ecs-ipc-namespace-test" "amazon/squid" "amazon/awscli" "amazon/image-cleanup-test-image1" "amazon/image-cleanup-test-image2" "amazon/image-cleanup-test-image3" "amazon/fluentd" "amazon/amazon-ecs-agent-introspection-validator" "amazon/amazon-ecs-taskmetadata-validator" "amazon/amazon-ecs-v3-task-endpoint-validator" "amazon/amazon-ecs-container-metadata-file-validator" "amazon/amazon-ecs-elastic-inference-validator" "amazon/task-server-endpoint-validator"; do
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it is trivial but I am wondering why this diff is the only line that specific changes are not highlighted in the deeper green for "amazon/task-server-endpoint-validator"? Or just it happens once in a while...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure, maybe it is a github bug lol

@sharanyad
Copy link
Contributor

could you please shorten the commit message to 75 characters or less?
You could a description in a different line below if needed.
Example commit message: c140bd3

This will  redirect request like //v2/credential to /v2/credential for the correct handler to handle it
@suneyz
Copy link
Contributor Author

suneyz commented Feb 14, 2019

could you please shorten the commit message to 75 characters or less?
You could a description in a different line below if needed.
Example commit message: c140bd3

Will do

@suneyz suneyz added bot/test and removed bot/test labels Feb 14, 2019
Copy link
Contributor

@sharanyad sharanyad left a comment

Choose a reason for hiding this comment

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

once tests pass

@suneyz
Copy link
Contributor Author

suneyz commented Feb 14, 2019

failed on flaky test TestDockerStopTimeout for both linux and arm. merge the change

@suneyz suneyz merged commit fc92bf4 into aws:dev Feb 14, 2019
@suneyz suneyz added this to the 1.25.3 milestone Feb 14, 2019
@aaithal
Copy link
Contributor

aaithal commented Feb 14, 2019

failed on flaky test TestDockerStopTimeout for both linux and arm. merge the change

Is there an issue tracking that? How long can we expect these tests to be flaky?

@suneyz
Copy link
Contributor Author

suneyz commented Feb 14, 2019

failed on flaky test TestDockerStopTimeout for both linux and arm. merge the change

Is there an issue tracking that? How long can we expect these tests to be flaky?

It is tracked in our sprint board.

@aaithal
Copy link
Contributor

aaithal commented Feb 14, 2019

It is tracked in our sprint board.

Can you please create an issue in this repo because that's where we track these things? That way, you can tie that into releases, track when it surfaced, when it was fixed etc. Also, as a customer, or as someone who doesn't have visibility into your sprint board, it's hard to track if there's nothing in the github repo related to that.

@suneyz
Copy link
Contributor Author

suneyz commented Feb 14, 2019

It is tracked in our sprint board.

Can you please create an issue in this repo because that's where we track these things? That way, you can tie that into releases, track when it surfaced, when it was fixed etc. Also, as a customer, or as someone who doesn't have visibility into your sprint board, it's hard to track if there's nothing in the github repo related to that.

Github issue created. #1855

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants