-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Inference API] Propagate product use case http header to EIS #124025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
timgrein
merged 41 commits into
elastic:main
from
timgrein:read-and-propagate-product-use-case-header-to-eis
Mar 12, 2025
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
ab712dd
WIP
timgrein b617e0a
[CI] Auto commit changes from spotless
2e8231a
Iterate (propagate InferenceContext & put HTTP header into thread con…
timgrein ca79955
Iter (product use case propagation works)
timgrein 2c12778
Iter (move request metadata extraction to parent request manager class)
timgrein cc52207
[CI] Auto commit changes from spotless
a1da2f6
Add docs to InferenceContext
timgrein a6e9297
Merge remote-tracking branch 'origin/read-and-propagate-product-use-c…
timgrein 82ce713
Update InferenceContext.java
timgrein e5c5933
Remove duplicate context from InferenceAction.Request
timgrein 634aaef
Merge remote-tracking branch 'origin/read-and-propagate-product-use-c…
timgrein 0302468
Add InferenceContextTests
timgrein ef35491
Add additional test case for context in InferenceActionRequestTests
timgrein 3abe303
Add new test cases to InferenceActionRequestTests
timgrein 517c943
Add new test cases to UnifiedCompletionActionRequestTests
timgrein 0bc06df
Add test to verify that the header is set in the thread context
timgrein 7a515bc
Remove TODO
timgrein cf55cb5
Add product use case header extraction test cases to BaseInferenceAct…
timgrein 8d44488
Remove addressed TODO and spotlessApply
timgrein 139f7a5
Add product use case propagation tests in ElasticInferenceServiceTests
timgrein 280f0cf
Merge branch 'main' into read-and-propagate-product-use-case-header-t…
timgrein 0a3b0a0
Fix compilation error
timgrein cd1beee
Update docs/changelog/124025.yaml
timgrein 1c0a3c4
Replace InferenceContext.empty() with InferenceContext.EMPTY_INSTANCE
timgrein d6a7bb9
Merge remote-tracking branch 'origin/read-and-propagate-product-use-c…
timgrein 89a973a
Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/…
timgrein 2f881e0
Use .get(0) instead of getFirst to avoid compilation errors in backport.
timgrein e5153a1
Add TransportVersion for 8_X
timgrein 149a094
Add TODO to remove temporary product use case propagation
timgrein 69687d5
Add comment with rationale explaining difference in header extraction
timgrein bc1a74f
Ensure that productUseCase field in InferenceContext is non-null
timgrein 8ab08f9
Merge branch 'main' into read-and-propagate-product-use-case-header-t…
timgrein e34359c
Merge branch 'main' into read-and-propagate-product-use-case-header-t…
timgrein a7d0f27
spotlessApply
timgrein e494a39
fix checkstyle errors in xpack core plugin
timgrein 5b90efb
Fix checkstyle errors in inference plugin
timgrein 418241f
[CI] Auto commit changes from spotless
9163207
Fix test in InferenceActionRequestTests and adapt the structure to be…
timgrein 5d4b92f
Merge remote-tracking branch 'origin/read-and-propagate-product-use-c…
timgrein fa47c8c
Add equals/hashCode to InferenceContext
timgrein 0515e1a
Merge branch 'main' into read-and-propagate-product-use-case-header-t…
timgrein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 124025 | ||
| summary: "[Inference API] Propagate product use case http header to EIS" | ||
| area: Machine Learning | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...ck/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/InferenceContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.core.inference; | ||
|
|
||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.xcontent.ToXContent; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Record for storing context alongside an inference request, typically used for metadata. | ||
| * This is mainly used to pass along inference context on the transport layer without relying on | ||
| * {@link org.elasticsearch.common.util.concurrent.ThreadContext}, which depending on the internal | ||
| * {@link org.elasticsearch.client.internal.Client} throws away parts of the context, when passed along the transport layer. | ||
| * | ||
| * @param productUseCase - for now mainly used by Elastic Inference Service | ||
| */ | ||
| public record InferenceContext(String productUseCase) implements Writeable, ToXContent { | ||
|
|
||
| public static final InferenceContext EMPTY_INSTANCE = new InferenceContext(""); | ||
|
|
||
| public InferenceContext { | ||
| Objects.requireNonNull(productUseCase); | ||
| } | ||
|
|
||
| public InferenceContext(StreamInput in) throws IOException { | ||
| this(in.readString()); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeString(productUseCase); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
|
|
||
| builder.field("product_use_case", productUseCase); | ||
|
|
||
| builder.endObject(); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| InferenceContext that = (InferenceContext) o; | ||
| return Objects.equals(productUseCase, that.productUseCase); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hashCode(productUseCase); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should verify non-null so the transport layer doesn't hate us for not using
writeOptionalString:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, adjusted with Ensure that productUseCase field in InferenceContext is non-null