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

Respond directly with badges rather than redirecting #4559

Closed
wants to merge 5 commits into from

Conversation

davidfischer
Copy link
Contributor

This changes the docs badges to be served directly from Django. This is less efficient but gives us precise caching control and centralizes all the cache control in one place.

One possible optimization is to cache the part where we read from storage. The "passing" graphic doesn't change frequently. However, it is possible that reading from cache isn't really faster than reading from storage.

If merged, #4558 can be closed.
Fixes #4557.

@davidfischer davidfischer requested a review from a team August 22, 2018 23:02
@davidfischer
Copy link
Contributor Author

Hmmm tests are failing if you don't run collectstatic first. I'll see if I can resolve this.

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

I'm a little hesitant to reintroduce proxying to third-party servers in our web stack. I guess we do this with Azure Storage already in the Cold Storage stuff, but it times out after 1 second. We probably want to confirm it does something similar here.

else:
url = badge_path % 'failing'

with staticfiles_storage.open(url) as fd:
Copy link
Member

@ericholscher ericholscher Aug 23, 2018

Choose a reason for hiding this comment

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

Is there a way to put a timeout on this call? We used to do this exact same thing with shields.io, but whenever they had downtime, it took down our entire web stack because we'd end up just spinning our web processes waiting for badges.

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 weren't doing 302s to shields.io? I knew we used to use shields.io but I didn't look into precisely how it was implemented. Doing redirects seems like it wouldn't rely on them being up. Badges would be down when shields.io is down but it wouldn't affect our servers at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like #711 introduced shields.io. It introduced it by streaming the HTTP response from shields which is definitely brittle as you describe. When they're down, it would cause problems for us unless we specify timeouts correctly.

However, it looks like things switched to redirecting to shields.io (in this commit 47757de which doesn't really have a PR). That seems like a step in the right direction for sure. #3057 swapped shields.io for self-hosted SVGs but there's no information in the PR as to why that was desirable. To me it seems like a step back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a way to put a timeout on this call?

To answer this question directly, I don't see a way to add a specific timeout to this call using the version of the Azure libraries we are using. The default timeout is long too (65 seconds).

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 shields had a decent amount of downtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like this is the issue ticket about it: #2065

with staticfiles_storage.open(url) as fd:
return HttpResponse(
fd.read(),
content_type='image/svg+xml',
Copy link
Member

Choose a reason for hiding this comment

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

Isn't here the place where we want to add some specific cache headers for lowering down the cache time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The method itself has the @never_cache decorator which handles that.

Copy link
Member

Choose a reason for hiding this comment

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

Perfect! I'm sorry, I didn't see it.

@davidfischer
Copy link
Contributor Author

I'm going to close this PR in favor of #4558. After discussion, I think that PR coupled with getting the cache-control headers right on the CDN is the best approach.

@stsewd stsewd deleted the davidfischer/badges-respond-directly branch October 1, 2018 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong badge status in README.rst file, but correct status in RTD documentation
3 participants