diff options
-rw-r--r-- | app/assets/javascripts/performance_bar/components/performance_bar_app.vue | 7 | ||||
-rw-r--r-- | changelogs/unreleased/an-peek-jaeger.yml | 5 | ||||
-rw-r--r-- | config/initializers/peek.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/tracing.rb | 19 | ||||
-rw-r--r-- | lib/peek/views/tracing.rb | 13 | ||||
-rw-r--r-- | spec/lib/gitlab/tracing_spec.rb | 66 |
6 files changed, 111 insertions, 0 deletions
diff --git a/app/assets/javascripts/performance_bar/components/performance_bar_app.vue b/app/assets/javascripts/performance_bar/components/performance_bar_app.vue index 74faa35358d..1ec2784cc5a 100644 --- a/app/assets/javascripts/performance_bar/components/performance_bar_app.vue +++ b/app/assets/javascripts/performance_bar/components/performance_bar_app.vue @@ -134,6 +134,13 @@ export default { >ms / <span title="Invoke Count">{{ currentRequest.details.gc.invokes }}</span> gc </span> </div> + <div + v-if="currentRequest.details && currentRequest.details.tracing" + id="peek-view-trace" + class="view" + > + <a :href="currentRequest.details.tracing.tracing_url"> trace </a> + </div> <request-selector v-if="currentRequest" :current-request="currentRequest" diff --git a/changelogs/unreleased/an-peek-jaeger.yml b/changelogs/unreleased/an-peek-jaeger.yml new file mode 100644 index 00000000000..8659ee4f9e0 --- /dev/null +++ b/changelogs/unreleased/an-peek-jaeger.yml @@ -0,0 +1,5 @@ +--- +title: Provide a performance bar link to the Jaeger UI +merge_request: 24902 +author: +type: other diff --git a/config/initializers/peek.rb b/config/initializers/peek.rb index a6f43415ec5..e051e5c68c4 100644 --- a/config/initializers/peek.rb +++ b/config/initializers/peek.rb @@ -19,6 +19,7 @@ Peek.into Peek::Views::Gitaly Peek.into Peek::Views::Rblineprof Peek.into Peek::Views::Redis Peek.into Peek::Views::GC +Peek.into Peek::Views::Tracing if Gitlab::Tracing.tracing_url_enabled? # rubocop:disable Naming/ClassAndModuleCamelCase class PEEK_DB_CLIENT diff --git a/lib/gitlab/tracing.rb b/lib/gitlab/tracing.rb index 3c4db42ac06..0d9b0be1c8e 100644 --- a/lib/gitlab/tracing.rb +++ b/lib/gitlab/tracing.rb @@ -13,5 +13,24 @@ module Gitlab def self.connection_string ENV['GITLAB_TRACING'] end + + def self.tracing_url_template + ENV['GITLAB_TRACING_URL'] + end + + def self.tracing_url_enabled? + enabled? && tracing_url_template.present? + end + + # This will provide a link into the distributed tracing for the current trace, + # if it has been captured. + def self.tracing_url + return unless tracing_url_enabled? + + tracing_url_template % { + correlation_id: Gitlab::CorrelationId.current_id.to_s, + service: Gitlab.process_name + } + end end end diff --git a/lib/peek/views/tracing.rb b/lib/peek/views/tracing.rb new file mode 100644 index 00000000000..0de32a8fdda --- /dev/null +++ b/lib/peek/views/tracing.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Peek + module Views + class Tracing < View + def results + { + tracing_url: Gitlab::Tracing.tracing_url + } + end + end + end +end diff --git a/spec/lib/gitlab/tracing_spec.rb b/spec/lib/gitlab/tracing_spec.rb new file mode 100644 index 00000000000..2cddc895026 --- /dev/null +++ b/spec/lib/gitlab/tracing_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'rspec-parameterized' + +describe Gitlab::Tracing do + using RSpec::Parameterized::TableSyntax + + describe '.enabled?' do + where(:connection_string, :enabled_state) do + nil | false + "" | false + "opentracing://jaeger" | true + end + + with_them do + it 'should return the correct state for .enabled?' do + expect(described_class).to receive(:connection_string).and_return(connection_string) + + expect(described_class.enabled?).to eq(enabled_state) + end + end + end + + describe '.tracing_url_enabled?' do + where(:enabled?, :tracing_url_template, :tracing_url_enabled_state) do + false | nil | false + false | "" | false + false | "http://localhost" | false + true | nil | false + true | "" | false + true | "http://localhost" | true + end + + with_them do + it 'should return the correct state for .tracing_url_enabled?' do + expect(described_class).to receive(:enabled?).and_return(enabled?) + allow(described_class).to receive(:tracing_url_template).and_return(tracing_url_template) + + expect(described_class.tracing_url_enabled?).to eq(tracing_url_enabled_state) + end + end + end + + describe '.tracing_url' do + where(:tracing_url_enabled?, :tracing_url_template, :correlation_id, :process_name, :tracing_url) do + false | "https://localhost" | "123" | "web" | nil + true | "https://localhost" | "123" | "web" | "https://localhost" + true | "https://localhost?service=%{service}" | "123" | "web" | "https://localhost?service=web" + true | "https://localhost?c=%{correlation_id}" | "123" | "web" | "https://localhost?c=123" + true | "https://localhost?c=%{correlation_id}&s=%{service}" | "123" | "web" | "https://localhost?c=123&s=web" + true | "https://localhost?c=%{correlation_id}" | nil | "web" | "https://localhost?c=" + end + + with_them do + it 'should return the correct state for .tracing_url' do + expect(described_class).to receive(:tracing_url_enabled?).and_return(tracing_url_enabled?) + allow(described_class).to receive(:tracing_url_template).and_return(tracing_url_template) + allow(Gitlab::CorrelationId).to receive(:current_id).and_return(correlation_id) + allow(Gitlab).to receive(:process_name).and_return(process_name) + + expect(described_class.tracing_url).to eq(tracing_url) + end + end + end +end |