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

add automatic caching for discovery requests, refreshing on a miss #238

Merged
merged 4 commits into from
Nov 27, 2018

Conversation

fabianvf
Copy link
Member

This adds an automatic cache of discovery requests that is written to /tmp/osrcp-${BASE_64_ENCODED_OPENSHIFT_HOST).json.

This cache will persist until invalidate_cache is called manually, or until a resource is not found in the cache (making misses fairly expensive).

By necessity, also adds a JSON encoder and decoder for the resources.

May conflict with changes in #220 , so @asetty would you mind taking a look and seeing if there's something I should do to make this play more nicely with your work?

For the Ansible modules, this should cut the number of requests per task down significantly.

I don't know much about caching so please be brutal in your feedback.

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 19, 2018
Copy link
Member

@dymurray dymurray left a comment

Choose a reason for hiding this comment

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

This worked great for me, I was able to verify that subsequent runs from the operator were not sending the discovery requests through the proxy.

if not self.__cache.get('version'):
self.__cache['version'] = {'kubernetes': load_json(self.request('get', '/version'))}
try:
self.__cache['version']['openshift'] = load_json(self.request('get', '/version/openshift'))
Copy link
Member

Choose a reason for hiding this comment

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

I believe /version/openshift no longer exists, is this just to maintain legacy support?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I imagine this is usually run against older versions of openshift so I figured I would just leave it in.

@fabianvf
Copy link
Member Author

@willthames any thoughts on this?

if PY3:
default_cache_id = default_cache_id.encode('utf-8')
self.__resources = ResourceContainer({}, client=self)
self.__cache_file = cache_file or '/tmp/osrcp-{0}.json'.format(base64.b64encode(default_cache_id).decode('utf-8'))
Copy link
Contributor

Choose a reason for hiding this comment

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

should probably use $TMPDIR rather than defaulting to /tmp

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch

@willthames
Copy link
Contributor

@fabianvf I'll run this in on my test suite next time I have some spare time, but I like the concept.

@willthames
Copy link
Contributor

willthames commented Nov 22, 2018

Speed up of tests from Aus to us-west-2 is 58 seconds down to 31 seconds

This is similar performance to #220 - would this get down to 15 seconds with both? :)

@asetty
Copy link
Contributor

asetty commented Nov 22, 2018

I should be able to merge this with my changes without too much headache, just have to be mindful when rebasing or vice versa depending which merges first.
Speaking of #220, I'll try to make some time soon to get it finished up and merged. I haven't completely forgot about it :)

@fabianvf
Copy link
Member Author

@willthames added better tempfile stuff, ready to merge unless you have an objection.

@willthames
Copy link
Contributor

I think this is a great change @fabianvf, merge away!

@fabianvf fabianvf merged commit c6f2168 into openshift:master Nov 27, 2018
willthames pushed a commit to willthames/openshift-restclient-python that referenced this pull request Dec 13, 2018
…penshift#238)

* add automatic caching for discovery requests, refreshing on a miss

* fix base64 encode in python3

* Don't replace ResourceContainer on cache invalidation so that the second attempt succeeds

* Use more generic temp directory and path operations
@fabianvf
Copy link
Member Author

/cherrypick release-0.8

@openshift-cherrypick-robot

@fabianvf: new pull request created: #257

In response to this:

/cherrypick release-0.8

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.

fabianvf added a commit to fabianvf/openshift-restclient-python that referenced this pull request Jan 11, 2019
…penshift#238)

* add automatic caching for discovery requests, refreshing on a miss

* fix base64 encode in python3

* Don't replace ResourceContainer on cache invalidation so that the second attempt succeeds

* Use more generic temp directory and path operations

(cherry picked from commit c6f2168)
fabianvf added a commit that referenced this pull request Jan 11, 2019
)

* add automatic caching for discovery requests, refreshing on a miss

* fix base64 encode in python3

* Don't replace ResourceContainer on cache invalidation so that the second attempt succeeds

* Use more generic temp directory and path operations

(cherry picked from commit c6f2168)
willthames pushed a commit to willthames/openshift-restclient-python that referenced this pull request Nov 22, 2019
…penshift#238)

* add automatic caching for discovery requests, refreshing on a miss

* fix base64 encode in python3

* Don't replace ResourceContainer on cache invalidation so that the second attempt succeeds

* Use more generic temp directory and path operations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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