Skip to content

perf: list only the page's filer jobs - #196

Merged
uniqueg merged 8 commits into
devfrom
perf/177-filer-job-selector
Nov 16, 2026
Merged

uniqueg merged 8 commits into
devfrom
perf/177-filer-job-selector

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

GET /tasks read all filer jobs in the namespace (!job-type) on every request that matched at least one task. Since #160, each finished outputs filer's job can carry up to about 200 KB of output file logs. Now it reads only the filer jobs of the page's matching tasks.

  • KubernetesClientWrapper.listFilerJobsOfTasks(taskIds) selects !job-type,taskmaster-name in (<ids>), in batches of 100 tasks per request (about 1.4 KB of selector). Taskmasters of tesk-core 0.12.0 and later put the label on their filer jobs (tesk-core#147).
  • Fallback for older taskmasters, whose filer jobs have no label: listUnlabelledFilerJobs() selects !job-type,!taskmaster-name. TesServiceImpl calls it only if a page task has no labelled filer job and may have filer jobs. A task may have filer jobs if its stored task has inputs, outputs or volumes, or can't be read (TesKubernetesConverter.mayHaveFilerJobs). Before tesk-core 0.11.0, the taskmaster ran the outputs filer for any of the three. A taskmaster labels all its filer jobs or none, so one labelled job (e.g. the inputs filer's) rules out the fallback. Unlabelled jobs come from taskmasters before 0.12.0, which don't store output file logs, so they are small, and there are none once old tasks are deleted.
  • listAllFilerJobs is removed. The trace advisor covers the two new list* methods.
  • Docs:
    • docs/api.md ("Output file logs") explains what GET /tasks reads and when the fallback runs.
    • docs/index.md ("Getting tasks") has a short note.
  • Release and upgrade notes: not in this PR. 2.0.0 is prepared and tagged without this change, and the repo has no place for unreleased changes (as with fix: honour forwarded headers outside Kubernetes #193). The next release's notes and upgrade notes need an entry. Suggested points: GET /tasks reads only the page's filer jobs by label, with a fallback to the unlabelled filer jobs of taskmasters before tesk-core 0.12.0. It needs no new permissions (it still lists jobs), and old tasks keep their states. Listing gets cheaper once the taskmaster is of tesk-core 0.12.0 or later and the tasks of older taskmasters are deleted. (perf: list only the page's outputs filer jobs #177, perf: list only the page's filer jobs #196)

Closes #177

Verification

  • TDD: the new tests in KubernetesClientWrapperTest and TesServiceImplListTest were written first and failed (compilation) before the change. The tests for the review fixes (TesKubernetesConverterTest.mayHaveFilerJobs and the fallback cases in TesServiceImplListTest) were written along with the fixes.
  • New WireMock integration test ListTaskFilerJobsIT. It uses failOnUnmatchedRequests and the exact selectors, and covers two cases: labelled and unlabelled filer jobs mixed on one page, and no fallback request when every task has a labelled filer job. The shared list stubs in MockUtil and NoAuthIT now match both filer selectors.
  • Local runs on JDK 21 (Temurin):
    • ./mvnw clean verify checkstyle:check: BUILD SUCCESS, with 18572 unit tests and 124 integration tests, all JaCoCo coverage checks met, and 0 Checkstyle violations.
    • spotless:check crashes on JDK 21. Instead, I formatted the changed files with google-java-format 1.7 --aosp on Java 8, the version spotless uses; --dry-run reports nothing. The CI job "Lint" checks this.
    • mkdocs build --strict: passed.
  • 385cb48 only removes the 2.0.0 release-note bullet and the "To 2.0.0" upgrade item again (docs only, light lane).
  • CI on 385cb48: all checks passed (Lint, Test, Docs, Smoke test, Scan image, CodeQL, Codecov patch/project, Sourcery), CI passed green.

Sourcery: one thread (the batch test derived its expectations from the constant). Fixed in ffbcaac with a fixed 101-task fixture, and resolved. A second thread said the selector also returns inputs filer jobs. Declined, because no label tells the inputs filer from the outputs filer. The inputs filer jobs are small, and a labelled one is what lets a task skip the fallback.

Review

Two rounds of adversarial and quality reviewer subagents.

  • Round 1: the fallback fired for tasks that never have filer jobs. It was then limited to tasks with outputs.
  • Round 2: limiting it to tasks with outputs was wrong for taskmasters before tesk-core 0.11.0, which ran the outputs filer for tasks with inputs or volumes too. The condition is now inputs, outputs or volumes, and the stored task is parsed once.
  • Also fixed:
    • Filer jobs without labels no longer cause an NPE.
    • The needless distinct() is gone.
    • The batch-size constant and its Javadoc are corrected.
    • The docs describe the fallback accurately.

Declined review findings

  • Batches go out one after another, so page_size=2048 makes 21 filer requests. Kept: each request is small, and the default of 256 makes 3. The docs name the batch size.
  • Shared helpers for failed filer jobs in the unit test and the IT: kept separate, as other ITs keep their own job builders too.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Limit task listing to page-relevant filer jobs while preserving compatibility with older taskmasters.

Bug Fixes:

  • Reduce the cost of GET /tasks by avoiding namespace-wide filer-job reads for normal task listing.

Enhancements:

  • Select labelled filer jobs only for tasks on the requested page, batching task IDs to keep selectors manageable.
  • Add a conditional fallback for unlabelled filer jobs from older taskmasters so task states remain accurate during migration.
  • Determine when a task may have filer jobs and retain tracing support for the new listing operations.

Documentation:

  • Document page-scoped filer-job discovery, batching, and the fallback for older taskmasters.

Tests:

  • Add unit and WireMock integration coverage for labelled selection, batching, fallback behavior, and avoiding unnecessary fallback requests.

uniqueg and others added 4 commits November 16, 2026 06:28
GET /tasks selected all filer jobs in the namespace (!job-type), and
each finished outputs filer's job can carry up to about 200 KB of
output file logs. Select the filer jobs of the page's matching tasks by
their label taskmaster-name (tesk-core#147, tesk-core 0.12.0), in
batches of 100 tasks per request. Filer jobs of older taskmasters have
no label: if a matching task has no labelled filer job, also list the
unlabelled filer jobs (!job-type,!taskmaster-name), so that tasks
started before the taskmaster upgrade keep their state.

Closes #177

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The unlabelled filer jobs were listed whenever a page's task had no
labelled filer job, also for tasks that never get an outputs filer
(no outputs). Only the outputs filer counts for a task, so fall back
only for tasks whose stored task has outputs or can't be read. Treat
filer jobs without labels as unlabelled instead of failing, drop the
needless distinct(), and document when the fallback runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Taskmasters before tesk-core 0.11.0 ran the outputs filer for tasks
with inputs, outputs or volumes, not only for tasks with outputs. Skip
the fallback to unlabelled filer jobs only for tasks whose stored task
has none of them, so that such old tasks keep their state in lists.
Parse the stored task once for the check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg self-assigned this Nov 16, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Select filer jobs for the page's task IDs in bounded batches, and orchestrate the labelled-job lookup with the conditional legacy fallback.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapper.java L19, L42-48, L362-398
  • src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java L340-374 (+4 small edits)

Determine conservatively whether an older task may have filer jobs, while parsing its stored task once for both this check and field reads.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java L479-497, L504-514, L525-528

Documentation

Explain the page-scoped filer lookup, its legacy fallback conditions, and why the fallback becomes empty after old tasks are deleted.

  • docs/api.md L303-321
  • docs/index.md L92-97

Tests

Verify labelled selection, batching, empty input, and selection of unlabelled legacy filer jobs in the Kubernetes client wrapper.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapperTest.java L23-27, L467-528

Cover the task-level fallback decision, including old task shapes, unreadable stored tasks, and filer jobs without labels.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverterTest.java L1063-1089
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImplListTest.java L17-20, L353-493 (+5 small edits)

Exercise task listing against a strict WireMock Kubernetes API and update shared stubs to accept the new filer selectors.

  • src/integration-test/java/uk/ac/ebi/tsc/tesk/ListTaskFilerJobsIT.java L1-185
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/MockUtil.java L128-131
  • src/integration-test/java/uk/ac/ebi/tsc/tesk/NoAuthIT.java L373-374

Update trace-advisor expectations for the two filer-listing methods.

  • src/test/java/uk/ac/ebi/tsc/tesk/config/TraceInterceptorConfigurationTest.java L49-50

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6aefa40) to head (b48b632).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #196   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           54        54           
  Lines         2314      2351   +37     
  Branches       272       275    +3     
=========================================
+ Hits          2314      2351   +37     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 16, 2026 05:58
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit b48b632

#177 perf: list only the page's outputs filer jobs · 2 of 3 met

# Requirement Status Notes
1 Select only the matching tasks' outputs filer jobs, batching long selectors. 🟡 Partly met The selector batches task IDs and limits results to filer jobs belonging to those tasks, but it also selects their inputs filer jobs.
2 Keep a fallback listing for filer jobs without the label from older taskmasters. ✅ Met The service lists unlabelled filer jobs when a matching task may have filers but has no labelled filer job.
3 Document the listing cost in docs/api.md. ✅ Met The Output file logs section explains the added job size and the label-based listing and fallback.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/test/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapperTest.java" line_range="491" />
<code_context>
+    @Test
+    public void listFilerJobsOfTasks_inBatches() throws ApiException {
+        List<String> taskIds =
+                IntStream.range(0, KubernetesClientWrapper.FILER_SELECTOR_BATCH_SIZE + 1)
+                        .mapToObj(i -> "task-" + i)
+                        .collect(Collectors.toList());
</code_context>
<issue_to_address>
**Batch limit can grow unnoticed**

When the batch-size constant is changed to an incorrect larger value, `listFilerJobsOfTasks_inBatches` builds both its input and expected selectors from `FILER_SELECTOR_BATCH_SIZE` (lines 491 and 509–514), so changing that constant to 500 still passes while requests contain 500 task IDs instead of the documented 100.

Assert that `FILER_SELECTOR_BATCH_SIZE` is 100, or use a fixed 101-task fixture and assert the 100-plus-1 split.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/test/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapperTest.java:491


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New gaps against the linked issues

sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Nov 16, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

uniqueg and others added 2 commits November 16, 2026 07:06
2.0.0's release prep is merged and tagged without this change, which
ships in a later release. Remove its bullet from the 2.0.0 release
notes and its item from "To 2.0.0" in the upgrade notes; the next
release's notes need the entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New gaps against the linked issues

@sourcery-ai
sourcery-ai Bot dismissed their stale review November 16, 2026 06:13

Sourcery withdrew this approval because the latest commits introduced blocking findings.

@uniqueg
uniqueg merged commit 16c3e90 into dev Nov 16, 2026
25 checks passed
@uniqueg
uniqueg deleted the perf/177-filer-job-selector branch November 16, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: list only the page's outputs filer jobs

1 participant