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

Parse YAML ExpansionService configs directly using SnakeYAML #31406

Merged

Conversation

chamikaramj
Copy link
Contributor

This fixes #31405.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions github-actions bot added the java label May 25, 2024
Copy link
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@chamikaramj
Copy link
Contributor Author

assign set of reviewers

Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @kennknowles for label java.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@chamikaramj
Copy link
Contributor Author

Failures don't seem to be related.

@chamikaramj chamikaramj added this to the 2.57.0 Release milestone May 28, 2024
@chamikaramj chamikaramj requested a review from Abacn May 28, 2024 20:10
@chamikaramj
Copy link
Contributor Author

@kennknowles @Abacn friendly ping since I'd like to get this into the 2.57.0 release.

@@ -41,10 +41,8 @@ dependencies {
implementation project(path: ":sdks:java:core", configuration: "shadow")
implementation project(path: ":runners:java-fn-execution")
implementation project(path: ":sdks:java:harness")
implementation "org.yaml:snakeyaml:2.0"
Copy link
Member

Choose a reason for hiding this comment

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

put this in the BeamModulePlugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to revert, pls see the top level comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved back to the top level.

try (InputStream stream = new FileInputStream(allowListFileObj)) {
return AllowList.parseFromYamlStream(stream);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to add a message to these RuntimeException wrappers, like "when opening file to parse as ExpansionServiceConfig"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

File configFileObj = new File(configFile);
if (!configFileObj.exists()) {
throw new IllegalArgumentException("Config file " + configFile + " does not exist");
}
try {
return mapper.readValue(configFileObj, ExpansionServiceConfig.class);
try (InputStream stream = new FileInputStream(configFileObj)) {
Copy link
Member

Choose a reason for hiding this comment

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

Here too, would be nice to add a message to these RuntimeException wrappers, like "when opening file to parse as ExpansionServiceConfig"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Yaml yaml = new Yaml();
Map<Object, Object> config = yaml.load(inputStream);

if (config != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Readability: Reverse the if statement and make it if (config == null) throw IllegalArgumentException

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

public abstract String getVersion();

@SuppressWarnings("mutable")
Copy link
Member

Choose a reason for hiding this comment

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

Would making it ImmutableList be just as good as suppression?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added these since I got some random warnings when compiling but seems like this didn't fully resolve the issue. So removing these suppressions for now.

@chamikaramj chamikaramj force-pushed the expansion_service_upgrade_yaml_config branch from fa1c9b7 to 4e9f30c Compare May 31, 2024 19:39
@github-actions github-actions bot added build and removed build labels May 31, 2024
Copy link
Contributor Author

@chamikaramj chamikaramj left a comment

Choose a reason for hiding this comment

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

Thanks. PTAL.

@@ -41,10 +41,8 @@ dependencies {
implementation project(path: ":sdks:java:core", configuration: "shadow")
implementation project(path: ":runners:java-fn-execution")
implementation project(path: ":sdks:java:harness")
implementation "org.yaml:snakeyaml:2.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

try (InputStream stream = new FileInputStream(allowListFileObj)) {
return AllowList.parseFromYamlStream(stream);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

File configFileObj = new File(configFile);
if (!configFileObj.exists()) {
throw new IllegalArgumentException("Config file " + configFile + " does not exist");
}
try {
return mapper.readValue(configFileObj, ExpansionServiceConfig.class);
try (InputStream stream = new FileInputStream(configFileObj)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Yaml yaml = new Yaml();
Map<Object, Object> config = yaml.load(inputStream);

if (config != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

public abstract String getVersion();

@SuppressWarnings("mutable")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added these since I got some random warnings when compiling but seems like this didn't fully resolve the issue. So removing these suppressions for now.

@chamikaramj chamikaramj force-pushed the expansion_service_upgrade_yaml_config branch from 4e9f30c to 27c70b8 Compare May 31, 2024 20:01
@github-actions github-actions bot added build and removed build labels May 31, 2024
@chamikaramj
Copy link
Contributor Author

Seems like this results in a test failure. Looking.

@chamikaramj chamikaramj force-pushed the expansion_service_upgrade_yaml_config branch from 27c70b8 to 3f024f5 Compare May 31, 2024 21:53
@chamikaramj
Copy link
Contributor Author

chamikaramj commented May 31, 2024

Seems like simply defining SnakeYAML at top level causes "./gradlew :runners:java-fn-execution:test" to fail due to the conflict [1]. So reverted that and defining the dependency at the sub-module level now.

[1] #26743 (comment)

@kennknowles
Copy link
Member

Seems like simply defining SnakeYAML at top level causes "./gradlew :runners:java-fn-execution:test" to fail due to the conflict [1]. So reverted that and defining the dependency at the sub-module level now.

[1] #26743 (comment)

Oh I just meant defining library.java.snakeyaml = <string for dep> so it should be just an alias. That alone should be a noop for the actual deps, just a way of factoring the gradle files. Is there a conflict in that case? Do we have another module that depends on snakeyaml at a different version? Or it sounds like we just can't use snakeyaml at all because of GCP dependency on Jackson?

@chamikaramj
Copy link
Contributor Author

Yeah, there's an actual conflict tracked here: #26743

This PR was a workaround.

@chamikaramj chamikaramj force-pushed the expansion_service_upgrade_yaml_config branch from 3f024f5 to eba6ef0 Compare June 2, 2024 18:36
@github-actions github-actions bot added build and removed build labels Jun 2, 2024
@chamikaramj
Copy link
Contributor Author

This is not a release blocker anymore since #31473 was merged but I think it's still good to get this in to simplify by removing the Jackson dependency from the Expansion Service.

PTAL.

Copy link
Member

@kennknowles kennknowles left a comment

Choose a reason for hiding this comment

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

LGTM when green

@chamikaramj
Copy link
Contributor Author

Thanks.

Java pre-commit passed. Two other failures seems to be unrelated and just flake test suites.

@chamikaramj chamikaramj merged commit 4ad7037 into apache:master Jun 3, 2024
27 of 30 checks passed
@Abacn
Copy link
Contributor

Abacn commented Jun 3, 2024

Hadoop IO Direct failure is due to this change. It's passing on master branch: https://github.com/apache/beam/actions/workflows/beam_PreCommit_Java_Hadoop_IO_Direct.yml?query=event%3Aschedule

The cause is snakeyaml version change: snakeyaml 2.x is not compatible with cassandra-all used in the test

I tried to pin snakeyaml version in #31473 but here more beam component introduced snakeyaml 2.x dependency and the pinned dependency appearently got overwritten

@chamikaramj
Copy link
Contributor Author

Hmm, this is just bumping the existing dependency in core from 2.0 to 2.2. Lemme try some tests. Feel free to send a revert if needed.

@chamikaramj
Copy link
Contributor Author

Seems like #31485 fixes the issue.

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.

[Bug]: Parse YAML ExpansionService configs directly using SnakeYAML
3 participants