Skip to content
Snippets Groups Projects
Commit 70224190 authored by Ian Baum's avatar Ian Baum Committed by Marin Jankovski
Browse files

Updating changes to include prometheus in omnibus-gitlab

* Continued from brian-brazil/omnibus-gitlab-prometheus
* Include prometheus and node-exporter, both disabled by default
* Adding some more detailed testing
* Formatting updates
* Both should run under the same user
parent 4afebc5f
No related branches found
No related tags found
1 merge request!1227Include prometheus
Showing
with 273 additions and 118 deletions
#
## Copyright:: Copyright (c) 2014 GitLab.com
## License:: Apache License, Version 2.0
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
# Copyright:: Copyright (c) 2017 GitLab Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
 
name "node-exporter"
default_version "v0.13.0"
name 'node-exporter'
default_version 'v0.13.0'
 
license "APACHE-2.0"
license_file "LICENSE"
license 'APACHE-2.0'
license_file 'LICENSE'
 
source git: "https://github.com/prometheus/node_exporter.git"
source git: 'https://github.com/prometheus/node_exporter.git'
 
relative_path "src/github.com/prometheus/node_exporter"
relative_path 'src/github.com/prometheus/node_exporter'
 
build do
env = with_standard_compiler_flags(with_embedded_path)
env = {
'GOPATH' => "#{Omnibus::Config.source_dir}/node-exporter",
'GO15VENDOREXPERIMENT' => '1' # Build machines have go 1.5.x, use vendor directory
}
env['GOPATH'] = "#{Omnibus::Config.source_dir}/node-exporter"
env['GO15VENDOREXPERIMENT'] = '1' # Build machines have go 1.5.x, use vendor directory
exporter_source_dir = "#{Omnibus::Config.source_dir}/node-exporter"
cwd = "#{exporter_source_dir}/src/github.com/prometheus/node_exporter"
 
command "go build", env: env, cwd: cwd
copy "node_exporter", "#{install_dir}/embedded/bin/"
command 'go build', env: env, cwd: cwd
copy 'node_exporter', "#{install_dir}/embedded/bin/"
end
Loading
Loading
@@ -962,33 +962,31 @@ default['gitlab']['registry-nginx']['proxy_set_headers'] = {
"X-Forwarded-Proto" => "$scheme"
}
 
####
# Prometheus Node Exporter
####
default['gitlab']['node-exporter']['enable'] = true
default['gitlab']['node-exporter']['username'] = "gitlab-node-exporter"
default['gitlab']['node-exporter']['uid'] = nil
default['gitlab']['node-exporter']['gid'] = nil
default['gitlab']['node-exporter']['shell'] = "/bin/sh"
default['gitlab']['node-exporter']['home'] = "/var/opt/gitlab/node-exporter"
default['gitlab']['node-exporter']['log_directory'] = "/var/log/gitlab/node-exporter"
default['gitlab']['node-exporter']['flags'] = {
'collector.textfile.directory' => File.join(node['gitlab']['node-exporter']['home'], 'textfile_collector')
}
####
# Prometheus server
####
default['gitlab']['prometheus']['enable'] = true
default['gitlab']['prometheus']['username'] = "gitlab-prometheus"
default['gitlab']['prometheus']['enable'] = false
default['gitlab']['prometheus']['username'] = 'gitlab-prometheus'
default['gitlab']['prometheus']['uid'] = nil
default['gitlab']['prometheus']['gid'] = nil
default['gitlab']['prometheus']['shell'] = "/bin/sh"
default['gitlab']['prometheus']['home'] = "/var/opt/gitlab/prometheus"
default['gitlab']['prometheus']['log_directory'] = "/var/log/gitlab/prometheus"
default['gitlab']['prometheus']['shell'] = '/bin/sh'
default['gitlab']['prometheus']['home'] = '/var/opt/gitlab/prometheus'
default['gitlab']['prometheus']['log_directory'] = '/var/log/gitlab/prometheus'
default['gitlab']['prometheus']['scrape_interval'] = 15
default['gitlab']['prometheus']['scrape_timeout'] = 15
default['gitlab']['prometheus']['flags'] = {
'storage.local.path' => File.join(node['gitlab']['prometheus']['home'], 'data'),
'storage.local.path' => "#{node['gitlab']['prometheus']['home']}/data",
'storage.local.memory-chunks' => '50000',
'storage.local.max-chunks-to-persist' => '40000',
'config.file' => File.join(node['gitlab']['prometheus']['home'], 'prometheus.yml'),
'config.file' => "#{node['gitlab']['prometheus']['home']}/prometheus.yml"
}
####
# Prometheus Node Exporter
####
default['gitlab']['node-exporter']['enable'] = false
default['gitlab']['node-exporter']['home'] = '/var/opt/gitlab/node-exporter'
default['gitlab']['node-exporter']['log_directory'] = '/var/log/gitlab/node-exporter'
default['gitlab']['node-exporter']['flags'] = {
'collector.textfile.directory' => "#{node['gitlab']['node-exporter']['home']}/textfile_collector"
}
Loading
Loading
@@ -86,13 +86,6 @@ class AccountHelper
node['gitlab']['registry']['group']
end
 
