Commit 4d925f21 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Move InfluxDB settings to ApplicationSetting

parent 540eb0a9
......@@ -67,6 +67,14 @@ def application_setting_params
restricted_visibility_levels: [],
import_sources: []
......@@ -156,5 +156,58 @@
= f.number_field :max_artifacts_size, class: 'form-control'
%legend Metrics
These settings require a restart to take effect.
= f.label :metrics_enabled do
= f.check_box :metrics_enabled
Enable InfluxDB Metrics
= f.label :metrics_host, 'InfluxDB host', class: 'control-label col-sm-2'
= f.text_field :metrics_host, class: 'form-control', placeholder: ''
= f.label :metrics_database, 'InfluxDB database', class: 'control-label col-sm-2'
= f.text_field :metrics_database, class: 'form-control', placeholder: 'gitlab'
The name of the InfluxDB database to store data in. Users will have to
create this database manually, GitLab does not do so automatically.
= f.label :metrics_username, 'InfluxDB username', class: 'control-label col-sm-2'
= f.text_field :metrics_username, class: 'form-control'
= f.label :metrics_password, 'InfluxDB password', class: 'control-label col-sm-2'
= f.text_field :metrics_password, class: 'form-control'
= f.label :metrics_pool_size, 'Connection pool size', class: 'control-label col-sm-2'
= f.number_field :metrics_pool_size, class: 'form-control'
The amount of InfluxDB connections to open. Connections are opened
lazily. Users using multi-threaded application servers should ensure
enough connections are available (at minimum the amount of application
server threads).
= f.label :metrics_timeout, 'Connection timeout', class: 'control-label col-sm-2'
= f.number_field :metrics_timeout, class: 'form-control'
The amount of seconds after which an InfluxDB connection will time
= f.label :metrics_method_call_threshold, 'Method Call Threshold (ms)', class: 'control-label col-sm-2'
= f.number_field :metrics_method_call_threshold, class: 'form-control'
A method call is only tracked when it takes longer to complete than
the given amount of milliseconds.
= f.submit 'Save', class: 'btn btn-primary'
......@@ -449,26 +449,9 @@ production: &base
# Ban an IP for one hour (3600s) after too many auth attempts
# bantime: 3600
host: localhost
enabled: false
# The name of the InfluxDB database to store metrics in.
database: gitlab
# Credentials to use for logging in to InfluxDB.
# username:
# password:
# The amount of InfluxDB connections to open.
# pool_size: 16
# The timeout of a connection in seconds.
# timeout: 10
# The minimum amount of milliseconds a method call has to take before it's
# tracked. Defaults to 10.
# method_call_threshold: 10
<<: *base
enabled: false
<<: *base
......@@ -511,10 +494,6 @@ test:
user_filter: ''
group_base: 'ou=groups,dc=example,dc=com'
admin_group: ''
enabled: false
<<: *base
enabled: false
......@@ -32,10 +32,17 @@
instrument_class_hierarchy(ActiveRecord::Base) do |_, method|
loc = method.source_location
instrument_class_hierarchy(ActiveRecord::Base) do |klass, method|
# Instrumenting the ApplicationSetting class can lead to an infinite
# loop. Since the data is cached any way we don't really need to
# instrument it.
if klass == ApplicationSetting
loc = method.source_location
loc && loc[0].start_with?(models) && method.source =~ regex
loc && loc[0].start_with?(models) && method.source =~ regex
class InfluxdbSettings < ActiveRecord::Migration
def change
add_column :application_settings, :metrics_enabled, :boolean, default: false
add_column :application_settings, :metrics_host, :string,
default: 'localhost'
add_column :application_settings, :metrics_database, :string,
default: 'gitlab'
add_column :application_settings, :metrics_username, :string
add_column :application_settings, :metrics_password, :string
add_column :application_settings, :metrics_pool_size, :integer, default: 16
add_column :application_settings, :metrics_timeout, :integer, default: 10
add_column :application_settings, :metrics_method_call_threshold,
:integer, default: 10
......@@ -11,7 +11,7 @@
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151224123230) do
ActiveRecord::Schema.define(version: 20151228150906) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -52,6 +52,14 @@
t.string "runners_registration_token"
t.boolean "require_two_factor_authentication", default: false
t.integer "two_factor_grace_period", default: 48
t.boolean "metrics_enabled", default: false
t.string "metrics_host", default: "localhost"
t.string "metrics_database", default: "gitlab"
t.string "metrics_username"
t.string "metrics_password"
t.integer "metrics_pool_size", default: 16
t.integer "metrics_timeout", default: 10
t.integer "metrics_method_call_threshold", default: 10
create_table "audit_events", force: :cascade do |t|
......@@ -4,16 +4,29 @@ module Metrics
METRICS_ROOT = Rails.root.join('lib', 'gitlab', 'metrics').to_s
# Returns the current settings, ensuring we _always_ have a default set of
# metrics settings (even during tests, when the migrations are lacking,
# etc). This ensures the application is able to boot up even when the
# migrations have not been executed.
def self.settings
ApplicationSetting.current || {
metrics_pool_size: 16,
metrics_timeout: 10,
metrics_enabled: false,
metrics_method_call_threshold: 10
def self.pool_size
Settings.metrics['pool_size'] || 16
def self.timeout
Settings.metrics['timeout'] || 10
def self.enabled?
def self.mri?
......@@ -21,7 +34,10 @@ def self.mri?
def self.method_call_threshold
Settings.metrics['method_call_threshold'] || 10
# This is memoized since this method is called for every instrumented
# method. Loading data from an external cache on every method call slows
# things down too much.
@method_call_threshold ||= settings[:metrics_method_call_threshold]
def self.pool
......@@ -52,10 +68,10 @@ def self.last_relative_application_frame
# "@foo ||= bar" is _not_ thread-safe.
if enabled?
@pool = pool_size, timeout: timeout) do
host = Settings.metrics['host']
db = Settings.metrics['database']
user = Settings.metrics['username']
pw = Settings.metrics['password']
host = settings[:metrics_host]
db = settings[:metrics_database]
user = settings[:metrics_username]
pw = settings[:metrics_password], host: host, username: user, password: pw)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment