-
Notifications
You must be signed in to change notification settings - Fork 0
Retry quay.io request on 520 responses #5
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ module Quayio | |||||
| module Scanner | ||||||
| class Image < Struct.new(:name, :quayio_token, :whitelist) | ||||||
| RELEVANT_SEVERITIES = %w(High Critical) | ||||||
| MAX_ATTEMPTS = 5 | ||||||
|
|
||||||
| def vulnerable? | ||||||
| quayio? && image_exists? && scanned? && high_vulnerabilities_present? | ||||||
|
|
@@ -44,14 +45,22 @@ def tag | |||||
| def raw_image | ||||||
| return @raw_image if defined? @raw_image | ||||||
|
|
||||||
| @raw_image = begin | ||||||
| JSON.parse( | ||||||
| RestClient.get("https://quay.io/api/v1/repository/#{repo}/tag/#{tag}/images", | ||||||
| authorization: "Bearer #{quayio_token}", accept: :json) | ||||||
| )['images'].first | ||||||
| rescue RestClient::ExceptionWithResponse => err | ||||||
| return nil if err.http_code == 404 # ignore unknown repos | ||||||
| raise err | ||||||
| (1..MAX_ATTEMPTS).each do |attempt| | ||||||
| begin | ||||||
| response = RestClient.get( | ||||||
| "https://quay.io/api/v1/repository/#{repo}/tag/#{tag}/images", | ||||||
| authorization: "Bearer #{quayio_token}", | ||||||
| accept: :json) | ||||||
| rescue RestClient::ExceptionWithResponse => err | ||||||
| return nil if err.http_code == 404 # ignore unknown repos | ||||||
| if err.http_code == 520 and attempt < MAX_ATTEMPTS | ||||||
| sleep(rand(10)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warum hier ein Zufall beim warten auf den nächsten Versuch? Ich kenne sonst das Pattern, dass mit jedem weiteren Versuch länger gewartet wird (als Optimierung der Gesamtwartezeit). Ich würde daher schreiben
Suggested change
Das
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Das Problem scheint daher zu kommen, dass bei einem Check-Request alle Docker-Nodes gleichzeitig zu quay.io rennen. Das würde sich nicht ändern, wenn alle Nodes deterministisch warten, um dann erneut gleichzeitig bei quay.io anzufragen. Ich will hier bewusst für eine zufällige zeitliche Streuung der Requests über die einzelnen Nodes sorgen. |
||||||
| next | ||||||
| end | ||||||
| raise err | ||||||
| end | ||||||
| @raw_image = JSON.parse(response)['images'].first | ||||||
| return @raw_image | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
|
|
||||||
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.
Warum versucht ihr es nur bei 520? Das ist ja sogar ein Spezialfall von Cloudflare. Warum nehmt ihr nicht einfach alle 500?
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.
Hm, gute Frage, ich bin unentschlossen. Uns nervt gerade der 520, weil wir wissen, dass das ein temporäres Problem ist und das weggeht, wenn zu einem späteren Zeitpunkt ein erneuter Request kommt. Andere 500 haben wir nicht gesehen und wir wissen auch nicht, wie dann die Situation aussieht. Daher würde ich für den Moment abwarten, bis wir in eine solche Situation kommen und dann bewerten, ob wir alle 500 abfangen.