Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KXI-45990 Add option to disable hydrate from insights #308

Merged
merged 3 commits into from
May 20, 2024
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export namespace ext {
export const connectedContextStrings: Array<string> = [];
export const connectionsList: Array<KdbNode | InsightsNode> = [];
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";
Expand Down
37 changes: 24 additions & 13 deletions src/services/connectionManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { sanitizeQuery } from "../utils/queryUtils";
import {
getHash,
getInsights,
getInsightsHydrate,
getNetworkChangesWatcher,
getServerName,
getServers,
removeLocalConnectionContext,
Expand Down Expand Up @@ -121,6 +123,7 @@ export class ConnectionManagementService {
refreshDataSourcesPanel();
}
if (ext.connectedConnectionList.length === 1) {
getNetworkChangesWatcher();
this.startMonitoringNetworkConn();
this.rehidrateInsightsConnections();
}
Expand Down Expand Up @@ -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();
}
}
}

Expand All @@ -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);
Expand All @@ -370,12 +378,15 @@ export class ConnectionManagementService {
/* istanbul ignore next */
public async rehidrateInsightsConnections(): Promise<void> {
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);
}
}
29 changes: 29 additions & 0 deletions src/utils/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,35 @@ export function getHideDetailedConsoleQueryOutput(): void {
ext.hideDetailedConsoleQueryOutput = setting;
}
}

export function getNetworkChangesWatcher(): void {
const setting = workspace
.getConfiguration()
.get<boolean | undefined>("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<boolean | undefined>("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]");
Expand Down
158 changes: 118 additions & 40 deletions test/suite/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
Loading