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

Iceberg sink uses Parameters::get to ensure parameter definition exists #171

Merged
merged 5 commits into from
Apr 16, 2022

Conversation

liuml07
Copy link
Contributor

@liuml07 liuml07 commented Apr 13, 2022

Context

#170 (comment)

It looks like we should be using Parameters::get without the default value in this case. That would surface the runtime exception and hence the problem in this case.

Checklist

  • ./gradlew build compiles code correctly
  • Added new tests where applicable
  • ./gradlew test passes all tests
  • Extended README or added javadocs where applicable
  • Added copyright headers for new files from CONTRIBUTING.md

Copy link
Contributor

@codyrioux codyrioux left a comment

Choose a reason for hiding this comment

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

Left a comment on the get method. I don't think it actually requires any action but worth a discussion. Otherwise LGTM!

public Object get(String key, Object defaultValue) {
Object value = defaultValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do the semantics actually change with this? My initial read of the code says no, but if it does it may unintentionally impact other jobs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, all branches will assign value so it's redundant to have an initial value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it's cosmetic and I can revert that. Or better I can rewrite the whole function to use multiple returns.

        try {
            final Object value = get(key);
            return value != null ? value : defaultValue;
        } catch (ParameterException ex) {
            return defaultValue;
        }

* Get parameter value given key without validation.
*
* If the key is not defined or missing a provided value, the given default value will be returned.
*/
public Object get(String key, Object defaultValue) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if you have a default value of null for the parameter and pass in a non-default value here as part of defaultValue? What should be the expected behavior? Can we also write tests for this to ensure the behavior remains consistent as we advance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question, but I really do not have the answer. The expected behavior depends on how it's now being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to this code snippet: https://github.com/Netflix/mantis/blob/master/mantis-runtime/src/main/java/io/mantisrx/runtime/parameter/ParameterUtils.java#L309-L315

It seems "default value of null for the parameter" means the parameter does not have a default value, i.e. missing in the definition. In that case, this get() method is doing the right thing: return the provided defaultValue. We can add a test for this.

@liuml07
Copy link
Contributor Author

liuml07 commented Apr 13, 2022

Actually some existing tests fail due to the test parameter "state" is not complete - not including all parameter definitions. So we will need to update the test code a bit. I'll make this ready for review after I fix that failing test in a non-intrusive way.

@github-actions
Copy link

github-actions bot commented Apr 13, 2022

Unit Test Results

109 files  +1  109 suites  +1   5m 34s ⏱️ +2s
477 tests +2  458 ✔️ +2  19 💤 ±0  0 ±0 

Results for commit d1d0c25. ± Comparison against base commit e6778e8.

♻️ This comment has been updated with latest results.

@liuml07 liuml07 marked this pull request as ready for review April 13, 2022 21:53
@liuml07
Copy link
Contributor Author

liuml07 commented Apr 13, 2022

failing test seems unrelated.

@sundargates sundargates mentioned this pull request Apr 13, 2022
5 tasks
@liuml07 liuml07 changed the title Iceberg sink to use Parameters::get to ensure parameter definition exists Iceberg sink uses Parameters::get to ensure parameter definition exists Apr 15, 2022
@liuml07
Copy link
Contributor Author

liuml07 commented Apr 15, 2022

All green. I'll merge by EoD. CC: @sundargates

@@ -25,6 +25,7 @@ dependencies {
api project(':mantis-common')
api libraries.slf4jApi
testImplementation libraries.junit4
testImplementation libraries.junitJupiter
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't junit-jupiter meant for usage with junit5?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It works just fine if we only use the utility assertion methods from Jupiter. But I agree, it's better not to mix JUnit 4 and Jupiter. I have written the assertThrows in the testing code instead of pulling junitJupiter. I'll file a follow-up PR to upgrade JUnit 4 to Jupiter inmantis-runtime module.

@liuml07 liuml07 force-pushed the liuml07/iceberg-sink-ensures-parameters-defined branch from 44f04e4 to d1d0c25 Compare April 16, 2022 00:35
@liuml07
Copy link
Contributor Author

liuml07 commented Apr 16, 2022

testJobComplete (io.mantisrx.master.jobcluster.JobClusterTest) failed but it seems unrelated. Let me merge from master and see if it's still failing.

@liuml07 liuml07 merged commit f6938d2 into master Apr 16, 2022
@liuml07 liuml07 deleted the liuml07/iceberg-sink-ensures-parameters-defined branch April 16, 2022 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants