Commit 4340fc4c authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'daemon-instead-of-worker-for-elastic-queue-monitoring' into 'master'

Use Sampler instead of worker for monitoring Global Search queue

See merge request gitlab-org/gitlab!28304
parents d4a878f9 6eb87b64
...@@ -477,11 +477,6 @@ production: &base ...@@ -477,11 +477,6 @@ production: &base
elastic_index_bulk_cron_worker: elastic_index_bulk_cron_worker:
cron: "*/1 * * * *" cron: "*/1 * * * *"
# Elasticsearch metrics
# NOTE: This will only take effect if Elasticsearch is enabled.
elastic_metrics_update_worker:
cron: "*/1 * * * *"
registry: registry:
# enabled: true # enabled: true
# host: registry.example.com # host: registry.example.com
......
...@@ -546,9 +546,6 @@ Gitlab.ee do ...@@ -546,9 +546,6 @@ Gitlab.ee do
Settings.cron_jobs['elastic_index_bulk_cron_worker'] ||= Settingslogic.new({}) Settings.cron_jobs['elastic_index_bulk_cron_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['elastic_index_bulk_cron_worker']['cron'] ||= '*/1 * * * *' Settings.cron_jobs['elastic_index_bulk_cron_worker']['cron'] ||= '*/1 * * * *'
Settings.cron_jobs['elastic_index_bulk_cron_worker']['job_class'] ||= 'ElasticIndexBulkCronWorker' Settings.cron_jobs['elastic_index_bulk_cron_worker']['job_class'] ||= 'ElasticIndexBulkCronWorker'
Settings.cron_jobs['elastic_metrics_update_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['elastic_metrics_update_worker']['cron'] ||= '*/1 * * * *'
Settings.cron_jobs['elastic_metrics_update_worker']['job_class'] ||= 'ElasticMetricsUpdateWorker'
Settings.cron_jobs['sync_seat_link_worker'] ||= Settingslogic.new({}) Settings.cron_jobs['sync_seat_link_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['sync_seat_link_worker']['cron'] ||= "#{rand(60)} 0 * * *" Settings.cron_jobs['sync_seat_link_worker']['cron'] ||= "#{rand(60)} 0 * * *"
Settings.cron_jobs['sync_seat_link_worker']['job_class'] = 'SyncSeatLinkWorker' Settings.cron_jobs['sync_seat_link_worker']['job_class'] = 'SyncSeatLinkWorker'
...@@ -725,6 +722,7 @@ Settings.monitoring['ip_whitelist'] ||= ['127.0.0.1/8'] ...@@ -725,6 +722,7 @@ Settings.monitoring['ip_whitelist'] ||= ['127.0.0.1/8']
Settings.monitoring['unicorn_sampler_interval'] ||= 10 Settings.monitoring['unicorn_sampler_interval'] ||= 10
Settings.monitoring['puma_sampler_interval'] ||= 5 Settings.monitoring['puma_sampler_interval'] ||= 5
Settings.monitoring['ruby_sampler_interval'] ||= 60 Settings.monitoring['ruby_sampler_interval'] ||= 60
Settings.monitoring['global_search_sampler_interval'] ||= 60
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['address'] ||= 'localhost' Settings.monitoring.sidekiq_exporter['address'] ||= 'localhost'
......
...@@ -43,6 +43,10 @@ if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled? ...@@ -43,6 +43,10 @@ if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled?
defined?(::Prometheus::Client.reinitialize_on_pid_change) && Prometheus::Client.reinitialize_on_pid_change 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::RubySampler.initialize_instance(Settings.monitoring.ruby_sampler_interval).start
if Gitlab.ee? && Gitlab::Runtime.sidekiq?
Gitlab::Metrics::Samplers::GlobalSearchSampler.instance(Settings.monitoring.global_search_sampler_interval).start
end
rescue IOError => e rescue IOError => e
Gitlab::ErrorTracking.track_exception(e) Gitlab::ErrorTracking.track_exception(e)
Gitlab::Metrics.error_detected! Gitlab::Metrics.error_detected!
......
...@@ -31,13 +31,6 @@ ...@@ -31,13 +31,6 @@
:resource_boundary: :unknown :resource_boundary: :unknown
:weight: 1 :weight: 1
:idempotent: true :idempotent: true
- :name: cronjob:elastic_metrics_update
:feature_category: :global_search
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent: true
- :name: cronjob:geo_container_repository_sync_dispatch - :name: cronjob:geo_container_repository_sync_dispatch
:feature_category: :geo_replication :feature_category: :geo_replication
:has_external_dependencies: :has_external_dependencies:
......
# frozen_string_literal: true
class ElasticMetricsUpdateWorker
include ApplicationWorker
include ExclusiveLeaseGuard
# rubocop:disable Scalability/CronWorkerContext
# This worker does not perform work scoped to a context
include CronjobQueue
# rubocop:enable Scalability/CronWorkerContext
feature_category :global_search
idempotent!
LEASE_TIMEOUT = 5.minutes
def perform
try_obtain_lease { Elastic::MetricsUpdateService.new.execute }
end
private
def lease_timeout
LEASE_TIMEOUT
end
end
# frozen_string_literal: true
module Gitlab
module Metrics
module Samplers
class GlobalSearchSampler < BaseSampler
def sample
::Elastic::MetricsUpdateService.new.execute
end
end
end
end
end
...@@ -2,18 +2,16 @@ ...@@ -2,18 +2,16 @@
require 'spec_helper' require 'spec_helper'
describe ElasticMetricsUpdateWorker do describe Gitlab::Metrics::Samplers::GlobalSearchSampler do
include ExclusiveLeaseHelpers subject { described_class.new(60.seconds) }
describe '.perform' do
it 'executes the service under an exclusive lease' do
expect_to_obtain_exclusive_lease('elastic_metrics_update_worker')
describe '#sample' do
it 'invokes the Elastic::MetricsUpdateService' do
expect_next_instance_of(::Elastic::MetricsUpdateService) do |service| expect_next_instance_of(::Elastic::MetricsUpdateService) do |service|
expect(service).to receive(:execute) expect(service).to receive(:execute)
end end
described_class.new.perform subject.sample
end end
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