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

SNOW-189106 Kafka Connector to Support External OAuth #671

Merged
merged 15 commits into from
Aug 18, 2023

Conversation

sfc-gh-alhuang
Copy link
Contributor

@sfc-gh-alhuang sfc-gh-alhuang commented Jul 24, 2023

Things to do before merging this PR

According to @sfc-gh-japatel, this PR should be merge after the OAuth is support in SDK.
Update the Ingest SDK version, and modify the test should make this work. All the tests required modified are commented with TODOs.
After this PR is checked in, update local profile.json to pass the test.

Change

Support OAuth authenticator of streaming ingest with KC. For more details, please refer to the doc. Jira link: SNOW-189106

Test

OAuth authenticator for streaming ingest sdk is not released yet, tests with streaming ingest client are currently disabled until SNOW-352846 is released. Three profile.json.gpg files are updated for OAuth testing.

Copy link
Collaborator

@sfc-gh-rcheng sfc-gh-rcheng left a comment

Choose a reason for hiding this comment

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

Added some thoughts and requested some test changes. Don't have full context on this change, so lets wait for a review from toby/jay

@codecov
Copy link

codecov bot commented Jul 25, 2023

Codecov Report

Merging #671 (ac23d7d) into master (52f0a8a) will increase coverage by 0.07%.
Report is 3 commits behind head on master.
The diff coverage is 91.72%.

@@            Coverage Diff             @@
##           master     #671      +/-   ##
==========================================
+ Coverage   87.88%   87.96%   +0.07%     
==========================================
  Files          50       50              
  Lines        4144     4261     +117     
  Branches      449      468      +19     
==========================================
+ Hits         3642     3748     +106     
- Misses        332      342      +10     
- Partials      170      171       +1     
Files Changed Coverage Δ
...owflake/kafka/connector/internal/SnowflakeURL.java 96.87% <ø> (+3.12%) ⬆️
...a/connector/internal/streaming/StreamingUtils.java 88.77% <80.00%> (-1.59%) ⬇️
...main/java/com/snowflake/kafka/connector/Utils.java 91.51% <86.44%> (-1.19%) ⬇️
...wflake/kafka/connector/SnowflakeSinkConnector.java 94.49% <100.00%> (+3.67%) ⬆️
.../kafka/connector/SnowflakeSinkConnectorConfig.java 88.51% <100.00%> (+0.31%) ⬆️
...wflake/kafka/connector/internal/InternalUtils.java 93.79% <100.00%> (+1.48%) ⬆️
...or/internal/SnowflakeConnectionServiceFactory.java 96.55% <100.00%> (-0.12%) ⬇️
...lake/kafka/connector/internal/SnowflakeErrors.java 98.05% <100.00%> (+1.11%) ⬆️

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

pom.xml Outdated
@@ -156,6 +156,7 @@
<version>2.22.0</version>
<configuration>
<skipTests>${skipUnitTests}</skipTests>
<trimStackTrace>false</trimStackTrace>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be deleted afterwards.

Copy link
Collaborator

Choose a reason for hiding this comment

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

before you push this pr or in a separate PR?

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'll deleted this before pushing this PR.

