Commit e3922741 authored by Dylan Griffith's avatar Dylan Griffith

Show Elasticsearch in performance bar

In https://gitlab.com/gitlab-org/gitlab/-/merge_requests/32822 we added
instrumentation for Elasticsearch. This follows the same pattern used in
lib/peek/views/gitaly.rb to display call counts, duration and extra
details in the performance bar.

See https://gitlab.com/gitlab-org/gitlab/-/issues/214279
parent ff4425ba
......@@ -57,6 +57,11 @@ export default {
header: s__('PerformanceBar|Redis calls'),
keys: ['cmd'],
},
{
metric: 'es',
header: s__('PerformanceBar|Elasticsearch calls'),
keys: ['request', 'body'],
},
{
metric: 'total',
header: s__('PerformanceBar|Frontend resources'),
......
......@@ -9,6 +9,7 @@ Peek.into Peek::Views::Host
Peek.into Peek::Views::ActiveRecord
Peek.into Peek::Views::Gitaly
Peek.into Peek::Views::RedisDetailed
Peek.into Peek::Views::Elasticsearch
Peek.into Peek::Views::Rugged
Peek.into Peek::Views::BulletDetailed if defined?(Bullet)
......
# frozen_string_literal: true
require 'spec_helper'
# We don't want to interact with Elasticsearch in GitLab FOSS so we test
# this in ee/ only. The code exists in FOSS and won't do anything.
describe Peek::Views::Elasticsearch, :elastic, :request_store do
before do
allow(::Gitlab::PerformanceBar).to receive(:enabled_for_request?).and_return(true)
ensure_elasticsearch_index!
end
describe '#results' do
let(:results) { described_class.new.results }
it 'includes performance details' do
expect(results[:calls]).to be > 0
expect(results[:duration]).to be_kind_of(String)
expect(results[:details].last[:method]).to eq("POST")
expect(results[:details].last[:path]).to eq("gitlab-test/_refresh")
end
end
end
# frozen_string_literal: true
module Peek
module Views
class Elasticsearch < DetailedView
DEFAULT_THRESHOLDS = {
calls: 5,
duration: 1000,
individual_call: 1000
}.freeze
THRESHOLDS = {
production: {
calls: 5,
duration: 1000,
individual_call: 1000
}
}.freeze
def key
'es'
end
def self.thresholds
@thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS)
end
private
def duration
::Gitlab::Instrumentation::ElasticsearchTransport.query_time * 1000
end
def calls
::Gitlab::Instrumentation::ElasticsearchTransport.get_request_count
end
def call_details
::Gitlab::Instrumentation::ElasticsearchTransport.detail_store
end
def format_call_details(call)
super.merge(request: "#{call[:method]} #{call[:path]}")
end
end
end
end
......@@ -15478,6 +15478,9 @@ msgstr ""
msgid "PerformanceBar|Download"
msgstr ""
msgid "PerformanceBar|Elasticsearch calls"
msgstr ""
msgid "PerformanceBar|Frontend resources"
msgstr ""
......
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