Storing of application metrics in InfluxDB
This adds the ability to write application metrics (e.g. SQL timings) to
InfluxDB. These metrics can in turn be visualized using Grafana, or
really anything else that can read from InfluxDB. These metrics can be
used to track application performance over time, between different Ruby
versions, different GitLab versions, etc.
== Transaction Metrics
Currently the following is tracked on a per transaction basis (a
transaction is a Rails request or a single Sidekiq job):
* Timings per query along with the raw (obfuscated) SQL and information
about what file the query originated from.
* Timings per view along with the path of the view and information about
what file triggered the rendering process.
* The duration of a request itself along with the controller/worker
class and method name.
* The duration of any instrumented method calls (more below).
== Sampled Metrics
Certain metrics can't be directly associated with a transaction. For
example, a process' total memory usage is unrelated to any running
transactions. While a transaction can result in the memory usage going
up there's no accurate way to determine what transaction is to blame,
this becomes especially problematic in multi-threaded environments.
To solve this problem there's a separate thread that takes samples at a
fixed interval. This thread (using the class Gitlab::Metrics::Sampler)
currently tracks the following:
* The process' total memory usage.
* The number of file descriptors opened by the process.
* The amount of Ruby objects (using ObjectSpace.count_objects).
* GC statistics such as timings, heap slots, etc.
The default/current interval is 15 seconds, any smaller interval might
put too much pressure on InfluxDB (especially when running dozens of
processes).
== Method Instrumentation
While currently not yet used methods can be instrumented to track how
long they take to run. Unlike the likes of New Relic this doesn't
require modifying the source code (e.g. including modules), it all
happens from the outside. For example, to track `User.by_login` we'd add
the following code somewhere in an initializer:
Gitlab::Metrics::Instrumentation.
instrument_method(User, :by_login)
to instead instrument an instance method:
Gitlab::Metrics::Instrumentation.
instrument_instance_method(User, :save)
Instrumentation for either all public model methods or a few crucial
ones will be added in the near future, I simply haven't gotten to doing
so just yet.
== Configuration
By default metrics are disabled. This means users don't have to bother
setting anything up if they don't want to. Metrics can be enabled by
editing one's gitlab.yml configuration file (see
config/gitlab.yml.example for example settings).
== Writing Data To InfluxDB
Because InfluxDB is still a fairly young product I expect the worse.
Data loss, unexpected reboots, the database not responding, you name it.
Because of this data is _not_ written to InfluxDB directly, instead it's
queued and processed by Sidekiq. This ensures that users won't notice
anything when InfluxDB is giving trouble.
The metrics worker can be started in a standalone manner as following:
bundle exec sidekiq -q metrics
The corresponding class is called MetricsWorker.
2015-12-09 10:45:51 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Metrics do
|
2017-05-29 08:19:43 -04:00
|
|
|
include StubENV
|
|
|
|
|
2015-12-31 11:47:07 -05:00
|
|
|
describe '.settings' do
|
|
|
|
it 'returns a Hash' do
|
|
|
|
expect(described_class.settings).to be_an_instance_of(Hash)
|
Storing of application metrics in InfluxDB
This adds the ability to write application metrics (e.g. SQL timings) to
InfluxDB. These metrics can in turn be visualized using Grafana, or
really anything else that can read from InfluxDB. These metrics can be
used to track application performance over time, between different Ruby
versions, different GitLab versions, etc.
== Transaction Metrics
Currently the following is tracked on a per transaction basis (a
transaction is a Rails request or a single Sidekiq job):
* Timings per query along with the raw (obfuscated) SQL and information
about what file the query originated from.
* Timings per view along with the path of the view and information about
what file triggered the rendering process.
* The duration of a request itself along with the controller/worker
class and method name.
* The duration of any instrumented method calls (more below).
== Sampled Metrics
Certain metrics can't be directly associated with a transaction. For
example, a process' total memory usage is unrelated to any running
transactions. While a transaction can result in the memory usage going
up there's no accurate way to determine what transaction is to blame,
this becomes especially problematic in multi-threaded environments.
To solve this problem there's a separate thread that takes samples at a
fixed interval. This thread (using the class Gitlab::Metrics::Sampler)
currently tracks the following:
* The process' total memory usage.
* The number of file descriptors opened by the process.
* The amount of Ruby objects (using ObjectSpace.count_objects).
* GC statistics such as timings, heap slots, etc.
The default/current interval is 15 seconds, any smaller interval might
put too much pressure on InfluxDB (especially when running dozens of
processes).
== Method Instrumentation
While currently not yet used methods can be instrumented to track how
long they take to run. Unlike the likes of New Relic this doesn't
require modifying the source code (e.g. including modules), it all
happens from the outside. For example, to track `User.by_login` we'd add
the following code somewhere in an initializer:
Gitlab::Metrics::Instrumentation.
instrument_method(User, :by_login)
to instead instrument an instance method:
Gitlab::Metrics::Instrumentation.
instrument_instance_method(User, :save)
Instrumentation for either all public model methods or a few crucial
ones will be added in the near future, I simply haven't gotten to doing
so just yet.
== Configuration
By default metrics are disabled. This means users don't have to bother
setting anything up if they don't want to. Metrics can be enabled by
editing one's gitlab.yml configuration file (see
config/gitlab.yml.example for example settings).
== Writing Data To InfluxDB
Because InfluxDB is still a fairly young product I expect the worse.
Data loss, unexpected reboots, the database not responding, you name it.
Because of this data is _not_ written to InfluxDB directly, instead it's
queued and processed by Sidekiq. This ensures that users won't notice
anything when InfluxDB is giving trouble.
The metrics worker can be started in a standalone manner as following:
bundle exec sidekiq -q metrics
The corresponding class is called MetricsWorker.
2015-12-09 10:45:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.enabled?' do
|
|
|
|
it 'returns a boolean' do
|
2017-05-23 10:16:23 -04:00
|
|
|
expect(described_class.enabled?).to be_in([true, false])
|
Storing of application metrics in InfluxDB
This adds the ability to write application metrics (e.g. SQL timings) to
InfluxDB. These metrics can in turn be visualized using Grafana, or
really anything else that can read from InfluxDB. These metrics can be
used to track application performance over time, between different Ruby
versions, different GitLab versions, etc.
== Transaction Metrics
Currently the following is tracked on a per transaction basis (a
transaction is a Rails request or a single Sidekiq job):
* Timings per query along with the raw (obfuscated) SQL and information
about what file the query originated from.
* Timings per view along with the path of the view and information about
what file triggered the rendering process.
* The duration of a request itself along with the controller/worker
class and method name.
* The duration of any instrumented method calls (more below).
== Sampled Metrics
Certain metrics can't be directly associated with a transaction. For
example, a process' total memory usage is unrelated to any running
transactions. While a transaction can result in the memory usage going
up there's no accurate way to determine what transaction is to blame,
this becomes especially problematic in multi-threaded environments.
To solve this problem there's a separate thread that takes samples at a
fixed interval. This thread (using the class Gitlab::Metrics::Sampler)
currently tracks the following:
* The process' total memory usage.
* The number of file descriptors opened by the process.
* The amount of Ruby objects (using ObjectSpace.count_objects).
* GC statistics such as timings, heap slots, etc.
The default/current interval is 15 seconds, any smaller interval might
put too much pressure on InfluxDB (especially when running dozens of
processes).
== Method Instrumentation
While currently not yet used methods can be instrumented to track how
long they take to run. Unlike the likes of New Relic this doesn't
require modifying the source code (e.g. including modules), it all
happens from the outside. For example, to track `User.by_login` we'd add
the following code somewhere in an initializer:
Gitlab::Metrics::Instrumentation.
instrument_method(User, :by_login)
to instead instrument an instance method:
Gitlab::Metrics::Instrumentation.
instrument_instance_method(User, :save)
Instrumentation for either all public model methods or a few crucial
ones will be added in the near future, I simply haven't gotten to doing
so just yet.
== Configuration
By default metrics are disabled. This means users don't have to bother
setting anything up if they don't want to. Metrics can be enabled by
editing one's gitlab.yml configuration file (see
config/gitlab.yml.example for example settings).
== Writing Data To InfluxDB
Because InfluxDB is still a fairly young product I expect the worse.
Data loss, unexpected reboots, the database not responding, you name it.
Because of this data is _not_ written to InfluxDB directly, instead it's
queued and processed by Sidekiq. This ensures that users won't notice
anything when InfluxDB is giving trouble.
The metrics worker can be started in a standalone manner as following:
bundle exec sidekiq -q metrics
The corresponding class is called MetricsWorker.
2015-12-09 10:45:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-15 17:41:47 -04:00
|
|
|
describe '.prometheus_metrics_enabled_unmemoized' do
|
|
|
|
subject { described_class.send(:prometheus_metrics_enabled_unmemoized) }
|
|
|
|
|
|
|
|
context 'prometheus metrics enabled in config' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:current_application_settings).and_return(prometheus_metrics_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when metrics folder is present' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:metrics_folder_present?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'metrics are enabled' do
|
|
|
|
expect(subject).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when metrics folder is missing' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:metrics_folder_present?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'metrics are disabled' do
|
|
|
|
expect(subject).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-22 09:47:04 -04:00
|
|
|
describe '.prometheus_metrics_enabled?' do
|
|
|
|
it 'returns a boolean' do
|
2017-05-23 10:16:23 -04:00
|
|
|
expect(described_class.prometheus_metrics_enabled?).to be_in([true, false])
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.influx_metrics_enabled?' do
|
|
|
|
it 'returns a boolean' do
|
2017-05-23 10:16:23 -04:00
|
|
|
expect(described_class.influx_metrics_enabled?).to be_in([true, false])
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-04 06:47:10 -04:00
|
|
|
describe '.submit_metrics' do
|
2015-12-29 07:40:42 -05:00
|
|
|
it 'prepares and writes the metrics to InfluxDB' do
|
|
|
|
connection = double(:connection)
|
|
|
|
pool = double(:pool)
|
|
|
|
|
|
|
|
expect(pool).to receive(:with).and_yield(connection)
|
|
|
|
expect(connection).to receive(:write_points).with(an_instance_of(Array))
|
2017-05-01 11:13:33 -04:00
|
|
|
expect(described_class).to receive(:pool).and_return(pool)
|
2015-12-29 07:40:42 -05:00
|
|
|
|
|
|
|
described_class.submit_metrics([{ 'series' => 'kittens', 'tags' => {} }])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-04 06:47:10 -04:00
|
|
|
describe '.prepare_metrics' do
|
2015-12-29 07:40:42 -05:00
|
|
|
it 'returns a Hash with the keys as Symbols' do
|
2017-06-21 09:48:12 -04:00
|
|
|
metrics = described_class
|
|
|
|
.prepare_metrics([{ 'values' => {}, 'tags' => {} }])
|
2015-12-29 07:40:42 -05:00
|
|
|
|
|
|
|
expect(metrics).to eq([{ values: {}, tags: {} }])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'escapes tag values' do
|
|
|
|
metrics = described_class.prepare_metrics([
|
|
|
|
{ 'values' => {}, 'tags' => { 'foo' => 'bar=' } }
|
|
|
|
])
|
|
|
|
|
|
|
|
expect(metrics).to eq([{ values: {}, tags: { 'foo' => 'bar\\=' } }])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'drops empty tags' do
|
|
|
|
metrics = described_class.prepare_metrics([
|
|
|
|
{ 'values' => {}, 'tags' => { 'cats' => '', 'dogs' => nil } }
|
|
|
|
])
|
|
|
|
|
|
|
|
expect(metrics).to eq([{ values: {}, tags: {} }])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-04 06:47:10 -04:00
|
|
|
describe '.escape_value' do
|
2015-12-29 07:40:42 -05:00
|
|
|
it 'escapes an equals sign' do
|
|
|
|
expect(described_class.escape_value('foo=')).to eq('foo\\=')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'casts values to Strings' do
|
|
|
|
expect(described_class.escape_value(10)).to eq('10')
|
|
|
|
end
|
|
|
|
end
|
2016-04-04 08:00:35 -04:00
|
|
|
|
|
|
|
describe '.measure' do
|
|
|
|
context 'without a transaction' do
|
|
|
|
it 'returns the return value of the block' do
|
2017-05-01 11:13:33 -04:00
|
|
|
val = described_class.measure(:foo) { 10 }
|
2016-04-04 08:00:35 -04:00
|
|
|
|
|
|
|
expect(val).to eq(10)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a transaction' do
|
|
|
|
let(:transaction) { Gitlab::Metrics::Transaction.new }
|
|
|
|
|
|
|
|
before do
|
2017-06-21 09:48:12 -04:00
|
|
|
allow(described_class).to receive(:current_transaction)
|
|
|
|
.and_return(transaction)
|
2016-04-04 08:00:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds a metric to the current transaction' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(transaction).to receive(:increment)
|
|
|
|
.with('foo_real_time', a_kind_of(Numeric))
|
2016-04-04 08:00:35 -04:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(transaction).to receive(:increment)
|
|
|
|
.with('foo_cpu_time', a_kind_of(Numeric))
|
2016-04-04 08:00:35 -04:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(transaction).to receive(:increment)
|
|
|
|
.with('foo_call_count', 1)
|
2016-04-11 07:27:24 -04:00
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
described_class.measure(:foo) { 10 }
|
2016-04-04 08:00:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the return value of the block' do
|
2017-05-01 11:13:33 -04:00
|
|
|
val = described_class.measure(:foo) { 10 }
|
2016-04-04 08:00:35 -04:00
|
|
|
|
|
|
|
expect(val).to eq(10)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-12 06:00:21 -04:00
|
|
|
|
|
|
|
describe '.tag_transaction' do
|
|
|
|
context 'without a transaction' do
|
|
|
|
it 'does nothing' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction)
|
|
|
|
.not_to receive(:add_tag)
|
2016-04-12 06:00:21 -04:00
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
described_class.tag_transaction(:foo, 'bar')
|
2016-04-12 06:00:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a transaction' do
|
|
|
|
let(:transaction) { Gitlab::Metrics::Transaction.new }
|
|
|
|
|
|
|
|
it 'adds the tag to the transaction' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(described_class).to receive(:current_transaction)
|
|
|
|
.and_return(transaction)
|
2016-04-12 06:00:21 -04:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(transaction).to receive(:add_tag)
|
|
|
|
.with(:foo, 'bar')
|
2016-04-12 06:00:21 -04:00
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
described_class.tag_transaction(:foo, 'bar')
|
2016-04-12 06:00:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-20 16:42:52 -04:00
|
|
|
|
|
|
|
describe '.action=' do
|
|
|
|
context 'without a transaction' do
|
|
|
|
it 'does nothing' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction)
|
|
|
|
.not_to receive(:action=)
|
2016-04-20 16:42:52 -04:00
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
described_class.action = 'foo'
|
2016-04-20 16:42:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a transaction' do
|
|
|
|
it 'sets the action of a transaction' do
|
|
|
|
trans = Gitlab::Metrics::Transaction.new
|
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(described_class).to receive(:current_transaction)
|
|
|
|
.and_return(trans)
|
2016-04-20 16:42:52 -04:00
|
|
|
|
|
|
|
expect(trans).to receive(:action=).with('foo')
|
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
described_class.action = 'foo'
|
2016-04-20 16:42:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-07-28 09:08:57 -04:00
|
|
|
|
|
|
|
describe '#series_prefix' do
|
|
|
|
it 'returns a String' do
|
|
|
|
expect(described_class.series_prefix).to be_an_instance_of(String)
|
|
|
|
end
|
|
|
|
end
|
2016-08-16 10:18:48 -04:00
|
|
|
|
|
|
|
describe '.add_event' do
|
|
|
|
context 'without a transaction' do
|
|
|
|
it 'does nothing' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction)
|
|
|
|
.not_to receive(:add_event)
|
2016-08-16 10:18:48 -04:00
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
described_class.add_event(:meow)
|
2016-08-16 10:18:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a transaction' do
|
|
|
|
it 'adds an event' do
|
|
|
|
transaction = Gitlab::Metrics::Transaction.new
|
|
|
|
|
|
|
|
expect(transaction).to receive(:add_event).with(:meow)
|
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(described_class).to receive(:current_transaction)
|
|
|
|
.and_return(transaction)
|
2016-08-16 10:18:48 -04:00
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
described_class.add_event(:meow)
|
2016-08-16 10:18:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-22 09:47:04 -04:00
|
|
|
|
|
|
|
shared_examples 'prometheus metrics API' do
|
|
|
|
describe '#counter' do
|
|
|
|
subject { described_class.counter(:couter, 'doc') }
|
|
|
|
|
|
|
|
describe '#increment' do
|
2017-05-23 10:16:23 -04:00
|
|
|
it 'successfully calls #increment without arguments' do
|
|
|
|
expect { subject.increment }.not_to raise_exception
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'successfully calls #increment with 1 argument' do
|
|
|
|
expect { subject.increment({}) }.not_to raise_exception
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'successfully calls #increment with 2 arguments' do
|
|
|
|
expect { subject.increment({}, 1) }.not_to raise_exception
|
|
|
|
end
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#summary' do
|
|
|
|
subject { described_class.summary(:summary, 'doc') }
|
|
|
|
|
|
|
|
describe '#observe' do
|
2017-05-23 10:16:23 -04:00
|
|
|
it 'successfully calls #observe with 2 arguments' do
|
|
|
|
expect { subject.observe({}, 2) }.not_to raise_exception
|
|
|
|
end
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#gauge' do
|
|
|
|
subject { described_class.gauge(:gauge, 'doc') }
|
|
|
|
|
2017-05-23 10:16:23 -04:00
|
|
|
describe '#set' do
|
|
|
|
it 'successfully calls #set with 2 arguments' do
|
|
|
|
expect { subject.set({}, 1) }.not_to raise_exception
|
|
|
|
end
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#histogram' do
|
|
|
|
subject { described_class.histogram(:histogram, 'doc') }
|
|
|
|
|
|
|
|
describe '#observe' do
|
2017-05-23 10:16:23 -04:00
|
|
|
it 'successfully calls #observe with 2 arguments' do
|
|
|
|
expect { subject.observe({}, 2) }.not_to raise_exception
|
|
|
|
end
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'prometheus metrics disabled' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:prometheus_metrics_enabled?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'prometheus metrics API'
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
describe '#null_metric' do
|
2017-05-22 09:47:04 -04:00
|
|
|
subject { described_class.provide_metric(:test) }
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
it { is_expected.to be_a(Gitlab::Metrics::NullMetric) }
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#counter' do
|
|
|
|
subject { described_class.counter(:counter, 'doc') }
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
it { is_expected.to be_a(Gitlab::Metrics::NullMetric) }
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#summary' do
|
|
|
|
subject { described_class.summary(:summary, 'doc') }
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
it { is_expected.to be_a(Gitlab::Metrics::NullMetric) }
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#gauge' do
|
|
|
|
subject { described_class.gauge(:gauge, 'doc') }
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
it { is_expected.to be_a(Gitlab::Metrics::NullMetric) }
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#histogram' do
|
|
|
|
subject { described_class.histogram(:histogram, 'doc') }
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
it { is_expected.to be_a(Gitlab::Metrics::NullMetric) }
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'prometheus metrics enabled' do
|
2017-06-06 22:24:30 -04:00
|
|
|
let(:metrics_multiproc_dir) { Dir.mktmpdir }
|
2017-05-29 08:19:43 -04:00
|
|
|
|
2017-05-22 09:47:04 -04:00
|
|
|
before do
|
2017-06-06 22:24:30 -04:00
|
|
|
stub_const('Prometheus::Client::Multiprocdir', metrics_multiproc_dir)
|
2017-05-22 09:47:04 -04:00
|
|
|
allow(described_class).to receive(:prometheus_metrics_enabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'prometheus metrics API'
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
describe '#null_metric' do
|
2017-05-22 09:47:04 -04:00
|
|
|
subject { described_class.provide_metric(:test) }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#counter' do
|
|
|
|
subject { described_class.counter(:name, 'doc') }
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
it { is_expected.not_to be_a(Gitlab::Metrics::NullMetric) }
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#summary' do
|
|
|
|
subject { described_class.summary(:name, 'doc') }
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
it { is_expected.not_to be_a(Gitlab::Metrics::NullMetric) }
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#gauge' do
|
|
|
|
subject { described_class.gauge(:name, 'doc') }
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
it { is_expected.not_to be_a(Gitlab::Metrics::NullMetric) }
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#histogram' do
|
|
|
|
subject { described_class.histogram(:name, 'doc') }
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
it { is_expected.not_to be_a(Gitlab::Metrics::NullMetric) }
|
2017-05-22 09:47:04 -04:00
|
|
|
end
|
|
|
|
end
|
Storing of application metrics in InfluxDB
This adds the ability to write application metrics (e.g. SQL timings) to
InfluxDB. These metrics can in turn be visualized using Grafana, or
really anything else that can read from InfluxDB. These metrics can be
used to track application performance over time, between different Ruby
versions, different GitLab versions, etc.
== Transaction Metrics
Currently the following is tracked on a per transaction basis (a
transaction is a Rails request or a single Sidekiq job):
* Timings per query along with the raw (obfuscated) SQL and information
about what file the query originated from.
* Timings per view along with the path of the view and information about
what file triggered the rendering process.
* The duration of a request itself along with the controller/worker
class and method name.
* The duration of any instrumented method calls (more below).
== Sampled Metrics
Certain metrics can't be directly associated with a transaction. For
example, a process' total memory usage is unrelated to any running
transactions. While a transaction can result in the memory usage going
up there's no accurate way to determine what transaction is to blame,
this becomes especially problematic in multi-threaded environments.
To solve this problem there's a separate thread that takes samples at a
fixed interval. This thread (using the class Gitlab::Metrics::Sampler)
currently tracks the following:
* The process' total memory usage.
* The number of file descriptors opened by the process.
* The amount of Ruby objects (using ObjectSpace.count_objects).
* GC statistics such as timings, heap slots, etc.
The default/current interval is 15 seconds, any smaller interval might
put too much pressure on InfluxDB (especially when running dozens of
processes).
== Method Instrumentation
While currently not yet used methods can be instrumented to track how
long they take to run. Unlike the likes of New Relic this doesn't
require modifying the source code (e.g. including modules), it all
happens from the outside. For example, to track `User.by_login` we'd add
the following code somewhere in an initializer:
Gitlab::Metrics::Instrumentation.
instrument_method(User, :by_login)
to instead instrument an instance method:
Gitlab::Metrics::Instrumentation.
instrument_instance_method(User, :save)
Instrumentation for either all public model methods or a few crucial
ones will be added in the near future, I simply haven't gotten to doing
so just yet.
== Configuration
By default metrics are disabled. This means users don't have to bother
setting anything up if they don't want to. Metrics can be enabled by
editing one's gitlab.yml configuration file (see
config/gitlab.yml.example for example settings).
== Writing Data To InfluxDB
Because InfluxDB is still a fairly young product I expect the worse.
Data loss, unexpected reboots, the database not responding, you name it.
Because of this data is _not_ written to InfluxDB directly, instead it's
queued and processed by Sidekiq. This ensures that users won't notice
anything when InfluxDB is giving trouble.
The metrics worker can be started in a standalone manner as following:
bundle exec sidekiq -q metrics
The corresponding class is called MetricsWorker.
2015-12-09 10:45:51 -05:00
|
|
|
end
|