-
Notifications
You must be signed in to change notification settings - Fork 138
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
Fix breaking change caused by opensearch core #1187
Conversation
Signed-off-by: zane-neo <zaniu@amazon.com>
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.
spotless is failing.
@@ -93,7 +93,7 @@ static Connector fromStream(StreamInput in) throws IOException { | |||
} | |||
|
|||
static Connector createConnector(XContentBuilder builder, String connectorProtocol) throws IOException { | |||
String jsonStr = Strings.toString(builder); | |||
String jsonStr = StringUtils.xContentBuilderToString(builder); |
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.
Can't we do : builder.toString()
. Core also did the same: opensearch-project/OpenSearch@d090a7f
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.
Yup thats the right way to do it.
The static method was refactored and moved to XContentBuilder
@@ -82,4 +84,8 @@ public static Map<String, String> getParameterMap(Map<String, ?> parameterObjs) | |||
} | |||
return parameters; | |||
} | |||
|
|||
public static String xContentBuilderToString(XContentBuilder builder) { |
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.
I believe we don't need this method.
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.
XContentBuilder already supports toString
.
if (wrapWithObject) { | ||
builder.startObject(); | ||
} | ||
obj.toXContent(builder, ToXContent.EMPTY_PARAMS); | ||
if (wrapWithObject) { | ||
builder.endObject(); | ||
} | ||
String jsonStr = Strings.toString(builder); | ||
String jsonStr = StringUtils.xContentBuilderToString(builder); |
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.
same: builder.toString()
and all other places as well.
@@ -26,15 +26,15 @@ public static <T> void testParse(ToXContentObject obj, Function<XContentParser, | |||
} | |||
|
|||
public static <T> void testParse(ToXContentObject obj, Function<XContentParser, T> function, boolean wrapWithObject) throws IOException { | |||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); | |||
XContentBuilder builder = XContentFactory.jsonBuilder(); |
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.
XContentBuilder builder = XContentFactory.jsonBuilder(); | |
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON); |
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.
Just curious to know why we should prefer MediaTypeRegistry.contentBuilder(XContentType.JSON);
over XContentFactory.jsonBuilder();
? as both are doing the same.
public static XContentBuilder jsonBuilder() throws IOException {
return MediaTypeRegistry.contentBuilder(XContentType.JSON);
}
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.
In this case it doesnt matter since we are using XContentType.JSON
anyway. But incase we'd like to use a different MediaType
(down the line in future) the plugin is abstracted out about the format OpenSearch engine uses. So I would prefer MediaType
where ever possible.
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.
With this change: opensearch-project/OpenSearch#9156 it would make XContentType.JSON
generic.
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.
I prefer to use the previous one because this is more like a syntactic sugar, and in ml-commons we support only json format for now, we can use MediaTypeRegistry
in the future if we need to support different media type.
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.
I prefer to use the previous one because this is more like a syntactic sugar,
I think this is fine for now. I was leaning toward eliminating XContentFactory
altogether so as to not tempt a developer to use it in opensearch-core
(and create the circular library dependency problem) but we already enforce no circular dependencies with the opensearch-core
library. What we don't enforce are circular dependencies between other libraries.
The intent is for opensearch-core
to be the "center of gravity". For example, downstream plugin/extensions takes a required dependency on core and optional dependencies on the other libraries (e.g., x-content, geo, telementry, aggregations, mappers, replication, storage). This keeps the downstream opensearch dependencies lean. Why do we care? Because if someone wants to run an OpenSearch as a function (e.g., lambda, or cloud function) package size limits affect bootstrap times, class loading, and overall customer cost. Developers can afford to be more memory wreckless if the project only runs on self hosted, but load times and package sizes matter in cloud native deployments. This is why I'm so adamant on breaking down the monolith and not building a bloated comprehensive opensearch-sdk
.
Signed-off-by: zane-neo <zaniu@amazon.com>
Codecov Report
@@ Coverage Diff @@
## 2.x #1187 +/- ##
============================================
- Coverage 78.94% 78.91% -0.03%
- Complexity 2118 2121 +3
============================================
Files 167 167
Lines 8633 8641 +8
Branches 869 870 +1
============================================
+ Hits 6815 6819 +4
- Misses 1425 1428 +3
- Partials 393 394 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@saratvemulapalli this is not actually a bug. I will reply today to the issue in details today. |
@zane-neo BWC test is failing. Are we planning to fix this? |
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.
LGTM. Thanks for fixing that breaking change. For BWC failure, that seems a different issue, can fix in a separate PR
Description
Fix breaking changes caused by opensearch core change.
Issues Resolved
NA
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.