Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter settings by result and groupid #5497

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/OpenQA/Schema/ResultSet/JobSettings.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ sub jobs_for_setting ($self, $options) {
$key_like =~ s/\*/\%/g;
my $list_value = $options->{list_value};
my $list_value_like = "%${list_value}%";
my $filter_results = $options->{filter_results} if $options->{filter_results};
my $groupids = $options->{gids} if $options->{gids};

# Get the highest job id to limit the number of jobs that need to be considered (to improve performance)
my $dbh = $self->result_source->schema->storage->dbh;
Expand All @@ -25,10 +27,15 @@ sub jobs_for_setting ($self, $options) {

# Instead of limiting the number of jobs, this query could also use a trigram gin index to achieve even better
# performance (at the cost of disk space and setup complexity)
$sth = $dbh->prepare(
if ($filter_results && $groupids) {
$sth = $dbh->prepare(
'SELECT job_id, value FROM job_settings INNER JOIN jobs ON jobs.id=job_settings.job_id WHERE key LIKE ? AND value LIKE ? AND jobs.result = ? AND jobs.group_id = ? AND job_id > ? ORDER BY job_settings.job_id DESC');
$sth->execute($key_like, $list_value_like, $filter_results, $groupids, $min_id);
} else {
$sth = $dbh->prepare(
'SELECT job_id, value FROM job_settings WHERE key LIKE ? AND value LIKE ? AND job_id > ? ORDER BY job_id DESC');
$sth->execute($key_like, $list_value_like, $min_id);

$sth->execute($key_like, $list_value_like, $min_id);
}
Comment on lines -28 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jobgroup id is irrelevant at this stage, if a job matches the search, but it is pre-filtered from the list of results, in the end will hide the data from the user.

Also be aware of the discussion on slack about this route not returning all of the information

# Match list values
my @jobs;
for my $row (@{$sth->fetchall_arrayref}) {
Expand Down
9 changes: 8 additions & 1 deletion lib/OpenQA/WebAPI/Controller/API/V1/JobSettings.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ sub jobs ($self) {
my $validation = $self->validation;
$validation->required('key')->like(qr/^[\w\*]+$/);
$validation->required('list_value')->like(qr/^\w+$/);
$validation->optional('results')->like(qr/^\w+$/);
$validation->optional('list_groupids')->like(qr/^[\w\*]+$/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other queries we support "group_glob" and "not_group_globs". Introduing "list_groupids" here looks like a new, inconsistent approach. Also see the second suggestion in https://progress.opensuse.org/issues/131279#Suggestions How about extending the current group_glob support into here?

As alternative, potentially even simpler, see https://progress.opensuse.org/issues/131279#Suggestions number 3 stating "squads" could be mapped into openQA for example with special job settings, e.g. QE Core ensures to trigger all their tests with _SQUAD='QE Core' and then be able to filter by that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see a straight way to invoke group_glob inside the lib/OpenQA/WebAPI/Controller/API/V1/JobSettings.pm. That is because the variables are tight inside _compose_job_overview_search_args.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the code cannot be reused it would at least make sense to keep the design/usage consistent from a user perspective. (And I think this is also mainly what @okurz was asking for.)

return $self->reply->validation_error({format => 'json'}) if $validation->has_error;

my $key = $validation->param('key');
my $list_value = $validation->param('list_value');
my $jobs = $self->schema->resultset('JobSettings')->jobs_for_setting({key => $key, list_value => $list_value});
my $filter_result = $validation->param('results') // undef;
my $gids = $validation->param('list_groupids') // undef;
my $jobs = $self->schema->resultset('JobSettings')->jobs_for_setting({key => $key,
list_value => $list_value,
filter_results => $filter_result,
gids => $gids});
$self->render(json => {jobs => $jobs});
}

Expand Down
Loading