Skip to content

Commit 0199879

Browse files
sfc-gh-ggengclaude
andcommitted
[SNOW-3249917] JDBC removal Step 10c (part 2): Remove SFSession from exceptions + telemetry
Remove SFSession/SFBaseSession from SnowflakeSQLLoggedException and TelemetryClient. Session was always null from ingest callers. SnowflakeSQLLoggedException: - Remove SFBaseSession/SFSession from all 15 constructor signatures - Remove IB telemetry dead code (session was always null, so ibInstance was always null — only OOB path ever executed) - Remove sendInBandTelemetryMessage, createIBValue (dead code) - Simplify sendTelemetryData to always send OOB - Remove Telemetry/TelemetryField(JDBC)/TelemetryUtil(JDBC) imports - Update all callers (~12 files) to remove null session argument TelemetryClient: - Remove SFSession field and session-based constructor - Remove createTelemetry(Connection/SFSession) factory methods - Simplify isTelemetryEnabled() (no session check) - Remove session-based auth header and HTTP call branch in sendBatch() - Remove SFSession, SnowflakeConnectionV1, Connection, SQLException, UnexpectedException imports Remaining JDBC imports: 6 (HttpUtil + SnowflakeSQLException in TelemetryClient, HttpUtil + RestRequest + ExecTimeTelemetryData + HttpResponseContextDto in SnowflakeGCSClient) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 57ce4ac commit 0199879

File tree

15 files changed

+55
-394
lines changed

15 files changed

+55
-394
lines changed

src/main/java/net/snowflake/ingest/connection/telemetry/TelemetryClient.java

