diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/generators/gitlab/snowplow_event_definition_generator.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/database/gitlab_loose_foreign_keys.yml | 4 | ||||
-rw-r--r-- | lib/gitlab/metrics/exporter/base_exporter.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/metrics/exporter/web_exporter.rb | 36 | ||||
-rw-r--r-- | lib/gitlab/pipeline_scope_counts.rb | 41 | ||||
-rw-r--r-- | lib/gitlab/process_memory_cache/helper.rb | 51 |
6 files changed, 103 insertions, 40 deletions
diff --git a/lib/generators/gitlab/snowplow_event_definition_generator.rb b/lib/generators/gitlab/snowplow_event_definition_generator.rb index 497d0cd512a..827e87dc313 100644 --- a/lib/generators/gitlab/snowplow_event_definition_generator.rb +++ b/lib/generators/gitlab/snowplow_event_definition_generator.rb @@ -65,7 +65,12 @@ module Gitlab end def file_name - "#{event_category}_#{event_action}.yml".underscore.gsub("/", "__") + name = remove_special_chars("#{Time.current.to_i}_#{event_category}_#{event_action}") + "#{name[0..95]}.yml" # max 100 chars, see https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/2030#note_679501200 + end + + def remove_special_chars(input) + input.gsub("::", "__").gsub(/[^A-Za-z0-9_]/, '') end end end diff --git a/lib/gitlab/database/gitlab_loose_foreign_keys.yml b/lib/gitlab/database/gitlab_loose_foreign_keys.yml index 531b9f58a48..4a796b6c265 100644 --- a/lib/gitlab/database/gitlab_loose_foreign_keys.yml +++ b/lib/gitlab/database/gitlab_loose_foreign_keys.yml @@ -87,6 +87,10 @@ ci_build_report_results: - table: projects column: project_id on_delete: async_delete +ci_job_artifacts: + - table: projects + column: project_id + on_delete: async_delete ci_builds: - table: users column: user_id diff --git a/lib/gitlab/metrics/exporter/base_exporter.rb b/lib/gitlab/metrics/exporter/base_exporter.rb index 190d3d3fd2f..4874ef62e41 100644 --- a/lib/gitlab/metrics/exporter/base_exporter.rb +++ b/lib/gitlab/metrics/exporter/base_exporter.rb @@ -9,8 +9,6 @@ module Gitlab class BaseExporter < Daemon attr_reader :server - attr_accessor :readiness_checks - def initialize(settings, log_enabled:, log_file:, gc_requests: false, **options) super(**options) @@ -85,7 +83,7 @@ module Gitlab end def readiness_probe - ::Gitlab::HealthChecks::Probes::Collection.new(*readiness_checks) + ::Gitlab::HealthChecks::Probes::Collection.new end def liveness_probe diff --git a/lib/gitlab/metrics/exporter/web_exporter.rb b/lib/gitlab/metrics/exporter/web_exporter.rb index c05ad8ccf42..761fcdceb5b 100644 --- a/lib/gitlab/metrics/exporter/web_exporter.rb +++ b/lib/gitlab/metrics/exporter/web_exporter.rb @@ -4,17 +4,6 @@ module Gitlab module Metrics module Exporter class WebExporter < BaseExporter - ExporterCheck = Struct.new(:exporter) do - def readiness - Gitlab::HealthChecks::Result.new( - 'web_exporter', exporter.running) - end - - def available? - true - end - end - RailsMetricsInitializer = Struct.new(:app) do def call(env) Gitlab::Metrics::RailsSlis.initialize_request_slis_if_needed! @@ -23,24 +12,9 @@ module Gitlab end end - attr_reader :running - # This exporter is always run on master process def initialize(**options) super(Settings.monitoring.web_exporter, log_enabled: true, log_file: 'web_exporter.log', **options) - - # DEPRECATED: - # these `readiness_checks` are deprecated - # as presenting no value in a way how we run - # application: https://gitlab.com/gitlab-org/gitlab/issues/35343 - self.readiness_checks = [ - WebExporter::ExporterCheck.new(self), - Gitlab::HealthChecks::PumaCheck - ] - end - - def mark_as_not_running! - @running = false end private @@ -53,16 +27,6 @@ module Gitlab run app end end - - def start_working - @running = true - super - end - - def stop_working - mark_as_not_running! - super - end end end end diff --git a/lib/gitlab/pipeline_scope_counts.rb b/lib/gitlab/pipeline_scope_counts.rb new file mode 100644 index 00000000000..02f4ea33ddf --- /dev/null +++ b/lib/gitlab/pipeline_scope_counts.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Gitlab + class PipelineScopeCounts + attr_reader :project + + PIPELINES_COUNT_LIMIT = 1000 + + def self.declarative_policy_class + 'Ci::ProjectPipelinesPolicy' + end + + def initialize(current_user, project, params) + @current_user = current_user + @project = project + @params = params + end + + def all + finder.execute.limit(PIPELINES_COUNT_LIMIT).count + end + + def running + finder({ scope: "running" }).execute.limit(PIPELINES_COUNT_LIMIT).count + end + + def finished + finder({ scope: "finished" }).execute.limit(PIPELINES_COUNT_LIMIT).count + end + + def pending + finder({ scope: "pending" }).execute.limit(PIPELINES_COUNT_LIMIT).count + end + + private + + def finder(params = {}) + ::Ci::PipelinesFinder.new(@project, @current_user, @params.merge(params)) + end + end +end diff --git a/lib/gitlab/process_memory_cache/helper.rb b/lib/gitlab/process_memory_cache/helper.rb new file mode 100644 index 00000000000..8d436c14b48 --- /dev/null +++ b/lib/gitlab/process_memory_cache/helper.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module Gitlab + class ProcessMemoryCache + module Helper + def fetch_memory_cache(key, &payload) + cache = cache_backend.read(key) + + if cache && !stale_cache?(key, cache) + cache[:data] + else + store_cache(key, &payload) + end + end + + def invalidate_memory_cache(key) + touch_cache_timestamp(key) + end + + private + + def touch_cache_timestamp(key, time = Time.current.to_f) + shared_backend.write(key, time) + end + + def stale_cache?(key, cache_info) + shared_timestamp = shared_backend.read(key) + return true unless shared_timestamp + + shared_timestamp.to_f > cache_info[:cached_at].to_f + end + + def store_cache(key) + data = yield + time = Time.current.to_f + + cache_backend.write(key, data: data, cached_at: time) + touch_cache_timestamp(key, time) unless shared_backend.read(key) + data + end + + def shared_backend + Rails.cache + end + + def cache_backend + ::Gitlab::ProcessMemoryCache.cache_backend + end + end + end +end |