diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-05 12:21:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-05 12:21:54 +0300 |
commit | a92d6b36c2d2892e8c070efb169f0c06815900ee (patch) | |
tree | e7119c41b0e0d0eb0cff50b19fbb2bb34315f5a4 /lib/gitlab | |
parent | 39a48637e52c4afc58341edfb10167947d961b33 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
15 files changed, 47 insertions, 76 deletions
diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events.rb b/lib/gitlab/analytics/cycle_analytics/stage_events.rb index 58572446de6..f6e22044142 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events.rb @@ -47,27 +47,29 @@ module Gitlab ] }.freeze - def [](identifier) + def self.[](identifier) events.find { |e| e.identifier.to_s.eql?(identifier.to_s) } || raise(KeyError) end # hash for defining ActiveRecord enum: identifier => number - def to_enum - ENUM_MAPPING.each_with_object({}) { |(k, v), hash| hash[k.identifier] = v } + def self.to_enum + enum_mapping.each_with_object({}) { |(k, v), hash| hash[k.identifier] = v } end - # will be overridden in EE with custom events - def pairing_rules + def self.pairing_rules PAIRING_RULES end - # will be overridden in EE with custom events - def events + def self.events EVENTS end - module_function :[], :to_enum, :pairing_rules, :events + def self.enum_mapping + ENUM_MAPPING + end end end end end + +Gitlab::Analytics::CycleAnalytics::StageEvents.prepend_if_ee('::EE::Gitlab::Analytics::CycleAnalytics::StageEvents') diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb index 6af1b90bccc..9f0ca80ba50 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class CodeStageStart < SimpleStageEvent + class CodeStageStart < StageEvent def self.name s_("CycleAnalyticsEvent|Issue first mentioned in a commit") end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/issue_created.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/issue_created.rb index 8c9a80740a9..a159580b7bd 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/issue_created.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/issue_created.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class IssueCreated < SimpleStageEvent + class IssueCreated < StageEvent def self.name s_("CycleAnalyticsEvent|Issue created") end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/issue_first_mentioned_in_commit.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/issue_first_mentioned_in_commit.rb index fe7f2d85f8b..a3b7fa16daf 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/issue_first_mentioned_in_commit.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/issue_first_mentioned_in_commit.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class IssueFirstMentionedInCommit < SimpleStageEvent + class IssueFirstMentionedInCommit < MetricsBasedStageEvent def self.name s_("CycleAnalyticsEvent|Issue first mentioned in a commit") end @@ -20,12 +20,6 @@ module Gitlab def timestamp_projection issue_metrics_table[:first_mentioned_in_commit_at] end - - # rubocop: disable CodeReuse/ActiveRecord - def apply_query_customization(query) - query.joins(:metrics) - end - # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end.rb index 77e4092b9ab..0ea98e82ecc 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class IssueStageEnd < SimpleStageEvent + class IssueStageEnd < MetricsBasedStageEvent def self.name PlanStageStart.name end @@ -26,7 +26,7 @@ module Gitlab # rubocop: disable CodeReuse/ActiveRecord def apply_query_customization(query) - query.joins(:metrics).where(issue_metrics_table[:first_added_to_board_at].not_eq(nil).or(issue_metrics_table[:first_associated_with_milestone_at].not_eq(nil))) + super.where(issue_metrics_table[:first_added_to_board_at].not_eq(nil).or(issue_metrics_table[:first_associated_with_milestone_at].not_eq(nil))) end # rubocop: enable CodeReuse/ActiveRecord end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_created.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_created.rb index 7059c425b8f..013e068e479 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_created.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_created.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class MergeRequestCreated < SimpleStageEvent + class MergeRequestCreated < StageEvent def self.name s_("CycleAnalyticsEvent|Merge request created") end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_first_deployed_to_production.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_first_deployed_to_production.rb index 3d7482eaaf0..654d0befbc3 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_first_deployed_to_production.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_first_deployed_to_production.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class MergeRequestFirstDeployedToProduction < SimpleStageEvent + class MergeRequestFirstDeployedToProduction < MetricsBasedStageEvent def self.name s_("CycleAnalyticsEvent|Merge request first deployed to production") end @@ -23,7 +23,7 @@ module Gitlab # rubocop: disable CodeReuse/ActiveRecord def apply_query_customization(query) - query.joins(:metrics).where(timestamp_projection.gteq(mr_table[:created_at])) + super.where(timestamp_projection.gteq(mr_table[:created_at])) end # rubocop: enable CodeReuse/ActiveRecord end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_finished.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_finished.rb index 36bb4d6fc8d..a0b1c12756f 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_finished.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_finished.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class MergeRequestLastBuildFinished < SimpleStageEvent + class MergeRequestLastBuildFinished < MetricsBasedStageEvent def self.name s_("CycleAnalyticsEvent|Merge request last build finish time") end @@ -20,12 +20,6 @@ module Gitlab def timestamp_projection mr_metrics_table[:latest_build_finished_at] end - - # rubocop: disable CodeReuse/ActiveRecord - def apply_query_customization(query) - query.joins(:metrics) - end - # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_started.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_started.rb index 468d9899cc7..da3b5cdfaa4 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_started.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_started.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class MergeRequestLastBuildStarted < SimpleStageEvent + class MergeRequestLastBuildStarted < MetricsBasedStageEvent def self.name s_("CycleAnalyticsEvent|Merge request last build start time") end @@ -20,12 +20,6 @@ module Gitlab def timestamp_projection mr_metrics_table[:latest_build_started_at] end - - # rubocop: disable CodeReuse/ActiveRecord - def apply_query_customization(query) - query.joins(:metrics) - end - # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_merged.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_merged.rb index 82ecaf1cd6b..e67a6f7eea6 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_merged.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_merged.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class MergeRequestMerged < SimpleStageEvent + class MergeRequestMerged < MetricsBasedStageEvent def self.name s_("CycleAnalyticsEvent|Merge request merged") end @@ -20,12 +20,6 @@ module Gitlab def timestamp_projection mr_metrics_table[:merged_at] end - - # rubocop: disable CodeReuse/ActiveRecord - def apply_query_customization(query) - query.joins(:metrics) - end - # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/metrics_based_stage_event.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/metrics_based_stage_event.rb new file mode 100644 index 00000000000..4ca8745abe4 --- /dev/null +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/metrics_based_stage_event.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module Analytics + module CycleAnalytics + module StageEvents + class MetricsBasedStageEvent < StageEvent + # rubocop: disable CodeReuse/ActiveRecord + def apply_query_customization(query) + query.joins(:metrics) + end + # rubocop: enable CodeReuse/ActiveRecord + end + end + end + end +end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start.rb index 7ece7d62faa..37168a1fb0f 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class PlanStageStart < SimpleStageEvent + class PlanStageStart < MetricsBasedStageEvent def self.name s_("CycleAnalyticsEvent|Issue first associated with a milestone or issue first added to a board") end @@ -26,8 +26,7 @@ module Gitlab # rubocop: disable CodeReuse/ActiveRecord def apply_query_customization(query) - query - .joins(:metrics) + super .where(issue_metrics_table[:first_added_to_board_at].not_eq(nil).or(issue_metrics_table[:first_associated_with_milestone_at].not_eq(nil))) .where(issue_metrics_table[:first_mentioned_in_commit_at].not_eq(nil)) end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/production_stage_end.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/production_stage_end.rb index 607371a32e8..b249f6874e7 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/production_stage_end.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/production_stage_end.rb @@ -4,7 +4,7 @@ module Gitlab module Analytics module CycleAnalytics module StageEvents - class ProductionStageEnd < SimpleStageEvent + class ProductionStageEnd < StageEvent def self.name PlanStageStart.name end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/simple_stage_event.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/simple_stage_event.rb deleted file mode 100644 index 253c489d822..00000000000 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/simple_stage_event.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module Analytics - module CycleAnalytics - module StageEvents - # Represents a simple event that usually refers to one database column and does not require additional user input - class SimpleStageEvent < StageEvent - end - end - end - end -end diff --git a/lib/gitlab/sidekiq_middleware/metrics.rb b/lib/gitlab/sidekiq_middleware/metrics.rb index 64e77a2d828..bd819843bd4 100644 --- a/lib/gitlab/sidekiq_middleware/metrics.rb +++ b/lib/gitlab/sidekiq_middleware/metrics.rb @@ -13,8 +13,8 @@ module Gitlab @metrics[:sidekiq_concurrency].set({}, Sidekiq.options[:concurrency].to_i) end - def call(worker, job, queue) - labels = create_labels(worker, queue) + def call(_worker, job, queue) + labels = create_labels(queue) queue_duration = ::Gitlab::InstrumentationHelper.queue_duration_for_job(job) @metrics[:sidekiq_jobs_queue_duration_seconds].observe(labels, queue_duration) if queue_duration @@ -62,20 +62,10 @@ module Gitlab } end - def create_labels(worker, queue) - labels = { queue: queue } - return labels unless worker.include? WorkerAttributes - - labels[:latency_sensitive] = true if worker.latency_sensitive_worker? - labels[:external_deps] = true if worker.worker_has_external_dependencies? - - feature_category = worker.get_feature_category - labels[:feat_cat] = feature_category if feature_category - - resource_boundary = worker.get_worker_resource_boundary - labels[:boundary] = resource_boundary if resource_boundary && resource_boundary != :unknown - - labels + def create_labels(queue) + { + queue: queue + } end def get_thread_cputime |