Skip to content

Pull host spoofing logic into an http client#1458

Merged
google-prow-robot merged 1 commit intoknative:masterfrom
jonjohnsonjr:spoofing-client
Jul 3, 2018
Merged

Pull host spoofing logic into an http client#1458
google-prow-robot merged 1 commit intoknative:masterfrom
jonjohnsonjr:spoofing-client

Conversation

@jonjohnsonjr
Copy link
Copy Markdown
Contributor

This little abstraction hoists the hostname spoofing into its own http
client so that it is reusable outside of the context of waiting for an
endpoint to return a specific response.

@google-prow-robot google-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 3, 2018
@jonjohnsonjr jonjohnsonjr changed the title Pull host spoofing logc into an http client Pull host spoofing logic into an http client Jul 3, 2018
@jonjohnsonjr
Copy link
Copy Markdown
Contributor Author

/assign @tcnghia @bobcatfish

@adrcunha
Copy link
Copy Markdown
Contributor

adrcunha commented Jul 3, 2018

Nice!

/approve
/lgtm
/woof
/hold

Holding so @bobcatfish can take a look.

@google-prow-robot
Copy link
Copy Markdown

@adrcunha: dog image

Details

In response to this:

Nice!

/approve
/lgtm
/woof
/hold

Holding so @bobcatfish can take a look.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@google-prow-robot google-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed lgtm Indicates that a PR is ready to be merged. labels Jul 3, 2018
@adrcunha
Copy link
Copy Markdown
Contributor

adrcunha commented Jul 3, 2018

/lgtm

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 3, 2018
@jonjohnsonjr
Copy link
Copy Markdown
Contributor Author

/hold

Going to pull this into a separate file per #1460 (comment)

Copy link
Copy Markdown
Contributor

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

