-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
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 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. |
I think it makes sense to rename the handler function... thoughts on changing |
TODO: Working on adding tests to the proxy |
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 @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. |
@joelanford Makes sense to me. If others agree I'm happy to make that change. |
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
pkg/ansible/proxy/proxy.go
Outdated
|
||
// 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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:
After changes:
Overall this is a ~75% reduction in the time it takes to GET resources from the cluster.
TODO