diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-14 06:13:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-14 06:13:17 +0300 |
commit | b1238272e1ce6a56eb713d48c9cc00a2fc95d77d (patch) | |
tree | 4376546175cf48c75bb95df02c95fbdb03a43fb2 /lib/gitlab | |
parent | 0c2b535267434504ea93a0c76ce1ac4ea7f2319e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
9 files changed, 55 insertions, 14 deletions
diff --git a/lib/gitlab/background_migration/backfill_imported_issue_search_data.rb b/lib/gitlab/background_migration/backfill_imported_issue_search_data.rb index 8c151bc36ac..e230fe46466 100644 --- a/lib/gitlab/background_migration/backfill_imported_issue_search_data.rb +++ b/lib/gitlab/background_migration/backfill_imported_issue_search_data.rb @@ -15,7 +15,7 @@ module Gitlab def perform each_sub_batch do |sub_batch| update_search_data(sub_batch) - rescue ActiveRecord::StatementInvalid => e + rescue ActiveRecord::StatementInvalid => e # rubocop:todo BackgroundMigration/AvoidSilentRescueExceptions -- https://gitlab.com/gitlab-org/gitlab/-/issues/431592 raise unless e.cause.is_a?(PG::ProgramLimitExceeded) && e.message.include?('string is too long for tsvector') update_search_data_individually(sub_batch) @@ -44,7 +44,7 @@ module Gitlab relation.pluck(:id).each do |issue_id| update_search_data(relation.klass.where(id: issue_id)) sleep(pause_ms * 0.001) - rescue ActiveRecord::StatementInvalid => e + rescue ActiveRecord::StatementInvalid => e # rubocop:todo BackgroundMigration/AvoidSilentRescueExceptions -- https://gitlab.com/gitlab-org/gitlab/-/issues/431592 raise unless e.cause.is_a?(PG::ProgramLimitExceeded) && e.message.include?('string is too long for tsvector') logger.error( diff --git a/lib/gitlab/background_migration/migrate_links_for_vulnerability_findings.rb b/lib/gitlab/background_migration/migrate_links_for_vulnerability_findings.rb index 0b79bc143db..4f1f70f3337 100644 --- a/lib/gitlab/background_migration/migrate_links_for_vulnerability_findings.rb +++ b/lib/gitlab/background_migration/migrate_links_for_vulnerability_findings.rb @@ -36,7 +36,7 @@ module Gitlab def migrate_remediations(findings, existing_links) findings.each do |finding| create_links(build_links_from(finding, existing_links)) - rescue ActiveRecord::StatementInvalid => e + rescue ActiveRecord::StatementInvalid => e # rubocop:todo BackgroundMigration/AvoidSilentRescueExceptions -- https://gitlab.com/gitlab-org/gitlab/-/issues/431592 logger.error( message: e.message, class: self.class.name, @@ -76,7 +76,7 @@ module Gitlab return [] if parsed_links.blank? parsed_links.select { |link| link.try(:[], 'url').present? }.uniq - rescue JSON::ParserError => e + rescue JSON::ParserError => e # rubocop:todo BackgroundMigration/AvoidSilentRescueExceptions -- https://gitlab.com/gitlab-org/gitlab/-/issues/431592 logger.warn( message: e.message, class: self.class.name diff --git a/lib/gitlab/background_migration/migrate_remediations_for_vulnerability_findings.rb b/lib/gitlab/background_migration/migrate_remediations_for_vulnerability_findings.rb index 9eadef96db6..c6a41bc1c65 100644 --- a/lib/gitlab/background_migration/migrate_remediations_for_vulnerability_findings.rb +++ b/lib/gitlab/background_migration/migrate_remediations_for_vulnerability_findings.rb @@ -74,7 +74,7 @@ module Gitlab create_finding_remediations(finding.id, result_ids) end - rescue StandardError => e + rescue StandardError => e # rubocop:todo BackgroundMigration/AvoidSilentRescueExceptions -- https://gitlab.com/gitlab-org/gitlab/-/issues/431592 logger.error( message: e.message, class: self.class.name, diff --git a/lib/gitlab/background_migration/populate_vulnerability_dismissal_fields.rb b/lib/gitlab/background_migration/populate_vulnerability_dismissal_fields.rb index ee0f73cc3de..c310c10d7fa 100644 --- a/lib/gitlab/background_migration/populate_vulnerability_dismissal_fields.rb +++ b/lib/gitlab/background_migration/populate_vulnerability_dismissal_fields.rb @@ -58,7 +58,7 @@ module Gitlab def populate_for(vulnerability) log_warning(vulnerability) unless vulnerability.copy_dismissal_information - rescue StandardError => error + rescue StandardError => error # rubocop:todo BackgroundMigration/AvoidSilentRescueExceptions -- https://gitlab.com/gitlab-org/gitlab/-/issues/431592 log_error(error, vulnerability) end diff --git a/lib/gitlab/background_migration/reset_status_on_container_repositories.rb b/lib/gitlab/background_migration/reset_status_on_container_repositories.rb index 56506814dc0..a83c4625cb4 100644 --- a/lib/gitlab/background_migration/reset_status_on_container_repositories.rb +++ b/lib/gitlab/background_migration/reset_status_on_container_repositories.rb @@ -117,7 +117,7 @@ module Gitlab return DUMMY_TAGS unless response response['tags'] || [] - rescue StandardError + rescue StandardError # rubocop:todo BackgroundMigration/AvoidSilentRescueExceptions -- https://gitlab.com/gitlab-org/gitlab/-/issues/431592 DUMMY_TAGS end end diff --git a/lib/gitlab/internal_events.rb b/lib/gitlab/internal_events.rb index e2e4ea75dbf..a8f28615cd3 100644 --- a/lib/gitlab/internal_events.rb +++ b/lib/gitlab/internal_events.rb @@ -13,6 +13,7 @@ module Gitlab raise UnknownEventError, "Unknown event: #{event_name}" unless EventDefinitions.known_event?(event_name) increase_total_counter(event_name) + increase_weekly_total_counter(event_name) update_unique_counter(event_name, kwargs) trigger_snowplow_event(event_name, kwargs) if send_snowplow_event rescue StandardError => e @@ -28,6 +29,12 @@ module Gitlab Gitlab::Redis::SharedState.with { |redis| redis.incr(redis_counter_key) } end + def increase_weekly_total_counter(event_name) + redis_counter_key = + Gitlab::Usage::Metrics::Instrumentations::TotalCountMetric.redis_key(event_name, Date.today) + Gitlab::Redis::SharedState.with { |redis| redis.incr(redis_counter_key) } + end + def update_unique_counter(event_name, kwargs) unique_property = EventDefinitions.unique_property(event_name) return unless unique_property diff --git a/lib/gitlab/redis/sidekiq_status.rb b/lib/gitlab/redis/sidekiq_status.rb index 9b8bbf5a0ad..69e0c745c79 100644 --- a/lib/gitlab/redis/sidekiq_status.rb +++ b/lib/gitlab/redis/sidekiq_status.rb @@ -13,7 +13,7 @@ module Gitlab private def redis - primary_store = ::Redis.new(Gitlab::Redis::SharedState.params) + primary_store = ::Gitlab::Redis::SharedState.redis secondary_store = ::Redis.new(Gitlab::Redis::Queues.params) # rubocop:disable Cop/RedisQueueUsage MultiStore.new(primary_store, secondary_store, name.demodulize) diff --git a/lib/gitlab/redis/wrapper.rb b/lib/gitlab/redis/wrapper.rb index d5470bc0016..d3dc955d9e2 100644 --- a/lib/gitlab/redis/wrapper.rb +++ b/lib/gitlab/redis/wrapper.rb @@ -83,8 +83,6 @@ module Gitlab "::Gitlab::Instrumentation::Redis::#{store_name}".constantize end - private - def redis ::Redis.new(params) end diff --git a/lib/gitlab/usage/metrics/instrumentations/total_count_metric.rb b/lib/gitlab/usage/metrics/instrumentations/total_count_metric.rb index d07438f4bf7..ce7b2feb745 100644 --- a/lib/gitlab/usage/metrics/instrumentations/total_count_metric.rb +++ b/lib/gitlab/usage/metrics/instrumentations/total_count_metric.rb @@ -14,20 +14,56 @@ module Gitlab # class TotalCountMetric < BaseMetric include Gitlab::UsageDataCounters::RedisCounter + extend Gitlab::Usage::TimeSeriesStorable KEY_PREFIX = "{event_counters}_" - def self.redis_key(event_name) - KEY_PREFIX + event_name + def self.redis_key(event_name, date = nil) + base_key = KEY_PREFIX + event_name + return base_key unless date + + apply_time_aggregation(base_key, date) end def value - events.sum do |event| + return total_value if time_frame == 'all' + + period_value + end + + private + + def total_value + event_names.sum do |event_name| redis_usage_data do - total_count(self.class.redis_key(event[:name])) + total_count(self.class.redis_key(event_name)) end end end + + def period_value + keys = self.class.keys_for_aggregation(events: event_names, **time_constraint) + keys.sum do |key| + redis_usage_data do + total_count(key) + end + end + end + + def time_constraint + case time_frame + when '28d' + monthly_time_range + when '7d' + weekly_time_range + else + raise "Unknown time frame: #{time_frame} for #{self.class} :: #{events}" + end + end + + def event_names + events.pluck(:name) + end end end end |