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

pkg/ansible/proxy; Integrate caching to AO proxy #760

Merged
merged 16 commits into from
Dec 4, 2018

Conversation

dymurray
Copy link
Contributor

@dymurray dymurray commented Nov 19, 2018

Description of the change:
This change passes in the manager's cache into the proxy to prevent spamming APIserver with GET requests.

Motivation for the change:
Performance enhancements

Metrics
1000 sequential requests against a resource.
Before changes:

1m1.615s

After changes:

0m15.547s

Overall this is a ~75% reduction in the time it takes to GET resources from the cluster.

TODO

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 19, 2018
@openshift-ci-robot
Copy link

Hi @dymurray. Thanks for your PR.

I'm waiting for a operator-framework member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

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.

@dymurray
Copy link
Contributor Author

I think it makes sense to rename the handler function... thoughts on changing InjectOwnerReferenceHandler to RequestHandler or something more generic?

pkg/ansible/proxy/proxy.go Outdated Show resolved Hide resolved
pkg/ansible/proxy/proxy.go Outdated Show resolved Hide resolved
@shawn-hurley shawn-hurley added the language/ansible Issue is related to an Ansible operator project label Nov 19, 2018
@dymurray
Copy link
Contributor Author

TODO: Working on adding tests to the proxy

@joelanford
Copy link
Member

I think it makes sense to rename the handler function... thoughts on changing InjectOwnerReferenceHandler to RequestHandler or something more generic?

Another option could be to put the caching logic into a separate handler, since it doesn't look like it's used for the owner reference injection. Then we can add both to the HandlerChain

@shawn-hurley mentioned adding another handler at some point that automatically registers new watches for resources created by the ansible run, so that could be a third handler that gets added to the chain.

@dymurray dymurray changed the title [WIP] pkg/ansible/proxy; Integrate caching to AO proxy pkg/ansible/proxy; Integrate caching to AO proxy Nov 20, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 20, 2018
@dymurray
Copy link
Contributor Author

@joelanford Makes sense to me. If others agree I'm happy to make that change.

@shawn-hurley
Copy link
Member

I do like the idea of a handler chain. This would make turning off one or the other of the handlers easier as well.

if you want to do this as a follow-on I would be ok, if it is going to take minimal time and you can still use the tests that you wrote then if you could that would be awesome!

@joelanford sound good to you?

"sigs.k8s.io/controller-runtime/pkg/manager"
)

func TestHandler(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that instead of running the proxy, I think using this package would be the correct approach: https://golang.org/pkg/net/http/httptest/ to test the server and request

I would also like to see some tests using a fake cache and testing the correct logic.

https://godoc.org/k8s.io/client-go/tools/cache/testing#FakeControllerSource
and
https://godoc.org/sigs.k8s.io/controller-runtime/pkg/cache/informertest#FakeInformers

Lastly, if the test cases could look like the table driven tests

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'm having a lot of trouble integrating this. Will speak with you tomorrow about it.

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"

"k8s.io/klog"
Copy link
Member

@shawn-hurley shawn-hurley Nov 21, 2018

Choose a reason for hiding this comment

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

we should change this to use logr (edit to state the correct logger)

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 used logf from controller-runtime since that is what the proxy is using, is there anything wrong with that approach? Wasn't sure the benefits of using logr.


// Set X-Cache header to signal that response is served from Cache
w.Header().Set("X-Cache", "HIT")
// Pretty printing when hitting apiserver from CLI
Copy link
Member

Choose a reason for hiding this comment

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

Should there be a user agent check here to determine if the client is a human at a CLI?

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 could, is there a benefit to not indenting the JSON if this isn't a human from a CLI? My comment didn't intend to imply we only want to indent for pretty printing to a CLI, I was simply trying to mimic the response that the APIserver responds with. I can look to see if the apiserver checks the user agent before writing the response.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. The comment implied to me that you only wanted to pretty-print when the CLI is the client. If you want to always pretty-print, I suggest just removing the comment.

pkg/ansible/proxy/proxy.go Show resolved Hide resolved
pkg/ansible/proxy/proxy.go Show resolved Hide resolved
pkg/ansible/proxy/requestfactory/requestinfo.go Outdated Show resolved Hide resolved
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 26, 2018
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 27, 2018
@dymurray
Copy link
Contributor Author

Adding a TODO on refactoring the proxy tests. It appears we have things we need to update in controller-runtime before we can use a fake cache.

@shawn-hurley
Copy link
Member

@dymurray in the TODO can you mentation that the implementation fo this: https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/controller/controllertest/util.go#L44 needs to be done before we can truly use this as a fake.

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 29, 2018
Copy link
Member

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

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

LGTM

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2018
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 3, 2018
@shawn-hurley
Copy link
Member

@dymurray This looks like the Gopkg.toml is not correct, can you update?

@mhrivnak can you please re-review

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 4, 2018
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 4, 2018
@shawn-hurley shawn-hurley merged commit 061d185 into operator-framework:master Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language/ansible Issue is related to an Ansible operator project needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants