diff --git a/package-lock.json b/package-lock.json index ea13f79b..4e36204f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@vscode/webview-ui-toolkit": "^1.4.0", "@windozer/node-q": "^2.6.0", "ag-grid-community": "^31.3.1", - "axios": "^1.6.8", + "axios": "^1.7.0", "chevrotain": "^10.5.0", "csv-parser": "^3.0.0", "extract-zip": "^2.0.1", @@ -1670,9 +1670,9 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", - "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.0.tgz", + "integrity": "sha512-IiB0wQeKyPRdsFVhBgIo31FbzOyf2M6wYl7/NVutFwFBRMiAbjNiydJIHKeLmPugF4kJLfA1uWZ82Is2QzqqFA==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/package.json b/package.json index 28f8801e..e831f057 100644 --- a/package.json +++ b/package.json @@ -170,6 +170,16 @@ "description": "Hide detailed console query output", "default": true }, + "kdb.networkChangesWatcher": { + "type": "boolean", + "description": "Watch for network changes, if changes are detected, check if the Insights connection is still valid", + "default": true + }, + "kdb.insightsHydrate": { + "type": "boolean", + "description": "Hydrate the insights connection every 1 minute to keep it alive", + "default": true + }, "kdb.qHomeDirectory": { "type": "string", "description": "QHOME directory for q runtime" @@ -832,7 +842,7 @@ "@vscode/webview-ui-toolkit": "^1.4.0", "@windozer/node-q": "^2.6.0", "ag-grid-community": "^31.3.1", - "axios": "^1.6.8", + "axios": "^1.7.0", "chevrotain": "^10.5.0", "csv-parser": "^3.0.0", "extract-zip": "^2.0.1", diff --git a/src/extensionVariables.ts b/src/extensionVariables.ts index d295b420..5192b5d1 100644 --- a/src/extensionVariables.ts +++ b/src/extensionVariables.ts @@ -68,6 +68,8 @@ export namespace ext { export const connectedContextStrings: Array = []; export const connectionsList: Array = []; export let hideDetailedConsoleQueryOutput: boolean; + export let networkChangesWatcher: boolean; + export let insightsHydrate: boolean; export let connectionNode: KdbNode | InsightsNode | undefined; export const kdbDataSourceFolder = ".kdb-datasources"; export const kdbDataSourceFileExtension = ".ds"; diff --git a/src/services/connectionManagerService.ts b/src/services/connectionManagerService.ts index 80269933..6271d44e 100644 --- a/src/services/connectionManagerService.ts +++ b/src/services/connectionManagerService.ts @@ -22,6 +22,8 @@ import { sanitizeQuery } from "../utils/queryUtils"; import { getHash, getInsights, + getInsightsHydrate, + getNetworkChangesWatcher, getServerName, getServers, removeLocalConnectionContext, @@ -121,6 +123,7 @@ export class ConnectionManagementService { refreshDataSourcesPanel(); } if (ext.connectedConnectionList.length === 1) { + getNetworkChangesWatcher(); this.startMonitoringNetworkConn(); this.rehidrateInsightsConnections(); } @@ -341,10 +344,12 @@ export class ConnectionManagementService { } }); await Promise.all(checks); - if (whoTriggered === "networkMonitoring") { - this.startMonitoringNetworkConn(); - } else { - this.rehidrateInsightsConnections(); + if (ext.connectedConnectionList.length > 0) { + if (whoTriggered === "networkMonitoring") { + this.startMonitoringNetworkConn(); + } else { + this.rehidrateInsightsConnections(); + } } } @@ -357,9 +362,12 @@ export class ConnectionManagementService { JSON.stringify(previousNetworkState) !== JSON.stringify(currentNetworkState) ) { - clearInterval(intervalId); - previousNetworkState = currentNetworkState; - this.checkInsightsConnectionIsAlive("networkMonitoring"); + getNetworkChangesWatcher(); + if (ext.networkChangesWatcher) { + clearInterval(intervalId); + previousNetworkState = currentNetworkState; + this.checkInsightsConnectionIsAlive("networkMonitoring"); + } } if (ext.connectedConnectionList.length === 0) { clearInterval(intervalId); @@ -370,12 +378,15 @@ export class ConnectionManagementService { /* istanbul ignore next */ public async rehidrateInsightsConnections(): Promise { const intervalConns = setInterval(() => { - if (ext.connectedConnectionList.length > 0) { - clearInterval(intervalConns); - this.checkInsightsConnectionIsAlive("rehidrateConnections"); - } else { - clearInterval(intervalConns); + getInsightsHydrate(); + if (ext.insightsHydrate) { + if (ext.connectedConnectionList.length > 0) { + clearInterval(intervalConns); + this.checkInsightsConnectionIsAlive("rehidrateConnections"); + } else { + clearInterval(intervalConns); + } } - }, 120000); + }, 60000); } } diff --git a/src/utils/core.ts b/src/utils/core.ts index 6a2f013b..fca0fba8 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -188,6 +188,35 @@ export function getHideDetailedConsoleQueryOutput(): void { ext.hideDetailedConsoleQueryOutput = setting; } } + +export function getNetworkChangesWatcher(): void { + const setting = workspace + .getConfiguration() + .get("kdb.networkChangesWatcher"); + if (setting === undefined) { + workspace + .getConfiguration() + .update("kdb.networkChangesWatcher", true, ConfigurationTarget.Global); + ext.networkChangesWatcher = true; + } else { + ext.networkChangesWatcher = setting; + } +} + +export function getInsightsHydrate(): void { + const setting = workspace + .getConfiguration() + .get("kdb.insightsHydrate"); + if (setting === undefined) { + workspace + .getConfiguration() + .update("kdb.insightsHydrate", true, ConfigurationTarget.Global); + ext.insightsHydrate = true; + } else { + ext.insightsHydrate = setting; + } +} + export function setOutputWordWrapper(): void { let existWrap = false; const logConfig = workspace.getConfiguration("[Log]"); diff --git a/test/suite/utils.test.ts b/test/suite/utils.test.ts index a2fb6611..820247b5 100644 --- a/test/suite/utils.test.ts +++ b/test/suite/utils.test.ts @@ -111,71 +111,149 @@ describe("Utils", () => { getConfigurationStub.restore(); }); - describe("server alias", () => { - beforeEach(() => { - ext.kdbConnectionAliasList.length = 0; + it("should update configuration and set hideDetailedConsoleQueryOutput to true when setting is undefined", async () => { + getConfigurationStub.returns({ + get: sinon.stub().returns(undefined), + update: sinon.stub(), }); - afterEach(() => { - ext.kdbConnectionAliasList.length = 0; + await coreUtils.getHideDetailedConsoleQueryOutput(); + + sinon.assert.calledTwice(getConfigurationStub); + assert.strictEqual(ext.hideDetailedConsoleQueryOutput, true); + }); + + it("should set hideDetailedConsoleQueryOutput to setting when setting is defined", async () => { + getConfigurationStub.returns({ + get: sinon.stub().returns(false), + update: sinon.stub(), }); - it("should add insights alias to the list getInsightsAlias", () => { - const insightsDetail: InsightDetails = { - alias: "test", - server: "test", - auth: true, - }; - coreUtils.getInsightsAlias([insightsDetail]); - assert.strictEqual(ext.kdbConnectionAliasList.length, 1); + await coreUtils.getHideDetailedConsoleQueryOutput(); + + sinon.assert.calledOnce(getConfigurationStub); + assert.strictEqual(ext.hideDetailedConsoleQueryOutput, false); + }); + }); + + describe("getNetworkChangesWatcher", () => { + let getConfigurationStub: sinon.SinonStub; + + beforeEach(() => { + getConfigurationStub = sinon.stub( + vscode.workspace, + "getConfiguration", + ) as sinon.SinonStub; + }); + + afterEach(() => { + getConfigurationStub.restore(); + }); + + it("should update configuration and set getNetworkChangesWatcher to true when setting is undefined", async () => { + getConfigurationStub.returns({ + get: sinon.stub().returns(undefined), + update: sinon.stub(), }); - it("should add alias only from kdb server that have alias using getServerAlias", () => { - const serverList: ServerDetails[] = [ - { - serverName: "test", - serverAlias: "test", - serverPort: "5001", - managed: false, - auth: false, - tls: false, - }, - { - serverName: "test2", - serverAlias: undefined, - serverPort: "5001", - managed: false, - auth: false, - tls: false, - }, - ]; - coreUtils.getServerAlias(serverList); - assert.strictEqual(ext.kdbConnectionAliasList.length, 1); + await coreUtils.getNetworkChangesWatcher(); + + sinon.assert.calledTwice(getConfigurationStub); + assert.strictEqual(ext.networkChangesWatcher, true); + }); + + it("should set getNetworkChangesWatcher to setting when setting is defined", async () => { + getConfigurationStub.returns({ + get: sinon.stub().returns(false), + update: sinon.stub(), }); + + await coreUtils.getNetworkChangesWatcher(); + + sinon.assert.calledOnce(getConfigurationStub); + assert.strictEqual(ext.networkChangesWatcher, false); }); + }); - it("should update configuration and set hideDetailedConsoleQueryOutput to true when setting is undefined", async () => { + describe("getInsightsHydrate", () => { + let getConfigurationStub: sinon.SinonStub; + + beforeEach(() => { + getConfigurationStub = sinon.stub( + vscode.workspace, + "getConfiguration", + ) as sinon.SinonStub; + }); + + afterEach(() => { + getConfigurationStub.restore(); + }); + + it("should update configuration and set getInsightsHydrate to true when setting is undefined", async () => { getConfigurationStub.returns({ get: sinon.stub().returns(undefined), update: sinon.stub(), }); - await coreUtils.getHideDetailedConsoleQueryOutput(); + await coreUtils.getInsightsHydrate(); sinon.assert.calledTwice(getConfigurationStub); - assert.strictEqual(ext.hideDetailedConsoleQueryOutput, true); + assert.strictEqual(ext.insightsHydrate, true); }); - it("should set hideDetailedConsoleQueryOutput to setting when setting is defined", async () => { + it("should set getInsightsHydrate to setting when setting is defined", async () => { getConfigurationStub.returns({ get: sinon.stub().returns(false), update: sinon.stub(), }); - await coreUtils.getHideDetailedConsoleQueryOutput(); + await coreUtils.getInsightsHydrate(); sinon.assert.calledOnce(getConfigurationStub); - assert.strictEqual(ext.hideDetailedConsoleQueryOutput, false); + assert.strictEqual(ext.insightsHydrate, false); + }); + }); + + describe("server alias", () => { + beforeEach(() => { + ext.kdbConnectionAliasList.length = 0; + }); + + afterEach(() => { + ext.kdbConnectionAliasList.length = 0; + }); + + it("should add insights alias to the list getInsightsAlias", () => { + const insightsDetail: InsightDetails = { + alias: "test", + server: "test", + auth: true, + }; + coreUtils.getInsightsAlias([insightsDetail]); + assert.strictEqual(ext.kdbConnectionAliasList.length, 1); + }); + + it("should add alias only from kdb server that have alias using getServerAlias", () => { + const serverList: ServerDetails[] = [ + { + serverName: "test", + serverAlias: "test", + serverPort: "5001", + managed: false, + auth: false, + tls: false, + }, + { + serverName: "test2", + serverAlias: undefined, + serverPort: "5001", + managed: false, + auth: false, + tls: false, + }, + ]; + coreUtils.getServerAlias(serverList); + assert.strictEqual(ext.kdbConnectionAliasList.length, 1); }); });