Can you also update the docs in adding_tests.md? some description of this interface there might make this all crystal clear (helps for a review too! cuz then i can start with the docs before diving into the nitty gritty

Comment thread test/request.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the idea of exposing a polling interface that is specifically oriented around polling response objects safely.

It took me a while (and talking with you) to understand why bodyMatcher is replacing the body of the response after reading it, but now that I understand (it's so you can poll it without changing it, and also so you can return the response object untarnished), what do you think about this idea: what if the interface to inState (i.e. the ResponseChecker) took a different object, not the actual response, but a response object you have constructed that contains the body of the response, the error code, etc.? then ppl can do whatever they want to it in inState without causing side effects (in the currently implementation, there's nothing to stop someone from avoiding bodyMatcher and doing all kinds of terrible things to the response in their inState - maybe by accident!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh. I like this!

Comment thread test/request.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the comment describing this function could have more detail about the assumed interface, e.g. details such as the response body should not be consumed (or maybe that wont be a problem, see above), and what is returned (or you could include more of this in adding_tests.md)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll add a longer comment to the ResponseChecker type, let me know if that does not address your concern here.

Comment thread test/request.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

two things i am not so fond of here:

  1. I find it very hard to tell the difference between bodyMatcher, matchesBody and eventuallyMatchesBody based on name and docs (esp. eventuallyMatchesBody b/c from the name and description i thought that function itself was doing polling)
  2. I don't like it that these have been made with a specific usage in mind: being invoked in a polling method, but also are intended to be used in a non-polling context. i'd prefer if the part that is going to be used in a non-polling context was factored out and the poll-ready interface was only used when polling is involved

Copy link
Copy Markdown
Contributor Author

@jonjohnsonjr jonjohnsonjr Jul 3, 2018

Choose a reason for hiding this comment

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

bodyMatcher

This should mostly go away with your other suggestion.

used in a non-polling context

Yeah this was a bit of a shortcut, I'll break these down.

@google-prow-robot google-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 3, 2018
@jonjohnsonjr
Copy link
Copy Markdown
Contributor Author

/assign @mattmoor

@jonjohnsonjr
Copy link
Copy Markdown
Contributor Author

I welcome any and all bikeshedding for names :)

@mattmoor
Copy link
Copy Markdown
Member

mattmoor commented Jul 3, 2018

/lgtm
/approve

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 3, 2018
Copy link
Copy Markdown
Contributor

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

Looking good! Still would love to see some docs in adding_tests.md :D

/lgtm
/approve
/meow space
/hold

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

😎

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how do you feel about these timeouts being the SAME values in multiple files but also duplicated everywhere? i dont have any good ideas what else to do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't understand, can you elaborate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

part of why you dont understand is that i derped - i thought you were adding a new set of timeouts.

as it stands these will only exist here but then also in crd_checks - i guess 2 spots isnt so bad

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

niiiice 😎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

😎

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this a pattern people use? ive never seen this before so it seems strange to me but im probably not used to it!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

im interested in why this is called Interface instead of something like SpoofingClientInterface

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To avoid the stutter. If another package wants to implement this, I prefer spoof.Interface to spoof.SpoofingClientInterface. If this ends up with more than one interface, I'd readily change it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

okee dokee, thanks for explaining

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should probably have some docs/comments somewhere that explain the scope for this, e.g. this is cant be reused for multiple Ingresses (tied to an ingress)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea, thanks.

Comment thread test/request.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how about something like:

"EventuallyMatchesBody is the same as MatchesBody, but will return false, nil if the response does not match, which will prompt polling methods such as SpoofingClient.Poll to retry the request"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've incorporated your comment and changed the structure of EventuallyMatchesBody to mirror MatchesBody so that it's easier to compare them. I also added a comment describing the behavior of each failure condition to make it explicit why the false case does what it does.

WDYT?

@google-prow-robot
Copy link
Copy Markdown

@bobcatfish: cat image

Details

In response to this:

Looking good! Still would love to see some docs in adding_tests.md :D

/lgtm
/approve
/meow space
/hold

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@google-prow-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adrcunha, bobcatfish, jonjohnsonjr, mattmoor

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-prow-robot google-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 3, 2018
This little abstraction hoists the hostname spoofing into its own http
client so that it is reusable outside of the context of waiting for an
endpoint to return a specific response.
Copy link
Copy Markdown
Contributor Author

@jonjohnsonjr jonjohnsonjr left a comment

Choose a reason for hiding this comment

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

I think that's everything, please LMK if I missed anything. Thanks for the review 🤸‍♂️

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

😎

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

😎

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To avoid the stutter. If another package wants to implement this, I prefer spoof.Interface to spoof.SpoofingClientInterface. If this ends up with more than one interface, I'd readily change it.

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea, thanks.

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't understand, can you elaborate?

Comment thread test/request.go Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've incorporated your comment and changed the structure of EventuallyMatchesBody to mirror MatchesBody so that it's easier to compare them. I also added a comment describing the behavior of each failure condition to make it explicit why the false case does what it does.

WDYT?

@jonjohnsonjr
Copy link
Copy Markdown
Contributor Author

/hold cancel

This should be ready for a final look @bobcatfish 👍

@google-prow-robot google-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 3, 2018
Copy link
Copy Markdown
Contributor

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

/lgtm

EXCITING

Comment thread test/adding_tests.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

niiiiiice

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

part of why you dont understand is that i derped - i thought you were adding a new set of timeouts.

as it stands these will only exist here but then also in crd_checks - i guess 2 spots isnt so bad

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

okee dokee, thanks for explaining

Comment thread test/spoof/spoof.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😱

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 3, 2018
@google-prow-robot google-prow-robot merged commit 562140f into knative:master Jul 3, 2018
@jonjohnsonjr jonjohnsonjr deleted the spoofing-client branch July 3, 2018 23:20
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/knative-serving that referenced this pull request Oct 3, 2025
…e-v1.16

[release-v1.16] Update OWNERS file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants