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

[Feature/extensions] Added dependency information to Extensions #5438

Conversation

mloufra
Copy link
Contributor

@mloufra mloufra commented Dec 2, 2022

Signed-off-by: Frank Lou mloufra@amazon.com

Description

  • Create ExtensionDependency class with two field (uniqueId and version) to get and store dependency information data
  • Add optional field List<ExtensionDependency> dependencies in DiscoveryExtension class to let Jackson ObjectMapper can automatically map the dependencies entry to List<ExtensionDependency>.
  • Update the extensions.yml to show how it looks like after get the dependency information.

Issues Resolved

Fixs opensearch-project/opensearch-sdk-java#151

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
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

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.

@mloufra mloufra requested a review from owaiskazi19 December 2, 2022 19:38
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2022

Gradle Check (Jenkins) Run Completed with:

@mloufra mloufra requested a review from dbwiddis December 5, 2022 17:06
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2022

Gradle Check (Jenkins) Run Completed with:

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

Good start. Don't forget you'll need tests.

}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
pluginInfo.writeTo(out);
((DiscoveryNode) dependencies).writeTo(out);
Copy link
Member

Choose a reason for hiding this comment

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

Dependencies is a List, you shouldn't cast it to another class. I believe you either want out.writeList(List<? extends Writeable> list) here, or you want to write an integer of the size and then write each list element. See example here

