diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-16 21:06:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-16 21:06:05 +0300 |
commit | 930ff68c1efc380cb7522aa9b3884842eecb2486 (patch) | |
tree | 208f21205f9c8ee90e9722c6f641169d9a1569bf /app | |
parent | 84727c8209a4412e21111a07f99b0438b03232de (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/graphql/resolvers/issues_resolver.rb | 19 | ||||
-rw-r--r-- | app/graphql/types/order.rb | 8 | ||||
-rw-r--r-- | app/graphql/types/sort.rb | 10 | ||||
-rw-r--r-- | app/graphql/types/sort_enum.rb | 13 | ||||
-rw-r--r-- | app/models/ci/build_metadata.rb | 46 | ||||
-rw-r--r-- | app/models/concerns/routable.rb | 20 | ||||
-rw-r--r-- | app/models/project.rb | 3 | ||||
-rw-r--r-- | app/presenters/ci/build_metadata_presenter.rb | 3 |
8 files changed, 70 insertions, 52 deletions
diff --git a/app/graphql/resolvers/issues_resolver.rb b/app/graphql/resolvers/issues_resolver.rb index b50186c5a82..4e71a7a9ead 100644 --- a/app/graphql/resolvers/issues_resolver.rb +++ b/app/graphql/resolvers/issues_resolver.rb @@ -11,31 +11,32 @@ module Resolvers description: 'The list of IIDs of issues, e.g., [1, 2]' argument :state, Types::IssuableStateEnum, required: false, - description: "Current state of Issue" + description: 'Current state of Issue' argument :label_name, GraphQL::STRING_TYPE.to_list_type, required: false, - description: "Labels applied to the Issue" + description: 'Labels applied to the Issue' argument :created_before, Types::TimeType, required: false, - description: "Issues created before this date" + description: 'Issues created before this date' argument :created_after, Types::TimeType, required: false, - description: "Issues created after this date" + description: 'Issues created after this date' argument :updated_before, Types::TimeType, required: false, - description: "Issues updated before this date" + description: 'Issues updated before this date' argument :updated_after, Types::TimeType, required: false, - description: "Issues updated after this date" + description: 'Issues updated after this date' argument :closed_before, Types::TimeType, required: false, - description: "Issues closed before this date" + description: 'Issues closed before this date' argument :closed_after, Types::TimeType, required: false, - description: "Issues closed after this date" + description: 'Issues closed after this date' argument :search, GraphQL::STRING_TYPE, # rubocop:disable Graphql/Descriptions required: false - argument :sort, Types::Sort, # rubocop:disable Graphql/Descriptions + argument :sort, Types::SortEnum, + description: 'Sort issues by this criteria', required: false, default_value: 'created_desc' diff --git a/app/graphql/types/order.rb b/app/graphql/types/order.rb deleted file mode 100644 index c5e1cc406b4..00000000000 --- a/app/graphql/types/order.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -module Types - class Types::Order < Types::BaseEnum - value "id", "Created at date" - value "updated_at", "Updated at date" - end -end diff --git a/app/graphql/types/sort.rb b/app/graphql/types/sort.rb deleted file mode 100644 index 1f756fdab69..00000000000 --- a/app/graphql/types/sort.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -module Types - class Types::Sort < Types::BaseEnum - value "updated_desc", "Updated at descending order" - value "updated_asc", "Updated at ascending order" - value "created_desc", "Created at descending order" - value "created_asc", "Created at ascending order" - end -end diff --git a/app/graphql/types/sort_enum.rb b/app/graphql/types/sort_enum.rb new file mode 100644 index 00000000000..3245cb33e0d --- /dev/null +++ b/app/graphql/types/sort_enum.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Types + class SortEnum < BaseEnum + graphql_name 'Sort' + description 'Common sort values' + + value 'updated_desc', 'Updated at descending order' + value 'updated_asc', 'Updated at ascending order' + value 'created_desc', 'Created at descending order' + value 'created_asc', 'Created at ascending order' + end +end diff --git a/app/models/ci/build_metadata.rb b/app/models/ci/build_metadata.rb index f281cbd1d6f..89cdd8c64f8 100644 --- a/app/models/ci/build_metadata.rb +++ b/app/models/ci/build_metadata.rb @@ -4,9 +4,12 @@ module Ci # The purpose of this class is to store Build related data that can be disposed. # Data that should be persisted forever, should be stored with Ci::Build model. class BuildMetadata < ApplicationRecord + BuildTimeout = Struct.new(:value, :source) + extend Gitlab::Ci::Model include Presentable include ChronicDurationAttribute + include Gitlab::Utils::StrongMemoize self.table_name = 'ci_builds_metadata' @@ -25,17 +28,16 @@ module Ci enum timeout_source: { unknown_timeout_source: 1, project_timeout_source: 2, - runner_timeout_source: 3 + runner_timeout_source: 3, + job_timeout_source: 4 } def update_timeout_state - return unless build.runner.present? + timeout = timeout_with_highest_precedence - project_timeout = project&.build_timeout - timeout = [project_timeout, build.runner.maximum_timeout].compact.min - timeout_source = timeout < project_timeout ? :runner_timeout_source : :project_timeout_source + return unless timeout - update(timeout: timeout, timeout_source: timeout_source) + update(timeout: timeout.value, timeout_source: timeout.source) end private @@ -43,5 +45,37 @@ module Ci def set_build_project self.project_id ||= self.build.project_id end + + def timeout_with_highest_precedence + [(job_timeout || project_timeout), runner_timeout].compact.min_by { |timeout| timeout.value } + end + + def project_timeout + strong_memoize(:project_timeout) do + BuildTimeout.new(project&.build_timeout, :project_timeout_source) + end + end + + def job_timeout + return unless build.options + + strong_memoize(:job_timeout) do + if timeout_from_options = build.options[:job_timeout] + BuildTimeout.new(timeout_from_options, :job_timeout_source) + end + end + end + + def runner_timeout + return unless runner_timeout_set? + + strong_memoize(:runner_timeout) do + BuildTimeout.new(build.runner.maximum_timeout, :runner_timeout_source) + end + end + + def runner_timeout_set? + build.runner&.maximum_timeout.to_i > 0 + end end end diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb index 8b011bca72c..57118bf7a6b 100644 --- a/app/models/concerns/routable.rb +++ b/app/models/concerns/routable.rb @@ -33,16 +33,9 @@ module Routable # # Returns a single object, or nil. def find_by_full_path(path, follow_redirects: false) - routable_calls_counter.increment(method: 'find_by_full_path') - - if Feature.enabled?(:routable_two_step_lookup) - # Case sensitive match first (it's cheaper and the usual case) - # If we didn't have an exact match, we perform a case insensitive search - found = includes(:route).find_by(routes: { path: path }) || where_full_path_in([path]).take - else - order_sql = Arel.sql("(CASE WHEN routes.path = #{connection.quote(path)} THEN 0 ELSE 1 END)") - found = where_full_path_in([path]).reorder(order_sql).take - end + # Case sensitive match first (it's cheaper and the usual case) + # If we didn't have an exact match, we perform a case insensitive search + found = includes(:route).find_by(routes: { path: path }) || where_full_path_in([path]).take return found if found @@ -61,19 +54,12 @@ module Routable def where_full_path_in(paths) return none if paths.empty? - routable_calls_counter.increment(method: 'where_full_path_in') - wheres = paths.map do |path| "(LOWER(routes.path) = LOWER(#{connection.quote(path)}))" end includes(:route).where(wheres.join(' OR ')).references(:routes) end - - # Temporary instrumentation of method calls - def routable_calls_counter - @routable_calls_counter ||= Gitlab::Metrics.counter(:gitlab_routable_calls_total, 'Number of calls to Routable by method') - end end def full_name diff --git a/app/models/project.rb b/app/models/project.rb index 96c715095f6..59c187fac31 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -58,6 +58,7 @@ class Project < ApplicationRecord ACCESS_REQUEST_APPROVERS_TO_BE_NOTIFIED_LIMIT = 10 SORTING_PREFERENCE_FIELD = :projects_sort + MAX_BUILD_TIMEOUT = 1.month cache_markdown_field :description, pipeline: :description @@ -430,7 +431,7 @@ class Project < ApplicationRecord validates :build_timeout, allow_nil: true, numericality: { greater_than_or_equal_to: 10.minutes, - less_than: 1.month, + less_than: MAX_BUILD_TIMEOUT, only_integer: true, message: _('needs to be between 10 minutes and 1 month') } diff --git a/app/presenters/ci/build_metadata_presenter.rb b/app/presenters/ci/build_metadata_presenter.rb index 015b1f67db7..4871bb3a919 100644 --- a/app/presenters/ci/build_metadata_presenter.rb +++ b/app/presenters/ci/build_metadata_presenter.rb @@ -5,7 +5,8 @@ module Ci TIMEOUT_SOURCES = { unknown_timeout_source: nil, project_timeout_source: 'project', - runner_timeout_source: 'runner' + runner_timeout_source: 'runner', + job_timeout_source: 'job' }.freeze presents :metadata |