Skip to content

Commit e696653

Browse files
Karnav123leibale
andauthored
Add support for LATENCY LATEST (#2514)
* Add support for LATENCY LATEST. * Fix the review comments. * Fix the review comments. * Update LATENCY_LATEST.ts * Update dockers.ts * Update LATENCY_GRAPH.spec.ts * enable debug mode in tests --------- Co-authored-by: Leibale Eidelman <[email protected]>
1 parent 499ea85 commit e696653

File tree

5 files changed

+57
-13
lines changed

5 files changed

+57
-13
lines changed

packages/client/lib/client/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import * as KEYS from '../commands/KEYS';
8484
import * as LASTSAVE from '../commands/LASTSAVE';
8585
import * as LATENCY_DOCTOR from '../commands/LATENCY_DOCTOR';
8686
import * as LATENCY_GRAPH from '../commands/LATENCY_GRAPH';
87+
import * as LATENCY_LATEST from '../commands/LATENCY_LATEST';
8788
import * as LOLWUT from '../commands/LOLWUT';
8889
import * as MEMORY_DOCTOR from '../commands/MEMORY_DOCTOR';
8990
import * as MEMORY_MALLOC_STATS from '../commands/MEMORY_MALLOC-STATS';
@@ -290,6 +291,8 @@ export default {
290291
latencyDoctor: LATENCY_DOCTOR,
291292
LATENCY_GRAPH,
292293
latencyGraph: LATENCY_GRAPH,
294+
LATENCY_LATEST,
295+
latencyLatest: LATENCY_LATEST,
293296
LOLWUT,
294297
lolwut: LOLWUT,
295298
MEMORY_DOCTOR,

packages/client/lib/commands/LATENCY_GRAPH.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,5 @@ describe('LATENCY GRAPH', () => {
2424
typeof await client.latencyGraph('command'),
2525
'string'
2626
);
27-
}, {
28-
serverArguments: testUtils.isVersionGreaterThan([7]) ?
29-
['--enable-debug-command', 'yes'] :
30-
GLOBAL.SERVERS.OPEN.serverArguments
31-
});
27+
}, GLOBAL.SERVERS.OPEN);
3228
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {strict as assert} from 'assert';
2+
import testUtils, {GLOBAL} from '../test-utils';
3+
import { transformArguments } from './LATENCY_LATEST';
4+
5+
describe('LATENCY LATEST', () => {
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
transformArguments(),
9+
['LATENCY', 'LATEST']
10+
);
11+
});
12+
13+
testUtils.testWithClient('client.latencyLatest', async client => {
14+
await Promise.all([
15+
client.configSet('latency-monitor-threshold', '100'),
16+
client.sendCommand(['DEBUG', 'SLEEP', '1'])
17+
]);
18+
const latency = await client.latencyLatest();
19+
assert.ok(Array.isArray(latency));
20+
for (const [name, timestamp, latestLatency, allTimeLatency] of latency) {
21+
assert.equal(typeof name, 'string');
22+
assert.equal(typeof timestamp, 'number');
23+
assert.equal(typeof latestLatency, 'number');
24+
assert.equal(typeof allTimeLatency, 'number');
25+
}
26+
}, GLOBAL.SERVERS.OPEN);
27+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { RedisCommandArguments } from '.';
2+
3+
export function transformArguments(): RedisCommandArguments {
4+
return ['LATENCY', 'LATEST'];
5+
}
6+
7+
export declare function transformReply(): Array<[
8+
name: string,
9+
timestamp: number,
10+
latestLatency: number,
11+
allTimeLatency: number
12+
]>;

packages/client/lib/test-utils.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,43 @@ import TestUtils from '@redis/test-utils';
22
import { SinonSpy } from 'sinon';
33
import { promiseTimeout } from './utils';
44

5-
export default new TestUtils({
6-
dockerImageName: 'redis',
7-
dockerImageVersionArgument: 'redis-version'
5+
const utils = new TestUtils({
6+
dockerImageName: 'redis',
7+
dockerImageVersionArgument: 'redis-version'
88
});
99

10+
export default utils;
11+
12+
const DEBUG_MODE_ARGS = utils.isVersionGreaterThan([7]) ?
13+
['--enable-debug-command', 'yes'] :
14+
[];
15+
1016
export const GLOBAL = {
1117
SERVERS: {
1218
OPEN: {
13-
serverArguments: []
19+
serverArguments: [...DEBUG_MODE_ARGS]
1420
},
1521
PASSWORD: {
16-
serverArguments: ['--requirepass', 'password'],
22+
serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS],
1723
clientOptions: {
1824
password: 'password'
1925
}
2026
}
2127
},
2228
CLUSTERS: {
2329
OPEN: {
24-
serverArguments: []
30+
serverArguments: [...DEBUG_MODE_ARGS]
2531
},
2632
PASSWORD: {
27-
serverArguments: ['--requirepass', 'password'],
33+
serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS],
2834
clusterConfiguration: {
2935
defaults: {
3036
password: 'password'
3137
}
3238
}
3339
},
3440
WITH_REPLICAS: {
35-
serverArguments: [],
41+
serverArguments: [...DEBUG_MODE_ARGS],
3642
numberOfMasters: 2,
3743
numberOfReplicas: 1,
3844
clusterConfiguration: {

0 commit comments

Comments
 (0)