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

Added additional parameter TELEMETRY_SERVICE_AVAILABLE to support disabling Telemetry #2034

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions src/main/java/net/snowflake/client/core/SFBaseSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public abstract class SFBaseSession {
private boolean formatDateWithTimezone;
private boolean enableCombineDescribe;
private boolean clientTelemetryEnabled = false;
private boolean isTelemetryServiceAvailable = true;
private boolean useSessionTimezone;
private boolean defaultFormatDateWithTimezone = true;
private boolean getDateUseNullTimezone = true;
Expand Down Expand Up @@ -1016,6 +1017,14 @@ public void setClientTelemetryEnabled(boolean clientTelemetryEnabled) {
this.clientTelemetryEnabled = clientTelemetryEnabled;
}

public boolean isTelemetryServiceAvailable() {
return isTelemetryServiceAvailable;
}

public void setTelemetryServiceAvailable(boolean isTelemetryServiceAvailable) {
this.isTelemetryServiceAvailable = isTelemetryServiceAvailable;
}

public int getArrayBindStageThreshold() {
return arrayBindStageThreshold;
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class SFSession extends SFBaseSession {
private static final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.getObjectMapper();
private static final String SF_PATH_SESSION_HEARTBEAT = "/session/heartbeat";
private static final String SF_PATH_QUERY_MONITOR = "/monitoring/queries/";
public static final String TELEMETRY_SERVICE_AVAILABLE = "TELEMETRY_SERVICE_AVAILABLE";

// temporarily have this variable to avoid hardcode.
// Need to be removed when a better way to organize session parameter is introduced.
private static final String CLIENT_STORE_TEMPORARY_CREDENTIAL =
Expand Down Expand Up @@ -750,6 +752,20 @@ public synchronized void open() throws SFException, SnowflakeSQLException {
HttpUtil.setConnectionTimeout(loginInput.getConnectionTimeoutInMillis());
HttpUtil.setSocketTimeout(loginInput.getSocketTimeoutInMillis());

String telemetryValue =
loginInput
.getSessionParameters()
.getOrDefault(TELEMETRY_SERVICE_AVAILABLE, Boolean.TRUE)
.toString();

boolean isTelemetryServiceAvailable = Boolean.parseBoolean(telemetryValue);

if (!isTelemetryServiceAvailable) {
logger.debug("Telemetry Service is not available");
}

setTelemetryServiceAvailable(isTelemetryServiceAvailable);

runDiagnosticsIfEnabled();

SFLoginOutput loginOutput =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class TelemetryClient implements Telemetry {
private TelemetryClient(SFSession session, int flushSize) {
this.session = session;
this.serverUrl = session.getUrl();
this.isTelemetryServiceAvailable = session.isTelemetryServiceAvailable();
this.httpClient = null;

if (this.serverUrl.endsWith("/")) {
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/net/snowflake/client/core/SFLoginInputTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package net.snowflake.client.core;

import static net.snowflake.client.core.SFSession.TELEMETRY_SERVICE_AVAILABLE;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;

public class SFLoginInputTest {

Expand All @@ -19,4 +25,15 @@ public void testGetHostFromServerUrlWithProtocolShouldNotThrow() throws SFExcept
sfLoginInput.setServerUrl("https://host.com");
assertEquals("host.com", sfLoginInput.getHostFromServerUrl());
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
@NullSource
public void testGetTelemetryServiceAvailableShouldReturnCorrectValue(Boolean value) {
SFLoginInput sfLoginInput = new SFLoginInput();
Map<String, Object> sessionParameters = new HashMap<>();
sessionParameters.put(TELEMETRY_SERVICE_AVAILABLE, value);
sfLoginInput.setSessionParameters(sessionParameters);
assertEquals(value, sfLoginInput.getSessionParameters().get(TELEMETRY_SERVICE_AVAILABLE));
}
}