def node_exporter_user
node['gitlab']['node-exporter']['username']
end
def node_exporter_group
node['gitlab']['node-exporter']['group']
end
def prometheus_user
node['gitlab']['prometheus']['username']
end
Loading
Loading
#
# Copyright:: Copyright (c) 2017 GitLab Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
 
module Prometheus
module PrometheusHelper
class << self
def flags_for(node, service)
config = []
Loading
Loading
Loading
Loading
@@ -16,37 +16,31 @@
# limitations under the License.
#
account_helper = AccountHelper.new(node)
node_exporter_user = account_helper.node_exporter_user
node_exporter_user = account_helper.prometheus_user
node_exporter_log_dir = node['gitlab']['node-exporter']['log_directory']
node_exporter_home = node['gitlab']['node-exporter']['home']
textfile_dir = node['gitlab']['node-exporter']['flags']['collector.textfile.directory']
 
account "Node exporter user and group" do
username node_exporter_user
uid node['gitlab']['node-exporter']['uid']
ugid node_exporter_user
groupname node_exporter_user
gid node['gitlab']['node-exporter']['gid']
shell node['gitlab']['node-exporter']['shell']
manage node['gitlab']['manage-accounts']['enable']
end
# node-exporter runs under the prometheus user account. If prometheus is
# disabled, it's up to this recipe to create the account
include_recipe 'gitlab::prometheus_user'
 
directory node_exporter_log_dir do
owner node_exporter_user
mode "0700"
mode '0700'
recursive true
end
 
directory textfile_dir do
directory textfile_dir do
owner node_exporter_user
mode "0755"
mode '0755'
recursive true
end
 
runit_service "node-exporter" do
runit_service 'node-exporter' do
options({
:log_directory => node_exporter_log_dir
log_directory: node_exporter_log_dir
}.merge(params))
log_options node['gitlab']['logging'].to_hash.merge(node['gitlab']['node-exporter'].to_hash)
log_options node['gitlab']['logging'].to_hash.merge(
node['gitlab']['node-exporter'].to_hash
)
end
#
# Copyright:: Copyright (c) 2012 Opscode, Inc.
# Copyright:: Copyright (c) 2014 GitLab.com
# License:: Apache License, Version 2.0
# Copyright:: Copyright (c) 2017 GitLab Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Loading
Loading
@@ -15,44 +13,38 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
account_helper = AccountHelper.new(node)
prometheus_user = account_helper.prometheus_user
prometheus_log_dir = node['gitlab']['prometheus']['log_directory']
prometheus_dir = node['gitlab']['prometheus']['home']
 
account "Prometheus user and group" do
username prometheus_user
uid node['gitlab']['prometheus']['uid']
ugid prometheus_user
groupname prometheus_user
gid node['gitlab']['prometheus']['gid']
shell node['gitlab']['prometheus']['shell']
manage node['gitlab']['manage-accounts']['enable']
end
include_recipe 'gitlab::prometheus_user'
 
directory prometheus_dir do
owner prometheus_user
mode "0755"
mode '0755'
recursive true
end
 
directory prometheus_log_dir do
owner prometheus_user
mode "0700"
mode '0700'
recursive true
end
 
template "#{prometheus_dir}/prometheus.yml" do
source "prometheus.yml.erb"
source 'prometheus.yml.erb'
owner prometheus_user
mode "0644"
notifies :restart, "service[prometheus]"
mode '0644'
notifies :restart, 'service[prometheus]'
end
 
runit_service "prometheus" do
runit_service 'prometheus' do
options({
:log_directory => prometheus_log_dir
log_directory: prometheus_log_dir
}.merge(params))
log_options node['gitlab']['logging'].to_hash.merge(node['gitlab']['registry'].to_hash)
log_options node['gitlab']['logging'].to_hash.merge(
node['gitlab']['registry'].to_hash
)
end
#
# Copyright:: Copyright (c) 2012 Opscode, Inc.
# Copyright:: Copyright (c) 2016 GitLab Inc.
# License:: Apache License, Version 2.0
# Copyright:: Copyright (c) 2017 GitLab Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Loading
Loading
@@ -16,6 +14,6 @@
# limitations under the License.
#
 
