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 1853185 jdbc driver v3.16 native okta http retry storm #2064

Open
wants to merge 88 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
a657244
SNOW-1853185: Base for OktaWiremockIT
sfc-gh-fpawlowski Feb 4, 2025
7cc2b33
SNOW-1853185: OktaWiremockIT with working endpoint
sfc-gh-fpawlowski Feb 5, 2025
23fd381
SNOW-1853185: OktaWiremockIT with working endpoint
sfc-gh-fpawlowski Feb 5, 2025
6ae4b1f
SNOW-1853185: OktaWiremockIT with port inclusion comments
sfc-gh-fpawlowski Feb 5, 2025
7f38b4a
Merge branch 'SNOW-1853185-jdbc-driver-v-3-16-native-okta-http-retry'…
sfc-gh-fpawlowski Feb 5, 2025
fcc5e08
Update SnowflakeDriverIT.java
sfc-gh-fpawlowski Feb 5, 2025
adf022c
Merge remote-tracking branch 'origin/SNOW-1853185-JDBC-Driver-v3.16-N…
sfc-gh-fpawlowski Feb 5, 2025
110faf0
SNOW-1853185: Reverted test commit
sfc-gh-fpawlowski Feb 5, 2025
0ab28ca
SNOW-1853185: Wiremock working test
sfc-gh-fpawlowski Feb 5, 2025
675a045
SNOW-1853185: Wiremock files structure organized
sfc-gh-fpawlowski Feb 5, 2025
f553892
SNOW-1853185: Wiremock files read from file
sfc-gh-fpawlowski Feb 5, 2025
ffabd53
SNOW-1853185: Rest request refactored
sfc-gh-fpawlowski Feb 6, 2025
4a54ab5
SNOW-1853185: Retry context manager added
sfc-gh-fpawlowski Feb 7, 2025
d393961
SNOW-1853185: Retry manager called
sfc-gh-fpawlowski Feb 9, 2025
4b60e61
Merge branch 'master' into SNOW-1853185-JDBC-Driver-v3.16-Native-Okta…
sfc-gh-fpawlowski Feb 9, 2025
c6daa3d
SNOW-1853185: Revert renaming isSocketTimeoutNoBackoff because of fai…
sfc-gh-fpawlowski Feb 9, 2025
5cb1272
SNOW-1853185: Added missing dependencies to tests
sfc-gh-fpawlowski Feb 9, 2025
c0c6389
SNOW-1853185: Javadoc fixes
sfc-gh-fpawlowski Feb 9, 2025
e9e964d
SNOW-1853185: Javadoc fixes
sfc-gh-fpawlowski Feb 9, 2025
d049d2c
SNOW-1853185: Formatting run
sfc-gh-fpawlowski Feb 9, 2025
73095ff
SNOW-1853185: Changed test to check time between calls to okta
sfc-gh-fpawlowski Feb 9, 2025
9327ce9
SNOW-1853185: Made tests check 429 is waited. Added deserialization
sfc-gh-fpawlowski Feb 10, 2025
d6dbcf5
SNOW-1853185: Code formatted
sfc-gh-fpawlowski Feb 10, 2025
0423238
SNOW-1853185: Code formatted
sfc-gh-fpawlowski Feb 10, 2025
fddcf10
SNOW-1853185: TODOs removed
sfc-gh-fpawlowski Feb 10, 2025
2bae032
SNOW-1853185: Replaced .* imports with specific
sfc-gh-fpawlowski Feb 10, 2025
d05b8c6
SNOW-1853185: Formatted
sfc-gh-fpawlowski Feb 10, 2025
1c66ff4
Merge branch 'master' into SNOW-1853185-JDBC-Driver-v3.16-Native-Okta…
sfc-gh-fpawlowski Feb 11, 2025
478a360
SNOW-1853185: Replaced custom Exception type with ThrowingCallable
sfc-gh-fpawlowski Feb 11, 2025
e3b8e2f
SNOW-1853185: Code cleanup - added docs, improved visibility and argu…
sfc-gh-fpawlowski Feb 11, 2025
780f97a
SNOW-1853185: Added javadocs and comments from PR
sfc-gh-fpawlowski Feb 11, 2025
678970f
SNOW-1853185: ThrowingFunction added and RetryManager migrated to use it
sfc-gh-fpawlowski Feb 12, 2025
0782b70
SNOW-1853185: Renamed RetryContextManager to RetryContext
sfc-gh-fpawlowski Feb 12, 2025
f4506b3
SNOW-1853185: visibility limited of retrycontext
sfc-gh-fpawlowski Feb 12, 2025
0d8df42
SNOW-1853185: Changed assertion types to hamcrest
sfc-gh-fpawlowski Feb 12, 2025
1e3c87b
SNOW-1853185: Implemented reading files using BufferedReader
sfc-gh-fpawlowski Feb 12, 2025
f3b3d19
SNOW-1853185: Test pom.xml - version moved to properties
sfc-gh-fpawlowski Feb 12, 2025
80f8ceb
SNOW-1853185: Code formatted
sfc-gh-fpawlowski Feb 12, 2025
1fa8914
SNOW-1853185: Code formatted
sfc-gh-fpawlowski Feb 12, 2025
88375a3
SNOW-1853185: Merged master
sfc-gh-fpawlowski Feb 17, 2025
0e730b2
SNOW-1853185: Unified federated auth flow methods to make them all ac…
sfc-gh-fpawlowski Feb 17, 2025
2f400b9
SNOW-1853185: Test scenarios added for better testing of retries
sfc-gh-fpawlowski Feb 18, 2025
a5da37d
SNOW-1853185: Fixed scenarios for wiremock names
sfc-gh-fpawlowski Feb 24, 2025
6d6a2bc
SNOW-1853185: Always 429 in step 4 scenario json
sfc-gh-fpawlowski Feb 24, 2025
73f6beb
SNOW-1853185: All scenarios cleaned up
sfc-gh-fpawlowski Feb 25, 2025
f034564
SNOW-1853185: Fixed mocking tests with new signature
sfc-gh-fpawlowski Feb 25, 2025
370dfa9
SNOW-1853185: removed DTOs for custom getAllSErveEvents
sfc-gh-fpawlowski Feb 25, 2025
209f0d1
SNOW-1853185: Session util cleaned up
sfc-gh-fpawlowski Feb 25, 2025
5738ebe
SNOW-1853185: Tests with wiremock added
sfc-gh-fpawlowski Feb 25, 2025
510afd2
SNOW-1853185: Renamed RetryContext back to RetryContextManager
sfc-gh-fpawlowski Feb 25, 2025
51ecb7a
SNOW-1853185: RetryContext implemented to pass information in a unifi…
sfc-gh-fpawlowski Feb 25, 2025
38fc5e8
SNOW-1853185: Code formatted
sfc-gh-fpawlowski Feb 25, 2025
c9f8628
Merge branch 'master' into SNOW-1853185-JDBC-Driver-v3.16-Native-Okta…
sfc-gh-fpawlowski Feb 25, 2025
cd935c6
SNOW-1853185: Unified wiremock scenarios storing
sfc-gh-fpawlowski Feb 26, 2025
ed90019
SNOW-1853185: Unified wiremock scenarios storing
sfc-gh-fpawlowski Feb 26, 2025
b5200c7
SNOW-1853185: Wiremock scenarios naming fixed
sfc-gh-fpawlowski Feb 26, 2025
2735c79
SNOW-1853185: Fixed poml to store correct values
sfc-gh-fpawlowski Feb 26, 2025
f8aeb21
SNOW-1853185: Pom test
sfc-gh-fpawlowski Feb 26, 2025
2a40d99
SNOW-1853185: Reverted unused pom dependencies.
sfc-gh-fpawlowski Feb 26, 2025
54b5fa4
Merge branch 'master' into SNOW-1853185-JDBC-Driver-v3.16-Native-Okta…
sfc-gh-fpawlowski Feb 26, 2025
50c4019
SNOW-1853185: Disabled tests that fail temporarily
sfc-gh-fpawlowski Feb 26, 2025
618e9b3
SNOW-1853185: Disabled tests that fail temporarily
sfc-gh-fpawlowski Feb 26, 2025
a182353
Revert "SNOW-1853185: Disabled tests that fail temporarily"
sfc-gh-fpawlowski Feb 26, 2025
c5610a4
SNOW-1853185: Disabled tests that fail temporarily
sfc-gh-fpawlowski Feb 26, 2025
e2af82d
SNOW-1853185: Disabled tests that fail temporarily
sfc-gh-fpawlowski Feb 26, 2025
a894e28
SNOW-1853185: Disabled getAllServeEvents
sfc-gh-fpawlowski Feb 26, 2025
5435cac
SNOW-1853185: Disabled getAllServeEvents
sfc-gh-fpawlowski Feb 26, 2025
465d438
SNOW-1853185: Disabled getAllServeEvents
sfc-gh-fpawlowski Feb 26, 2025
c084bfc
SNOW-1853185: Rolled back to api calls for serve events
sfc-gh-fpawlowski Feb 26, 2025
c7efcbb
SNOW-1853185: Rolled back to api calls for serve events
sfc-gh-fpawlowski Feb 26, 2025
c24cebb
Code formatted
sfc-gh-fpawlowski Feb 26, 2025
b46061a
Revert "SNOW-1853185: Pom test"
sfc-gh-fpawlowski Feb 27, 2025
90f14bd
merged master
sfc-gh-fpawlowski Feb 27, 2025
fd7ede3
Merge branch 'master' into fpawlowski/pom-xml-test-wiremock
sfc-gh-fpawlowski Feb 27, 2025
bc35ce9
SNOW-1853185: Added missing dependency
sfc-gh-fpawlowski Feb 27, 2025
1ef1bc5
SNOW-1853185: Changed httpclient dependency
sfc-gh-fpawlowski Mar 1, 2025
dc1f1fe
SNOW-1853185: charset in new version of utils
sfc-gh-fpawlowski Mar 1, 2025
e6925fb
SNOW-1853185: Added dependency for tests
sfc-gh-fpawlowski Mar 2, 2025
b0cdcd5
SNOW-1853185: Changed tag to fix tests
sfc-gh-fpawlowski Mar 2, 2025
509f1ac
SNOW-1853185: Disabled tests to check connection issues source
sfc-gh-fpawlowski Mar 2, 2025
ad6f2ab
SNOW-1853185: Disabled tests to check connection issues source
sfc-gh-fpawlowski Mar 2, 2025
0f8cfbe
SNOW-1853185: Merged test branch
sfc-gh-fpawlowski Mar 2, 2025
5f2d4c2
SNOW-1853185: Removed setting jvm properties
sfc-gh-fpawlowski Mar 2, 2025
c3dcf65
SNOW-1853185: Removed setting jvm properties and added sso/saml reque…
sfc-gh-fpawlowski Mar 3, 2025
db56fb9
SNOW-1853185: Removed setting jvm properties method
sfc-gh-fpawlowski Mar 3, 2025
99eacab
SNOW-1853185: Added error handling proper way
sfc-gh-fpawlowski Mar 3, 2025
49ce131
SNOW-1853185: Tests added for token url
sfc-gh-fpawlowski Mar 3, 2025
5a86577
SNOW-1853185: formatted
sfc-gh-fpawlowski Mar 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions TestOnly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@
<artifactId>jna-platform</artifactId>
<version>${jna.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.16</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.snowflake.client;

import net.snowflake.client.jdbc.SnowflakeSQLException;

/**
* A functional interface similar to {@code Callable<V>}, but whose {@code call()} method is
* permitted to throw a {@link SnowflakeSQLException}.
*
* @param <V> the result type of the call method
*/
@FunctionalInterface
public interface CallableThrowingSnowflakeSqlException<V> {
/**
* Computes a result, potentially throwing a {@code SnowflakeSQLException}.
*
* @return the computed result
* @throws SnowflakeSQLException if a SQL exception occurs during execution
*/
V call() throws SnowflakeSQLException;
}
100 changes: 94 additions & 6 deletions src/main/java/net/snowflake/client/core/HttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.snowflake.client.log.SFLogger;
import net.snowflake.client.log.SFLoggerFactory;
import net.snowflake.client.log.SFLoggerUtil;
import net.snowflake.client.util.RetryContextManager;
import net.snowflake.client.util.SecretDetector;
import net.snowflake.client.util.Stopwatch;
import net.snowflake.common.core.SqlState;
Expand Down Expand Up @@ -621,6 +622,24 @@ static String executeRequestWithoutCookies(
new ExecTimeTelemetryData());
}

