feat(api): filter job statistics by group globs#7344
feat(api): filter job statistics by group globs#7344okurz wants to merge 1 commit intoos-autoinst:masterfrom
Conversation
Motivation Users need to filter out jobs in development job groups from the statistics returned by the /api/v1/isos/job_stats endpoint, similar to what is currently available for the /tests and /tests/overview endpoints. Design Choices We reused the existing `groups_for_globs` helper in the Iso API controller to parse the `group_glob` and `not_group_glob` parameters. This helper provides a list of matching job groups. We extract the group IDs and pass them to the ScheduledProducts resultset's `job_statistics` method. The SQL query is then dynamically constructed to filter by the target group IDs in the `most_recent_jobs` block. To ensure consistency with other filtered views in openQA, jobs without a group (group_id IS NULL) are included when using only negative filters (not_group_glob), but excluded when explicit positive filters (group_glob) are applied. Benefits This enhancement gives users consistent and flexible filtering capabilities across different endpoints, allowing them to isolate or ignore specific environments (like "Development") and obtain more relevant job statistics.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7344 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 419 419
Lines 44427 44448 +21
=========================================
+ Hits 44427 44448 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| if ($group_ids && @$group_ids) { | ||
| my $placeholders = join ', ', ('?') x @$group_ids; | ||
| $group_filter | ||
| = 'AND (mrj.group_id IN (' |
There was a problem hiding this comment.
This should use IN ANY(?) and pass the IDs for this single static placeholder as array ref. At least I think this is possible with PostgreSQL. This has the great advantage of simplifying the code and then PostgreSQL always sees the same SQL code which is also more efficient. (Or two versions of the SQL code in case we still need different versions for with group IDs and for without group IDs.)
| $sth->bind_param(4, $arch); | ||
| $sth->bind_param(5, $build); | ||
| $sth->execute; | ||
| $sth->execute(@binds); |
There was a problem hiding this comment.
The binds that are always present could still be in this line, e.g.:
| $sth->execute(@binds); | |
| $sth->execute($distri, $version, $flavor, $arch, $build, @binds); |
This way we would avoid copying the variables to an array just to copy them again when making the argument list.
(And with my other suggestion @binds would probably only contain 0 or 1 elements.)
Motivation
Users need to filter out jobs in development job groups from the statistics
returned by the /api/v1/isos/job_stats endpoint, similar to what is currently
available for the /tests and /tests/overview endpoints.
Design Choices
We reused the existing
groups_for_globshelper in the Iso API controller toparse the
group_globandnot_group_globparameters. This helper providesa list of matching job groups. We extract the group IDs and pass them to the
ScheduledProducts resultset's
job_statisticsmethod. The SQL query is thendynamically constructed to filter by the target group IDs in the
most_recent_jobsblock.To ensure consistency with other filtered views in openQA, jobs without a
group (group_id IS NULL) are included when using only negative filters
(not_group_glob), but excluded when explicit positive filters (group_glob)
are applied.
Benefits
This enhancement gives users consistent and flexible filtering capabilities
across different endpoints, allowing them to isolate or ignore specific
environments (like "Development") and obtain more relevant job statistics.
This also helps me for qem-bot's handling of increment-approve, see
https://progress.opensuse.org/issues/198728