try {
return e.getKey() + "=" + URLEncoder.encode(e.getValue(), "UTF-8");
} catch (UnsupportedEncodingException ex) {
throw SnowflakeErrors.ERROR_1004.getException(ex);

Choose a reason for hiding this comment

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

Not covered by code coverage.

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 think this could only happens if the encoder name is not UTF-8. Ref

return respBody.get(tokenType).toString().replaceAll("^\"|\"$", "");
}
}
} catch (Exception ignored) {

Choose a reason for hiding this comment

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

Why is this being ignored?

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 think it could be ignored and retries until the maximum retries count is reach.

Copy link
Collaborator

Choose a reason for hiding this comment

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

lets add a logger.warn here and print out message from exception.

Copy link

@sfc-gh-tjones sfc-gh-tjones left a comment

Choose a reason for hiding this comment

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

@sfc-gh-japatel @sfc-gh-rcheng can you be the primary reviewers for this? Thanks!

public static final String SF_AUTHENTICATOR = "snowflake.authenticator";
public static final String SF_OAUTH_CLIENT_ID = "snowflake.oauth.client.id";
public static final String SF_OAUTH_CLIENT_SECRET = "snowflake.oauth.client.secret";
public static final String SF_OAUTH_REFRESH_TOKEN = "snowflake.refresh.token";
Copy link
Collaborator

Choose a reason for hiding this comment

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

thinking out loud: do we need oauth here as well to be consistent? since it only applies to oauth
snowflake.oauth.refresh.token

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to add oauth here. Added oauth prefix since cliend_id might seems misleading, what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

makes sense to me

AUTHENTICATOR,
Type.STRING,
"",
Importance.LOW,
Copy link
Collaborator

Choose a reason for hiding this comment

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

any reason this is low and rest are high importance?

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 thought this is an optional parameter when we use jwt. While client_id , client_secret and refresh_token is required when using oauth. Do you think we should make all of the low?


// Exponential backoff retries
try {
Thread.sleep((1L << retries) * 1000L);
Copy link
Collaborator

Choose a reason for hiding this comment

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

where is the retry logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a retry logic that can be reused in KC?

@@ -7,6 +7,7 @@
import static com.snowflake.kafka.connector.internal.TestUtils.getConfig;
import static org.junit.Assert.assertEquals;

import com.snowflake.kafka.connector.internal.OAuthConstants;
Copy link
Collaborator

Choose a reason for hiding this comment

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

overall I am seeing great value addition for all types of tests.
I dont see End to End tests though, do you plan to add it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline. Will added in another PR.

Copy link
Collaborator

@sfc-gh-japatel sfc-gh-japatel left a comment

Choose a reason for hiding this comment

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

lgtm!
Suggested some minor changes but none of them are blocker. Looking forward to end to end tests. Thanks for adding UT, IT tests but running it real kafka connect env might have its own issues which might not unravel here.

Good stuff @sfc-gh-alhuang

Copy link
Contributor

@sfc-gh-tzhang sfc-gh-tzhang left a comment

Choose a reason for hiding this comment

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

Left some comments, PTAL! My main concern is about code duplication, please see if anything could be reused, thanks!

|| connectorConfigs.getOrDefault(Utils.PRIVATE_KEY_PASSPHRASE, "").contains("${file:"))
// If using snowflake_jwt and authentication, and private key or private key passphrase is
// provided through file, skip validation
if (connectorConfigs
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we're adding a new option, could you ask @sfc-gh-xhuang or @sfc-gh-lema to update our online doc?


// Exponential backoff retries
try {
Thread.sleep((1L << retries) * 1000L);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a retry logic that can be reused in KC?

Copy link
Contributor

@sfc-gh-tzhang sfc-gh-tzhang left a comment

Choose a reason for hiding this comment

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

LGTM, ship it!

@sfc-gh-alhuang sfc-gh-alhuang merged commit 13cd421 into master Aug 18, 2023
30 checks passed
@sfc-gh-alhuang sfc-gh-alhuang deleted the alhuang-oauth branch August 18, 2023 19:59
khsoneji pushed a commit to confluentinc/snowflake-kafka-connector that referenced this pull request Oct 12, 2023
khsoneji pushed a commit to confluentinc/snowflake-kafka-connector that referenced this pull request Oct 12, 2023
khsoneji pushed a commit to confluentinc/snowflake-kafka-connector that referenced this pull request Oct 12, 2023
khsoneji pushed a commit to confluentinc/snowflake-kafka-connector that referenced this pull request Oct 12, 2023
EduardHantig pushed a commit to streamkap-com/snowflake-kafka-connector that referenced this pull request Feb 1, 2024
@eliax1996
Copy link

The linked doc in the pr isn't accessible freely :)
don't know if its intentional but opens a form to require the permission accessing it

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.

7 participants