public static String executeGeneralRequest(
Copy link
Contributor

Choose a reason for hiding this comment

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

let's mark as internal or remove public

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'm not sure if that's possible - it is still used in multiple places - e.g. in SessionUtil.java
(I gave a longer answer in the next comment to why I kept those)

HttpUtil.executeGeneralRequest(
postRequest,
loginInput.getLoginTimeout(),
loginInput.getAuthTimeout(),
loginInput.getSocketTimeoutInMillis(),
0,
loginInput.getHttpClientSettingsKey());

Copy link
Contributor

Choose a reason for hiding this comment

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

then we can mark some methods with @SnowflakeJdbcInternalApi

HttpRequestBase httpRequest,
int retryTimeout,
int authTimeout,
int socketTimeout,
int retryCount,
HttpClientSettingsKey ocspAndProxyAndGzipKey)
throws SnowflakeSQLException, IOException {
return executeGeneralRequest(
httpRequest,
retryTimeout,
authTimeout,
socketTimeout,
retryCount,
ocspAndProxyAndGzipKey,
null);
}

/**
* Executes a HTTP request for Snowflake.
*
Expand All @@ -630,6 +649,7 @@ static String executeRequestWithoutCookies(
* @param socketTimeout socket timeout (in ms)
* @param retryCount retry count for the request
* @param ocspAndProxyAndGzipKey OCSP mode and proxy settings for httpclient
* @param retryContextManager RetryContextManager passed to RestRequest
* @return response
* @throws SnowflakeSQLException if Snowflake error occurs
* @throws IOException raises if a general IO error occurs
Expand All @@ -640,7 +660,8 @@ public static String executeGeneralRequest(
int authTimeout,
int socketTimeout,
int retryCount,
HttpClientSettingsKey ocspAndProxyAndGzipKey)
HttpClientSettingsKey ocspAndProxyAndGzipKey,
RetryContextManager retryContextManager)
throws SnowflakeSQLException, IOException {
logger.debug("Executing general request");
return executeRequest(
Expand All @@ -654,7 +675,8 @@ public static String executeGeneralRequest(
false, // no retry parameter
false, // no retry on HTTP 403
ocspAndProxyAndGzipKey,
new ExecTimeTelemetryData());
new ExecTimeTelemetryData(),
retryContextManager);
}

/**
Expand Down Expand Up @@ -695,6 +717,34 @@ public static String executeGeneralRequest(
new ExecTimeTelemetryData());
}

public static String executeRequest(
HttpRequestBase httpRequest,
int retryTimeout,
int authTimeout,
int socketTimeout,
int maxRetries,
int injectSocketTimeout,
AtomicBoolean canceling,
boolean includeRetryParameters,
boolean retryOnHTTP403,
HttpClientSettingsKey ocspAndProxyKey,
ExecTimeTelemetryData execTimeData)
throws SnowflakeSQLException, IOException {
return executeRequest(
httpRequest,
retryTimeout,
authTimeout,
socketTimeout,
maxRetries,
injectSocketTimeout,
canceling,
includeRetryParameters,
retryOnHTTP403,
ocspAndProxyKey,
execTimeData,
null);
}

/**
* Executes a HTTP request for Snowflake.
*
Expand All @@ -709,6 +759,7 @@ public static String executeGeneralRequest(
* @param retryOnHTTP403 whether to retry on HTTP 403 or not
* @param ocspAndProxyKey OCSP mode and proxy settings for httpclient
* @param execTimeData query execution time telemetry data object
* @param retryContextManager RetryContextManager passed to RestRequest
* @return response
* @throws SnowflakeSQLException if Snowflake error occurs
* @throws IOException raises if a general IO error occurs
Expand All @@ -724,7 +775,8 @@ public static String executeRequest(
boolean includeRetryParameters,
boolean retryOnHTTP403,
HttpClientSettingsKey ocspAndProxyKey,
ExecTimeTelemetryData execTimeData)
ExecTimeTelemetryData execTimeData,
RetryContextManager retryContextManager)
throws SnowflakeSQLException, IOException {
boolean ocspEnabled = !(ocspAndProxyKey.getOcspMode().equals(OCSPMode.DISABLE_OCSP_CHECKS));
logger.debug("Executing request with OCSP enabled: {}", ocspEnabled);
Expand All @@ -742,7 +794,40 @@ public static String executeRequest(
true, // include request GUID
retryOnHTTP403,
getHttpClient(ocspAndProxyKey),
execTimeData);
execTimeData,
retryContextManager);
}

private static String executeRequestInternal(
HttpRequestBase httpRequest,
int retryTimeout,
int authTimeout,
int socketTimeout,
int maxRetries,
int injectSocketTimeout,
AtomicBoolean canceling,
boolean withoutCookies,
boolean includeRetryParameters,
boolean includeRequestGuid,
boolean retryOnHTTP403,
CloseableHttpClient httpClient,
ExecTimeTelemetryData execTimeData)
throws SnowflakeSQLException, IOException {
return executeRequestInternal(
httpRequest,
retryTimeout,
authTimeout,
socketTimeout,
maxRetries,
injectSocketTimeout,
canceling,
withoutCookies,
includeRetryParameters,
includeRequestGuid,
retryOnHTTP403,
httpClient,
execTimeData,
null);
}

/**
Expand All @@ -764,6 +849,7 @@ public static String executeRequest(
* @param includeRequestGuid whether to include request_guid
* @param retryOnHTTP403 whether to retry on HTTP 403
* @param httpClient client object used to communicate with other machine
* @param retryContextManager RetryContextManager passed to RestRequest
* @return response in String
* @throws SnowflakeSQLException if Snowflake error occurs
* @throws IOException raises if a general IO error occurs
Expand All @@ -781,7 +867,8 @@ private static String executeRequestInternal(
boolean includeRequestGuid,
boolean retryOnHTTP403,
CloseableHttpClient httpClient,
ExecTimeTelemetryData execTimeData)
ExecTimeTelemetryData execTimeData,
RetryContextManager retryContextManager)
throws SnowflakeSQLException, IOException {
// HttpRequest.toString() contains request URI. Scrub any credentials, if
// present, before logging
Expand Down Expand Up @@ -815,7 +902,8 @@ private static String executeRequestInternal(
includeRetryParameters,
includeRequestGuid,
retryOnHTTP403,
execTimeData);
execTimeData,
retryContextManager);
if (logger.isDebugEnabled() && stopwatch != null) {
stopwatch.stop();
}
Expand Down
Loading
Loading