runit_service "prometheus" do
runit_service 'prometheus' do
action :disable
end
#
# Copyright:: Copyright (c) 2017 GitLab Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
account_helper = AccountHelper.new(node)
prometheus_user = account_helper.prometheus_user
prometheus_dir = node['gitlab']['prometheus']['home']
account "Prometheus user and group" do
username prometheus_user
uid node['gitlab']['prometheus']['uid']
ugid prometheus_user
groupname prometheus_user
home prometheus_dir
gid node['gitlab']['prometheus']['gid']
shell node['gitlab']['prometheus']['shell']
manage node['gitlab']['manage-accounts']['enable']
end
global:
scrape_interval: 15s
scrape_timeout: 15s
scrape_interval: <%= node['gitlab']['prometheus']['scrape_interval'] %>s
scrape_timeout: <%= node['gitlab']['prometheus']['scrape_timeout'] %>s
 
scrape_configs:
- job_name: prometheus
Loading
Loading
Loading
Loading
@@ -2,4 +2,4 @@
exec 2>&1
<%= render("mount_point_check.erb") %>
umask 077
exec chpst -P -U <%= node['gitlab']['node-exporter']['username'] %> -u <%= node['gitlab']['node-exporter']['username'] %> /opt/gitlab/embedded/bin/node_exporter <%= Prometheus::flags_for(node, 'node-exporter') %>
exec chpst -P -U <%= node['gitlab']['prometheus']['username'] %> -u <%= node['gitlab']['prometheus']['username'] %> /opt/gitlab/embedded/bin/node_exporter <%= PrometheusHelper::flags_for(node, 'node-exporter') %>
Loading
Loading
@@ -2,4 +2,4 @@
exec 2>&1
<%= render("mount_point_check.erb") %>
umask 077
exec chpst -P -U <%= node['gitlab']['prometheus']['username'] %> -u <%= node['gitlab']['prometheus']['username'] %> /opt/gitlab/embedded/bin/prometheus <%= Prometheus::flags_for(node, 'prometheus') %>
exec chpst -P -U <%= node['gitlab']['prometheus']['username'] %> -u <%= node['gitlab']['prometheus']['username'] %> /opt/gitlab/embedded/bin/prometheus <%= PrometheusHelper::flags_for(node, 'prometheus') %>
Loading
Loading
@@ -77,4 +77,19 @@ describe 'gitlab::default' do
expect(chef_run).to_not create_directory('/etc/gitlab')
end
end
context 'prometheus is disabled default' do
it 'includes the prometheus_disable recipe' do
expect(chef_run).to include_recipe('gitlab::prometheus_disable')
expect(chef_run).to_not include_recipe('gitlab::prometheus')
end
end
context 'with prometheus enabled' do
before { stub_gitlab_rb(prometheus: { enable: true }) }
it 'includes the prometheus recipe' do
expect(chef_run).to include_recipe('gitlab::prometheus')
expect(chef_run).to_not include_recipe('gitlab::prometheus_disable')
end
end
end
Loading
Loading
@@ -5,31 +5,58 @@ describe 'gitlab::node-exporter' do
 
before do
allow(Gitlab).to receive(:[]).and_call_original
stub_gitlab_rb(
node_exporter: { enable: true }
)
end
 
context 'when node-exporter is enabled' do
let(:config_template) { chef_run.template('/var/log/gitlab/node-exporter/config') }
 
it_behaves_like "enabled runit service", "node-exporter", "root", "root"
before do
stub_gitlab_rb(
node_exporter: { enable: true }
)
end
it_behaves_like 'enabled runit service', 'node-exporter', 'root', 'root'
 
it 'populates the files with expected configuration' do
expect(config_template).to notify('ruby_block[reload node-exporter svlogd configuration]')
 
expect(chef_run).to render_file('/opt/gitlab/sv/node-exporter/run')
.with_content(/exec chpst -P/)
expect(chef_run).to render_file('/opt/gitlab/sv/node-exporter/run')
.with_content(/\/opt\/gitlab\/embedded\/bin\/node_exporter/)
expect(chef_run).to render_file('/opt/gitlab/sv/node-exporter/run')
.with_content(/\/textfile_collector/)
.with_content { |content|
expect(content).to match(/exec chpst -P/)
expect(content).to match(/\/opt\/gitlab\/embedded\/bin\/node_exporter/)
expect(content).to match(/\/textfile_collector/)
}
 
expect(chef_run).to render_file('/opt/gitlab/sv/node-exporter/log/run')
.with_content(/exec svlogd -tt \/var\/log\/gitlab\/node-exporter/)
end
end
 
