Commit c6c96708 authored by Jacob Schatz's avatar Jacob Schatz

Merge branch 'master' into improved-leave-project

parents 8ee6abaa 3a227b5a
...@@ -67,6 +67,14 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -67,6 +67,14 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:user_oauth_applications, :user_oauth_applications,
:shared_runners_enabled, :shared_runners_enabled,
:max_artifacts_size, :max_artifacts_size,
:metrics_enabled,
:metrics_host,
:metrics_database,
:metrics_username,
:metrics_password,
:metrics_pool_size,
:metrics_timeout,
:metrics_method_call_threshold,
restricted_visibility_levels: [], restricted_visibility_levels: [],
import_sources: [] import_sources: []
) )
......
...@@ -156,5 +156,58 @@ ...@@ -156,5 +156,58 @@
.col-sm-10 .col-sm-10
= f.number_field :max_artifacts_size, class: 'form-control' = f.number_field :max_artifacts_size, class: 'form-control'
%fieldset
%legend Metrics
%p
These settings require a restart to take effect.
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :metrics_enabled do
= f.check_box :metrics_enabled
Enable InfluxDB Metrics
.form-group
= f.label :metrics_host, 'InfluxDB host', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :metrics_host, class: 'form-control', placeholder: 'influxdb.example.com'
.form-group
= f.label :metrics_database, 'InfluxDB database', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :metrics_database, class: 'form-control', placeholder: 'gitlab'
.help-block
The name of the InfluxDB database to store data in. Users will have to
create this database manually, GitLab does not do so automatically.
.form-group
= f.label :metrics_username, 'InfluxDB username', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :metrics_username, class: 'form-control'
.form-group
= f.label :metrics_password, 'InfluxDB password', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :metrics_password, class: 'form-control'
.form-group
= f.label :metrics_pool_size, 'Connection pool size', class: 'control-label col-sm-2'
.col-sm-10
= f.number_field :metrics_pool_size, class: 'form-control'
.help-block
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).
.form-group
= f.label :metrics_timeout, 'Connection timeout', class: 'control-label col-sm-2'
.col-sm-10
= f.number_field :metrics_timeout, class: 'form-control'
.help-block
The amount of seconds after which an InfluxDB connection will time
out.
.form-group
= f.label :metrics_method_call_threshold, 'Method Call Threshold (ms)', class: 'control-label col-sm-2'
.col-sm-10
= f.number_field :metrics_method_call_threshold, class: 'form-control'
.help-block
A method call is only tracked when it takes longer to complete than
the given amount of milliseconds.
.form-actions .form-actions
= f.submit 'Save', class: 'btn btn-primary' = f.submit 'Save', class: 'btn btn-primary'
...@@ -449,26 +449,9 @@ production: &base ...@@ -449,26 +449,9 @@ production: &base
# #
# Ban an IP for one hour (3600s) after too many auth attempts # Ban an IP for one hour (3600s) after too many auth attempts
# bantime: 3600 # bantime: 3600
metrics:
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
development: development:
<<: *base <<: *base
metrics:
enabled: false
test: test:
<<: *base <<: *base
...@@ -511,10 +494,6 @@ test: ...@@ -511,10 +494,6 @@ test:
user_filter: '' user_filter: ''
group_base: 'ou=groups,dc=example,dc=com' group_base: 'ou=groups,dc=example,dc=com'
admin_group: '' admin_group: ''
metrics:
enabled: false
staging: staging:
<<: *base <<: *base
metrics:
enabled: false
...@@ -32,10 +32,17 @@ if Gitlab::Metrics.enabled? ...@@ -32,10 +32,17 @@ if Gitlab::Metrics.enabled?
) )
Gitlab::Metrics::Instrumentation. Gitlab::Metrics::Instrumentation.
instrument_class_hierarchy(ActiveRecord::Base) do |_, method| instrument_class_hierarchy(ActiveRecord::Base) do |klass, method|
loc = method.source_location # 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
false
else
loc = method.source_location
loc && loc[0].start_with?(models) && method.source =~ regex loc && loc[0].start_with?(models) && method.source =~ regex
end
end end
end end
......
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
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -52,6 +52,14 @@ ActiveRecord::Schema.define(version: 20151224123230) do ...@@ -52,6 +52,14 @@ ActiveRecord::Schema.define(version: 20151224123230) do
t.string "runners_registration_token" t.string "runners_registration_token"
t.boolean "require_two_factor_authentication", default: false t.boolean "require_two_factor_authentication", default: false
t.integer "two_factor_grace_period", default: 48 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
end end
create_table "audit_events", force: :cascade do |t| create_table "audit_events", force: :cascade do |t|
......
...@@ -6,11 +6,11 @@ If a user is both in a project group and in the project itself, the highest perm ...@@ -6,11 +6,11 @@ If a user is both in a project group and in the project itself, the highest perm
If a user is a GitLab administrator they receive all permissions. If a user is a GitLab administrator they receive all permissions.
On public projects the Guest role is not enforced. On public projects the Guest role is not enforced.
All users will be able to create issues, leave comments, and pull or download the project code. All users will be able to create issues, leave comments, and pull or download the project code.
To add or import a user, you can follow the [project users and members To add or import a user, you can follow the [project users and members
documentation](doc/workflow/add-user/add-user.md). documentation](../workflow/add-user/add-user.md).
## Project ## Project
......
...@@ -4,16 +4,33 @@ module Gitlab ...@@ -4,16 +4,33 @@ module Gitlab
METRICS_ROOT = Rails.root.join('lib', 'gitlab', 'metrics').to_s METRICS_ROOT = Rails.root.join('lib', 'gitlab', 'metrics').to_s
PATH_REGEX = /^#{RAILS_ROOT}\/?/ PATH_REGEX = /^#{RAILS_ROOT}\/?/
# 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
if ApplicationSetting.table_exists? and curr = ApplicationSetting.current
curr
else
{
metrics_pool_size: 16,
metrics_timeout: 10,
metrics_enabled: false,
metrics_method_call_threshold: 10
}
end
end
def self.pool_size def self.pool_size
Settings.metrics['pool_size'] || 16 settings[:metrics_pool_size]
end end
def self.timeout def self.timeout
Settings.metrics['timeout'] || 10 settings[:metrics_timeout]
end end
def self.enabled? def self.enabled?
!!Settings.metrics['enabled'] settings[:metrics_enabled]
end end
def self.mri? def self.mri?
...@@ -21,7 +38,10 @@ module Gitlab ...@@ -21,7 +38,10 @@ module Gitlab
end end
def self.method_call_threshold 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]
end end
def self.pool def self.pool
...@@ -52,10 +72,10 @@ module Gitlab ...@@ -52,10 +72,10 @@ module Gitlab
# "@foo ||= bar" is _not_ thread-safe. # "@foo ||= bar" is _not_ thread-safe.
if enabled? if enabled?
@pool = ConnectionPool.new(size: pool_size, timeout: timeout) do @pool = ConnectionPool.new(size: pool_size, timeout: timeout) do
host = Settings.metrics['host'] host = settings[:metrics_host]
db = Settings.metrics['database'] db = settings[:metrics_database]
user = Settings.metrics['username'] user = settings[:metrics_username]
pw = Settings.metrics['password'] pw = settings[:metrics_password]
InfluxDB::Client.new(db, host: host, username: user, password: pw) InfluxDB::Client.new(db, host: host, username: user, password: pw)
end end
......
...@@ -29,7 +29,7 @@ describe Gitlab::Metrics do ...@@ -29,7 +29,7 @@ describe Gitlab::Metrics do
it 'returns an Array containing a file path and line number' do it 'returns an Array containing a file path and line number' do
file, line = described_class.last_relative_application_frame file, line = described_class.last_relative_application_frame
expect(line).to eq(30) expect(line).to eq(__LINE__ - 2)
expect(file).to eq('spec/lib/gitlab/metrics_spec.rb') expect(file).to eq('spec/lib/gitlab/metrics_spec.rb')
end end
end end
......
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