Commit 046295d3 authored by Stan Hu's avatar Stan Hu

Fix Gitaly duration timings for conflict and search 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. ListConflictFiles
2. SearchFilesByContent

Part of https://gitlab.com/gitlab-org/gitlab/-/issues/30334
parent 081d1801
---
title: Fix Gitaly duration timings for conflicts and search RPCs
merge_request: 34909
author:
type: other
...@@ -20,9 +20,9 @@ module Gitlab ...@@ -20,9 +20,9 @@ module Gitlab
our_commit_oid: @our_commit_oid, our_commit_oid: @our_commit_oid,
their_commit_oid: @their_commit_oid their_commit_oid: @their_commit_oid
) )
response = GitalyClient.call(@repository.storage, :conflicts_service, :list_conflict_files, request, timeout: GitalyClient.long_timeout) GitalyClient.streaming_call(@repository.storage, :conflicts_service, :list_conflict_files, request, timeout: GitalyClient.long_timeout) do |response|
GitalyClient::ConflictFilesStitcher.new(response, @gitaly_repo)
GitalyClient::ConflictFilesStitcher.new(response, @gitaly_repo) end
end end
def conflicts? def conflicts?
......
...@@ -334,9 +334,9 @@ module Gitlab ...@@ -334,9 +334,9 @@ module Gitlab
def search_files_by_content(ref, query, options = {}) def search_files_by_content(ref, query, options = {})
request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query) request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query)
response = GitalyClient.call(@storage, :repository_service, :search_files_by_content, request, timeout: GitalyClient.default_timeout) GitalyClient.streaming_call(@storage, :repository_service, :search_files_by_content, request, timeout: GitalyClient.default_timeout) do |response|
search_results_from_response(response, options)
search_results_from_response(response, options) end
end end
def disconnect_alternates def disconnect_alternates
...@@ -403,14 +403,18 @@ module Gitlab ...@@ -403,14 +403,18 @@ module Gitlab
def gitaly_fetch_stream_to_file(save_path, rpc_name, request_class, timeout) def gitaly_fetch_stream_to_file(save_path, rpc_name, request_class, timeout)
request = request_class.new(repository: @gitaly_repo) request = request_class.new(repository: @gitaly_repo)
response = GitalyClient.call( GitalyClient.streaming_call(
@storage, @storage,
:repository_service, :repository_service,
rpc_name, rpc_name,
request, request,
timeout: timeout timeout: timeout
) ) do |response|
write_stream_to_file(response, save_path)
end
end
def write_stream_to_file(response, save_path)
File.open(save_path, 'wb') do |f| File.open(save_path, 'wb') do |f|
response.each do |message| response.each do |message|
f.write(message.data) f.write(message.data)
......
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