Skip to content
Snippets Groups Projects
Commit 4afebc5f authored by Brian Brazil's avatar Brian Brazil Committed by Marin Jankovski
Browse files

Add Prometheus to omnibus.

parent 4e6dfb76
No related branches found
No related tags found
1 merge request!1227Include prometheus
Showing
with 231 additions and 9 deletions
Loading
Loading
@@ -115,6 +115,7 @@ dependency "gitlab-scripts"
dependency "gitlab-config-template"
dependency "mattermost"
dependency "node-exporter"
dependency "prometheus"
 
# version manifest file
dependency "version-manifest"
Loading
Loading
#
## 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.
##
#
name "prometheus"
default_version "v1.4.1"
license "APACHE-2.0"
license_file "LICENSE"
source git: "https://github.com/prometheus/prometheus.git"
relative_path "src/github.com/prometheus/prometheus"
build do
env = with_standard_compiler_flags(with_embedded_path)
env = {
'GOPATH' => "#{Omnibus::Config.source_dir}/prometheus",
'GO15VENDOREXPERIMENT' => '1' # Build machines have go 1.5.x, use vendor directory
}
exporter_source_dir = "#{Omnibus::Config.source_dir}/prometheus"
cwd = "#{exporter_source_dir}/src/github.com/prometheus/prometheus"
command "go build ./cmd/prometheus", env: env, cwd: cwd
copy "prometheus", "#{install_dir}/embedded/bin/"
end
Loading
Loading
@@ -17,6 +17,8 @@ by default:
| Unicorn | Yes | Socket | Port (8080) | X |
| GitLab Workhorse | Yes | Socket | Port (8181) | X |
| Nginx status | Yes | Port | X | 8060 |
| Node exporter | Yes | Port | X | 9100 |
| Prometheus | Yes | Port | X | 9090 |
| Redis Sentinel | No | Port | X | 26379 |
| Incoming email | No | Port | X | 143 |
| Elastic search | No | Port | X | 9200 |
Loading
Loading
Loading
Loading
@@ -966,13 +966,29 @@ default['gitlab']['registry-nginx']['proxy_set_headers'] = {
# Prometheus Node Exporter
####
default['gitlab']['node-exporter']['enable'] = true
default['gitlab']['node-exporter']['username'] = "node-exporter"
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' => node['gitlab']['node-exporter']['home'] + '/textfile_collector'
'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']['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']['flags'] = {
'storage.local.path' => File.join(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'),
}
Loading
Loading
@@ -93,6 +93,13 @@ class AccountHelper
def node_exporter_group
node['gitlab']['node-exporter']['group']
end
def prometheus_user
node['gitlab']['prometheus']['username']
end
def prometheus_group
node['gitlab']['prometheus']['group']
end
 
def users
%W(
Loading
Loading
@@ -105,6 +112,7 @@ class AccountHelper
#{mattermost_user}
#{registry_user}
#{node_exporter_user}
#{prometheus_user}
)
end
 
Loading
Loading
@@ -119,6 +127,7 @@ class AccountHelper
#{mattermost_group}
#{registry_group}
#{node_exporter_group}
#{prometheus_group}
)
end
end
Loading
Loading
@@ -81,6 +81,7 @@ module Gitlab
gitlab_pages Mash.new
registry Mash.new
node_exporter Mash.new
prometheus Mash.new
sentinel Mash.new
node nil
external_url nil
Loading
Loading
@@ -197,8 +198,9 @@ module Gitlab
"gitlab_pages",
"registry",
"sentinel",
"gitaly"
"node_exporter"
"gitaly",
"node_exporter",
"prometheus"
].each do |key|
rkey = key.gsub('_', '-')
results['gitlab'][rkey] = Gitlab[key]
Loading
Loading
Loading
Loading
@@ -51,6 +51,7 @@ module Logging
gitlab-pages
registry
node_exporter
prometheus
}.each do |runit_sv|
Gitlab[runit_sv.gsub('-', '_')]['svlogd_prefix'] ||= "#{Gitlab['node']['hostname']} #{runit_sv}: "
end
Loading
Loading
Loading
Loading
@@ -2,11 +2,14 @@
module Prometheus
class << self
def flags_for(node, service)
config = ""
node['gitlab'][service]["flags"].each do |flag_key, flag_value|
config += "-#{flag_key}=#{flag_value} " unless flag_value.empty?
config = []
node['gitlab'][service]['flags'].each do |flag_key, flag_value|
next if flag_value.empty?
config << "-#{flag_key}=#{flag_value}"
end
config
config.join(" ")
end
end
end
Loading
Loading
@@ -125,7 +125,8 @@ include_recipe "gitlab::logrotate_folders_and_configs"
"mattermost",
"gitlab-pages",
"registry",
"node-exporter"
"node-exporter",
"prometheus"
].each do |service|
if node["gitlab"][service]["enable"]
include_recipe "gitlab::#{service}"
Loading
Loading
#
# Copyright:: Copyright (c) 2012 Opscode, Inc.
# 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.
#
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
directory prometheus_dir do
owner prometheus_user
mode "0755"
recursive true
end
directory prometheus_log_dir do
owner prometheus_user
mode "0700"
recursive true
end
template "#{prometheus_dir}/prometheus.yml" do
source "prometheus.yml.erb"
owner prometheus_user
mode "0644"
notifies :restart, "service[prometheus]"
end
runit_service "prometheus" do
options({
:log_directory => prometheus_log_dir
}.merge(params))
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
#
# 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.
#
runit_service "prometheus" do
action :disable
end
global:
scrape_interval: 15s
scrape_timeout: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
<% if node['gitlab']['node-exporter']['enable'] %>
- job_name: node
static_configs:
- targets: ['localhost:9100']
<% end -%>
<%= "s#@svlogd_size" if @svlogd_size %>
<%= "n#@svlogd_num" if @svlogd_num %>
<%= "t#@svlogd_timeout" if @svlogd_timeout %>
<%= "!#@svlogd_filter" if @svlogd_filter %>
<%= "u#@svlogd_udp" if @svlogd_udp %>
<%= "p#@svlogd_prefix" if @svlogd_prefix %>
#!/bin/sh
exec svlogd -tt <%= @options[:log_directory] %>
#!/bin/sh
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') %>
require 'chef_helper'
describe 'gitlab::prometheus' do
let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') }
before do
allow(Gitlab).to receive(:[]).and_call_original
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 '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/)
expect(chef_run).to render_file('/var/opt/gitlab/prometheus/prometheus.yml')
.with_content(/scrape_interval: 15s/)
expect(chef_run).to render_file('/opt/gitlab/sv/prometheus/log/run')
.with_content(/exec svlogd -tt \/var\/log\/gitlab\/prometheus/)
end
end
context 'when storage path is changed' do
before do
stub_gitlab_rb(prometheus: {flags: {'storage.local.path': 'foo'}})
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
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