Commit 7a3dbba0 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch '345802-sk-health-check-settings' into 'master'

Allow instantiating SidekiqExporter with settings

See merge request gitlab-org/gitlab!74875
parents 28fdda78 405c21ac
...@@ -1260,6 +1260,12 @@ production: &base ...@@ -1260,6 +1260,12 @@ production: &base
# address: localhost # address: localhost
# port: 8082 # port: 8082
sidekiq_health_checks:
# enabled: true
# log_enabled: false
# address: localhost
# port: 8082
# Web exporter is a dedicated Rack server running alongside Puma to expose Prometheus metrics # Web exporter is a dedicated Rack server running alongside Puma to expose Prometheus metrics
# It runs alongside the `/metrics` endpoints to ease the publish of metrics # It runs alongside the `/metrics` endpoints to ease the publish of metrics
web_exporter: web_exporter:
......
...@@ -919,11 +919,23 @@ Settings.webpack.dev_server['https'] ||= false ...@@ -919,11 +919,23 @@ Settings.webpack.dev_server['https'] ||= false
# #
Settings['monitoring'] ||= Settingslogic.new({}) Settings['monitoring'] ||= Settingslogic.new({})
Settings.monitoring['ip_whitelist'] ||= ['127.0.0.1/8'] Settings.monitoring['ip_whitelist'] ||= ['127.0.0.1/8']
Settings.monitoring['sidekiq_exporter'] ||= Settingslogic.new({}) Settings.monitoring['sidekiq_exporter'] ||= Settingslogic.new({})
Settings.monitoring.sidekiq_exporter['enabled'] ||= false Settings.monitoring.sidekiq_exporter['enabled'] ||= false
Settings.monitoring.sidekiq_exporter['log_enabled'] ||= false Settings.monitoring.sidekiq_exporter['log_enabled'] ||= false
Settings.monitoring.sidekiq_exporter['address'] ||= 'localhost' Settings.monitoring.sidekiq_exporter['address'] ||= 'localhost'
Settings.monitoring.sidekiq_exporter['port'] ||= 8082 Settings.monitoring.sidekiq_exporter['port'] ||= 8082
# TODO: Once we split out health checks from SidekiqExporter, we
# should not let this default to the same settings anymore; we only
# do this for back-compat currently.
# https://gitlab.com/gitlab-org/gitlab/-/issues/345804
Settings.monitoring['sidekiq_health_checks'] ||= Settingslogic.new({})
Settings.monitoring.sidekiq_health_checks['enabled'] ||= Settings.monitoring.sidekiq_exporter['enabled']
Settings.monitoring.sidekiq_health_checks['log_enabled'] ||= Settings.monitoring.sidekiq_exporter['log_enabled']
Settings.monitoring.sidekiq_health_checks['address'] ||= Settings.monitoring.sidekiq_exporter['address']
Settings.monitoring.sidekiq_health_checks['port'] ||= Settings.monitoring.sidekiq_exporter['port']
Settings.monitoring['web_exporter'] ||= Settingslogic.new({}) Settings.monitoring['web_exporter'] ||= Settingslogic.new({})
Settings.monitoring.web_exporter['enabled'] ||= false Settings.monitoring.web_exporter['enabled'] ||= false
Settings.monitoring.web_exporter['address'] ||= 'localhost' Settings.monitoring.web_exporter['address'] ||= 'localhost'
......
...@@ -31,11 +31,17 @@ end ...@@ -31,11 +31,17 @@ end
if Gitlab::Runtime.sidekiq? && (!ENV['SIDEKIQ_WORKER_ID'] || ENV['SIDEKIQ_WORKER_ID'] == '0') if Gitlab::Runtime.sidekiq? && (!ENV['SIDEKIQ_WORKER_ID'] || ENV['SIDEKIQ_WORKER_ID'] == '0')
# The single worker outside of a sidekiq-cluster, or the first worker (sidekiq_0) # The single worker outside of a sidekiq-cluster, or the first worker (sidekiq_0)
# in a cluster of processes, is responsible for serving health checks. # in a cluster of processes, is responsible for serving health checks.
#
# Do not clean the metrics directory here - the supervisor script should
# have already taken care of that.
Sidekiq.configure_server do |config| Sidekiq.configure_server do |config|
config.on(:startup) do config.on(:startup) do
# Do not clean the metrics directory here - the supervisor script should # In https://gitlab.com/gitlab-org/gitlab/-/issues/345804 we are looking to
# have already taken care of that # only serve health-checks from a worker process; for backwards compatibility
Gitlab::Metrics::Exporter::SidekiqExporter.instance.start # we still go through the metrics exporter server, but start to configure it
# with the new settings keys.
exporter_settings = Settings.monitoring.sidekiq_health_checks
Gitlab::Metrics::Exporter::SidekiqExporter.instance(exporter_settings).start
end end
end end
end end
......
...@@ -11,12 +11,14 @@ module Gitlab ...@@ -11,12 +11,14 @@ module Gitlab
attr_accessor :readiness_checks attr_accessor :readiness_checks
def enabled? def initialize(settings, **options)
settings.enabled super(**options)
@settings = settings
end end
def settings def enabled?
raise NotImplementedError settings.enabled
end end
def log_filename def log_filename
...@@ -25,6 +27,8 @@ module Gitlab ...@@ -25,6 +27,8 @@ module Gitlab
private private
attr_reader :settings
def start_working def start_working
logger = WEBrick::Log.new(log_filename) logger = WEBrick::Log.new(log_filename)
logger.time_format = "[%Y-%m-%dT%H:%M:%S.%L%z]" logger.time_format = "[%Y-%m-%dT%H:%M:%S.%L%z]"
......
...@@ -4,10 +4,6 @@ module Gitlab ...@@ -4,10 +4,6 @@ module Gitlab
module Metrics module Metrics
module Exporter module Exporter
class SidekiqExporter < BaseExporter class SidekiqExporter < BaseExporter
def settings
Settings.monitoring.sidekiq_exporter
end
def log_filename def log_filename
if settings['log_enabled'] if settings['log_enabled']
File.join(Rails.root, 'log', 'sidekiq_exporter.log') File.join(Rails.root, 'log', 'sidekiq_exporter.log')
......
...@@ -27,7 +27,7 @@ module Gitlab ...@@ -27,7 +27,7 @@ module Gitlab
# This exporter is always run on master process # This exporter is always run on master process
def initialize def initialize
super super(Settings.monitoring.web_exporter)
# DEPRECATED: # DEPRECATED:
# these `readiness_checks` are deprecated # these `readiness_checks` are deprecated
...@@ -39,10 +39,6 @@ module Gitlab ...@@ -39,10 +39,6 @@ module Gitlab
] ]
end end
def settings
Gitlab.config.monitoring.web_exporter
end
def log_filename def log_filename
File.join(Rails.root, 'log', 'web_exporter.log') File.join(Rails.root, 'log', 'web_exporter.log')
end end
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Metrics::Exporter::BaseExporter do RSpec.describe Gitlab::Metrics::Exporter::BaseExporter do
let(:exporter) { described_class.new }
let(:log_filename) { File.join(Rails.root, 'log', 'sidekiq_exporter.log') }
let(:settings) { double('settings') } let(:settings) { double('settings') }
let(:exporter) { described_class.new(settings) }
let(:log_filename) { File.join(Rails.root, 'log', 'sidekiq_exporter.log') }
before do before do
allow_any_instance_of(described_class).to receive(:log_filename).and_return(log_filename) allow_any_instance_of(described_class).to receive(:log_filename).and_return(log_filename)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Metrics::Exporter::SidekiqExporter do RSpec.describe Gitlab::Metrics::Exporter::SidekiqExporter do
let(:exporter) { described_class.new } let(:exporter) { described_class.new(Settings.monitoring.sidekiq_exporter) }
after do after do
exporter.stop exporter.stop
......
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