context 'when node-exporter is enabled and prometheus is disabled' do
before do
stub_gitlab_rb(
prometheus: { enable: false },
node_exporter: { enable: true }
)
end
it 'should create the gitlab-prometheus account if prometheus is disabled' do
expect(chef_run).to create_user('gitlab-prometheus')
end
end
context 'when log dir is changed' do
before do
stub_gitlab_rb(node_exporter: {log_directory: 'foo'})
stub_gitlab_rb(
node_exporter: {
log_directory: 'foo',
enable: true
}
)
end
it 'populates the files with expected configuration' do
expect(chef_run).to render_file('/opt/gitlab/sv/node-exporter/log/run')
Loading
Loading
Loading
Loading
@@ -5,38 +5,87 @@ describe 'gitlab::prometheus' do
 
before do
allow(Gitlab).to receive(:[]).and_call_original
stub_gitlab_rb(
prometheus: {
enable: true
}
)
end
 
context 'when prometheus is enabled' do
let(:config_template) { chef_run.template('/var/log/gitlab/prometheus/config') }
 
it_behaves_like "enabled runit service", "prometheus", "root", "root"
it_behaves_like 'enabled runit service', 'prometheus', 'root', 'root'
 
it 'populates the files with expected configuration' do
expect(config_template).to notify('ruby_block[reload prometheus svlogd configuration]')
 
expect(chef_run).to render_file('/opt/gitlab/sv/prometheus/run')
.with_content(/exec chpst -P/)
expect(chef_run).to render_file('/opt/gitlab/sv/prometheus/run')
.with_content(/\/opt\/gitlab\/embedded\/bin\/prometheus/)
expect(chef_run).to render_file('/opt/gitlab/sv/prometheus/run')
.with_content(/prometheus.yml/)
.with_content { |content|
expect(content).to match(/exec chpst -P/)
expect(content).to match(/\/opt\/gitlab\/embedded\/bin\/prometheus/)
expect(content).to match(/prometheus.yml/)
}
 
expect(chef_run).to render_file('/var/opt/gitlab/prometheus/prometheus.yml')
.with_content(/scrape_interval: 15s/)
.with_content { |content|
expect(content).to match(/scrape_interval: 15s/)
expect(content).to match(/scrape_timeout: 15s/)
}
 
expect(chef_run).to render_file('/opt/gitlab/sv/prometheus/log/run')
.with_content(/exec svlogd -tt \/var\/log\/gitlab\/prometheus/)
end
it 'should create a gitlab-prometheus user account' do
expect(chef_run).to create_user('gitlab-prometheus')
end
end
 
context 'when storage path is changed' do
before do
stub_gitlab_rb(prometheus: {flags: {'storage.local.path': 'foo'}})
stub_gitlab_rb(
prometheus: {
flags: { 'storage.local.path': 'foo' },
enable: true
}
)
end
it 'populates the files with expected configuration' do
expect(chef_run).to render_file('/opt/gitlab/sv/prometheus/run')
.with_content(/storage.local.path=foo/)
end
end
context 'when scrape_interval is changed' do
before do
stub_gitlab_rb(
prometheus: {
scrape_interval: 9999,
enable: true
}
)
end
it 'renders prometheus.yml with the non-default value' do
expect(chef_run).to render_file('/var/opt/gitlab/prometheus/prometheus.yml')
.with_content(/scrape_interval: 9999s/)
end
end
context 'when scrape_timeout is changed' do
before do
stub_gitlab_rb(
prometheus: {
scrape_timeout: 8888,
enable: true
}
)
end
it 'renders prometheus.yml with the non-default value' do
expect(chef_run).to render_file('/var/opt/gitlab/prometheus/prometheus.yml')
.with_content(/scrape_timeout: 8888s/)
end
end
end
#
# Copyright:: Copyright (c) 2017 GitLab Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require_relative '../../files/gitlab-cookbooks/gitlab/libraries/prometheus_helper.rb'
require 'chef_helper'
describe PrometheusHelper do
let(:chef_run) { ChefSpec::SoloRunner.new }
subject { described_class.new(chef_run.node) }
context 'flags_for' do
context 'with default options' do
it 'returns the correct default config string' do
chef_run.converge('gitlab::default')
expect(PrometheusHelper.flags_for(chef_run.node, 'prometheus')).to eq(
'-storage.local.path=/var/opt/gitlab/prometheus/data -storage.local.memory-chunks=50000 -storage.local.max-chunks-to-persist=40000 -config.file=/var/opt/gitlab/prometheus/prometheus.yml')
end
end
context 'with custom options' do
before { allow(Gitlab).to receive(:[]).and_call_original }
it 'does not return the correct string if any attributes have been changed' do
chef_run.node.set['gitlab']['prometheus']['home'] = '/fake/dir'
chef_run.converge('gitlab::default')
expect(PrometheusHelper.flags_for(chef_run.node, 'prometheus')).to eq(
'-storage.local.path=/fake/dir/data -storage.local.memory-chunks=50000 -storage.local.max-chunks-to-persist=40000 -config.file=/fake/dir/prometheus.yml')
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment