Skip to content

feat: filter tasks by state and tags - #149

Merged
uniqueg merged 6 commits into
devfrom
feat/143-filter-state-tags
Nov 12, 2026
Merged

uniqueg merged 6 commits into
devfrom
feat/143-filter-state-tags

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

GET /tasks accepts the TES 1.1 filters state, tag_key and tag_value. Before, Spring ignored them and every task was listed.

  • state accepts every tesState of TES 1.1. TesState gets CANCELING and PREEMPTED (the issue asks for this here); TESK API doesn't report them yet (feat: report the CANCELING and PREEMPTED states #144). Other values give 400 Bad Request with "Invalid value of parameter state.", without the value.
  • tag_key/tag_value are zipped by position and matched as in the specification's table. A repeated key is one more tag that must match (AND). Empty keys filter nothing, as an empty name_prefix or state does. More values than keys, also empty ones, give 400. Commas stay part of a key or value: an @InitBinder keeps Spring from splitting a single String[] value at commas.
  • Name and tags filter the page's taskmaster jobs before the executor and filer jobs and the pods are listed. The state is applied once they are, and only if the filter asks for it. Pages can be shorter than page_size, as with name_prefix.
  • The converter reads the tags of the stored task (json-input), using the parser it already uses for the number of executors (readStoredTaskField).
  • The parameters are in /v2/api-docs: state with its enum, the tag arrays with collectionFormat: multi.
  • PREEMPTED is added to COMPLETED_STATES (a task in it can't be cancelled). This doesn't change behaviour until feat: report the CANCELING and PREEMPTED states #144 reports the state; feat: report the CANCELING and PREEMPTED states #144 (stacked on this PR) tests it.
  • Docs: docs/api.md (endpoint table, "Listing tasks").

Closes #143

Verification

  • ./mvnw -B clean verify with Temurin 8 (as in CI): 86 integration tests and all unit tests pass. spotless:check and checkstyle:check pass.
  • New tests:
    • TaskFilterTest: the specification's tag table, repeated keys, empty parameters, too many values, null values.
    • TesServiceImplListTest: tags, state in all views, combined filters, next page token, the other lists skipped.
    • TesKubernetesConverterTest: extractTags.
    • TasksApiControllerTest: every state, invalid states not echoed, zipping, commas, 400, empty filters.
    • NoAuthIT: filters end to end with Kubernetes mocked, and the parameters in /v2/api-docs.
  • Regression check: with the @InitBinder disabled, listTasks_singleTagKeyKeepsCommas fails.
  • mkdocs build --strict passes.
  • CI: all checks pass on 45efdbc (with the Sourcery fixes), including codecov/patch; codecov/project stays pending, as on the earlier commits.

Declined review findings

  • Upgrade and release notes for the new filters (quality reviewer): the PRs merged after 1.2.0 (feat: accept the task fields of TES 1.1 #133, feat: support private executor images #141) added none either; these notes are written in the release-prep PR.

  • Shared helper for tags(...) in the tests: done for the service test, which uses TaskFilterTest.filterTags. The task-tags helper stays local.

  • TaskFilter.NONE is used only in tests and Javadoc: kept as the documented "no filter" value.

  • Sourcery: 2 threads, both answered and resolved (extra empty values now refused; state snapshot documented).

Open questions

None.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV

Summary by Sourcery

Enable TES 1.1 state and tag filtering for task listings with documented validation, pagination, and API metadata support.

New Features:

  • Add TES 1.1 task-list filtering by state and tags, including positional tag key/value matching and support for CANCELING and PREEMPTED states.

Bug Fixes:

  • Ensure task-list query parameters are validated correctly and comma-containing tag values are preserved.

Enhancements:

  • Apply combined name, tag, and state filters consistently across task views while preserving pagination behavior and avoiding unnecessary Kubernetes lookups.
  • Expose the new task-list filters in the API description and user documentation.

Documentation:

  • Document state and tag filtering semantics, validation, pagination, and supported TES states for GET /tasks.

Tests:

  • Add unit, controller, service, converter, and end-to-end coverage for state and tag filtering, validation, pagination, API metadata, and stored task tags.

uniqueg and others added 3 commits November 12, 2026 07:54
GET /tasks accepts the TES 1.1 filters state, tag_key and tag_value.
Before, Spring ignored them and listed all tasks.

- state takes every tesState of TES 1.1; TesState gets CANCELING and
  PREEMPTED so that they are accepted (TESK doesn't report them yet).
  Other values give 400 naming the parameter.
- tag_key/tag_value are zipped into tags, matched as in the
  specification's table; more values than keys give 400. Commas stay
  part of a key or value (Spring would split a single value).
- Name and tags filter the taskmaster jobs of a page before the other
  jobs are listed, the state once they are; pages can be shorter, as
  with name_prefix.
- The parameters are in the API description, the arrays with
  collectionFormat multi.

Closes #143

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Review fixes for the task filters:

- A repeated tag_key is one more tag that must match, instead of its
  last value replacing the others (an empty one widened the filter).
- Empty tag_key and empty extra tag_value parameters filter nothing,
  like an empty name_prefix or state.
- The converter reads the tags of the stored task, with the parser it
  uses for the number of executors, instead of a second ObjectMapper
  in the service.
- PREEMPTED counts as ended for cancelling; TaskFilter gets hasState.
- Tests for null tag values and for invalid states not being echoed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Round-2 review fixes: converter tests for extractTags, a null filter
value matches any value (as an empty one) instead of failing, and the
docs say that values keep their positions after an empty tag_key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add the TES 1.1 states and introduce a reusable filter structure for task names, states, and tags.

  • src/main/java/uk/ac/ebi/tsc/tesk/tes/model/TesState.java L8, L28-32
  • src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TaskFilter.java L1-126

API

Expose state and repeated tag filters in the task-list API and update the service contract to accept the combined filter.

  • src/main/java/uk/ac/ebi/tsc/tesk/tes/api/TasksApi.java L10, L116-118, L131
  • src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesService.java L51-52, L61

Uses of the API

Bind the new query parameters, preserve commas in tag arrays, construct the filter, and pass it to the service.

  • src/main/java/uk/ac/ebi/tsc/tesk/tes/api/TasksApiController.java L45-55, L96-110, L135-147 (+3 small edits)

Implementation

Treat preempted tasks as completed for cancellation checks and read stored task tags through the converter’s existing JSON-field parser.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java L114
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java L358-390, L401-407

Filter taskmaster jobs by name and tags before listing related Kubernetes resources, then apply the requested state filter to the assembled tasks.

  • src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java L267-273, L292-297, L314-320 (+2 small edits)

Return a bad-request error when tag values outnumber tag keys without exposing submitted values.

  • src/main/java/uk/ac/ebi/tsc/tesk/tes/exception/InvalidTagFilterException.java L1-17

Documentation

Document the new list filters, their matching rules, and the possibility of shorter filtered pages.

  • docs/api.md L12, L39-65

Tests

Verify the list-filter behavior through the mocked Kubernetes integration path and check its published API description.

  • src/integration-test/java/uk/ac/ebi/tsc/tesk/NoAuthIT.java L20-29, L295-402

Cover extraction of tags from stored tasks, including absent, malformed, and null-valued tag data.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverterTest.java L798-831

Check HTTP binding and validation for state and tag parameters, including repeated values and commas.

  • src/test/java/uk/ac/ebi/tsc/tesk/tes/api/TasksApiControllerTest.java L22-25, L563-568, L590-714 (+2 small edits)

Exercise filter construction and matching semantics for names, states, and tags.

  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TaskFilterTest.java L1-184

Verify service filtering order, combined filters, page tokens, and avoiding unnecessary Kubernetes lists.

  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImplListTest.java L111-127, L135-151, L209-345 (+8 small edits)

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 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.07%. Comparing base (f2f3728) to head (f9f84c9).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #149      +/-   ##
==========================================
+ Coverage   72.52%   73.07%   +0.54%     
==========================================
  Files          68       70       +2     
  Lines        2883     2941      +58     
  Branches      318      330      +12     
==========================================
+ Hits         2091     2149      +58     
  Misses        651      651              
  Partials      141      141              

☔ 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.

The patch coverage of Codecov needs both branches of the null checks
in zipTags.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
@uniqueg
uniqueg marked this pull request as ready for review November 12, 2026 08:46
@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit f9f84c9

#143 feat: filter tasks by state and tags · 7 of 7 met

# Requirement Status Notes
1 Accept every TES 1.1 state value; reject other values with 400 naming state. ✅ Met TesState includes CANCELING and PREEMPTED; the controller tests valid and invalid states.
2 Match tag_key/tag_value pairs as in the specification, requiring every key and matching an empty or missing value to any value. ✅ Met TaskFilter zips the parameters by position and matches every tag; tests cover the specification's cases, including missing keys and empty tag values.
3 Reject more tag_values than tag_keys with 400. ✅ Met zipTags checks the array lengths and throws InvalidTagFilterException; tests include extra empty values.
4 Combine filters with name_prefix, page_size, page_token and all views, with paging behavior documented for filtered pages. ✅ Met Name and tag filters apply to each taskmaster page before related jobs are listed; state filtering uses the assembled task, and the response retains Kubernetes' next-page token. Tests cover combined filters, views, and the token.
5 Include the parameters in /v2/api-docs. ✅ Met The integration test checks the state enum and the tag arrays' collectionFormat: multi.
6 Add unit and controller tests, including the specification's tag match table. ✅ Met TaskFilterTest covers the tag matching cases; controller and integration tests cover parameter handling and filtering.
7 Document both filters and short pages in docs/api.md under “Listing tasks.” ✅ Met The section describes state and tag filtering, their combination, and why filtered pages can be short.

@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 2 issues

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

## Individual Comments

### Comment 1
<location path="src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java" line_range="300-305" />
<code_context>
                 taskmasterJobs.getItems().stream()
-                        .filter(job -> hasNamePrefix(job, namePrefix))
+                        .filter(job -> filter.matchesName(taskName(job)))
+                        .filter(
+                                job ->
+                                        !filter.hasTags()
</code_context>
<issue_to_address>
**State filters use mixed job snapshots**

When a task changes state while the separate Kubernetes lists for the request are being fetched, `listTasks` derives each task's state from taskmaster, executor, filer, and pod lists fetched separately; a task transition between those reads produces a state that never existed as a whole, so the requested state filter can omit a task that matches or return one that does not.

Use a consistent snapshot for the data used to derive state, or explicitly document and test that state-filter results are best-effort during concurrent task transitions.
</issue_to_address>

### Comment 2
<location path="src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TaskFilter.java" line_range="70-71" />
<code_context>
+        List<String> keys = tagKeys == null ? Collections.emptyList() : tagKeys;
+        List<String> values = tagValues == null ? Collections.emptyList() : tagValues;
+        for (int i = keys.size(); i < values.size(); i++) {
+            if (values.get(i) != null && !values.get(i).isEmpty()) {
+                throw new InvalidTagFilterException();
+            }
+        }
</code_context>
<issue_to_address>
**Empty extra values accepted**

The issue asks for 400 whenever there are more `tag_value`s than `tag_key`s. This code exempts empty extra values, so those requests are accepted instead.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java:305, src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TaskFilter.java:71


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

As the issue asks, more tag_values than tag_keys give 400, also empty
ones. The docs say that the state filter uses the state the response
reports, read with several requests to Kubernetes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV

@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
uniqueg merged commit f974342 into dev Nov 12, 2026
25 checks passed
@uniqueg
uniqueg deleted the feat/143-filter-state-tags branch November 12, 2026 10:47
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.

feat: filter tasks by state and tags

1 participant