-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into SNOW-1814745-Fix-aborting-requests-in-Http…
…Client
- Loading branch information
Showing
18 changed files
with
499 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,13 +30,6 @@ npm install | |
PACKAGE_NAME=$(cd $WORKSPACE && ls snowflake-sdk*.tgz) | ||
npm install $WORKSPACE/${PACKAGE_NAME} | ||
|
||
# Since @azure lib has lost compatibility with node14 | ||
#some dependencies have to be replaced by an older version | ||
nodeVersion=$(node -v) | ||
if [[ "$nodeVersion" == 'v14.'* ]]; then | ||
npm install @azure/[email protected] | ||
fi | ||
|
||
echo "[INFO] Setting test parameters" | ||
if [[ "$LOCAL_USER_NAME" == "jenkins" ]]; then | ||
echo "[INFO] Use the default test parameters.json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
exports.paramsNames = {}; | ||
exports.paramsNames.SF_REQUEST_GUID = 'request_guid'; | ||
exports.paramsNames = Object.freeze({ | ||
SF_REQUEST_GUID: 'request_guid', | ||
SF_REQUEST_ID: 'requestId', | ||
SF_TOKEN: 'token', | ||
SF_WAREHOUSE_NAME: 'warehouse', | ||
SF_DB_NAME: 'databaseName', | ||
SF_SCHEMA_NAME: 'schemaName', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,202 @@ | ||
const LoggingUtil = require('../logger/logging_util'); | ||
const sfParams = require('../constants/sf_params'); | ||
|
||
// Initial whitelist for attributes - they will be described with values | ||
const DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITH_VALUES = [ | ||
'baseUrl', | ||
'path', | ||
'method', | ||
sfParams.paramsNames.SF_REQUEST_ID, | ||
sfParams.paramsNames.SF_REQUEST_GUID, | ||
sfParams.paramsNames.SF_WAREHOUSE_NAME, | ||
sfParams.paramsNames.SF_DB_NAME, | ||
sfParams.paramsNames.SF_SCHEMA_NAME, | ||
]; | ||
|
||
// Initial blacklist for attributes - described as present/not present only | ||
const DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITHOUT_VALUES = [ | ||
sfParams.paramsNames.SF_TOKEN | ||
]; | ||
|
||
// Helper function to resolve attributes arrays given defaults and overrides. | ||
function resolveAttributeList(defaultAttrs, overrideAttrs) { | ||
return overrideAttrs || defaultAttrs; | ||
} | ||
|
||
/** | ||
* Should work with not yet parsed options as well (before calling prepareRequestOptions method). | ||
* Describes a request based on its options. | ||
* Should work with not-yet-parsed options as well (before calling prepareRequestOptions method). | ||
* | ||
* @param requestOptions - object representing the request data with top-level keys | ||
* @returns {string} | ||
* @param {Object} requestOptions - Object representing the request data with top-level keys. | ||
* @param {Object} [options] - Options for describing attributes. | ||
* @param {Array<string>} [options.overrideAttributesDescribedWithValues] | ||
* @param {Array<string>} [options.overrideAttributesDescribedWithoutValues] | ||
* @returns {string} A string representation of the request data. | ||
*/ | ||
exports.describeRequestFromOptions = function (requestOptions) { | ||
return exports.describeRequestData({ method: requestOptions.method, url: requestOptions.url, guid: requestOptions.params?.[sfParams.paramsNames.SF_REQUEST_GUID] }); | ||
}; | ||
function describeRequestFromOptions( | ||
requestOptions, | ||
{ | ||
overrideAttributesDescribedWithValues, | ||
overrideAttributesDescribedWithoutValues | ||
} = {} | ||
) { | ||
const describingAttributesWithValues = resolveAttributeList( | ||
DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITH_VALUES, | ||
overrideAttributesDescribedWithValues | ||
); | ||
|
||
const describingAttributesWithoutValues = resolveAttributeList( | ||
DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITHOUT_VALUES, | ||
overrideAttributesDescribedWithoutValues | ||
); | ||
|
||
const { method, url, params } = requestOptions || {}; | ||
|
||
return describeRequestData( | ||
{ method, url, params }, | ||
describingAttributesWithValues, | ||
describingAttributesWithoutValues | ||
); | ||
} | ||
|
||
/** | ||
* Creates string that represents response data. | ||
* Should allow to identify request, which was the source for this response. | ||
* @param response - axios response object | ||
* @returns {string} | ||
* Creates a string that represents request data from a response. | ||
* Helps to identify the request that was the source of the response. | ||
* | ||
* @param {Object} response - Axios response object. | ||
* @param {Object} [options] - Options for describing attributes. | ||
* @param {Array<string>} [options.overrideAttributesDescribedWithValues] | ||
* @param {Array<string>} [options.overrideAttributesDescribedWithoutValues] | ||
* @returns {string} A string representation of the request data. | ||
*/ | ||
exports.describeRequestFromResponse = function (response) { | ||
let methodUppercase = undefined; | ||
let url = undefined; | ||
let guid = undefined; | ||
const responseConfig = response.config; | ||
function describeRequestFromResponse( | ||
response, | ||
{ | ||
overrideAttributesDescribedWithValues, | ||
overrideAttributesDescribedWithoutValues | ||
} = {} | ||
) { | ||
let method; | ||
let url; | ||
let params; | ||
const responseConfig = response?.config; | ||
|
||
const describingAttributesWithValues = resolveAttributeList( | ||
DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITH_VALUES, | ||
overrideAttributesDescribedWithValues | ||
); | ||
|
||
const describingAttributesWithoutValues = resolveAttributeList( | ||
DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITHOUT_VALUES, | ||
overrideAttributesDescribedWithoutValues | ||
); | ||
|
||
if (responseConfig) { | ||
// Uppercase is used to allow finding logs corresponding to the same request - response pair, | ||
// by matching identical options' descriptions. | ||
methodUppercase = responseConfig.method.toUpperCase(); | ||
method = responseConfig.method; | ||
url = responseConfig.url; | ||
guid = responseConfig.params?.[sfParams.paramsNames.SF_REQUEST_GUID]; | ||
params = responseConfig.params; | ||
} | ||
|
||
return describeRequestData( | ||
{ method, url, params }, | ||
describingAttributesWithValues, | ||
describingAttributesWithoutValues | ||
); | ||
} | ||
|
||
/** | ||
* Constructs a string representation of request data. | ||
* | ||
* @param {Object} requestData - Object containing the method, url, and parameters. | ||
* @param {string} requestData.method - HTTP method. | ||
* @param {string} requestData.url - Request URL. | ||
* @param {Object} [requestData.params] - Additional query parameters. | ||
* @param {Array<string>} attributesWithValues - Attributes to describe with values. | ||
* @param {Array<string>} attributesWithoutValues - Attributes to describe without values. | ||
* @returns {string} A string describing the request data. | ||
*/ | ||
function describeRequestData( | ||
{ method, url, params } = {}, | ||
attributesWithValues, | ||
attributesWithoutValues | ||
) { | ||
const requestObject = { | ||
// Ensure consistent casing for methods to match request-response pairs in logs. | ||
method: method?.toUpperCase(), | ||
...constructURLData(url, params), | ||
}; | ||
|
||
return LoggingUtil.describeAttributes( | ||
requestObject, | ||
attributesWithValues, | ||
attributesWithoutValues | ||
); | ||
} | ||
|
||
/** | ||
* Constructs an object representing URL data including the base URL, path, and query parameters. | ||
* | ||
* @param {string} url - The full URL. | ||
* @param {Object} [params] - Additional query parameters. | ||
* @returns {Object} Contains baseUrl, path, and merged query parameters. | ||
*/ | ||
function constructURLData(url, params = {}) { | ||
if (!url) { | ||
return { baseUrl: undefined, path: undefined, queryParams: {} }; | ||
} | ||
return exports.describeRequestData({ method: methodUppercase, url: url, guid: guid }); | ||
}; | ||
|
||
exports.describeRequestData = function ({ method, url, guid } = {}) { | ||
const guidDescription = guid ? `, guid: ${guid}` : ''; | ||
return `[method: ${method}, url: ${url}` + guidDescription + ']'; | ||
}; | ||
const urlObj = new URL(url); | ||
const queryParams = { ...params }; | ||
|
||
urlObj.searchParams.forEach((value, key) => { | ||
queryParams[key] = value; | ||
}); | ||
|
||
const baseUrl = `${urlObj.protocol}//${urlObj.hostname}${urlObj.port ? `:${urlObj.port}` : ''}`; | ||
|
||
return { | ||
baseUrl: baseUrl, | ||
path: urlObj.pathname, | ||
...queryParams, | ||
}; | ||
} | ||
|
||
/** | ||
* @param {string} url - The URL to describe. | ||
* @param {Object} [options] - Options for describing attributes. | ||
* @param {Array<string>} [options.overrideAttributesDescribedWithValues] | ||
* @param {Array<string>} [options.overrideAttributesDescribedWithoutValues] | ||
* @returns {string} A string describing the URL. | ||
*/ | ||
function describeURL( | ||
url, | ||
{ | ||
overrideAttributesDescribedWithValues, | ||
overrideAttributesDescribedWithoutValues | ||
} = {} | ||
) { | ||
const describingAttributesWithValues = resolveAttributeList( | ||
DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITH_VALUES, | ||
overrideAttributesDescribedWithValues | ||
); | ||
|
||
const describingAttributesWithoutValues = resolveAttributeList( | ||
DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITHOUT_VALUES, | ||
overrideAttributesDescribedWithoutValues | ||
); | ||
|
||
const urlData = constructURLData(url); | ||
|
||
return LoggingUtil.describeAttributes( | ||
urlData, | ||
describingAttributesWithValues, | ||
describingAttributesWithoutValues | ||
); | ||
} | ||
|
||
exports.DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITH_VALUES = DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITH_VALUES; | ||
exports.DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITHOUT_VALUES = DEFAULT_ATTRIBUTES_DESCRIBING_REQUEST_WITHOUT_VALUES; | ||
|
||
exports.describeRequestFromOptions = describeRequestFromOptions; | ||
exports.describeRequestFromResponse = describeRequestFromResponse; | ||
exports.describeURL = describeURL; |
Oops, something went wrong.