@@ -61,6 +67,7 @@ public void writeTo(StreamOutput out) throws IOException {
public DiscoveryExtension(final StreamInput in) throws IOException {
super(in);
this.pluginInfo = new PluginInfo(in);
this.dependencies = new ArrayList<ExtensionDenpendency>();
Copy link
Member

Choose a reason for hiding this comment

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

You need the counterpart here of whatever you're writing in writeTo() above. Simplest approach is probably to read the list size, declare your array list with that size, and then iterate up to that size and add to it. See example here

There's another option of in.readList() that involves using a Reader but a more simple iteration will probably work here.

import org.opensearch.common.io.stream.Writeable;

public class ExtensionDenpendency implements Writeable {
public String uniqueId;
Copy link
Member

Choose a reason for hiding this comment

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

make these private since we have getters for them.

public ExtensionDenpendency(String uniqueId, Version version){
this.uniqueId = uniqueId;
this.version = version;
List<ExtensionDenpendency> dependencies = Collections.<ExtensionDenpendency>emptyList();
Copy link
Member

Choose a reason for hiding this comment

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

No need to add a generic type for Collections.emptyList(). It is inferred from the type definition.

@@ -333,7 +333,8 @@ private void extensionsDiscovery() throws IOException {
extension.getClassName(),
new ArrayList<String>(),
Boolean.parseBoolean(extension.hasNativeController())
)
),
new ArrayList<ExtensionDenpendency>()
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be extension.getDependencies()?

@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

Gradle Check (Jenkins) Run Completed with:

@mloufra
Copy link
Contributor Author

mloufra commented Dec 6, 2022

Good start. Don't forget you'll need tests.

for the tests, do you means ExtensionsOrchestratorTest.java or I need to create a new test for ExtensionDependency.java?

@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2022

Gradle Check (Jenkins) Run Completed with:

@mloufra mloufra requested a review from dbwiddis December 7, 2022 01:30
Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

This is looking really good! A few more tests needed!

CHANGELOG.md Outdated
@@ -128,6 +128,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Enforce type safety for RegisterTransportActionsRequest([#4796](https://github.com/opensearch-project/OpenSearch/pull/4796))
- Modified local node request to return Discovery Node ([#4862](https://github.com/opensearch-project/OpenSearch/pull/4862))
- Enforce type safety for NamedWriteableRegistryParseRequest ([#4923](https://github.com/opensearch-project/OpenSearch/pull/4923))
- Update dependency information ([#5438](https://github.com/opensearch-project/OpenSearch/pull/5438))
Copy link
Member

Choose a reason for hiding this comment

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

(Preference) Probably want this change log (and PR title) to be a little bit more self-explanatory, like "Add dependency information to Extensions"

}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
pluginInfo.writeTo(out);
out.writeVInt(dependencies.size());
for (ExtensionDependency result : dependencies) {
Copy link
Member

Choose a reason for hiding this comment

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

(Preference) Let's use a loop variable name representing what we actually have here, like dependency or dep.

@@ -43,6 +43,7 @@ public static class Extension {
private String className;
private String customFolderName;
private String hasNativeController;
private List<ExtensionDependency> dependencies;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what Jackson's ObjectMapper does reading in a list from a YAML file when it doesn't exist. (If an extension has no dependencies we may want to allow them to leave dependencies: blank. It may end up null.

Since Jackson uses the no-arg constructor right below this, I'd suggest you initialize this to an empty list in that no-arg constructor block.

Copy link
Member

Choose a reason for hiding this comment

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

Rereading this again, I see this is static inner Extension class here in ExtensionSettings. I don't think this is ever used or is needed at all. It's completely redundant with the DiscoveryExtension class which is used elsewhere.

The change to add the list of dependencies is done in the DiscoveryExtension class.

I actually think this entire inner class can be deleted. @owaiskazi19 do you agree?

Copy link
Contributor Author

@mloufra mloufra Dec 8, 2022

Choose a reason for hiding this comment

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

@dbwiddis Can we use Arrays.asList(new ExtensionDependency(extension.getUniqueId(), Version.fromString(extension.getOpensearchVersion()))) to replace extension.getDepdendency in ExtensionsOrchestrator, in this way, we can delete the getDependency method in ExtensionSetting.

Copy link
Member

Choose a reason for hiding this comment

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

@dbwiddis Can we use Arrays.asList(...

It's been a while since I did YAML import from Jackson. If Jackson reads in a list as an array, then:

  • define the dependencies in this class as an array
  • in ExtensionsOrchestrator, convert the array to a list as Arrays.asList(extension.getDependencies())

return dependencies;
}

public void setDependencies(List<ExtensionDependency> dependencies) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need a setter for this list.

@@ -184,6 +185,14 @@ public void setHasNativeController(String hasNativeController) {
this.hasNativeController = hasNativeController;
}

public List<ExtensionDependency> getDependenices() {
Copy link
Member

Choose a reason for hiding this comment

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

Typo in the getter name here.

)
);
assertEquals(expectedExtensionsList.size(), extensionsOrchestrator.extensionIdMap.values().size());
assertTrue(expectedExtensionsList.containsAll(extensionsOrchestrator.extensionIdMap.values()));
assertTrue(extensionsOrchestrator.extensionIdMap.values().containsAll(expectedExtensionsList));
}

public void testExtensionDependency() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

Great job on this test method for the new Dependency class.

You also need to alter the test for the DiscoveryExtension to test the new dependencies field.

Also higher up in the class, see where the YAML file is generated using a list of strings. You should add a dependency (or two) in the list for the second item (same as the test yaml file below), so you can:

  • test that the first extension's dependency list is empty
  • test that the second dependency list has an item with the appropriate unique ID and version.

@mloufra mloufra changed the title [Feature/extensions] Update dependency information [Feature/extensions] Add dependency information to Extensions Dec 7, 2022
@mloufra mloufra marked this pull request as ready for review December 7, 2022 17:59
@mloufra mloufra requested review from a team and reta as code owners December 7, 2022 17:59
@mloufra mloufra force-pushed the update-dependency-information branch from f550c57 to ea6c97c Compare December 7, 2022 22:25
@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2022

Gradle Check (Jenkins) Run Completed with:

@codecov-commenter
Copy link

Codecov Report

Merging #5438 (ea6c97c) into feature/extensions (b49e2af) will increase coverage by 0.12%.
The diff coverage is 80.00%.

@@                   Coverage Diff                    @@
##             feature/extensions    #5438      +/-   ##
========================================================
+ Coverage                 70.97%   71.09%   +0.12%     
- Complexity                58486    58541      +55     
========================================================
  Files                      4756     4757       +1     
  Lines                    278926   278956      +30     
  Branches                  40283    40287       +4     
========================================================
+ Hits                     197964   198321     +357     
+ Misses                    64810    64516     -294     
+ Partials                  16152    16119      -33     
Impacted Files Coverage Δ
...org/opensearch/extensions/ExtensionDependency.java 68.42% <68.42%> (ø)
.../org/opensearch/extensions/DiscoveryExtension.java 94.73% <100.00%> (+4.73%) ⬆️
.../opensearch/extensions/ExtensionsOrchestrator.java 66.84% <100.00%> (+0.18%) ⬆️
.../org/opensearch/extensions/ExtensionsSettings.java 96.61% <100.00%> (+0.05%) ⬆️
...cluster/coordination/PendingClusterStateStats.java 20.00% <0.00%> (-48.00%) ⬇️
...pensearch/action/ingest/DeletePipelineRequest.java 31.25% <0.00%> (-37.50%) ⬇️
...ion/admin/cluster/node/info/PluginsAndModules.java 53.12% <0.00%> (-34.38%) ⬇️
...search/search/aggregations/pipeline/EwmaModel.java 24.44% <0.00%> (-33.34%) ⬇️
...search/aggregations/pipeline/HoltWintersModel.java 21.47% <0.00%> (-29.54%) ⬇️
...opensearch/index/reindex/BulkByScrollResponse.java 48.38% <0.00%> (-28.23%) ⬇️
... and 457 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

Gradle Check (Jenkins) Run Completed with:

)
);
assertEquals(expectedExtensionsList.size(), extensionsOrchestrator.extensionIdMap.values().size());
assertTrue(expectedExtensionsList.containsAll(extensionsOrchestrator.extensionIdMap.values()));
assertTrue(extensionsOrchestrator.extensionIdMap.values().containsAll(expectedExtensionsList));
assertEquals(expectedExtensionsList.get(expectedExtensionsList.size() - 1), dependency.get(0));
Copy link
Member

Choose a reason for hiding this comment

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

This works, but since we know we created a single-dependency list, can we just get(0) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. we do not need the get(0), because we already create dependency as a single list and it is all we need.

Copy link
Member

Choose a reason for hiding this comment

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

You are right. we do not need the get(0), because we already create dependency as a single list and it is all we need.

Correct. We could even ignore the list and actually create a expectedDependency object.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@owaiskazi19 owaiskazi19 merged commit 895c2ae into opensearch-project:feature/extensions Dec 13, 2022
@mloufra mloufra deleted the update-dependency-information branch December 13, 2022 19:07
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.

5 participants