diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-13 06:08:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-13 06:08:51 +0300 |
commit | b9abe8515111c39c65321258d760aaf4773cb55f (patch) | |
tree | a58816df2053183f855389c37945ed17578a76aa /app | |
parent | fa1b90364dc73f27dc78b9d27114e4a197f2cfcb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/services/metrics/global_metrics_update_service.rb | 24 | ||||
-rw-r--r-- | app/workers/all_queues.yml | 9 | ||||
-rw-r--r-- | app/workers/metrics/global_metrics_update_worker.rb | 27 |
3 files changed, 60 insertions, 0 deletions
diff --git a/app/services/metrics/global_metrics_update_service.rb b/app/services/metrics/global_metrics_update_service.rb new file mode 100644 index 00000000000..356de58ba2e --- /dev/null +++ b/app/services/metrics/global_metrics_update_service.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Metrics + # Update metrics regarding GitLab instance wide + # + # Anything that is not specific to a machine, process, request or any other context + # can be updated from this services. + # + # Examples of metrics that qualify: + # * Global counters (instance users, instance projects...) + # * State of settings stored in the database (whether a feature is active or not, tuning values...) + # + class GlobalMetricsUpdateService + def execute + return unless ::Gitlab::Metrics.prometheus_metrics_enabled? + + maintenance_mode_metric.set({}, (::Gitlab.maintenance_mode? ? 1 : 0)) + end + + def maintenance_mode_metric + ::Gitlab::Metrics.gauge(:gitlab_maintenance_mode, 'Is GitLab Maintenance Mode enabled?') + end + end +end diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml index 89f8867fe62..6c3b4990023 100644 --- a/app/workers/all_queues.yml +++ b/app/workers/all_queues.yml @@ -543,6 +543,15 @@ :weight: 1 :idempotent: true :tags: [] +- :name: cronjob:metrics_global_metrics_update + :worker_name: Metrics::GlobalMetricsUpdateWorker + :feature_category: :metrics + :has_external_dependencies: false + :urgency: :low + :resource_boundary: :unknown + :weight: 1 + :idempotent: true + :tags: [] - :name: cronjob:namespaces_in_product_marketing_emails :worker_name: Namespaces::InProductMarketingEmailsWorker :feature_category: :experimentation_activation diff --git a/app/workers/metrics/global_metrics_update_worker.rb b/app/workers/metrics/global_metrics_update_worker.rb new file mode 100644 index 00000000000..326403a2f8f --- /dev/null +++ b/app/workers/metrics/global_metrics_update_worker.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Metrics + class GlobalMetricsUpdateWorker + include ApplicationWorker + + idempotent! + data_consistency :sticky + feature_category :metrics + + include ExclusiveLeaseGuard + # rubocop:disable Scalability/CronWorkerContext + # This worker does not perform work scoped to a context + include CronjobQueue + # rubocop:enable Scalability/CronWorkerContext + + LEASE_TIMEOUT = 2.minutes + + def perform + try_obtain_lease { ::Metrics::GlobalMetricsUpdateService.new.execute } + end + + def lease_timeout + LEASE_TIMEOUT + end + end +end |