Repository navigation
feat: filter tasks by state and tags - #149
Conversation
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
Reviewer's GuideData structuresAdd the TES 1.1 states and introduce a reusable filter structure for task names, states, and tags.
APIExpose state and repeated tag filters in the task-list API and update the service contract to accept the combined filter.
Uses of the APIBind the new query parameters, preserve commas in tag arrays, construct the filter, and pass it to the service.
ImplementationTreat preempted tasks as completed for cancellation checks and read stored task tags through the converter’s existing JSON-field parser.
Filter taskmaster jobs by name and tags before listing related Kubernetes resources, then apply the requested state filter to the assembled tasks.
Return a bad-request error when tag values outnumber tag keys without exposing submitted values.
DocumentationDocument the new list filters, their matching rules, and the possibility of shorter filtered pages.
TestsVerify the list-filter behavior through the mocked Kubernetes integration path and check its published API description.
Cover extraction of tags from stored tasks, including absent, malformed, and null-valued tag data.
Check HTTP binding and validation for state and tag parameters, including repeated values and commas.
Exercise filter construction and matching semantics for names, states, and tags.
Verify service filtering order, combined filters, page tokens, and avoiding unnecessary Kubernetes lists.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
Linked issuesChecked at commit f9f84c9 #143 feat: filter tasks by state and tags · 7 of 7 met
|
There was a problem hiding this comment.
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
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
Summary
GET /tasksaccepts the TES 1.1 filtersstate,tag_keyandtag_value. Before, Spring ignored them and every task was listed.stateaccepts everytesStateof TES 1.1.TesStategetsCANCELINGandPREEMPTED(the issue asks for this here); TESK API doesn't report them yet (feat: report the CANCELING and PREEMPTED states #144). Other values give400 Bad Requestwith "Invalid value of parameter state.", without the value.tag_key/tag_valueare 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 emptyname_prefixorstatedoes. More values than keys, also empty ones, give400. Commas stay part of a key or value: an@InitBinderkeeps Spring from splitting a singleString[]value at commas.page_size, as withname_prefix.json-input), using the parser it already uses for the number of executors (readStoredTaskField)./v2/api-docs:statewith its enum, the tag arrays withcollectionFormat: multi.PREEMPTEDis added toCOMPLETED_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/api.md(endpoint table, "Listing tasks").Closes #143
Verification
./mvnw -B clean verifywith Temurin 8 (as in CI): 86 integration tests and all unit tests pass.spotless:checkandcheckstyle:checkpass.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.@InitBinderdisabled,listTasks_singleTagKeyKeepsCommasfails.mkdocs build --strictpasses.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 usesTaskFilterTest.filterTags. The task-tags helper stays local.TaskFilter.NONEis 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:
Bug Fixes:
Enhancements:
Documentation:
Tests: