Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/*
* Replicated from snowflake-jdbc (v3.25.1)
* Source: https://github.com/snowflakedb/snowflake-jdbc/blob/v3.25.1/src/main/java/net/snowflake/client/core/ExecTimeTelemetryData.java
*
* Permitted differences: package. isNullOrEmpty uses StorageClientUtil.
* TelemetryService/TimeMeasurement use ingest versions (same package).
* @SnowflakeJdbcInternalApi removed.
*/
package net.snowflake.ingest.streaming.internal.fileTransferAgent;

import static net.snowflake.ingest.streaming.internal.fileTransferAgent.StorageClientUtil.isNullOrEmpty;

import net.minidev.json.JSONObject;

public class ExecTimeTelemetryData {
private final TimeMeasurement query = new TimeMeasurement();
private final TimeMeasurement bind = new TimeMeasurement();
private final TimeMeasurement gzip = new TimeMeasurement();
private final TimeMeasurement httpClient = new TimeMeasurement();
private final TimeMeasurement responseIOStream = new TimeMeasurement();
private final TimeMeasurement processResultChunk = new TimeMeasurement();
private final TimeMeasurement createResultSet = new TimeMeasurement();

private String batchId;
private String queryId;
private String queryFunction;
private int retryCount = 0;
private String retryLocations = "";
private Boolean ocspEnabled = false;
boolean sendData = true;

private String requestId;

public ExecTimeTelemetryData(String queryFunction, String batchId) {
this.query.setStart();
this.queryFunction = queryFunction;
this.batchId = batchId;
if (!TelemetryService.getInstance().isHTAPEnabled()) {
this.sendData = false;
}
}

public ExecTimeTelemetryData() {
this.sendData = false;
}

public void setBindStart() {
bind.setStart();
}

public void setOCSPStatus(Boolean ocspEnabled) {
this.ocspEnabled = ocspEnabled;
}

public void setBindEnd() {
this.bind.setEnd();
}

public void setHttpClientStart() {
httpClient.setStart();
}

public void setHttpClientEnd() {
httpClient.setEnd();
}

public void setGzipStart() {
gzip.setStart();
}

public void setGzipEnd() {
gzip.setEnd();
}

public void setQueryEnd() {
query.setEnd();
}

public void setQueryId(String queryId) {
this.queryId = queryId;
}

public void setProcessResultChunkStart() {
processResultChunk.setStart();
}

public void setProcessResultChunkEnd() {
processResultChunk.setEnd();
}

public void setResponseIOStreamStart() {
responseIOStream.setStart();
}

public void setResponseIOStreamEnd() {
responseIOStream.setEnd();
}

public void setCreateResultSetStart() {
createResultSet.setStart();
}

public void setCreateResultSetEnd() {
createResultSet.setEnd();
}

public void incrementRetryCount() {
this.retryCount++;
}

public void setRequestId(String requestId) {
this.requestId = requestId;
}

public void addRetryLocation(String location) {
if (isNullOrEmpty(this.retryLocations)) {
this.retryLocations = location;
} else {
this.retryLocations = this.retryLocations.concat(", ").concat(location);
}
}

long getTotalQueryTime() {
return query.getTime();
}

long getResultProcessingTime() {
if (createResultSet.getEnd() == 0 || processResultChunk.getStart() == 0) {
return -1;
}

return createResultSet.getEnd() - processResultChunk.getStart();
}

long getHttpRequestTime() {
return httpClient.getTime();
}

long getResultSetCreationTime() {
return createResultSet.getTime();
}

public String generateTelemetry() {
if (this.sendData) {
String eventType = "ExecutionTimeRecord";
JSONObject value = new JSONObject();
String valueStr;
value.put("eventType", eventType);
value.put("QueryStart", this.query.getStart());
value.put("BindStart", this.bind.getStart());
value.put("BindEnd", this.bind.getEnd());
value.put("GzipStart", this.gzip.getStart());
value.put("GzipEnd", this.gzip.getEnd());
value.put("HttpClientStart", this.httpClient.getStart());
value.put("HttpClientEnd", this.httpClient.getEnd());
value.put("ResponseIOStreamStart", this.responseIOStream.getStart());
value.put("ResponseIOStreamEnd", this.responseIOStream.getEnd());
value.put("ProcessResultChunkStart", this.processResultChunk.getStart());
value.put("ProcessResultChunkEnd", this.processResultChunk.getEnd());
value.put("CreateResultSetStart", this.createResultSet.getStart());
value.put("CreateResultSetEnd", this.createResultSet.getEnd());
value.put("QueryEnd", this.query.getEnd());
value.put("BatchID", this.batchId);
value.put("QueryID", this.queryId);
value.put("RequestID", this.requestId);
value.put("QueryFunction", this.queryFunction);
value.put("RetryCount", this.retryCount);
value.put("RetryLocations", this.retryLocations);
value.put("ocspEnabled", this.ocspEnabled);
value.put("ElapsedQueryTime", getTotalQueryTime());
value.put("ElapsedResultProcessTime", getResultProcessingTime());
value.put("Urgent", true);
valueStr = value.toString(); // Avoid adding exception stacktrace to user logs.
TelemetryService.getInstance().logExecutionTimeTelemetryEvent(value, eventType);
return valueStr;
}
return "";
}

public String getLogString() {
return "Query id: "
+ this.queryId
+ ", query function: "
+ this.queryFunction
+ ", batch id: "
+ this.batchId
+ ", request id: "
+ this.requestId
+ ", total query time: "
+ getTotalQueryTime() / 1000
+ " ms"
+ ", result processing time: "
+ getResultProcessingTime() / 1000
+ " ms"
+ ", result set creation time: "
+ getResultSetCreationTime() / 1000
+ " ms"
+ ", http request time: "
+ getHttpRequestTime() / 1000
+ " ms"
+ ", retry count: "
+ this.retryCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Replicated from snowflake-jdbc (v3.25.1)
* Source: https://github.com/snowflakedb/snowflake-jdbc/blob/v3.25.1/src/main/java/net/snowflake/client/core/HttpResponseContextDto.java
*
* Permitted differences: package. @SnowflakeJdbcInternalApi removed.
*/
package net.snowflake.ingest.streaming.internal.fileTransferAgent;

import org.apache.http.client.methods.CloseableHttpResponse;

public class HttpResponseContextDto {

private CloseableHttpResponse httpResponse;
private String unpackedCloseableHttpResponse;
private Exception savedEx;

// Constructors
public HttpResponseContextDto() {}

public HttpResponseContextDto(
CloseableHttpResponse httpResponse, String unpackedCloseableHttpResponse) {
this.httpResponse = httpResponse;
this.unpackedCloseableHttpResponse = unpackedCloseableHttpResponse;
}

public CloseableHttpResponse getHttpResponse() {
return httpResponse;
}

public void setHttpResponse(CloseableHttpResponse httpResponse) {
this.httpResponse = httpResponse;
}

public String getUnpackedCloseableHttpResponse() {
return unpackedCloseableHttpResponse;
}

public void setUnpackedCloseableHttpResponse(String unpackedCloseableHttpResponse) {
this.unpackedCloseableHttpResponse = unpackedCloseableHttpResponse;
}

public Exception getSavedEx() {
return savedEx;
}

public void setSavedEx(Exception savedEx) {
this.savedEx = savedEx;
}

@Override
public String toString() {
return "CloseableHttpResponseContextDto{"
+ "httpResponse="
+ httpResponse
+ ", unpackedCloseableHttpResponse="
+ unpackedCloseableHttpResponse
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Replicated from snowflake-jdbc (v3.25.1)
* Source: https://github.com/snowflakedb/snowflake-jdbc/blob/v3.25.1/src/main/java/net/snowflake/client/core/SFException.java
*
* Permitted differences: package. SFLogger/SFLoggerFactory use ingest versions.
* ErrorCode/ResourceBundleManager use ingest versions (same package).
*/
package net.snowflake.ingest.streaming.internal.fileTransferAgent;

import net.snowflake.ingest.streaming.internal.fileTransferAgent.log.SFLogger;
import net.snowflake.ingest.streaming.internal.fileTransferAgent.log.SFLoggerFactory;

public class SFException extends Throwable {
private static final SFLogger logger = SFLoggerFactory.getLogger(SFException.class);

private static final long serialVersionUID = 1L;

static final ResourceBundleManager errorResourceBundleManager =
ResourceBundleManager.getSingleton(ErrorCode.errorMessageResource);

private Throwable cause;
private String queryId;
private String sqlState;
private int vendorCode;
private Object[] params;

/**
* Use {@link SFException#SFException(String, Throwable, ErrorCode, Object...)}
*
* @param errorCode the error code
* @param params additional params
*/
@Deprecated
public SFException(ErrorCode errorCode, Object... params) {
this(null, null, errorCode, params);
}

/**
* use {@link SFException#SFException(String, Throwable, ErrorCode, Object...)}
*
* @param queryID the query id
* @param errorCode the error code
* @param params additional params
*/
@Deprecated
public SFException(String queryID, ErrorCode errorCode, Object... params) {
this(queryID, null, errorCode, params);
}

/**
* use {@link SFException#SFException(String, Throwable, ErrorCode, Object...)}
*
* @param cause throwable
* @param errorCode error code
* @param params additional params
*/
@Deprecated
public SFException(Throwable cause, ErrorCode errorCode, Object... params) {
this(null, cause, errorCode, params);
}

/**
* @param queryId query ID
* @param cause throwable
* @param errorCode error code
* @param params additional params
*/
public SFException(String queryId, Throwable cause, ErrorCode errorCode, Object... params) {
super(
errorResourceBundleManager.getLocalizedMessage(
String.valueOf(errorCode.getMessageCode()), params),
cause);

this.cause = null;
this.queryId = queryId;
this.sqlState = errorCode.getSqlState();
this.vendorCode = errorCode.getMessageCode();
this.params = params;
}

/**
* Get the error cause
*
* @return Throwable
*/
public Throwable getCause() {
return cause;
}

/**
* Get the query ID
*
* @return query ID string
*/
public String getQueryId() {
return queryId;
}

/**
* Get the SQL state
*
* @return SQL state string
*/
public String getSqlState() {
return sqlState;
}

/**
* Get the vendor code
*
* @return vendor code
*/
public int getVendorCode() {
return vendorCode;
}

/**
* Get additional parameters
*
* @return parameter array
*/
public Object[] getParams() {
return params;
}

@Override
public String toString() {
return super.toString()
+ (getQueryId() != null ? ", query id = " + getQueryId() : "")
+ (getSqlState() != null ? ", sql state = " + getSqlState() : "");
}
}
Loading
Loading