Skip to content

Commit 7390a6f

Browse files
committed
Make redis-exporter work with external Redis instances
This commit adds support for using redis-exporter with an external Redis instance when enabled via: ``` redis_exporter['enable'] = true ``` Omnibus GitLab disables redis-exporter if the bundled Redis instance is disabled, but previously when redis-exporter were enabled it would always attempt to talk to a local UNIX socket. This commit has been tested with Google Memorystore with TLS enabled. Note that TLS client auth is not yet supported.
1 parent 101f779 commit 7390a6f

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

files/gitlab-cookbooks/monitoring/libraries/prometheus.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,16 @@ def parse_redis_exporter_flags
118118
user_config = Gitlab['redis_exporter']
119119

120120
listen_address = user_config['listen_address'] || default_config['listen_address']
121+
disable_client_name = Gitlab['gitlab_rails']['redis_enable_client'] == false
122+
121123
default_config['flags'] = {
122-
'web.listen-address' => listen_address,
123-
'redis.addr' => "unix://#{Gitlab['node']['gitlab']['gitlab_rails']['redis_socket']}"
124+
'web.listen-address' => listen_address
124125
}
125126

127+
default_config['flags']['set-client-name'] = 'false' if disable_client_name
126128
default_config['flags'].merge!(user_config['flags']) if user_config.key?('flags')
127129

130+
# redis.addr is set in the recipe
128131
Gitlab['redis_exporter']['flags'] = default_config['flags']
129132
end
130133

files/gitlab-cookbooks/monitoring/recipes/redis-exporter.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@
4343
end
4444

4545
runtime_flags = PrometheusHelper.new(node).flags('redis_exporter')
46+
redis_helper = NewRedisHelper::RedisExporter.new(node)
47+
redis_url = redis_helper.formatted_redis_url
48+
4649
runit_service 'redis-exporter' do
4750
options({
4851
log_directory: logging_settings[:log_directory],
4952
log_user: logging_settings[:runit_owner],
5053
log_group: logging_settings[:runit_group],
5154
flags: runtime_flags,
52-
env_dir: redis_exporter_static_etc_dir
55+
env_dir: redis_exporter_static_etc_dir,
56+
redis_url: redis_url,
5357
}.merge(params))
5458
log_options logging_settings[:options]
5559
end

files/gitlab-cookbooks/monitoring/templates/sv-redis-exporter-run.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ umask 077
55
exec chpst -P -e <%= @options[:env_dir] %> \
66
-U <%= node['redis']['username'] %>:<%= node['gitlab']['user']['group'] %> \
77
-u <%= node['redis']['username'] %>:<%= node['gitlab']['user']['group'] %> \
8-
/opt/gitlab/embedded/bin/redis_exporter <%= @options[:flags] %>
8+
/opt/gitlab/embedded/bin/redis_exporter <%= @options[:flags] %> --redis.addr=<%= @options[:redis_url] %>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
module NewRedisHelper
4+
class RedisExporter < NewRedisHelper::Base
5+
def redis_params
6+
{
7+
url: redis_url
8+
}
9+
end
10+
11+
def formatted_redis_url
12+
url = redis_url
13+
14+
url.scheme == 'unix' ? "unix://#{url.path}" : url.to_s
15+
end
16+
17+
private
18+
19+
def node_access_keys
20+
%w[gitlab gitlab_rails]
21+
end
22+
23+
def support_sentinel_groupname?
24+
false
25+
end
26+
end
27+
end

spec/chef/cookbooks/monitoring/recipes/redis_exporter_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,34 @@
6767
end
6868
end
6969

70+
context 'when redis-exporter is enabled for an external Redis' do
71+
let(:config_template) { chef_run.template('/opt/gitlab/sv/redis-exporter/log/config') }
72+
73+
before do
74+
stub_gitlab_rb(
75+
redis_exporter: { enable: true },
76+
gitlab_rails: {
77+
redis_host: '1.2.3.4',
78+
redis_port: 6378,
79+
redis_ssl: true,
80+
redis_password: 'some-password',
81+
redis_enable_client: false
82+
}
83+
)
84+
end
85+
86+
it_behaves_like 'enabled runit service', 'redis-exporter', 'root', 'root'
87+
88+
it 'sets flags' do
89+
expect(chef_run).to render_file('/opt/gitlab/sv/redis-exporter/run')
90+
.with_content(/web.listen-address=localhost:9121/)
91+
expect(chef_run).to render_file('/opt/gitlab/sv/redis-exporter/run')
92+
.with_content(%r{redis.addr=rediss://:[email protected]:6378/})
93+
expect(chef_run).to render_file('/opt/gitlab/sv/redis-exporter/run')
94+
.with_content(/--set-client-name=false/)
95+
end
96+
end
97+
7098
context 'when log dir is changed' do
7199
before do
72100
stub_gitlab_rb(

0 commit comments

Comments
 (0)