diff options
author | Andrew Newdigate <andrew@gitlab.com> | 2018-11-21 23:48:48 +0000 |
---|---|---|
committer | Andrew Newdigate <andrew@gitlab.com> | 2018-11-22 09:54:44 +0000 |
commit | 79c6eee1e6e9a82a276edcd74288c3d889c43bdc (patch) | |
tree | bf07dc7bcfd5071e31cb8dd19e09f57cea472718 | |
parent | 9e422daeeb632b8145848cdd5f921b7739b81bb6 (diff) | |
download | gitlab-ce-an-grpc-downstream-correlation.tar.gz |
Add correlation injector middlewarean-grpc-downstream-correlation
-rw-r--r-- | .rubocop.yml | 1 | ||||
-rw-r--r-- | changelogs/unreleased/an-grpc-downstream-correlation.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/grpc_correlation_interceptor.rb | 38 |
4 files changed, 45 insertions, 1 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index 741403af009..dca993af5be 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -112,6 +112,7 @@ Naming/FileName: - CSS - DNS - EOF + - GRPC - GUID - HTML - HTTP diff --git a/changelogs/unreleased/an-grpc-downstream-correlation.yml b/changelogs/unreleased/an-grpc-downstream-correlation.yml new file mode 100644 index 00000000000..4334010dd40 --- /dev/null +++ b/changelogs/unreleased/an-grpc-downstream-correlation.yml @@ -0,0 +1,5 @@ +--- +title: Send correlation-ids downstream to Gitaly via GRPC +merge_request: 23293 +author: +type: other diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 8b455dc7696..81e852fe31b 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -60,7 +60,7 @@ module Gitlab @stubs[storage][name] ||= begin klass = stub_class(name) addr = stub_address(storage) - klass.new(addr, :this_channel_is_insecure) + klass.new(addr, :this_channel_is_insecure, interceptors: [Gitlab::GRPCCorrelationInterceptor.instance]) end end end diff --git a/lib/gitlab/grpc_correlation_interceptor.rb b/lib/gitlab/grpc_correlation_interceptor.rb new file mode 100644 index 00000000000..5bb8cf35c98 --- /dev/null +++ b/lib/gitlab/grpc_correlation_interceptor.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Gitlab + class GRPCCorrelationInterceptor < GRPC::ClientInterceptor + include Singleton + + def request_response(request:, call:, method:, metadata:) + inject_correlator(metadata) do + yield + end + end + + def client_streamer(requests:, call:, method:, metadata:) + inject_correlator(metadata) do + yield + end + end + + def server_streamer(request:, call:, method:, metadata:) + inject_correlator(metadata) do + yield + end + end + + def bidi_streamer(requests:, call:, method:, metadata:) + inject_correlator(metadata) do + yield + end + end + + private + + def inject_correlator(metadata) + metadata["x-gitlab-correlation-id"] = Gitlab::CorrelationId.current_id + yield + end + end +end |