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

CCDB-4354: preflight cross-fields validation for configuration PK_MODE #1157

Merged
merged 9 commits into from Jan 26, 2022

Conversation

fzhong-connect
Copy link
Member

Problem

Misconfigured pk.mode and delete.enabled combination should not be surfaced by throwing an exception when the connector or task starts. Instead, the connector should notify the user that it is configured incorrectly via the Connector::validate method.

Solution

Do cross-fields configuration validation in Connector::validate method, utilizing existing logic from PrimaryKeyModeRecommender.

Ref:

  1. How to Write a Connector for Kafka Connect
  2. kafka-connect-elasticsearch
  3. Connect Configuration Validation
Does this solution apply anywhere else?
  • yes
  • no
If yes, where?

Test Strategy

Testing done:
  • Unit tests
  • Integration tests
  • System tests
  • Manual tests

Release Plan

@fzhong-connect fzhong-connect requested a review from a team January 19, 2022 17:10
Copy link
Contributor

@C0urante C0urante left a comment

Choose a reason for hiding this comment

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

Thanks @fzhong-connect. I've left a few comments; anything beginning with "nit: " can be implemented or ignored at your discretion. The only significant one has to do with providing clear error messages to users; let me know what you think.

Also, what's the reasoning for targeting 10.2.x with this change? Based on https://docs.confluent.io/platform/current/installation/versions-interoperability.html#cp-and-apache-ak-compatibility, we're still providing support as far back as 5.2.x; if it's not too difficult with merge conflicts and the like, could we consider targeting that branch instead?

.findFirst()
.orElse(Collections.emptyList());

assertTrue(pkModeError.isEmpty());
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I prefer to do a comparison for tests like this since it gives a more informative message if the assertion fails:

Suggested change
assertTrue(pkModeError.isEmpty());
assertEquals(Optional.empty(), pkModeError);

.findFirst()
.orElse(Collections.emptyList());

assertTrue(pkModeError.isEmpty());
Copy link
Contributor

Choose a reason for hiding this comment

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

(Same nit RE: comparison for assertion)

Suggested change
assertTrue(pkModeError.isEmpty());
assertEquals(Optional.empty(), pkModeError);

@fzhong-connect
Copy link
Member Author

Thanks @fzhong-connect. I've left a few comments; anything beginning with "nit: " can be implemented or ignored at your discretion. The only significant one has to do with providing clear error messages to users; let me know what you think.

Also, what's the reasoning for targeting 10.2.x with this change? Based on https://docs.confluent.io/platform/current/installation/versions-interoperability.html#cp-and-apache-ak-compatibility, we're still providing support as far back as 5.2.x; if it's not too difficult with merge conflicts and the like, could we consider targeting that branch instead?

Thank you for taking time @C0urante .

The reason it's targeting 10.2.x is Nathan believes it mostly benefits user of the fully-managed connector on CCloud, he asked to start from the latest version on CC.

Comment on lines 82 to 85
if (!pkMode.recommendedValues().contains(pkMode.value())) {
pkMode.addErrorMessage("'" + pkMode.value() + "' is invalid:"
+ " Deletes are only supported for pk.mode 'record_key'");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this susceptible to false positives if the user gives a value for the pk.mode property that is invalid not because of conflict with delete.enabled but just because it doesn't correspond to a recognized primary key mode? For example, something like pk.mode = not_a_real_mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

that is great catch! thank you.

Copy link
Contributor

@C0urante C0urante 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 Frank!

@fzhong-connect fzhong-connect merged commit 63b0e97 into 10.2.x Jan 26, 2022
@fzhong-connect fzhong-connect deleted the ccdb-4354-preflight-validate branch January 26, 2022 18:34
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.

None yet

2 participants