Skip to content

Commit

Permalink
Add distinct set of limits for assets
Browse files Browse the repository at this point in the history
The generic default limit (that was taken from the "All tests" page for
jobs) doesn't make any sense here so this change allows us to configure the
limit for asset queries separately.

Related ticket: https://progress.opensuse.org/issues/120315
  • Loading branch information
Martchus committed Nov 11, 2022
1 parent 900d1d5 commit 786037e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions etc/openqa/openqa.ini
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ concurrent = 0
#previous_jobs_max_limit = 4000
# Maximum number of recent jobs to consider when returning jobs for a settings query (to prevent performance issues)
#job_settings_max_recent_jobs = 20000
# Default number of assets to include in asset listing request (to prevent performance issues)
#assets_default_limit = 100000
# Maximum number of next jobs to include asset listing request (to prevent performance issues)
#assets_max_limit = 200000

[archiving]
# Moves logs of jobs which are preserved during the cleanup because they are considered important
Expand Down
4 changes: 3 additions & 1 deletion lib/OpenQA/Setup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ sub read_config ($app) {
next_jobs_max_limit => 1000,
previous_jobs_default_limit => 400,
previous_jobs_max_limit => 4000,
job_settings_max_recent_jobs => 20000
job_settings_max_recent_jobs => 20000,
assets_default_limit => 100000,
assets_max_limit => 200000,
},
archiving => {
archive_preserved_important_jobs => 0,
Expand Down
2 changes: 1 addition & 1 deletion lib/OpenQA/WebAPI/Controller/API/V1/Asset.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sub list {
my $self = shift;
my $schema = $self->schema;
my $limits = OpenQA::App->singleton->config->{misc_limits};
my $limit = min($limits->{generic_max_limit}, $self->param('limit') // $limits->{generic_default_limit});
my $limit = min($limits->{assets_max_limit}, $self->param('limit') // $limits->{assets_default_limit});

my $rs = $schema->resultset("Assets")->search({}, {rows => $limit});
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
Expand Down
4 changes: 2 additions & 2 deletions t/api/02-assets.t
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ $t->json_is('/assets/6' => $listing->[0], "listing ok");
#check user specified and server-side limit
subtest 'server-side limit has precedence over user-specified limit' => sub {
my $limits = OpenQA::App->singleton->config->{misc_limits};
$limits->{generic_max_limit} = 5;
$limits->{generic_default_limit} = 2;
$limits->{assets_max_limit} = 5;
$limits->{assets_default_limit} = 2;

$t->get_ok('/api/v1/assets?limit=10', 'query with exceeding user-specified limit for assets')->status_is(200);
my $assets = $t->tx->res->json->{assets};
Expand Down
4 changes: 3 additions & 1 deletion t/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ subtest 'Test configuration default modes' => sub {
next_jobs_max_limit => 1000,
previous_jobs_default_limit => 400,
previous_jobs_max_limit => 4000,
job_settings_max_recent_jobs => 20000
job_settings_max_recent_jobs => 20000,
assets_default_limit => 100000,
assets_max_limit => 200000,
},
archiving => {
archive_preserved_important_jobs => 0,
Expand Down

0 comments on commit 786037e

Please sign in to comment.