Commit acce5905 authored by Pavlo Strokov's avatar Pavlo Strokov

Statistics about amount of clusters configured

GitLab should reports about setup used for Gitaly.
Usual Gitaly setup with multiple storages will report
none clusters used, but setup with Praefect with
multiple Gitalies behind will report amount of such
Praefects as clusters.

Related to: https://gitlab.com/gitlab-org/gitaly/-/issues/2664
parent f95b62ea
...@@ -612,6 +612,7 @@ The following is example content of the Usage Ping payload. ...@@ -612,6 +612,7 @@ The following is example content of the Usage Ping payload.
"gitaly": { "gitaly": {
"version": "12.10.0-rc1-93-g40980d40", "version": "12.10.0-rc1-93-g40980d40",
"servers": 56, "servers": 56,
"clusters": 14,
"filesystems": [ "filesystems": [
"EXT_2_3_4" "EXT_2_3_4"
] ]
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
module Gitaly module Gitaly
class Server class Server
SHA_VERSION_REGEX = /\A\d+\.\d+\.\d+-\d+-g([a-f0-9]{8})\z/.freeze SHA_VERSION_REGEX = /\A\d+\.\d+\.\d+-\d+-g([a-f0-9]{8})\z/.freeze
DEFAULT_REPLICATION_FACTOR = 1
class << self class << self
def all def all
...@@ -16,6 +17,10 @@ module Gitaly ...@@ -16,6 +17,10 @@ module Gitaly
def filesystems def filesystems
all.map(&:filesystem_type).compact.uniq all.map(&:filesystem_type).compact.uniq
end end
def gitaly_clusters
all.count { |g| g.replication_factor > DEFAULT_REPLICATION_FACTOR }
end
end end
attr_reader :storage attr_reader :storage
...@@ -73,6 +78,10 @@ module Gitaly ...@@ -73,6 +78,10 @@ module Gitaly
"Error getting the address: #{e.message}" "Error getting the address: #{e.message}"
end end
def replication_factor
storage_status&.replication_factor
end
private private
def storage_status def storage_status
......
...@@ -217,6 +217,7 @@ module Gitlab ...@@ -217,6 +217,7 @@ module Gitlab
gitaly: { gitaly: {
version: alt_usage_data { Gitaly::Server.all.first.server_version }, version: alt_usage_data { Gitaly::Server.all.first.server_version },
servers: alt_usage_data { Gitaly::Server.count }, servers: alt_usage_data { Gitaly::Server.count },
clusters: alt_usage_data { Gitaly::Server.gitaly_clusters },
filesystems: alt_usage_data(fallback: ["-1"]) { Gitaly::Server.filesystems } filesystems: alt_usage_data(fallback: ["-1"]) { Gitaly::Server.filesystems }
}, },
gitlab_pages: { gitlab_pages: {
......
...@@ -20,6 +20,7 @@ describe Gitaly::Server do ...@@ -20,6 +20,7 @@ describe Gitaly::Server do
it { is_expected.to respond_to(:git_binary_version) } it { is_expected.to respond_to(:git_binary_version) }
it { is_expected.to respond_to(:up_to_date?) } it { is_expected.to respond_to(:up_to_date?) }
it { is_expected.to respond_to(:address) } it { is_expected.to respond_to(:address) }
it { is_expected.to respond_to(:replication_factor) }
describe 'readable?' do describe 'readable?' do
context 'when the storage is readable' do context 'when the storage is readable' do
...@@ -134,4 +135,22 @@ describe Gitaly::Server do ...@@ -134,4 +135,22 @@ describe Gitaly::Server do
end end
end end
end end
describe 'replication_factor' do
context 'when examining for a given server' do
let(:storage_status) { double('storage_status', storage_name: 'default') }
before do
response = double('response', storage_statuses: [storage_status])
allow_next_instance_of(Gitlab::GitalyClient::ServerService) do |instance|
allow(instance).to receive(:info).and_return(response)
end
end
it do
allow(storage_status).to receive(:replication_factor).and_return(2)
expect(server.replication_factor).to eq(2)
end
end
end
end end
...@@ -255,6 +255,7 @@ describe Gitlab::UsageData, :aggregate_failures do ...@@ -255,6 +255,7 @@ describe Gitlab::UsageData, :aggregate_failures do
expect(subject[:database][:version]).to eq(Gitlab::Database.version) expect(subject[:database][:version]).to eq(Gitlab::Database.version)
expect(subject[:gitaly][:version]).to be_present expect(subject[:gitaly][:version]).to be_present
expect(subject[:gitaly][:servers]).to be >= 1 expect(subject[:gitaly][:servers]).to be >= 1
expect(subject[:gitaly][:clusters]).to be >= 0
expect(subject[:gitaly][:filesystems]).to be_an(Array) expect(subject[:gitaly][:filesystems]).to be_an(Array)
expect(subject[:gitaly][:filesystems].first).to be_a(String) expect(subject[:gitaly][:filesystems].first).to be_a(String)
end end
......
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