Skip to content

Commit

Permalink
SNOW-931105: Add createSessionlessTelemetry(CloseableHttpClient, Stri…
Browse files Browse the repository at this point in the history
…ng) method (#1527)

* add createSessionlessTelemetry(CloseableHttpClient, String) method

* fix style

* add comment to javadoc
  • Loading branch information
sfc-gh-ext-simba-jl authored Oct 13, 2023
1 parent 0a8680c commit f65ee55
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,26 @@ public static Telemetry createTelemetry(SFSession session, int flushSize) {
return new TelemetryClient(session, flushSize);
}

/**
* 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
* @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(
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/net/snowflake/client/jdbc/telemetry/TelemetryIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -197,6 +204,26 @@ 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<String, String> 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 {
Expand Down

0 comments on commit f65ee55

Please sign in to comment.