From ea4b30d6ef3ea4b5561fa0a402c65db08477e8fe Mon Sep 17 00:00:00 2001 From: Yury Shkoda Date: Mon, 31 Jul 2023 16:34:09 +0300 Subject: [PATCH 1/3] feat(request-client): made verbose mode easier to configure --- README.md | 8 ++++++-- src/SASjs.ts | 25 +++++++++++++++++++++++-- src/minified/sas9/SASjs.ts | 3 ++- src/request/RequestClient.ts | 5 ++++- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b08ef9c..8997f5d 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,11 @@ The `request()` method also has optional parameters such as a config object and The response object will contain returned tables and columns. Table names are always lowercase, and column names uppercase. -The adapter will also cache the logs (if debug enabled) and even the work tables. For performance, it is best to keep debug mode off. +The adapter will also cache the logs (if debug enabled) and even the work tables. For performance, it is best to keep debug mode off. + +### Verbose Mode + +Enabling debug will also enable a verbose mode that logs a summary of every HTTP response. Verbose mode can be disabled by calling `disableVerboseMode` method or enabled by `enableVerboseMode` method. Verbose mode can also be enabled/disabled by `startComputeJob` method. ### Session Manager @@ -272,7 +276,7 @@ Configuration on the client side involves passing an object on startup, which ca * `appLoc` - this is the folder (eg in metadata or SAS Drive) under which the SAS services are created. * `serverType` - either `SAS9`, `SASVIYA` or `SASJS`. The `SASJS` server type is for use with [sasjs/server](https://github.com/sasjs/server). * `serverUrl` - the location (including http protocol and port) of the SAS Server. Can be omitted, eg if serving directly from the SAS Web Server, or in streaming mode. -* `debug` - if `true` then SAS Logs and extra debug information is returned. +* `debug` - if `true` then SAS Logs and extra debug information is returned. Setting debug to true will also enable a verbose mode that will log every HTTP response summary. * `loginMechanism` - either `Default` or `Redirected`. See [SAS Logon](#sas-logon) section. * `useComputeApi` - Only relevant when the serverType is `SASVIYA`. If `true` the [Compute API](#using-the-compute-api) is used. If `false` the [JES API](#using-the-jes-api) is used. If `null` or `undefined` the [Web](#using-jes-web-app) approach is used. * `contextName` - Compute context on which the requests will be called. If missing or not provided, defaults to `Job Execution Compute context`. diff --git a/src/SASjs.ts b/src/SASjs.ts index c7ed3c0..6dc67b1 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -31,6 +31,7 @@ import { } from './job-execution' import { ErrorResponse } from './types/errors' import { LoginOptions, LoginResult } from './types/Login' +import { AxiosResponse } from 'axios' interface ExecuteScriptParams { linesOfCode: string[] @@ -880,7 +881,7 @@ export default class SASjs { } if (verboseMode) this.requestClient?.enableVerboseMode() - else this.requestClient?.disableVerboseMode() + else if (verboseMode === false) this.requestClient?.disableVerboseMode() return this.sasViyaApiClient?.executeComputeJob( sasJob, @@ -975,7 +976,8 @@ export default class SASjs { this.requestClient = new RequestClientClass( this.sasjsConfig.serverUrl, this.sasjsConfig.httpsAgentOptions, - this.sasjsConfig.requestHistoryLimit + this.sasjsConfig.requestHistoryLimit, + this.sasjsConfig.debug // enable verbose mode if debug is true ) } else { this.requestClient.setConfig( @@ -1139,4 +1141,23 @@ export default class SASjs { ) } } + + /** + * Enables verbose mode that will log a summary of every HTTP response. + * @param successCallBack - function that should be triggered on every HTTP response with the status 2**. + * @param errorCallBack - function that should be triggered on every HTTP response with the status different from 2**. + */ + public enableVerboseMode( + successCallBack?: (response: AxiosResponse) => AxiosResponse, + errorCallBack?: (response: AxiosResponse) => AxiosResponse + ) { + this.requestClient?.enableVerboseMode(successCallBack, errorCallBack) + } + + /** + * Turns off verbose mode to log every HTTP response. + */ + public disableVerboseMode() { + this.requestClient?.disableVerboseMode() + } } diff --git a/src/minified/sas9/SASjs.ts b/src/minified/sas9/SASjs.ts index 5832cb6..91d9a95 100644 --- a/src/minified/sas9/SASjs.ts +++ b/src/minified/sas9/SASjs.ts @@ -233,7 +233,8 @@ export default class SASjs { this.requestClient = new RequestClient( this.sasjsConfig.serverUrl, this.sasjsConfig.httpsAgentOptions, - this.sasjsConfig.requestHistoryLimit + this.sasjsConfig.requestHistoryLimit, + this.sasjsConfig.debug // enable verbose mode if debug is true ) } else { this.requestClient.setConfig( diff --git a/src/request/RequestClient.ts b/src/request/RequestClient.ts index 6d45a9e..181cbb0 100644 --- a/src/request/RequestClient.ts +++ b/src/request/RequestClient.ts @@ -69,11 +69,14 @@ export class RequestClient implements HttpClient { constructor( protected baseUrl: string, httpsAgentOptions?: https.AgentOptions, - requestsLimit?: number + requestsLimit?: number, + verboseMode?: boolean ) { this.createHttpClient(baseUrl, httpsAgentOptions) if (requestsLimit) this.requestsLimit = requestsLimit + + if (verboseMode) this.enableVerboseMode() } public setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions) { From 2119c81ebb4fbb482a8f161aecdc91a93c2e8942 Mon Sep 17 00:00:00 2001 From: Yury Shkoda Date: Mon, 31 Jul 2023 17:37:39 +0300 Subject: [PATCH 2/3] feat(sasjs-config): added verbose option --- README.md | 3 ++- src/SASjs.ts | 2 +- src/minified/sas9/SASjs.ts | 2 +- src/minified/sas9/WebJobExecutor.ts | 1 - src/types/SASjsConfig.ts | 4 ++++ 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8997f5d..ce0196f 100644 --- a/README.md +++ b/README.md @@ -276,7 +276,8 @@ Configuration on the client side involves passing an object on startup, which ca * `appLoc` - this is the folder (eg in metadata or SAS Drive) under which the SAS services are created. * `serverType` - either `SAS9`, `SASVIYA` or `SASJS`. The `SASJS` server type is for use with [sasjs/server](https://github.com/sasjs/server). * `serverUrl` - the location (including http protocol and port) of the SAS Server. Can be omitted, eg if serving directly from the SAS Web Server, or in streaming mode. -* `debug` - if `true` then SAS Logs and extra debug information is returned. Setting debug to true will also enable a verbose mode that will log every HTTP response summary. +* `debug` - if `true` then SAS Logs and extra debug information is returned. +* `verbose` - optional, if `true` then a summary of every HTTP response is logged. * `loginMechanism` - either `Default` or `Redirected`. See [SAS Logon](#sas-logon) section. * `useComputeApi` - Only relevant when the serverType is `SASVIYA`. If `true` the [Compute API](#using-the-compute-api) is used. If `false` the [JES API](#using-the-jes-api) is used. If `null` or `undefined` the [Web](#using-jes-web-app) approach is used. * `contextName` - Compute context on which the requests will be called. If missing or not provided, defaults to `Job Execution Compute context`. diff --git a/src/SASjs.ts b/src/SASjs.ts index 6dc67b1..e071ecc 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -977,7 +977,7 @@ export default class SASjs { this.sasjsConfig.serverUrl, this.sasjsConfig.httpsAgentOptions, this.sasjsConfig.requestHistoryLimit, - this.sasjsConfig.debug // enable verbose mode if debug is true + this.sasjsConfig.verbose ) } else { this.requestClient.setConfig( diff --git a/src/minified/sas9/SASjs.ts b/src/minified/sas9/SASjs.ts index 91d9a95..301369d 100644 --- a/src/minified/sas9/SASjs.ts +++ b/src/minified/sas9/SASjs.ts @@ -234,7 +234,7 @@ export default class SASjs { this.sasjsConfig.serverUrl, this.sasjsConfig.httpsAgentOptions, this.sasjsConfig.requestHistoryLimit, - this.sasjsConfig.debug // enable verbose mode if debug is true + this.sasjsConfig.verbose ) } else { this.requestClient.setConfig( diff --git a/src/minified/sas9/WebJobExecutor.ts b/src/minified/sas9/WebJobExecutor.ts index 4cf9393..61a2fbe 100644 --- a/src/minified/sas9/WebJobExecutor.ts +++ b/src/minified/sas9/WebJobExecutor.ts @@ -11,7 +11,6 @@ import { import { RequestClient } from '../../request/RequestClient' import { isRelativePath, - parseSasViyaDebugResponse, appendExtraResponseAttributes, convertToCSV } from '../../utils' diff --git a/src/types/SASjsConfig.ts b/src/types/SASjsConfig.ts index f366713..d2c0536 100644 --- a/src/types/SASjsConfig.ts +++ b/src/types/SASjsConfig.ts @@ -45,6 +45,10 @@ export class SASjsConfig { * Set to `true` to enable additional debugging. */ debug: boolean = true + /** + * Set to `true` to enable verbose mode that will log a summary of every HTTP response. + */ + verbose?: boolean = true /** * The name of the compute context to use when calling the Viya services directly. * Example value: 'SAS Job Execution compute context' From e511cd613ccfb039189c7e6406dd4dcf505b3533 Mon Sep 17 00:00:00 2001 From: Yury Shkoda Date: Mon, 31 Jul 2023 17:41:04 +0300 Subject: [PATCH 3/3] docs(verbose): fixed docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ce0196f..37234c0 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ The adapter will also cache the logs (if debug enabled) and even the work tables ### Verbose Mode -Enabling debug will also enable a verbose mode that logs a summary of every HTTP response. Verbose mode can be disabled by calling `disableVerboseMode` method or enabled by `enableVerboseMode` method. Verbose mode can also be enabled/disabled by `startComputeJob` method. +Set `verbose` to `true` to enable verbose mode that logs a summary of every HTTP response. Verbose mode can be disabled by calling `disableVerboseMode` method or enabled by `enableVerboseMode` method. Verbose mode can also be enabled/disabled by `startComputeJob` method. ### Session Manager