Commit 19cd49bf authored by Kerri Miller's avatar Kerri Miller

Merge branch '338726-add-es-version-tracking' into 'master'

Track version of Elasticsearch server used by self hosted clients

See merge request gitlab-org/gitlab!77365
parents 39192335 43021bb2
......@@ -115,6 +115,17 @@ module EE
usage_data
end
override :components_usage_data
def components_usage_data
usage_data = super
if ::Gitlab::CurrentSettings.elasticsearch_indexing?
usage_data[:advanced_search] = add_metric("AdvancedSearchMetric")
end
usage_data
end
def requirements_counts
return {} unless ::License.feature_available?(:requirements)
......
......@@ -285,6 +285,19 @@ module Gitlab
false
end
def server_info
info = client.info.fetch('version', {})
{
distribution: info.fetch('distribution', 'elasticsearch'),
version: info['number'],
build_type: info['build_type'],
lucene_version: info['lucene_version']
}
rescue StandardError
{}
end
private
def create_index(index_name, alias_name, with_alias, settings, mappings, options)
......
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class AdvancedSearchMetric < GenericMetric
fallback({})
value do
::Gitlab::Elastic::Helper.default.server_info
end
end
end
end
end
end
......@@ -394,4 +394,57 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do
is_expected.to include('created_by' => Gitlab::VERSION)
end
end
describe '#server_info' do
subject { helper.server_info }
context 'server is accessible' do
before do
allow(Gitlab::Elastic::Helper.default.client).to receive(:info).and_return(info)
end
context 'using elasticsearch' do
let(:info) do
{
'version' => {
'number' => '7.9.3',
'build_type' => 'docker',
'lucene_version' => '8.6.2'
}
}
end
it 'returns server info' do
is_expected.to include(distribution: 'elasticsearch', version: '7.9.3', build_type: 'docker', lucene_version: '8.6.2')
end
end
context 'using opensearch' do
let(:info) do
{
'version' => {
'distribution' => 'opensearch',
'number' => '1.0.0',
'build_type' => 'tar',
'lucene_version' => '8.10.1'
}
}
end
it 'returns server info' do
is_expected.to include(distribution: 'opensearch', version: '1.0.0', build_type: 'tar', lucene_version: '8.10.1')
end
end
end
context 'server is inaccessible' do
before do
allow(Gitlab::Elastic::Helper.default.client).to receive(:info).and_raise(StandardError)
end
it 'returns empty hash' do
is_expected.to eq({})
end
end
end
end
......@@ -182,6 +182,16 @@ RSpec.describe Gitlab::UsageData do
end
end
describe '.components_usage_data' do
subject { described_class.components_usage_data }
it 'gathers components usage data' do
stub_ee_application_setting(elasticsearch_indexing: true)
expect(subject[:advanced_search]).to eq(Gitlab::Elastic::Helper.default.server_info)
end
end
describe '.requirements_counts' do
subject { described_class.requirements_counts }
......
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