From 292f848a3f71d55e9b2ea84017b097526ad5e30a Mon Sep 17 00:00:00 2001 From: Joyce Ling <115662568+sfc-gh-ext-simba-jl@users.noreply.github.com> Date: Wed, 11 Oct 2023 18:37:42 -0700 Subject: [PATCH 1/3] add createSessionlessTelemetry(CloseableHttpClient, String) method --- .../jdbc/telemetry/TelemetryClient.java | 14 ++++++++++ .../client/jdbc/telemetry/TelemetryIT.java | 28 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java b/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java index 5201175c4..6cef2a94f 100644 --- a/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java +++ b/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java @@ -191,6 +191,20 @@ public static Telemetry createTelemetry(SFSession session, int flushSize) { * @param serverUrl server url * @return a telemetry connector */ + public static Telemetry createSessionlessTelemetry( + CloseableHttpClient httpClient, String serverUrl) { + // By default, use KEYPAIR_JWT as the auth type + return createSessionlessTelemetry(httpClient, serverUrl, "KEYPAIR_JWT", DEFAULT_FORCE_FLUSH_SIZE); + } + + /** + * Initialize the sessionless telemetry connector + * + * @param httpClient client object used to communicate with other machine + * @param serverUrl server url + * @param authType authorization type for sessionless telemetry + * @return a telemetry connector + */ public static Telemetry createSessionlessTelemetry( CloseableHttpClient httpClient, String serverUrl, String authType) { return createSessionlessTelemetry(httpClient, serverUrl, authType, DEFAULT_FORCE_FLUSH_SIZE); diff --git a/src/test/java/net/snowflake/client/jdbc/telemetry/TelemetryIT.java b/src/test/java/net/snowflake/client/jdbc/telemetry/TelemetryIT.java index 63fce6782..d859932ae 100644 --- a/src/test/java/net/snowflake/client/jdbc/telemetry/TelemetryIT.java +++ b/src/test/java/net/snowflake/client/jdbc/telemetry/TelemetryIT.java @@ -47,6 +47,13 @@ public void testTelemetry() throws Exception { testTelemetryInternal(telemetry); } + @Ignore + @Test + @ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubAction.class) + public void testSessionlessTelemetry() throws Exception, SFException { + testTelemetryInternal(createSessionlessTelemetry()); + } + @Ignore @Test @ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubAction.class) @@ -197,6 +204,27 @@ public void testClosedOAuthSessionlessTelemetry() throws Exception, SFException Assert.assertFalse(telemetry.sendBatchAsync().get()); } + // Helper function to create a sessionless telemetry + // using createSessionlessTelemetry(CloseableHttpClient httpClient, String serverUrl) + private TelemetryClient createSessionlessTelemetry() + throws SFException, SQLException, IOException { + setUpPublicKey(); + String privateKeyLocation = getFullPathFileInResource("rsa_key.p8"); + Map parameters = getConnectionParameters(); + String jwtToken = + SessionUtil.generateJWTToken( + null, privateKeyLocation, null, parameters.get("account"), parameters.get("user")); + + CloseableHttpClient httpClient = HttpUtil.buildHttpClient(null, null, false); + TelemetryClient telemetry = + (TelemetryClient) + TelemetryClient.createSessionlessTelemetry( + httpClient, + String.format("%s:%s", parameters.get("host"), parameters.get("port"))); + telemetry.refreshToken(jwtToken); + return telemetry; + } + // Helper function to create a sessionless telemetry using keypair JWT private TelemetryClient createJWTSessionlessTelemetry() throws SFException, SQLException, IOException { From be680741c2d69033fd30aa633262993c868b76e9 Mon Sep 17 00:00:00 2001 From: Joyce Ling <115662568+sfc-gh-ext-simba-jl@users.noreply.github.com> Date: Wed, 11 Oct 2023 19:03:35 -0700 Subject: [PATCH 2/3] fix style --- .../net/snowflake/client/jdbc/telemetry/TelemetryClient.java | 5 +++-- .../net/snowflake/client/jdbc/telemetry/TelemetryIT.java | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java b/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java index 6cef2a94f..e435e306e 100644 --- a/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java +++ b/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java @@ -193,8 +193,9 @@ public static Telemetry createTelemetry(SFSession session, int flushSize) { */ public static Telemetry createSessionlessTelemetry( CloseableHttpClient httpClient, String serverUrl) { - // By default, use KEYPAIR_JWT as the auth type - return createSessionlessTelemetry(httpClient, serverUrl, "KEYPAIR_JWT", DEFAULT_FORCE_FLUSH_SIZE); + // By default, use KEYPAIR_JWT as the auth type + return createSessionlessTelemetry( + httpClient, serverUrl, "KEYPAIR_JWT", DEFAULT_FORCE_FLUSH_SIZE); } /** diff --git a/src/test/java/net/snowflake/client/jdbc/telemetry/TelemetryIT.java b/src/test/java/net/snowflake/client/jdbc/telemetry/TelemetryIT.java index d859932ae..c9b9b6272 100644 --- a/src/test/java/net/snowflake/client/jdbc/telemetry/TelemetryIT.java +++ b/src/test/java/net/snowflake/client/jdbc/telemetry/TelemetryIT.java @@ -219,8 +219,7 @@ private TelemetryClient createSessionlessTelemetry() TelemetryClient telemetry = (TelemetryClient) TelemetryClient.createSessionlessTelemetry( - httpClient, - String.format("%s:%s", parameters.get("host"), parameters.get("port"))); + httpClient, String.format("%s:%s", parameters.get("host"), parameters.get("port"))); telemetry.refreshToken(jwtToken); return telemetry; } From 5d7062b52e47d9a786fbee3af24ae69adcebebc1 Mon Sep 17 00:00:00 2001 From: Joyce Ling <115662568+sfc-gh-ext-simba-jl@users.noreply.github.com> Date: Thu, 12 Oct 2023 11:55:35 -0700 Subject: [PATCH 3/3] add comment to javadoc --- .../net/snowflake/client/jdbc/telemetry/TelemetryClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java b/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java index e435e306e..b302edb1c 100644 --- a/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java +++ b/src/main/java/net/snowflake/client/jdbc/telemetry/TelemetryClient.java @@ -185,7 +185,7 @@ public static Telemetry createTelemetry(SFSession session, int flushSize) { } /** - * Initialize the sessionless telemetry connector + * Initialize the sessionless telemetry connector using KEYPAIR_JWT as the default auth type * * @param httpClient client object used to communicate with other machine * @param serverUrl server url