Commit 2eb346c7 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'hardcode-sampler-intervals' into 'master'

Hard-code non-configurable sampler intervals

Closes #218309

See merge request gitlab-org/gitlab!32776
parents 28d2c87d b3f2c8cf
......@@ -1078,8 +1078,6 @@ production: &base
monitoring:
# Time between sampling of unicorn socket metrics, in seconds
# unicorn_sampler_interval: 10
# Time between sampling of Puma metrics, in seconds
# puma_sampler_interval: 5
# IP whitelist to access monitoring endpoints
ip_whitelist:
- 127.0.0.0/8
......
......@@ -728,9 +728,6 @@ Settings.action_cable['worker_pool_size'] ||= 4
Settings['monitoring'] ||= Settingslogic.new({})
Settings.monitoring['ip_whitelist'] ||= ['127.0.0.1/8']
Settings.monitoring['unicorn_sampler_interval'] ||= 10
Settings.monitoring['puma_sampler_interval'] ||= 5
Settings.monitoring['ruby_sampler_interval'] ||= 60
Settings.monitoring['global_search_sampler_interval'] ||= 60
Settings.monitoring['sidekiq_exporter'] ||= Settingslogic.new({})
Settings.monitoring.sidekiq_exporter['enabled'] ||= false
Settings.monitoring.sidekiq_exporter['address'] ||= 'localhost'
......
......@@ -42,11 +42,11 @@ if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled?
Gitlab::Cluster::LifecycleEvents.on_worker_start do
defined?(::Prometheus::Client.reinitialize_on_pid_change) && Prometheus::Client.reinitialize_on_pid_change
Gitlab::Metrics::Samplers::RubySampler.initialize_instance(Settings.monitoring.ruby_sampler_interval).start
Gitlab::Metrics::Samplers::DatabaseSampler.initialize_instance(Gitlab::Metrics::Samplers::DatabaseSampler::SAMPLING_INTERVAL_SECONDS).start
Gitlab::Metrics::Samplers::RubySampler.initialize_instance.start
Gitlab::Metrics::Samplers::DatabaseSampler.initialize_instance.start
if Gitlab.ee? && Gitlab::Runtime.sidekiq?
Gitlab::Metrics::Samplers::GlobalSearchSampler.instance(Settings.monitoring.global_search_sampler_interval).start
Gitlab::Metrics::Samplers::GlobalSearchSampler.instance.start
end
rescue IOError => e
Gitlab::ErrorTracking.track_exception(e)
......@@ -59,7 +59,7 @@ if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled?
if Gitlab::Runtime.unicorn?
Gitlab::Metrics::Samplers::UnicornSampler.instance(Settings.monitoring.unicorn_sampler_interval).start
elsif Gitlab::Runtime.puma?
Gitlab::Metrics::Samplers::PumaSampler.instance(Settings.monitoring.puma_sampler_interval).start
Gitlab::Metrics::Samplers::PumaSampler.instance.start
end
Gitlab::Metrics.gauge(:deployments, 'GitLab Version', {}, :max).set({ version: Gitlab::VERSION }, 1)
......
......@@ -4,6 +4,8 @@ module Gitlab
module Metrics
module Samplers
class GlobalSearchSampler < BaseSampler
SAMPLING_INTERVAL_SECONDS = 60
def sample
::Elastic::MetricsUpdateService.new.execute
end
......
......@@ -3,7 +3,17 @@
require 'spec_helper'
describe Gitlab::Metrics::Samplers::GlobalSearchSampler do
subject { described_class.new(60.seconds) }
subject { described_class.new }
describe '#interval' do
it 'samples every sixty seconds by default' do
expect(subject.interval).to eq(60)
end
it 'samples at other intervals if requested' do
expect(described_class.new(11).interval).to eq(11)
end
end
describe '#sample' do
it 'invokes the Elastic::MetricsUpdateService' do
......
......@@ -6,8 +6,10 @@ module Gitlab
module Metrics
module Samplers
class BaseSampler < Daemon
attr_reader :interval
# interval - The sampling interval in seconds.
def initialize(interval)
def initialize(interval = self.class::SAMPLING_INTERVAL_SECONDS)
interval_half = interval.to_f / 2
@interval = interval
......
......@@ -4,6 +4,8 @@ module Gitlab
module Metrics
module Samplers
class PumaSampler < BaseSampler
SAMPLING_INTERVAL_SECONDS = 5
def metrics
@metrics ||= init_metrics
end
......
......@@ -6,9 +6,10 @@ module Gitlab
module Metrics
module Samplers
class RubySampler < BaseSampler
SAMPLING_INTERVAL_SECONDS = 60
GC_REPORT_BUCKETS = [0.005, 0.01, 0.02, 0.04, 0.07, 0.1, 0.5].freeze
def initialize(interval)
def initialize(*)
GC::Profiler.clear
metrics[:process_start_time_seconds].set(labels, Time.now.to_i)
......
......@@ -3,7 +3,17 @@
require 'spec_helper'
describe Gitlab::Metrics::Samplers::DatabaseSampler do
subject { described_class.new(described_class::SAMPLING_INTERVAL_SECONDS) }
subject { described_class.new }
describe '#interval' do
it 'samples every five seconds by default' do
expect(subject.interval).to eq(5)
end
it 'samples at other intervals if requested' do
expect(described_class.new(11).interval).to eq(11)
end
end
describe '#sample' do
before do
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
describe Gitlab::Metrics::Samplers::PumaSampler do
subject { described_class.new(5) }
subject { described_class.new }
let(:null_metric) { double('null_metric', set: nil, observe: nil) }
......@@ -11,6 +11,16 @@ describe Gitlab::Metrics::Samplers::PumaSampler do
allow(Gitlab::Metrics::NullMetric).to receive(:instance).and_return(null_metric)
end
describe '#interval' do
it 'samples every five seconds by default' do
expect(subject.interval).to eq(5)
end
it 'samples at other intervals if requested' do
expect(described_class.new(11).interval).to eq(11)
end
end
describe '#sample' do
before do
expect(subject).to receive(:puma_stats).and_return(puma_stats)
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
describe Gitlab::Metrics::Samplers::RubySampler do
let(:sampler) { described_class.new(5) }
let(:sampler) { described_class.new }
let(:null_metric) { double('null_metric', set: nil, observe: nil) }
before do
......@@ -18,6 +18,16 @@ describe Gitlab::Metrics::Samplers::RubySampler do
end
end
describe '#interval' do
it 'samples every sixty seconds by default' do
expect(subject.interval).to eq(60)
end
it 'samples at other intervals if requested' do
expect(described_class.new(11).interval).to eq(11)
end
end
describe '#sample' do
it 'adds a metric containing the process resident memory bytes' do
expect(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return(9000)
......
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