Commit c3eb0319 authored by Matija Čupić's avatar Matija Čupić Committed by Markus Koller

Use configurable page size for jobs in stages

Changelog: fixed
parent 0c4ab31a
......@@ -15,10 +15,8 @@ module Types
description: 'Group of jobs for the stage.'
field :detailed_status, Types::Ci::DetailedStatusType, null: true,
description: 'Detailed status of the stage.'
field :jobs, Ci::JobType.connection_type, null: true,
description: 'Jobs for the stage.',
method: 'latest_statuses',
max_page_size: 200
field :jobs, Types::Ci::JobType.connection_type, null: true,
description: 'Jobs for the stage.'
field :status, GraphQL::Types::String,
null: true,
description: 'Status of the pipeline stage.'
......@@ -49,6 +47,13 @@ module Types
end
end
def jobs
GraphQL::Pagination::ActiveRecordRelationConnection.new(
object.latest_statuses,
max_page_size: Gitlab::CurrentSettings.current_application_settings.jobs_per_stage_page_size
)
end
private
# rubocop: disable CodeReuse/ActiveRecord
......
......@@ -207,6 +207,10 @@ class ApplicationSetting < ApplicationRecord
numericality: { only_integer: true, greater_than_or_equal_to: 0,
less_than: ::Gitlab::Pages::MAX_SIZE / 1.megabyte }
validates :jobs_per_stage_page_size,
presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :default_artifacts_expire_in, presence: true, duration: true
validates :container_expiration_policies_enable_historic_entries,
......
# frozen_string_literal: true
class AddJobsPerStagePageSizeToApplicationSettings < Gitlab::Database::Migration[1.0]
def change
add_column :application_settings, :jobs_per_stage_page_size, :integer, default: 200, null: false
end
end
06e45cf159cf1182b34e83f893bcff65e4722dded2bf4cbcf61fafd652158823
\ No newline at end of file
......@@ -10371,6 +10371,7 @@ CREATE TABLE application_settings (
throttle_unauthenticated_api_enabled boolean DEFAULT false NOT NULL,
throttle_unauthenticated_api_requests_per_period integer DEFAULT 3600 NOT NULL,
throttle_unauthenticated_api_period_in_seconds integer DEFAULT 3600 NOT NULL,
jobs_per_stage_page_size integer DEFAULT 200 NOT NULL,
sidekiq_job_limiter_mode smallint DEFAULT 1 NOT NULL,
sidekiq_job_limiter_compression_threshold_bytes integer DEFAULT 100000 NOT NULL,
sidekiq_job_limiter_limit_bytes integer DEFAULT 0 NOT NULL,
......@@ -91,6 +91,9 @@ RSpec.describe ApplicationSetting do
.is_less_than(::Gitlab::Pages::MAX_SIZE / 1.megabyte)
end
it { is_expected.to validate_presence_of(:jobs_per_stage_page_size) }
it { is_expected.to validate_numericality_of(:jobs_per_stage_page_size).only_integer.is_greater_than_or_equal_to(0) }
it { is_expected.not_to allow_value(7).for(:minimum_password_length) }
it { is_expected.not_to allow_value(129).for(:minimum_password_length) }
it { is_expected.not_to allow_value(nil).for(:minimum_password_length) }
......
......@@ -4,11 +4,13 @@ require 'spec_helper'
RSpec.describe 'Query.project.pipeline.stages' do
include GraphqlHelpers
let(:project) { create(:project, :repository, :public) }
let(:user) { create(:user) }
let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let(:stage_graphql_data) { graphql_data['project']['pipeline']['stages'] }
subject(:post_query) { post_graphql(query, current_user: user) }
let_it_be(:project) { create(:project, :repository, :public) }
let_it_be(:user) { create(:user) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let(:stage_nodes) { graphql_data_at(:project, :pipeline, :stages, :nodes) }
let(:params) { {} }
let(:fields) do
......@@ -33,14 +35,42 @@ RSpec.describe 'Query.project.pipeline.stages' do
)
end
before do
before_all do
create(:ci_stage_entity, pipeline: pipeline, name: 'deploy')
post_graphql(query, current_user: user)
create_list(:ci_build, 2, pipeline: pipeline, stage: 'deploy')
end
it_behaves_like 'a working graphql query'
it_behaves_like 'a working graphql query' do
before do
post_query
end
end
it 'returns the stage of a pipeline' do
expect(stage_graphql_data['nodes'].first['name']).to eq('deploy')
post_query
expect(stage_nodes.first['name']).to eq('deploy')
end
describe 'job pagination' do
let(:job_nodes) { graphql_dig_at(stage_nodes, :jobs, :nodes) }
it 'returns up to default limit jobs per stage' do
post_query
expect(job_nodes.count).to eq(2)
end
context 'when the limit is manually set' do
before do
stub_application_setting(jobs_per_stage_page_size: 1)
end
it 'returns up to custom limit jobs per stage' do
post_query
expect(job_nodes.count).to eq(1)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment