Skip to content

Preserve multi-value request params through PathTrie iteration#145223

Merged
felixbarny merged 4 commits intoelastic:mainfrom
felixbarny:retain-multi-value-request-params
Apr 1, 2026
Merged

Preserve multi-value request params through PathTrie iteration#145223
felixbarny merged 4 commits intoelastic:mainfrom
felixbarny:retain-multi-value-request-params

Conversation

@felixbarny
Copy link
Copy Markdown
Member

@felixbarny felixbarny commented Mar 30, 2026

RestController#getAllHandlers was using Map.copyOf(requestParamsRef) to snapshot the original params before PathTrie iterations. Map.copyOf only sees the last value per key (via entrySet), silently dropping earlier values for repeated parameters like ?format=json&format=yaml.

  • Change getAllHandlers to accept RequestParams instead of Map<String, String>
  • Add RequestParams.copyOf(RequestParams) to deep-copy all multi-values
  • Add RequestParams.putAll(RequestParams) overload that copies every value in each key's list, unlike the inherited putAll(Map) which only sees the last value per key via entrySet
  • Add tests for copyOf, putAll(RequestParams), and a regression test in RestControllerTests

Follow-up from #144506

RestController#getAllHandlers was using Map.copyOf(requestParamsRef) to
snapshot the original params before PathTrie iterations. Map.copyOf only
sees the last value per key (via entrySet), silently dropping earlier
values for repeated parameters like ?format=json&format=yaml.

- Add RequestParams.copyOf(RequestParams) to deep-copy all multi-values
- Add RequestParams.putAll(RequestParams) overload that copies every
  value in each key's list, unlike the inherited putAll(Map) which only
  sees the last value per key via entrySet
- Change getAllHandlers to accept RequestParams instead of Map<String,String>
  and use the new methods
- Add tests for copyOf, putAll(RequestParams), and a regression test in
  RestControllerTests
@elasticsearchmachine elasticsearchmachine added external-contributor Pull request authored by a developer outside the Elasticsearch team needs:triage Requires assignment of a team area label v9.4.0 labels Mar 30, 2026
@felixbarny felixbarny requested a review from DaveCTurner March 30, 2026 16:53
@felixbarny felixbarny added >non-issue :Distributed/Network Http and internode communication implementations :Core/Infra/REST API REST infrastructure and utilities labels Mar 30, 2026
@elasticsearchmachine elasticsearchmachine added Team:Core/Infra Meta label for core/infra team Team:Distributed Meta label for distributed team. labels Mar 30, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Mar 30, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: a6b48841-97bb-4ba1-98d0-f95ca8cf587b

📥 Commits

Reviewing files that changed from the base of the PR and between 8d185e6 and 9712686.

📒 Files selected for processing (1)
  • server/src/main/java/org/elasticsearch/rest/RequestParams.java

📝 Walkthrough

Walkthrough

Two new utility methods were added to RequestParams: copyOf(RequestParams) to create an independent deep copy preserving multi-value entries, and putAll(RequestParams) to merge value lists from another instance. RestController.getAllHandlers was updated to use these methods when snapshotting and restoring request parameters during path iteration. Unit tests were added verifying copy independence, multi-value preservation, and correct merging behavior.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


Comment @coderabbitai help to get the list of available commands and usage tips.

felixbarny added a commit to felixbarny/elasticsearch that referenced this pull request Mar 31, 2026
Re-parses the raw URI via RequestParams.fromUri to capture all repeated
match[] values, working around the current limitation where request
processing keeps only the last value for repeated parameters (tracked in
elastic#145223).

Also calls repeatedParamAsList to mark the parameter as consumed so
Elasticsearch does not reject the request as having unrecognized params.

Adds IT test cases for all three endpoints (labels, label values, series)
that send two match[] selectors and verify only the matched series
contribute to the response.
felixbarny added a commit that referenced this pull request Mar 31, 2026
…45298)

Re-parses the raw URI via RequestParams.fromUri to capture all repeated
match[] values, working around the current limitation where request
processing keeps only the last value for repeated parameters (tracked in
#145223).

Also calls repeatedParamAsList to mark the parameter as consumed so
Elasticsearch does not reject the request as having unrecognized params.

Adds IT test cases for all three endpoints (labels, label values, series)
that send two match[] selectors and verify only the matched series
contribute to the response.
… params

Now that RestRequest preserves multi-value request parameters, remove
the workaround that re-parsed match[] from the raw URI via
RequestParams.fromUri().
ncordon pushed a commit to ncordon/elasticsearch that referenced this pull request Apr 1, 2026
…astic#145298)

Re-parses the raw URI via RequestParams.fromUri to capture all repeated
match[] values, working around the current limitation where request
processing keeps only the last value for repeated parameters (tracked in
elastic#145223).

Also calls repeatedParamAsList to mark the parameter as consumed so
Elasticsearch does not reject the request as having unrecognized params.

Adds IT test cases for all three endpoints (labels, label values, series)
that send two match[] selectors and verify only the matched series
contribute to the response.
Copy link
Copy Markdown
Member

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM

@felixbarny felixbarny merged commit 00ff9b1 into elastic:main Apr 1, 2026
35 checks passed
@felixbarny felixbarny deleted the retain-multi-value-request-params branch April 1, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/REST API REST infrastructure and utilities :Distributed/Network Http and internode communication implementations external-contributor Pull request authored by a developer outside the Elasticsearch team >non-issue Team:Core/Infra Meta label for core/infra team Team:Distributed Meta label for distributed team. v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants