From 26ad2ed8147fda4363bf205bbbd8ff9eeffc75d2 Mon Sep 17 00:00:00 2001 From: Kumar Arnav <36244620+Karnav123@users.noreply.github.com> Date: Thu, 18 May 2023 09:51:40 +0000 Subject: [PATCH 1/7] Add support for LATENCY LATEST. --- packages/client/lib/client/commands.ts | 3 +++ .../client/lib/commands/LATENCY_LATEST.spec.ts | 18 ++++++++++++++++++ packages/client/lib/commands/LATENCY_LATEST.ts | 14 ++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 packages/client/lib/commands/LATENCY_LATEST.spec.ts create mode 100644 packages/client/lib/commands/LATENCY_LATEST.ts diff --git a/packages/client/lib/client/commands.ts b/packages/client/lib/client/commands.ts index 2605962432a..1e2e5274c0a 100644 --- a/packages/client/lib/client/commands.ts +++ b/packages/client/lib/client/commands.ts @@ -84,6 +84,7 @@ import * as KEYS from '../commands/KEYS'; import * as LASTSAVE from '../commands/LASTSAVE'; import * as LATENCY_DOCTOR from '../commands/LATENCY_DOCTOR'; import * as LATENCY_GRAPH from '../commands/LATENCY_GRAPH'; +import * as LATENCY_LATEST from '../commands/LATENCY_LATEST'; import * as LOLWUT from '../commands/LOLWUT'; import * as MEMORY_DOCTOR from '../commands/MEMORY_DOCTOR'; import * as MEMORY_MALLOC_STATS from '../commands/MEMORY_MALLOC-STATS'; @@ -290,6 +291,8 @@ export default { latencyDoctor: LATENCY_DOCTOR, LATENCY_GRAPH, latencyGraph: LATENCY_GRAPH, + LATENCY_LATEST, + latencyLatest: LATENCY_LATEST, LOLWUT, lolwut: LOLWUT, MEMORY_DOCTOR, diff --git a/packages/client/lib/commands/LATENCY_LATEST.spec.ts b/packages/client/lib/commands/LATENCY_LATEST.spec.ts new file mode 100644 index 00000000000..f52515149c1 --- /dev/null +++ b/packages/client/lib/commands/LATENCY_LATEST.spec.ts @@ -0,0 +1,18 @@ +import {strict as assert} from 'assert'; +import testUtils, {GLOBAL} from '../test-utils'; +import { transformArguments } from './LATENCY_LATEST'; + +describe('LATENCY LATEST', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(), + ['LATENCY', 'LATEST'] + ); + }); + + testUtils.testWithClient('client.latencyLatest', async client => { + const latency = await client.latencyLatest(); + const latencyType = Array.isArray(latency); + assert.strictEqual(latencyType, true); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/LATENCY_LATEST.ts b/packages/client/lib/commands/LATENCY_LATEST.ts new file mode 100644 index 00000000000..48cac1212a1 --- /dev/null +++ b/packages/client/lib/commands/LATENCY_LATEST.ts @@ -0,0 +1,14 @@ +import { RedisCommandArguments } from '.'; + +export interface latenctStats{ + event : string, + timestamp: number, + latestLatency: number, + allTimeLatency: number +} + +export function transformArguments(): RedisCommandArguments { + return ['LATENCY', 'LATEST']; +} + +export declare function transformReply(): Array; From 99cd8b083eee50ca631c41d52d6971884a452bed Mon Sep 17 00:00:00 2001 From: Kumar Arnav <36244620+Karnav123@users.noreply.github.com> Date: Sun, 21 May 2023 14:49:06 +0000 Subject: [PATCH 2/7] Fix the review comments. --- .../client/lib/commands/LATENCY_LATEST.spec.ts | 13 +++++++++++-- packages/client/lib/commands/LATENCY_LATEST.ts | 14 ++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/client/lib/commands/LATENCY_LATEST.spec.ts b/packages/client/lib/commands/LATENCY_LATEST.spec.ts index f52515149c1..6ff748ebfb2 100644 --- a/packages/client/lib/commands/LATENCY_LATEST.spec.ts +++ b/packages/client/lib/commands/LATENCY_LATEST.spec.ts @@ -11,8 +11,17 @@ describe('LATENCY LATEST', () => { }); testUtils.testWithClient('client.latencyLatest', async client => { + await Promise.all([ + client.configSet('latency-monitor-threshold', '100'), + client.sendCommand(['DEBUG', 'SLEEP', '1']) + ]); const latency = await client.latencyLatest(); - const latencyType = Array.isArray(latency); - assert.strictEqual(latencyType, true); + assert.ok(Array.isArray(latency)); + for (const event of latency) { + assert.ok(typeof event.name === 'string', 'Name should be a string'); + assert.ok(typeof event.timestamp === 'number', 'Timestamp should be a number'); + assert.ok(typeof event.latestLatency === 'number', 'Latest latency should be a number'); + assert.ok(typeof event.allTimeLatency === 'number', 'All-time latency should be a number'); + } }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/client/lib/commands/LATENCY_LATEST.ts b/packages/client/lib/commands/LATENCY_LATEST.ts index 48cac1212a1..f30b5488d45 100644 --- a/packages/client/lib/commands/LATENCY_LATEST.ts +++ b/packages/client/lib/commands/LATENCY_LATEST.ts @@ -1,14 +1,12 @@ import { RedisCommandArguments } from '.'; -export interface latenctStats{ - event : string, - timestamp: number, - latestLatency: number, - allTimeLatency: number -} - export function transformArguments(): RedisCommandArguments { return ['LATENCY', 'LATEST']; } -export declare function transformReply(): Array; +export declare function transformReply(): Array<[ + name: string, + timestamp: number, + latestLatency: number, + allTimeLatency: number + ]>; From 4292a345a5d94658c7230da1c10444916776d4f1 Mon Sep 17 00:00:00 2001 From: Kumar Arnav <36244620+Karnav123@users.noreply.github.com> Date: Thu, 25 May 2023 08:49:13 +0000 Subject: [PATCH 3/7] Fix the review comments. --- packages/client/lib/commands/LATENCY_LATEST.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/client/lib/commands/LATENCY_LATEST.spec.ts b/packages/client/lib/commands/LATENCY_LATEST.spec.ts index 6ff748ebfb2..4087f212139 100644 --- a/packages/client/lib/commands/LATENCY_LATEST.spec.ts +++ b/packages/client/lib/commands/LATENCY_LATEST.spec.ts @@ -17,11 +17,11 @@ describe('LATENCY LATEST', () => { ]); const latency = await client.latencyLatest(); assert.ok(Array.isArray(latency)); - for (const event of latency) { - assert.ok(typeof event.name === 'string', 'Name should be a string'); - assert.ok(typeof event.timestamp === 'number', 'Timestamp should be a number'); - assert.ok(typeof event.latestLatency === 'number', 'Latest latency should be a number'); - assert.ok(typeof event.allTimeLatency === 'number', 'All-time latency should be a number'); + for (const [name, timestamp, latestLatency, allTimeLatency] of latency) { + assert.equal(typeof name, 'string'); + assert.equal(typeof timestamp, 'number'); + assert.equal(typeof latestLatency, 'number'); + assert.equal(typeof allTimeLatency, 'number'); } }, GLOBAL.SERVERS.OPEN); }); From d056978e26c87dd344d179fa81b2e3bd40c72b82 Mon Sep 17 00:00:00 2001 From: Leibale Eidelman Date: Sun, 28 May 2023 07:38:49 -0400 Subject: [PATCH 4/7] Update LATENCY_LATEST.ts --- packages/client/lib/commands/LATENCY_LATEST.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/lib/commands/LATENCY_LATEST.ts b/packages/client/lib/commands/LATENCY_LATEST.ts index f30b5488d45..3e4dd6236c6 100644 --- a/packages/client/lib/commands/LATENCY_LATEST.ts +++ b/packages/client/lib/commands/LATENCY_LATEST.ts @@ -9,4 +9,4 @@ export declare function transformReply(): Array<[ timestamp: number, latestLatency: number, allTimeLatency: number - ]>; +]>; From b79167d75791a294a5379c41d61df12b14eb7194 Mon Sep 17 00:00:00 2001 From: Leibale Eidelman Date: Sun, 28 May 2023 10:50:39 -0400 Subject: [PATCH 5/7] Update dockers.ts --- packages/test-utils/lib/dockers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/test-utils/lib/dockers.ts b/packages/test-utils/lib/dockers.ts index a7e1c610eee..e4ddbf1e1ed 100644 --- a/packages/test-utils/lib/dockers.ts +++ b/packages/test-utils/lib/dockers.ts @@ -55,7 +55,7 @@ async function spawnRedisServerDocker({ image, version }: RedisServerDockerConfi 'docker run -d --network host $(' + `docker build ${DOCKER_FODLER_PATH} -q ` + `--build-arg IMAGE=${image}:${version} ` + - `--build-arg REDIS_ARGUMENTS="--save '' --port ${port.toString()} ${serverArguments.join(' ')}"` + + `--build-arg REDIS_ARGUMENTS="--save '' --port ${port.toString()} --enable-debug-command yes ${serverArguments.join(' ')}"` + ')' ); From c68307c862fa0e6f1b4fd23c4b55cc4ef5c53ac9 Mon Sep 17 00:00:00 2001 From: Leibale Eidelman Date: Sun, 28 May 2023 10:51:17 -0400 Subject: [PATCH 6/7] Update LATENCY_GRAPH.spec.ts --- packages/client/lib/commands/LATENCY_GRAPH.spec.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/client/lib/commands/LATENCY_GRAPH.spec.ts b/packages/client/lib/commands/LATENCY_GRAPH.spec.ts index df4d5d466ab..21755a253b3 100644 --- a/packages/client/lib/commands/LATENCY_GRAPH.spec.ts +++ b/packages/client/lib/commands/LATENCY_GRAPH.spec.ts @@ -24,9 +24,5 @@ describe('LATENCY GRAPH', () => { typeof await client.latencyGraph('command'), 'string' ); - }, { - serverArguments: testUtils.isVersionGreaterThan([7]) ? - ['--enable-debug-command', 'yes'] : - GLOBAL.SERVERS.OPEN.serverArguments - }); + }, GLOBAL.SERVERS.OPEN); }); From 18cff90b1b891e622c10a289c6342e0755323256 Mon Sep 17 00:00:00 2001 From: Leibale Date: Mon, 29 May 2023 14:16:54 +0300 Subject: [PATCH 7/7] enable debug mode in tests --- packages/client/lib/test-utils.ts | 22 ++++++++++++++-------- packages/test-utils/lib/dockers.ts | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/client/lib/test-utils.ts b/packages/client/lib/test-utils.ts index 9032f1dd344..65d526f6019 100644 --- a/packages/client/lib/test-utils.ts +++ b/packages/client/lib/test-utils.ts @@ -2,18 +2,24 @@ import TestUtils from '@redis/test-utils'; import { SinonSpy } from 'sinon'; import { promiseTimeout } from './utils'; -export default new TestUtils({ - dockerImageName: 'redis', - dockerImageVersionArgument: 'redis-version' +const utils = new TestUtils({ + dockerImageName: 'redis', + dockerImageVersionArgument: 'redis-version' }); +export default utils; + +const DEBUG_MODE_ARGS = utils.isVersionGreaterThan([7]) ? + ['--enable-debug-command', 'yes'] : + []; + export const GLOBAL = { SERVERS: { OPEN: { - serverArguments: [] + serverArguments: [...DEBUG_MODE_ARGS] }, PASSWORD: { - serverArguments: ['--requirepass', 'password'], + serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS], clientOptions: { password: 'password' } @@ -21,10 +27,10 @@ export const GLOBAL = { }, CLUSTERS: { OPEN: { - serverArguments: [] + serverArguments: [...DEBUG_MODE_ARGS] }, PASSWORD: { - serverArguments: ['--requirepass', 'password'], + serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS], clusterConfiguration: { defaults: { password: 'password' @@ -32,7 +38,7 @@ export const GLOBAL = { } }, WITH_REPLICAS: { - serverArguments: [], + serverArguments: [...DEBUG_MODE_ARGS], numberOfMasters: 2, numberOfReplicas: 1, clusterConfiguration: { diff --git a/packages/test-utils/lib/dockers.ts b/packages/test-utils/lib/dockers.ts index e4ddbf1e1ed..a7e1c610eee 100644 --- a/packages/test-utils/lib/dockers.ts +++ b/packages/test-utils/lib/dockers.ts @@ -55,7 +55,7 @@ async function spawnRedisServerDocker({ image, version }: RedisServerDockerConfi 'docker run -d --network host $(' + `docker build ${DOCKER_FODLER_PATH} -q ` + `--build-arg IMAGE=${image}:${version} ` + - `--build-arg REDIS_ARGUMENTS="--save '' --port ${port.toString()} --enable-debug-command yes ${serverArguments.join(' ')}"` + + `--build-arg REDIS_ARGUMENTS="--save '' --port ${port.toString()} ${serverArguments.join(' ')}"` + ')' );