Skip to content

Commit 63511e5

Browse files
K4ST0Rleibale
andauthored
Add latency graph command (#2359)
* add latency graph command * fix coding style * Clean code * use "enable-debug-command" is redis 7+ only * Update LATENCY_GRAPH.spec.ts Co-authored-by: Leibale Eidelman <me@leibale.com>
1 parent fad2397 commit 63511e5

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

packages/client/lib/client/commands.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ import * as HELLO from '../commands/HELLO';
8181
import * as INFO from '../commands/INFO';
8282
import * as KEYS from '../commands/KEYS';
8383
import * as LASTSAVE from '../commands/LASTSAVE';
84+
import * as LATENCY_DOCTOR from '../commands/LATENCY_DOCTOR';
85+
import * as LATENCY_GRAPH from '../commands/LATENCY_GRAPH';
8486
import * as LOLWUT from '../commands/LOLWUT';
8587
import * as MEMORY_DOCTOR from '../commands/MEMORY_DOCTOR';
8688
import * as MEMORY_MALLOC_STATS from '../commands/MEMORY_MALLOC-STATS';
@@ -113,7 +115,6 @@ import * as SWAPDB from '../commands/SWAPDB';
113115
import * as TIME from '../commands/TIME';
114116
import * as UNWATCH from '../commands/UNWATCH';
115117
import * as WAIT from '../commands/WAIT';
116-
import * as LATENCY_DOCTOR from '../commands/LATENCY_DOCTOR';
117118

118119
export default {
119120
...CLUSTER_COMMANDS,
@@ -283,6 +284,8 @@ export default {
283284
lastSave: LASTSAVE,
284285
LATENCY_DOCTOR,
285286
latencyDoctor: LATENCY_DOCTOR,
287+
LATENCY_GRAPH,
288+
latencyGraph: LATENCY_GRAPH,
286289
LOLWUT,
287290
lolwut: LOLWUT,
288291
MEMORY_DOCTOR,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './LATENCY_GRAPH';
4+
5+
describe('LATENCY GRAPH', () => {
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
transformArguments('command'),
9+
[
10+
'LATENCY',
11+
'GRAPH',
12+
'command'
13+
]
14+
);
15+
});
16+
17+
testUtils.testWithClient('client.latencyGraph', async client => {
18+
await Promise.all([
19+
client.configSet('latency-monitor-threshold', '1'),
20+
client.sendCommand(['DEBUG', 'SLEEP', '0.001'])
21+
]);
22+
23+
assert.equal(
24+
typeof await client.latencyGraph('command'),
25+
'string'
26+
);
27+
}, {
28+
serverArguments: testUtils.isVersionGreaterThan([7]) ?
29+
['--enable-debug-command', 'yes'] :
30+
GLOBAL.SERVERS.OPEN.serverArguments
31+
});
32+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { RedisCommandArguments } from '.';
2+
3+
export type EventType =
4+
'active-defrag-cycle'
5+
| 'aof-fsync-always'
6+
| 'aof-stat'
7+
| 'aof-rewrite-diff-write'
8+
| 'aof-rename'
9+
| 'aof-write'
10+
| 'aof-write-active-child'
11+
| 'aof-write-alone'
12+
| 'aof-write-pending-fsync'
13+
| 'command'
14+
| 'expire-cycle'
15+
| 'eviction-cycle'
16+
| 'eviction-del'
17+
| 'fast-command'
18+
| 'fork'
19+
| 'rdb-unlink-temp-file';
20+
21+
export function transformArguments(event: EventType): RedisCommandArguments {
22+
return ['LATENCY', 'GRAPH', event];
23+
}
24+
25+
export declare function transformReply(): string;

0 commit comments

Comments
 (0)