Skip to content

Remove serialization logic from EIS authorization response#144021

Merged
dimitris-athanasiou merged 4 commits intoelastic:mainfrom
dimitris-athanasiou:remove-wire-serialization-from-inference-auth-response
Mar 12, 2026
Merged

Remove serialization logic from EIS authorization response#144021
dimitris-athanasiou merged 4 commits intoelastic:mainfrom
dimitris-athanasiou:remove-wire-serialization-from-inference-auth-response

Conversation

@dimitris-athanasiou
Copy link
Copy Markdown
Contributor

@dimitris-athanasiou dimitris-athanasiou commented Mar 11, 2026

ElasticInferenceServiceAuthorizationResponseEntity is encapsulating the response object EIS returns when ES is polling the authorizations API. The class is serializable (both wire and XContent) because it implements InferenceServiceResults. This was done in order to reuse the existing HTTP sender.

However, instances are never written to other nodes. Nor are they serialized to XContent.

This commit removes the unnecessary serialization logic.

Finally, it takes the opportunity to convert the class into a record which allows us to further remove some code.

`ElasticInferenceServiceAuthorizationResponseEntity` is encapsulating
the response object EIS returns when ES is polling the authorizations
API. The class implements `Writeable` indirectly via `InferenceServiceResults`.
This was done so in order to reuse the existing HTTP sender.

However, instances are never written to other nodes.

This commit removes unnecessary serialization logic.
It also adds tests for the `XContent` serialization.

Finally, it takes the opportunity to convert the class into a record.
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/search-inference-team (Team:Search - Inference)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 11, 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: 30dcd4be-f5b4-4c2d-b334-fbb867920383

📥 Commits

Reviewing files that changed from the base of the PR and between 66ebf8a and 5eb3d3c.

📒 Files selected for processing (1)
  • x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/AuthorizationTaskExecutorIT.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/AuthorizationTaskExecutorIT.java

📝 Walkthrough

Walkthrough

The PR converts ElasticInferenceServiceAuthorizationResponseEntity and its nested types to Java record types that implement ToXContentObject only, removes stream-based constructors and Writeable serialization (writeTo now unsupported), and drops getAuthorizedEndpoints() in favor of the record accessor authorizedEndpoints(). Tests moved from wire-serialization harness to XContent-based tests. Call sites were updated to use responseEntity.authorizedEndpoints(), and an integration test now seeds JSON responses for semi-random endpoints instead of constructing AuthorizedEndpoint instances in-test.

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

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

Copy link
Copy Markdown
Contributor

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! I left a comment wondering if we can throw in the top level toXContent() and remove the implements ToXContent* for the nested classes.

@Nullable String displayName,
@Nullable String fingerprint
) implements Writeable, ToXContentObject {
) implements ToXContentObject {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, I don't think the object will serialized to json either 🤔 I might be missing a place though. Could you check and see if we could just throw in the toXContent() of ElasticInferenceServiceAuthorizationResponseEntity? If so we can remove all the others I think to.

Copy link
Copy Markdown
Contributor Author

@dimitris-athanasiou dimitris-athanasiou Mar 11, 2026

Choose a reason for hiding this comment

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

The reason I kept this here is to enable the testing of its parsing side.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't we already have coverage of that in ElasticInferenceServiceAuthorizationResponseEntityTests.testParseAllFields()? I'm not sure we need to be relying on going from Object -> XContent -> Object just to test that we can correctly parse json.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, I missed that. OK, fair point. I'll remove the toXContent() stuff too and rely on that test instead.

@dimitris-athanasiou dimitris-athanasiou changed the title Remove wire serialization logic from EIS authorization response Remove serialization logic from EIS authorization response Mar 12, 2026
@dimitris-athanasiou
Copy link
Copy Markdown
Contributor Author

@DonalEvans @jonathan-buttner I have now also removed the XContent serialization logic. I have updated the PR title/description to reflect that.

Copy link
Copy Markdown
Contributor

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

Looks good, could we keep the toString() methods?

}

@Override
public String toString() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just curious why we were removing the toString()s? I found them helpful for debugging and I think we log it at debug somewhere 🤔 Maybe that's changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Java records produce equivalent toString(). Only difference is it uses [] instead of {}.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TIL!

@dimitris-athanasiou dimitris-athanasiou merged commit bfbfa78 into elastic:main Mar 12, 2026
36 checks passed
@dimitris-athanasiou dimitris-athanasiou deleted the remove-wire-serialization-from-inference-auth-response branch March 12, 2026 13:50
szybia added a commit to szybia/elasticsearch that referenced this pull request Mar 12, 2026
…elocations

* upstream/main: (49 commits)
  CCS logging fixes (elastic#144070)
  Improve CPS cluster exclusion handling (elastic#143488)
  Remove snapshot condition now that node_reduce phase is in non-snapshot builds (elastic#144090)
  Drop deprecation warnings when updating a mapping in the cluster state applier (elastic#143884) (elastic#144040)
  Add ensureGreenAndNoInitializingShards helper (elastic#144044)
  Removed unnecessary applies_to blocks from deprecated query (elastic#144096)
  [CPS] Use single CrossProjectModeDecider instance (elastic#144030)
  Fix ESQL TS requests with LIMIT 0 (elastic#144031)
  ESQL: Remove `create` methods in aggs (elastic#144098)
  ES|QL: Refactor ChangeLimitOperator (elastic#144017)
  Add Paginated Hit Source Tests (elastic#142592)
  Fix test failure not preferred (elastic#144019)
  Remove serialization logic from EIS authorization response (elastic#144021)
  ESQL: CSV schema inference and parsing enhancements (elastic#144050)
  ESQL: Fix incorrectly optimized fork with nullify unmapped_fields (elastic#143030)
  Fix MMR release test using subqueries (elastic#144087)
  Refactoring `UserAgentPlugin` (elastic#140712)
  Drop non-finite samples in Prometheus remote write (elastic#144055)
  [TEST] Wait for internal inference indices to be created in authorization IT (elastic#143885)
  Disable ndjson datasource QA tests in release-tests (elastic#143992)
  ...
michalborek pushed a commit to michalborek/elasticsearch that referenced this pull request Mar 23, 2026
…44021)

`ElasticInferenceServiceAuthorizationResponseEntity` is encapsulating
the response object EIS returns when ES is polling the authorizations
API. The class implements `Writeable` indirectly via `InferenceServiceResults`.
This was done so in order to reuse the existing HTTP sender.

However, instances are never written to other nodes.

This commit removes unnecessary serialization logic.
It also adds tests for the `XContent` serialization.

Finally, it takes the opportunity to convert the class into a record.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants