Commit f1d0bff1 authored by Stan Hu's avatar Stan Hu

Fix Gitaly duration timings of BlobService RPCs

For many Gitaly RPCs, previously the `gitaly_duration_s` log timings
only accounted for the initial request/response time. We now measure the
total time it takes to consume the streaming response for the following
RPCs:

1. GetBlob
2. GetLFSPointers
3. GetBlobs
4. GetNewLFSPointers

This came up in https://gitlab.com/gitlab-org/gitlab/-/issues/222247.

Part of https://gitlab.com/gitlab-org/gitlab/-/issues/30334
parent 081d1801
---
title: Fix Gitaly duration timings of BlobService RPCs
merge_request: 34906
author:
type: other
...@@ -15,28 +15,9 @@ module Gitlab ...@@ -15,28 +15,9 @@ module Gitlab
oid: oid, oid: oid,
limit: limit limit: limit
) )
response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_blob, request, timeout: GitalyClient.fast_timeout) GitalyClient.streaming_call(@gitaly_repo.storage_name, :blob_service, :get_blob, request, timeout: GitalyClient.fast_timeout) do |response|
consume_blob_response(response)
data = []
blob = nil
response.each do |msg|
if blob.nil?
blob = msg
end
data << msg.data
end end
return if blob.oid.blank?
data = data.join
Gitlab::Git::Blob.new(
id: blob.oid,
size: blob.size,
data: data,
binary: Gitlab::Git::Blob.binary?(data)
)
end end
def batch_lfs_pointers(blob_ids) def batch_lfs_pointers(blob_ids)
...@@ -47,10 +28,10 @@ module Gitlab ...@@ -47,10 +28,10 @@ module Gitlab
blob_ids: blob_ids blob_ids: blob_ids
) )
response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_lfs_pointers, request, timeout: GitalyClient.medium_timeout) GitalyClient.streaming_call(@gitaly_repo.storage_name, :blob_service, :get_lfs_pointers, request, timeout: GitalyClient.medium_timeout) do |response|
map_lfs_pointers(response) map_lfs_pointers(response)
end end
end
def get_blobs(revision_paths, limit = -1) def get_blobs(revision_paths, limit = -1)
return [] if revision_paths.empty? return [] if revision_paths.empty?
...@@ -65,16 +46,16 @@ module Gitlab ...@@ -65,16 +46,16 @@ module Gitlab
limit: limit limit: limit
) )
response = GitalyClient.call( GitalyClient.streaming_call(
@gitaly_repo.storage_name, @gitaly_repo.storage_name,
:blob_service, :blob_service,
:get_blobs, :get_blobs,
request, request,
timeout: GitalyClient.fast_timeout timeout: GitalyClient.fast_timeout
) ) do |response|
GitalyClient::BlobsStitcher.new(response) GitalyClient::BlobsStitcher.new(response)
end end
end
def get_blob_types(revision_paths, limit = -1) def get_blob_types(revision_paths, limit = -1)
return {} if revision_paths.empty? return {} if revision_paths.empty?
...@@ -89,16 +70,16 @@ module Gitlab ...@@ -89,16 +70,16 @@ module Gitlab
limit: limit limit: limit
) )
response = GitalyClient.call( GitalyClient.streaming_call(
@gitaly_repo.storage_name, @gitaly_repo.storage_name,
:blob_service, :blob_service,
:get_blobs, :get_blobs,
request, request,
timeout: GitalyClient.fast_timeout timeout: GitalyClient.fast_timeout
) ) do |response|
map_blob_types(response) map_blob_types(response)
end end
end
def get_new_lfs_pointers(revision, limit, not_in, dynamic_timeout = nil) def get_new_lfs_pointers(revision, limit, not_in, dynamic_timeout = nil)
request = Gitaly::GetNewLFSPointersRequest.new( request = Gitaly::GetNewLFSPointersRequest.new(
...@@ -120,29 +101,52 @@ module Gitlab ...@@ -120,29 +101,52 @@ module Gitlab
GitalyClient.medium_timeout GitalyClient.medium_timeout
end end
response = GitalyClient.call( GitalyClient.streaming_call(
@gitaly_repo.storage_name, @gitaly_repo.storage_name,
:blob_service, :blob_service,
:get_new_lfs_pointers, :get_new_lfs_pointers,
request, request,
timeout: timeout timeout: timeout
) ) do |response|
map_lfs_pointers(response) map_lfs_pointers(response)
end end
end
def get_all_lfs_pointers def get_all_lfs_pointers
request = Gitaly::GetAllLFSPointersRequest.new( request = Gitaly::GetAllLFSPointersRequest.new(
repository: @gitaly_repo repository: @gitaly_repo
) )
response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_all_lfs_pointers, request, timeout: GitalyClient.medium_timeout) GitalyClient.streaming_call(@gitaly_repo.storage_name, :blob_service, :get_all_lfs_pointers, request, timeout: GitalyClient.medium_timeout) do |response|
map_lfs_pointers(response) map_lfs_pointers(response)
end end
end
private private
def consume_blob_response(response)
data = []
blob = nil
response.each do |msg|
if blob.nil?
blob = msg
end
data << msg.data
end
return if blob.oid.blank?
data = data.join
Gitlab::Git::Blob.new(
id: blob.oid,
size: blob.size,
data: data,
binary: Gitlab::Git::Blob.binary?(data)
)
end
def map_lfs_pointers(response) def map_lfs_pointers(response)
response.flat_map do |message| response.flat_map do |message|
message.lfs_pointers.map do |lfs_pointer| message.lfs_pointers.map do |lfs_pointer|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment