Skip to content
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

Merged
merged 2 commits into from
Aug 9, 2023

Conversation

zane-neo
Copy link
Collaborator

@zane-neo zane-neo commented Aug 7, 2023

Description

Fix breaking changes caused by opensearch core change.

Issues Resolved

NA

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

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.

Signed-off-by: zane-neo <zaniu@amazon.com>
Copy link
Collaborator

@dhrubo-os dhrubo-os left a 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);
Copy link
Collaborator

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

Copy link
Member

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) {
Copy link
Collaborator

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.

Copy link
Member

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);
Copy link
Collaborator

@dhrubo-os dhrubo-os Aug 7, 2023

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();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
XContentBuilder builder = XContentFactory.jsonBuilder();
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);

Copy link
Collaborator

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);
    }

Copy link
Member

@saratvemulapalli saratvemulapalli Aug 7, 2023

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.

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link

@nknize nknize Aug 8, 2023

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.

@saratvemulapalli
Copy link
Member

I didnt realize there are multiple PRs already trying to fix the build, I was chasing a bug #1179 and ended up with compile problems.
Feel free to use changes from this PR: #1189

@zane-neo zane-neo temporarily deployed to ml-commons-cicd-env August 8, 2023 02:30 — with GitHub Actions Inactive
@zane-neo zane-neo temporarily deployed to ml-commons-cicd-env August 8, 2023 02:30 — with GitHub Actions Inactive
@zane-neo zane-neo temporarily deployed to ml-commons-cicd-env August 8, 2023 02:30 — with GitHub Actions Inactive
@zane-neo zane-neo temporarily deployed to ml-commons-cicd-env August 8, 2023 02:30 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Merging #1187 (56c63fa) into 2.x (5b4bd51) will decrease coverage by 0.03%.
Report is 2 commits behind head on 2.x.
The diff coverage is 90.00%.

@@             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     
Flag Coverage Δ
ml-commons 78.91% <90.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
.../opensearch/ml/action/handler/MLSearchHandler.java 87.23% <ø> (ø)
...n/model_group/TransportUpdateModelGroupAction.java 77.69% <ø> (ø)
.../cluster/MLCommonsClusterManagerEventListener.java 80.00% <ø> (ø)
...search/ml/helper/ConnectorAccessControlHelper.java 76.54% <ø> (ø)
...opensearch/ml/helper/ModelAccessControlHelper.java 79.81% <ø> (ø)
...a/org/opensearch/ml/model/MLModelGroupManager.java 84.48% <ø> (ø)
...main/java/org/opensearch/ml/task/MLTaskRunner.java 97.72% <ø> (ø)
...ch/ml/engine/algorithms/remote/ConnectorUtils.java 70.83% <87.50%> (+2.08%) ⬆️
...tion/connector/TransportCreateConnectorAction.java 78.12% <100.00%> (ø)
...java/org/opensearch/ml/utils/MLExceptionUtils.java 86.36% <100.00%> (ø)

... and 1 file with indirect coverage changes

@dhrubo-os
Copy link
Collaborator

I didnt realize there are multiple PRs already trying to fix the build, I was chasing a bug #1179 and ended up with compile problems.
Feel free to use changes from this PR: #1189

@saratvemulapalli this is not actually a bug. I will reply today to the issue in details today.

@dhrubo-os
Copy link
Collaborator

ava.lang.AssertionError
        at __randomizedtesting.SeedInfo.seed([5287C72090A89EF1:B9B8FAEEEA734B7B]:0)
        at org.junit.Assert.fail(Assert.java:87)
        at org.junit.Assert.assertTrue(Assert.java:42)
        at org.junit.Assert.assertTrue(Assert.java:53)
        at org.opensearch.ml.bwc.MLCommonsBackwardsCompatibilityIT.testBackwardsCompatibility(MLCommonsBackwardsCompatibilityIT.java:223)
  2> NOTE: leaving temporary files on disk at: /home/runner/work/ml-commons/ml-commons/plugin/build/testrun/mlCommonsBwcCluster#fullRestartClusterTask

@zane-neo BWC test is failing. Are we planning to fix this?

Copy link
Collaborator

@ylwu-amzn ylwu-amzn left a 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

@zane-neo zane-neo merged commit d3d4122 into opensearch-project:2.x Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants