Merge branch 'export-only-managed' into 'master'

Only enable exporters by default for services currently enabled on the node

Closes #2107

See merge request !1428
This commit is contained in:
DJ Mountney 2017-03-23 22:51:34 +00:00
commit 6305644134
6 changed files with 60 additions and 4 deletions

View File

@ -6,6 +6,8 @@ omnibus-gitlab repository.
9.0.1
- Allow configuration of prepared statement caching in Rails 169891c2
- Default redis promethues exporter to off if redis is not managed locally
- Default postgres promethues exporter to off if postgres is not managed locally
9.0

View File

@ -83,5 +83,9 @@ module Postgresql
Gitlab['mattermost']['sql_data_source_replicas'] = [Gitlab['mattermost']['sql_data_source']]
end
end
def postgresql_managed?
Gitlab['postgresql']['enable'].nil? ? Gitlab['node']['gitlab']['postgresql']['enable'] : Gitlab['postgresql']['enable']
end
end
end

View File

@ -15,6 +15,9 @@
# limitations under the License.
#
require_relative 'postgresql.rb'
require_relative 'redis.rb'
module Prometheus
class << self
def services
@ -28,9 +31,16 @@ module Prometheus
end
def parse_variables
parse_exporter_enabled
parse_flags
end
def parse_exporter_enabled
# Disable exporters by default if their service is not managed on this node
Gitlab['postgres_exporter']['enable'] ||= Postgresql.postgresql_managed?
Gitlab['redis_exporter']['enable'] ||= Redis.redis_managed?
end
def parse_flags
parse_prometheus_flags
parse_node_exporter_flags

View File

@ -63,6 +63,10 @@ module Redis
end
end
def redis_managed?
Gitlab['redis']['enable'].nil? ? node['gitlab']['redis']['enable'] : Gitlab['redis']['enable']
end
private
# Parses sentinel specific meta-data to fill gitlab_rails
@ -136,9 +140,5 @@ module Redis
def has_sentinels?
Gitlab['gitlab_rails']['redis_sentinels'] && !Gitlab['gitlab_rails']['redis_sentinels'].empty?
end
def redis_managed?
Gitlab['redis']['enable'].nil? ? node['gitlab']['redis']['enable'] : Gitlab['redis']['enable']
end
end
end

View File

@ -2,11 +2,31 @@ require 'chef_helper'
describe 'gitlab::postgres-exporter' do
let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') }
let(:node) { chef_run.node }
before do
allow(Gitlab).to receive(:[]).and_call_original
end
context 'when postgres is disabled locally' do
before do
stub_gitlab_rb(
postgresql: { enable: false }
)
end
it 'defaults the postgres-exporter to being disabled' do
expect(node['gitlab']['postgres-exporter']['enable']).to eq false
end
it 'allows postgres-exporter to be explicitly enabled' do
stub_gitlab_rb(postgres_exporter: { enable: true })
expect(node['gitlab']['postgres-exporter']['enable']).to eq true
end
end
context 'when postgres-exporter is enabled' do
let(:config_template) { chef_run.template('/var/log/gitlab/postgres-exporter/config') }

View File

@ -2,11 +2,31 @@ require 'chef_helper'
describe 'gitlab::redis-exporter' do
let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') }
let(:node) { chef_run.node }
before do
allow(Gitlab).to receive(:[]).and_call_original
end
context 'when redis is disabled locally' do
before do
stub_gitlab_rb(
redis: { enable: false }
)
end
it 'defaults the redis-exporter to being disabled' do
expect(node['gitlab']['redis-exporter']['enable']).to eq false
end
it 'allows redis-exporter to be explicitly enabled' do
stub_gitlab_rb(redis_exporter: { enable: true })
expect(node['gitlab']['redis-exporter']['enable']).to eq true
end
end
context 'when redis-exporter is enabled' do
let(:config_template) { chef_run.template('/var/log/gitlab/redis-exporter/config') }