diff --git a/files/gitlab-config-template/gitlab.rb.template b/files/gitlab-config-template/gitlab.rb.template index d8b7a014e1bb03631b825374c39df1c2e69825eb_ZmlsZXMvZ2l0bGFiLWNvbmZpZy10ZW1wbGF0ZS9naXRsYWIucmIudGVtcGxhdGU=..6afcd74e5a2ca294d58060b08cd2d4e32496a113_ZmlsZXMvZ2l0bGFiLWNvbmZpZy10ZW1wbGF0ZS9naXRsYWIucmIudGVtcGxhdGU= 100644 --- a/files/gitlab-config-template/gitlab.rb.template +++ b/files/gitlab-config-template/gitlab.rb.template @@ -2174,6 +2174,13 @@ ##! Manage gitlab-exporter sidekiq probes. false by default when Sentinels are ##! found. # gitlab_exporter['probe_sidekiq'] = true + +##! Manage gitlab-exporter elasticsearch probes. Add authorization header if security +##! is enabled. +# gitlab_exporter['probe_elasticsearch'] = false +# gitlab_exporter['elasticsearch_url'] = 'http://localhost:9200' +# gitlab_exporter['elasticsearch_authorization'] = 'Basic <yourbase64encodedcredentials>' + ##! Service name used to register GitLab Exporter as a Consul service # gitlab_exporter['consul_service_name'] = 'gitlab-exporter' ##! Semantic metadata used when registering GitLab Exporter as a Consul service diff --git a/files/gitlab-cookbooks/monitoring/attributes/default.rb b/files/gitlab-cookbooks/monitoring/attributes/default.rb index d8b7a014e1bb03631b825374c39df1c2e69825eb_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL2F0dHJpYnV0ZXMvZGVmYXVsdC5yYg==..6afcd74e5a2ca294d58060b08cd2d4e32496a113_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL2F0dHJpYnV0ZXMvZGVmYXVsdC5yYg== 100644 --- a/files/gitlab-cookbooks/monitoring/attributes/default.rb +++ b/files/gitlab-cookbooks/monitoring/attributes/default.rb @@ -111,6 +111,9 @@ default['monitoring']['gitlab-exporter']['listen_address'] = 'localhost' default['monitoring']['gitlab-exporter']['listen_port'] = '9168' default['monitoring']['gitlab-exporter']['probe_sidekiq'] = true +default['monitoring']['gitlab-exporter']['probe_elasticsearch'] = false +default['monitoring']['gitlab-exporter']['elasticsearch_url'] = nil +default['monitoring']['gitlab-exporter']['elasticsearch_authorization'] = nil default['monitoring']['gitlab-exporter']['env'] = { # See https://gitlab.com/gitlab-org/gitlab/-/issues/297241 'LD_PRELOAD' => '/opt/gitlab/embedded/lib/libjemalloc.so', diff --git a/files/gitlab-cookbooks/monitoring/recipes/gitlab-exporter.rb b/files/gitlab-cookbooks/monitoring/recipes/gitlab-exporter.rb index d8b7a014e1bb03631b825374c39df1c2e69825eb_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL3JlY2lwZXMvZ2l0bGFiLWV4cG9ydGVyLnJi..6afcd74e5a2ca294d58060b08cd2d4e32496a113_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL3JlY2lwZXMvZ2l0bGFiLWV4cG9ydGVyLnJi 100644 --- a/files/gitlab-cookbooks/monitoring/recipes/gitlab-exporter.rb +++ b/files/gitlab-cookbooks/monitoring/recipes/gitlab-exporter.rb @@ -56,6 +56,9 @@ notifies :restart, "runit_service[gitlab-exporter]" variables( probe_sidekiq: node['monitoring']['gitlab-exporter']['probe_sidekiq'], + probe_elasticsearch: node['monitoring']['gitlab-exporter']['probe_elasticsearch'], + elasticsearch_url: node['monitoring']['gitlab-exporter']['elasticsearch_url'], + elasticsearch_authorization: node['monitoring']['gitlab-exporter']['elasticsearch_authorization'], redis_url: redis_url, connection_string: connection_string, redis_enable_client: node['gitlab']['gitlab-rails']['redis_enable_client'] diff --git a/files/gitlab-cookbooks/monitoring/templates/gitlab-exporter.yml.erb b/files/gitlab-cookbooks/monitoring/templates/gitlab-exporter.yml.erb index d8b7a014e1bb03631b825374c39df1c2e69825eb_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL3RlbXBsYXRlcy9naXRsYWItZXhwb3J0ZXIueW1sLmVyYg==..6afcd74e5a2ca294d58060b08cd2d4e32496a113_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL3RlbXBsYXRlcy9naXRsYWItZXhwb3J0ZXIueW1sLmVyYg== 100644 --- a/files/gitlab-cookbooks/monitoring/templates/gitlab-exporter.yml.erb +++ b/files/gitlab-cookbooks/monitoring/templates/gitlab-exporter.yml.erb @@ -49,6 +49,19 @@ redis_enable_client: <%= @redis_enable_client %> <% end %> +<% if @probe_elasticsearch && @elasticsearch_url %> + elasticsearch: &elasticsearch + methods: + - probe_migrations + opts: + - url: "<%= @elasticsearch_url %>" + <% if @elasticsearch_authorization %> + options: + headers: + Authorization: <%= @elasticsearch_authorization %> + <% end %> +<% end %> + metrics: multiple: true ruby: @@ -57,6 +70,12 @@ sidekiq: <<: *sidekiq <% end %> + +<% if @probe_elasticsearch && @elasticsearch_url %> + elasticsearch: + <<: *elasticsearch +<% end %> + <% if node['gitlab']['gitlab-rails']['db_adapter'] == 'postgresql' -%> ci_builds: class_name: Database::CiBuildsProber diff --git a/spec/chef/cookbooks/monitoring/recipes/gitlab-exporter_spec.rb b/spec/chef/cookbooks/monitoring/recipes/gitlab-exporter_spec.rb index d8b7a014e1bb03631b825374c39df1c2e69825eb_c3BlYy9jaGVmL2Nvb2tib29rcy9tb25pdG9yaW5nL3JlY2lwZXMvZ2l0bGFiLWV4cG9ydGVyX3NwZWMucmI=..6afcd74e5a2ca294d58060b08cd2d4e32496a113_c3BlYy9jaGVmL2Nvb2tib29rcy9tb25pdG9yaW5nL3JlY2lwZXMvZ2l0bGFiLWV4cG9ydGVyX3NwZWMucmI= 100644 --- a/spec/chef/cookbooks/monitoring/recipes/gitlab-exporter_spec.rb +++ b/spec/chef/cookbooks/monitoring/recipes/gitlab-exporter_spec.rb @@ -115,6 +115,45 @@ end end + context 'when gitlab-exporter is enabled with elasticsearch probe configured' do + before do + stub_gitlab_rb( + gitlab_exporter: { enable: true, probe_elasticsearch: true, elasticsearch_url: "http://localhost:9200" } + ) + end + + it 'adds elasticsearch config' do + expect(chef_run).to render_file('/var/opt/gitlab/gitlab-exporter/gitlab-exporter.yml') + .with_content { |content| + expect(content).to match(/- url: "http:\/\/localhost:9200"/) + } + end + end + + context 'when gitlab-exporter is enabled with elasticsearch probe that uses basic auth' do + let(:authorization) { 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==' } + + before do + stub_gitlab_rb( + gitlab_exporter: { + enable: true, + probe_elasticsearch: true, + elasticsearch_url: "http://localhost:9200", + elasticsearch_authorization: authorization + } + ) + end + + it 'adds tranport options to elasticsearch config' do + expect(chef_run).to render_file('/var/opt/gitlab/gitlab-exporter/gitlab-exporter.yml') + .with_content { |content| + transport_options = YAML.load(content) # rubocop:disable Security/YAMLLoad + .dig('probes', 'elasticsearch', 'opts').first['options'] + expect(transport_options).to eq({ 'headers' => { 'Authorization' => authorization } }) + } + end + end + context 'with custom Redis settings' do before do stub_gitlab_rb(