Lines changed: 11 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@
88
import com.fasterxml.jackson.databind.node.ArrayNode;
99
import com.fasterxml.jackson.databind.node.ObjectNode;
1010
import java.io.IOException;
11-
import java.rmi.UnexpectedException;
12-
import java.sql.Connection;
13-
import java.sql.SQLException;
1411
import java.util.LinkedList;
1512
import java.util.Objects;
1613
import java.util.concurrent.Future;
1714
import net.snowflake.client.core.HttpUtil;
18-
import net.snowflake.client.core.SFSession;
19-
import net.snowflake.client.jdbc.SnowflakeConnectionV1;
2015
import net.snowflake.client.jdbc.SnowflakeSQLException;
2116
import net.snowflake.ingest.streaming.internal.fileTransferAgent.ObjectMapperFactory;
2217
import net.snowflake.ingest.streaming.internal.fileTransferAgent.TelemetryThreadPool;
@@ -32,7 +27,6 @@
3227
public class TelemetryClient implements Telemetry {
3328
private static final SFLogger logger = SFLoggerFactory.getLogger(TelemetryClient.class);
3429

35-
private static final String SF_PATH_TELEMETRY = "/telemetry/send";
3630
private static final String SF_PATH_TELEMETRY_SESSIONLESS = "/telemetry/send/sessionless";
3731

3832
// if the number of cached logs is larger than this threshold,
@@ -44,7 +38,6 @@ public class TelemetryClient implements Telemetry {
4438
private final String serverUrl;
4539
private final String telemetryUrl;
4640

47-
private final SFSession session;
4841
private LinkedList<TelemetryData> logBatch;
4942
private static final ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
5043

@@ -67,23 +60,6 @@ public class TelemetryClient implements Telemetry {
6760
// Retry timeout for the HTTP request
6861
private static final int TELEMETRY_HTTP_RETRY_TIMEOUT_IN_SEC = 1000;
6962

70-
private TelemetryClient(SFSession session, int flushSize) {
71-
this.session = session;
72-
this.serverUrl = session.getUrl();
73-
this.httpClient = null;
74-
75-
if (this.serverUrl.endsWith("/")) {
76-
this.telemetryUrl =
77-
this.serverUrl.substring(0, this.serverUrl.length() - 1) + SF_PATH_TELEMETRY;
78-
} else {
79-
this.telemetryUrl = this.serverUrl + SF_PATH_TELEMETRY;
80-
}
81-
82-
this.logBatch = new LinkedList<>();
83-
this.isClosed = false;
84-
this.forceFlushSize = flushSize;
85-
}
86-
8763
/**
8864
* Constructor for creating a sessionless telemetry client
8965
*
@@ -94,7 +70,6 @@ private TelemetryClient(SFSession session, int flushSize) {
9470
*/
9571
private TelemetryClient(
9672
CloseableHttpClient httpClient, String serverUrl, String authType, int flushSize) {
97-
this.session = null;
9873
this.serverUrl = serverUrl;
9974
this.httpClient = httpClient;
10075

@@ -127,8 +102,7 @@ private TelemetryClient(
127102
* @return whether client is enabled
128103
*/
129104
public boolean isTelemetryEnabled() {
130-
return (this.session == null || this.session.isClientTelemetryEnabled())
131-
&& this.isTelemetryServiceAvailable;
105+
return this.isTelemetryServiceAvailable;
132106
}
133107

134108
/** Disable any use of the client to add/send metrics */
@@ -137,54 +111,6 @@ public void disableTelemetry() {
137111
this.isTelemetryServiceAvailable = false;
138112
}
139113

140-
/**
141-
* Initialize the telemetry connector
142-
*
143-
* @param conn connection with the session to use for the connector
144-
* @param flushSize maximum size of telemetry batch before flush
145-
* @return a telemetry connector
146-
*/
147-
public static Telemetry createTelemetry(Connection conn, int flushSize) {
148-
try {
149-
return createTelemetry(
150-
(SFSession) conn.unwrap(SnowflakeConnectionV1.class).getSFBaseSession(), flushSize);
151-
} catch (SQLException ex) {
152-
logger.debug("Input connection is not a SnowflakeConnection", false);
153-
return null;
154-
}
155-
}
156-
157-
/**
158-
* Initialize the telemetry connector
159-
*
160-
* @param conn connection with the session to use for the connector
161-
* @return a telemetry connector
162-
*/
163-
public static Telemetry createTelemetry(Connection conn) {
164-
return createTelemetry(conn, DEFAULT_FORCE_FLUSH_SIZE);
165-
}
166-
167-
/**
168-
* Initialize the telemetry connector
169-
*
170-
* @param session session to use for telemetry dumps
171-
* @return a telemetry connector
172-
*/
173-
public static Telemetry createTelemetry(SFSession session) {
174-
return createTelemetry(session, DEFAULT_FORCE_FLUSH_SIZE);
175-
}
176-
177-
/**
178-
* Initialize the telemetry connector
179-
*
180-
* @param session session to use for telemetry dumps
181-
* @param flushSize maximum size of telemetry batch before flush
182-
* @return a telemetry connector
183-
*/
184-
public static Telemetry createTelemetry(SFSession session, int flushSize) {
185-
return new TelemetryClient(session, flushSize);
186-
}
187-
188114
/**
189115
* Initialize the sessionless telemetry connector using KEYPAIR_JWT as the default auth type
190116
*
@@ -330,14 +256,9 @@ private boolean sendBatch() throws IOException {
330256
this.logBatch = new LinkedList<>();
331257
}
332258

333-
if (this.session != null && this.session.isClosed()) {
334-
throw new UnexpectedException("Session is closed when sending log");
335-
}
336-
337259
if (!tmpList.isEmpty()) {
338260
Stopwatch stopwatch = new Stopwatch();
339261
stopwatch.start();
340-
// session shared with JDBC
341262
String payload = logsToString(tmpList);
342263

343264
logger.debugNoMask("Payload of telemetry is : " + payload);
@@ -346,35 +267,21 @@ private boolean sendBatch() throws IOException {
346267
post.setEntity(new StringEntity(payload));
347268
post.setHeader("Content-type", "application/json");
348269

349-
if (this.session == null) {
350-
post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
351-
post.setHeader("X-Snowflake-Authorization-Token-Type", this.authType);
352-
post.setHeader(HttpHeaders.ACCEPT, "application/json");
353-
} else {
354-
post.setHeader(
355-
HttpHeaders.AUTHORIZATION,
356-
"Snowflake Token=\"" + this.session.getSessionToken() + "\"");
357-
}
270+
post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
271+
post.setHeader("X-Snowflake-Authorization-Token-Type", this.authType);
272+
post.setHeader(HttpHeaders.ACCEPT, "application/json");
358273

359274
String response = null;
360275

361276
try {
362277
response =
363-
this.session == null
364-
? HttpUtil.executeGeneralRequest(
365-
post,
366-
TELEMETRY_HTTP_RETRY_TIMEOUT_IN_SEC,
367-
0,
368-
(int) HttpUtil.getSocketTimeout().toMillis(),
369-
0,
370-
this.httpClient)
371-
: HttpUtil.executeGeneralRequest(
372-
post,
373-
TELEMETRY_HTTP_RETRY_TIMEOUT_IN_SEC,
374-
0,
375-
this.session.getHttpClientSocketTimeout(),
376-
0,
377-
this.session.getHttpClientKey());
278+
HttpUtil.executeGeneralRequest(
279+
post,
280+
TELEMETRY_HTTP_RETRY_TIMEOUT_IN_SEC,
281+
0,
282+
(int) HttpUtil.getSocketTimeout().toMillis(),
283+
0,
284+
this.httpClient);
378285
stopwatch.stop();
379286
logger.debug(
380287
"Sending telemetry took {} ms. Batch size: {}",

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ public boolean handleStorageException(
240240

241241
throw new SnowflakeSQLLoggedException(
242242
queryId,
243-
null,
244243
SqlState.SYSTEM_ERROR,
245244
ErrorCode.S3_OPERATION_ERROR.getMessageCode(),
246245
ex1,
@@ -254,7 +253,6 @@ public boolean handleStorageException(
254253
} else {
255254
throw new SnowflakeSQLLoggedException(
256255
queryId,
257-
null,
258256
SqlState.SYSTEM_ERROR,
259257
ErrorCode.AWS_CLIENT_ERROR.getMessageCode(),
260258
ex,

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ public boolean handleStorageException(
189189
if (retryCount > gcsClient.getMaxRetries()) {
190190
throw new SnowflakeSQLLoggedException(
191191
queryId,
192-
null,
193192
SqlState.SYSTEM_ERROR,
194193
ErrorCode.GCP_SERVICE_ERROR.getMessageCode(),
195194
se,

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergAzureClient.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ private SFPair<InputStream, Boolean> createUploadStream(
308308
} catch (FileNotFoundException ex) {
309309
logger.logError("Failed to open input file", ex);
310310
throw new SnowflakeSQLLoggedException(
311-
null /* session */,
312311
SqlState.INTERNAL_ERROR,
313312
ErrorCode.INTERNAL_ERROR.getMessageCode(),
314313
ex,
@@ -317,7 +316,6 @@ private SFPair<InputStream, Boolean> createUploadStream(
317316
} catch (IOException ex) {
318317
logger.logError("Failed to open input stream", ex);
319318
throw new SnowflakeSQLLoggedException(
320-
null /* session */,
321319
SqlState.INTERNAL_ERROR,
322320
ErrorCode.INTERNAL_ERROR.getMessageCode(),
323321
ex,
@@ -373,7 +371,6 @@ private static void handleAzureException(
373371
if (retryCount > azClient.getMaxRetries()
374372
|| ((StorageException) ex).getHttpStatusCode() == 404) {
375373
throw new SnowflakeSQLLoggedException(
376-
null /* session */,
377374
SqlState.SYSTEM_ERROR,
378375
ErrorCode.AZURE_SERVICE_ERROR.getMessageCode(),
379376
se,
@@ -410,7 +407,6 @@ private static void handleAzureException(
410407
|| StorageClientUtil.getRootCause(ex) instanceof SocketTimeoutException) {
411408
if (retryCount > azClient.getMaxRetries()) {
412409
throw new SnowflakeSQLLoggedException(
413-
null /* session */,
414410
SqlState.SYSTEM_ERROR,
415411
ErrorCode.IO_ERROR.getMessageCode(),
416412
ex,
@@ -424,7 +420,6 @@ private static void handleAzureException(
424420
}
425421
} else {
426422
throw new SnowflakeSQLLoggedException(
427-
null /* session */,
428423
SqlState.SYSTEM_ERROR,
429424
ErrorCode.IO_ERROR.getMessageCode(),
430425
ex,

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergGCSClient.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ public String upload(
151151
String presignedUrl)
152152
throws SnowflakeSQLException {
153153
throw new SnowflakeSQLLoggedException(
154-
null,
155154
ErrorCode.INTERNAL_ERROR.getMessageCode(),
156155
SqlState.INTERNAL_ERROR,
157156
/* session= */ "IcebergGCSClient.upload" + " only works with pre-signed URL.");
@@ -324,7 +323,6 @@ private SFPair<InputStream, Boolean> createUploadStream(
324323
} catch (FileNotFoundException ex) {
325324
logger.logError("Failed to open input file", ex);
326325
throw new SnowflakeSQLLoggedException(
327-
null /* session */,
328326
SqlState.INTERNAL_ERROR,
329327
ErrorCode.INTERNAL_ERROR.getMessageCode(),
330328
ex,
@@ -333,7 +331,6 @@ private SFPair<InputStream, Boolean> createUploadStream(
333331
} catch (IOException ex) {
334332
logger.logError("Failed to open input stream", ex);
335333
throw new SnowflakeSQLLoggedException(
336-
null /* session */,
337334
SqlState.INTERNAL_ERROR,
338335
ErrorCode.INTERNAL_ERROR.getMessageCode(),
339336
ex,
@@ -368,7 +365,6 @@ private void handleStorageException(Exception ex, int retryCount, String operati
368365
// If we have exceeded the max number of retries, propagate the error
369366
if (retryCount > getMaxRetries()) {
370367
throw new SnowflakeSQLLoggedException(
371-
null /* session */,
372368
SqlState.SYSTEM_ERROR,
373369
ErrorCode.GCP_SERVICE_ERROR.getMessageCode(),
374370
se,
@@ -403,7 +399,6 @@ private void handleStorageException(Exception ex, int retryCount, String operati
403399
|| getRootCause(ex) instanceof SocketTimeoutException) {
404400
if (retryCount > getMaxRetries()) {
405401
throw new SnowflakeSQLLoggedException(
406-
null /* session */,
407402
SqlState.SYSTEM_ERROR,
408403
ErrorCode.IO_ERROR.getMessageCode(),
409404
ex,
@@ -417,7 +412,6 @@ private void handleStorageException(Exception ex, int retryCount, String operati
417412
}
418413
} else {
419414
throw new SnowflakeSQLLoggedException(
420-
null /* session */,
421415
SqlState.SYSTEM_ERROR,
422416
ErrorCode.IO_ERROR.getMessageCode(),
423417
ex,

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergS3Client.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ public ExecutorService newExecutor() {
356356
}
357357

358358
throw new SnowflakeSQLLoggedException(
359-
null,
360359
ErrorCode.INTERNAL_ERROR.getMessageCode(),
361360
SqlState.INTERNAL_ERROR,
362361
"Unexpected: upload unsuccessful without exception!");
@@ -433,7 +432,6 @@ private SFPair<InputStream, Boolean> createUploadStream(
433432
} catch (FileNotFoundException ex) {
434433
logger.logError("Failed to open input file", ex);
435434
throw new SnowflakeSQLLoggedException(
436-
null /* session */,
437435
SqlState.INTERNAL_ERROR,
438436
ErrorCode.INTERNAL_ERROR.getMessageCode(),
439437
ex,
@@ -442,7 +440,6 @@ private SFPair<InputStream, Boolean> createUploadStream(
442440
} catch (IOException ex) {
443441
logger.logError("Failed to open input stream", ex);
444442
throw new SnowflakeSQLLoggedException(
445-
null /* session */,
446443
SqlState.INTERNAL_ERROR,
447444
ErrorCode.INTERNAL_ERROR.getMessageCode(),
448445
ex,
@@ -486,7 +483,6 @@ private static void handleS3Exception(
486483
// does not return the ExpiredToken error code.
487484
// If session is null we cannot renew the token so throw the exception
488485
throw new SnowflakeSQLLoggedException(
489-
null /* session */,
490486
SqlState.SYSTEM_ERROR,
491487
ErrorCode.S3_OPERATION_ERROR.getMessageCode(),
492488
ex1,
@@ -498,7 +494,6 @@ private static void handleS3Exception(
498494
extendedRequestId);
499495
} else {
500496
throw new SnowflakeSQLLoggedException(
501-
null /* session */,
502497
SqlState.SYSTEM_ERROR,
503498
ErrorCode.AWS_CLIENT_ERROR.getMessageCode(),
504499
ex,
@@ -546,7 +541,6 @@ private static void handleS3Exception(
546541
|| getRootCause(ex) instanceof SocketTimeoutException) {
547542
if (retryCount > s3Client.getMaxRetries()) {
548543
throw new SnowflakeSQLLoggedException(
549-
null /* session */,
550544
SqlState.SYSTEM_ERROR,
551545
ErrorCode.IO_ERROR.getMessageCode(),
552546
ex,
@@ -560,7 +554,6 @@ private static void handleS3Exception(
560554
}
561555
} else {
562556
throw new SnowflakeSQLLoggedException(
563-
null /* session */,
564557
SqlState.SYSTEM_ERROR,
565558
ErrorCode.IO_ERROR.getMessageCode(),
566559
ex,

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergStorageClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ default String uploadWithPresignedUrlWithoutConnection(
8585
String presignedUrl)
8686
throws SnowflakeSQLException {
8787
throw new SnowflakeSQLLoggedException(
88-
null,
8988
ErrorCode.INTERNAL_ERROR.getMessageCode(),
9089
SqlState.INTERNAL_ERROR,
9190
/* session= */ "uploadWithPresignedUrlWithoutConnection"

0 commit comments

Comments
 (0)