Skip to content

Commit

Permalink
SNOW-844477: Allow connection property CLIENT_OUT_OF_BAND_TELEMETRY_E…
Browse files Browse the repository at this point in the history
…NABLED to disable OOB telemetry (#1464)

allow connection property to disable OOB telemetry
  • Loading branch information
sfc-gh-ext-simba-lb authored Jul 14, 2023
1 parent 6f05fec commit 6a8b926
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,15 @@ public synchronized void open() throws SFException, SnowflakeSQLException {
.setOCSPMode(getOCSPMode())
.setHttpClientSettingsKey(httpClientSettingsKey);

// Enable or disable OOB telemetry based on connection parameter. Default is disabled.
// The value may still change later when session parameters from the server are read.
if (getBooleanValue(
connectionPropertiesMap.get(SFSessionProperty.CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED))) {
TelemetryService.enable();
} else {
TelemetryService.disable();
}

// propagate OCSP mode to SFTrustManager. Note OCSP setting is global on JVM.
HttpUtil.initHttpClient(httpClientSettingsKey, null);
SFLoginOutput loginOutput =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;

import java.sql.Connection;
import java.sql.SQLException;
Expand Down Expand Up @@ -308,6 +308,58 @@ public void testHTAPTelemetry() throws SQLException {
}
}

/**
* Requires part 2 of SNOW-844477. Make sure CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED is true at
* account level. Tests connection property CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED=true
*/
@Ignore
@Test
public void testOOBTelemetryEnabled() throws SQLException {
Properties properties = new Properties();
properties.put("CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED", "true");
try (Connection con = getConnection(properties)) {
Statement statement = con.createStatement();
statement.execute("select 1");
// Make sure OOB telemetry is enabled
assertTrue(TelemetryService.getInstance().isEnabled());
}
}

/**
* Requires part 2 of SNOW-844477. Make sure CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED is false at
* account level. Tests connection property CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED=false
*/
@Ignore
@Test
public void testOOBTelemetryDisabled() throws SQLException {
Properties properties = new Properties();
properties.put("CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED", "false");
try (Connection con = getConnection(properties)) {
Statement statement = con.createStatement();
statement.execute("select 1");
// Make sure OOB telemetry is disabled
assertFalse(TelemetryService.getInstance().isEnabled());
}
}

/**
* Requires part 2 of SNOW-844477. Make sure CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED is true at
* account level. Tests connection property CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED=false but
* CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED is enabled on account level
*/
@Ignore
@Test
public void testOOBTelemetryEnabledOnServerDisabledOnClient() throws SQLException {
Properties properties = new Properties();
properties.put("CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED", "false");
try (Connection con = getConnection(properties)) {
Statement statement = con.createStatement();
statement.execute("select 1");
// Make sure OOB telemetry is enabled
assertTrue(TelemetryService.getInstance().isEnabled());
}
}

/**
* Test case for checking telemetry message for SnowflakeSQLExceptions. In-band telemetry should
* be used.
Expand Down

0 comments on commit 6a8b926

Please sign in to comment.