Skip to content

Commit 4ec97be

Browse files
fix #1956 - add support for LATENCY HISTORY (#2555)
* added support for LATENCY_HISTORY command * clean code * Update LATENCY_HISTORY.ts --------- Co-authored-by: Leibale Eidelman <[email protected]>
1 parent 6848f3d commit 4ec97be

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

packages/client/lib/client/commands.ts

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import * as KEYS from '../commands/KEYS';
8686
import * as LASTSAVE from '../commands/LASTSAVE';
8787
import * as LATENCY_DOCTOR from '../commands/LATENCY_DOCTOR';
8888
import * as LATENCY_GRAPH from '../commands/LATENCY_GRAPH';
89+
import * as LATENCY_HISTORY from '../commands/LATENCY_HISTORY';
8990
import * as LATENCY_LATEST from '../commands/LATENCY_LATEST';
9091
import * as LOLWUT from '../commands/LOLWUT';
9192
import * as MEMORY_DOCTOR from '../commands/MEMORY_DOCTOR';
@@ -298,6 +299,8 @@ export default {
298299
latencyDoctor: LATENCY_DOCTOR,
299300
LATENCY_GRAPH,
300301
latencyGraph: LATENCY_GRAPH,
302+
LATENCY_HISTORY,
303+
latencyHistory: LATENCY_HISTORY,
301304
LATENCY_LATEST,
302305
latencyLatest: LATENCY_LATEST,
303306
LOLWUT,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {strict as assert} from 'assert';
2+
import testUtils, {GLOBAL} from '../test-utils';
3+
import { transformArguments } from './LATENCY_HISTORY';
4+
5+
describe('LATENCY HISTORY', () => {
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
transformArguments('command'),
9+
['LATENCY', 'HISTORY', 'command']
10+
);
11+
});
12+
13+
testUtils.testWithClient('client.latencyHistory', async client => {
14+
await Promise.all([
15+
client.configSet('latency-monitor-threshold', '100'),
16+
client.sendCommand(['DEBUG', 'SLEEP', '1'])
17+
]);
18+
19+
const latencyHisRes = await client.latencyHistory('command');
20+
assert.ok(Array.isArray(latencyHisRes));
21+
for (const [timestamp, latency] of latencyHisRes) {
22+
assert.equal(typeof timestamp, 'number');
23+
assert.equal(typeof latency, 'number');
24+
}
25+
}, GLOBAL.SERVERS.OPEN);
26+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export type EventType = (
2+
'active-defrag-cycle' |
3+
'aof-fsync-always' |
4+
'aof-stat' |
5+
'aof-rewrite-diff-write' |
6+
'aof-rename' |
7+
'aof-write' |
8+
'aof-write-active-child' |
9+
'aof-write-alone' |
10+
'aof-write-pending-fsync' |
11+
'command' |
12+
'expire-cycle' |
13+
'eviction-cycle' |
14+
'eviction-del' |
15+
'fast-command' |
16+
'fork' |
17+
'rdb-unlink-temp-file'
18+
);
19+
20+
export function transformArguments(event: EventType) {
21+
return ['LATENCY', 'HISTORY', event];
22+
}
23+
24+
export declare function transformReply(): Array<[
25+
timestamp: number,
26+
latency: number,
27+
]>;

0 commit comments

Comments
 (0)