summaryrefslogtreecommitdiff
path: root/lib/container_registry
diff options
context:
space:
mode:
Diffstat (limited to 'lib/container_registry')
-rw-r--r--lib/container_registry/client.rb43
1 files changed, 36 insertions, 7 deletions
diff --git a/lib/container_registry/client.rb b/lib/container_registry/client.rb
index 35f299c17e4..6f5acabe81f 100644
--- a/lib/container_registry/client.rb
+++ b/lib/container_registry/client.rb
@@ -22,6 +22,23 @@ module ContainerRegistry
# Taken from: FaradayMiddleware::FollowRedirects
REDIRECT_CODES = Set.new [301, 302, 303, 307]
+ RETRY_EXCEPTIONS = [Faraday::Request::Retry::DEFAULT_EXCEPTIONS, Faraday::ConnectionFailed].flatten.freeze
+ RETRY_OPTIONS = {
+ max: 1,
+ interval: 5,
+ exceptions: RETRY_EXCEPTIONS
+ }.freeze
+
+ ERROR_CALLBACK_OPTIONS = {
+ callback: -> (env, exception) do
+ Gitlab::ErrorTracking.log_exception(
+ exception,
+ class: name,
+ url: env[:url]
+ )
+ end
+ }.freeze
+
def self.supports_tag_delete?
registry_config = Gitlab.config.registry
return false unless registry_config.enabled && registry_config.api_url.present?
@@ -97,12 +114,12 @@ module ContainerRegistry
end
def upload_blob(name, content, digest)
- upload = faraday.post("/v2/#{name}/blobs/uploads/")
+ upload = faraday(timeout_enabled: false).post("/v2/#{name}/blobs/uploads/")
return upload unless upload.success?
location = URI(upload.headers['location'])
- faraday.put("#{location.path}?#{location.query}") do |req|
+ faraday(timeout_enabled: false).put("#{location.path}?#{location.query}") do |req|
req.params['digest'] = digest
req.headers['Content-Type'] = 'application/octet-stream'
req.body = content
@@ -137,7 +154,7 @@ module ContainerRegistry
end
def put_tag(name, reference, manifest)
- response = faraday.put("/v2/#{name}/manifests/#{reference}") do |req|
+ response = faraday(timeout_enabled: false).put("/v2/#{name}/manifests/#{reference}") do |req|
req.headers['Content-Type'] = DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE
req.body = Gitlab::Json.pretty_generate(manifest)
end
@@ -158,6 +175,8 @@ module ContainerRegistry
yield(conn) if block_given?
+ conn.request(:retry, RETRY_OPTIONS)
+ conn.request(:gitlab_error_callback, ERROR_CALLBACK_OPTIONS)
conn.adapter :net_http
end
@@ -188,8 +207,8 @@ module ContainerRegistry
faraday_redirect.get(uri)
end
- def faraday
- @faraday ||= faraday_base do |conn|
+ def faraday(timeout_enabled: true)
+ @faraday ||= faraday_base(timeout_enabled: timeout_enabled) do |conn|
initialize_connection(conn, @options, &method(:accept_manifest))
end
end
@@ -205,12 +224,22 @@ module ContainerRegistry
def faraday_redirect
@faraday_redirect ||= faraday_base do |conn|
conn.request :json
+
+ conn.request(:retry, RETRY_OPTIONS)
+ conn.request(:gitlab_error_callback, ERROR_CALLBACK_OPTIONS)
conn.adapter :net_http
end
end
- def faraday_base(&block)
- Faraday.new(@base_uri, headers: { user_agent: "GitLab/#{Gitlab::VERSION}" }, &block)
+ def faraday_base(timeout_enabled: true, &block)
+ request_options = timeout_enabled ? Gitlab::HTTP::DEFAULT_TIMEOUT_OPTIONS : nil
+
+ Faraday.new(
+ @base_uri,
+ headers: { user_agent: "GitLab/#{Gitlab::VERSION}" },
+ request: request_options,
+ &block
+ )
end
def delete_if_exists(path)