diff --git a/packages/client/lib/client/commands.ts b/packages/client/lib/client/commands.ts index 1e2e5274c0a..631e1a80807 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_HISTORY from '../commands/LATENCY_HISTORY'; import * as LATENCY_LATEST from '../commands/LATENCY_LATEST'; import * as LOLWUT from '../commands/LOLWUT'; import * as MEMORY_DOCTOR from '../commands/MEMORY_DOCTOR'; @@ -291,6 +292,8 @@ export default { latencyDoctor: LATENCY_DOCTOR, LATENCY_GRAPH, latencyGraph: LATENCY_GRAPH, + LATENCY_HISTORY, + latencyHistory: LATENCY_HISTORY, LATENCY_LATEST, latencyLatest: LATENCY_LATEST, LOLWUT, diff --git a/packages/client/lib/commands/LATENCY_HISTORY.spec.ts b/packages/client/lib/commands/LATENCY_HISTORY.spec.ts new file mode 100644 index 00000000000..e79e969b261 --- /dev/null +++ b/packages/client/lib/commands/LATENCY_HISTORY.spec.ts @@ -0,0 +1,26 @@ +import {strict as assert} from 'assert'; +import testUtils, {GLOBAL} from '../test-utils'; +import { transformArguments } from './LATENCY_HISTORY'; + +describe('LATENCY HISTORY', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('command'), + ['LATENCY', 'HISTORY', 'command'] + ); + }); + + testUtils.testWithClient('client.latencyHistory', async client => { + await Promise.all([ + client.configSet('latency-monitor-threshold', '100'), + client.sendCommand(['DEBUG', 'SLEEP', '1']) + ]); + + const latencyHisRes = await client.latencyHistory('command'); + assert.ok(Array.isArray(latencyHisRes)); + for (const [timestamp, latency] of latencyHisRes) { + assert.equal(typeof timestamp, 'number'); + assert.equal(typeof latency, 'number'); + } + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/LATENCY_HISTORY.ts b/packages/client/lib/commands/LATENCY_HISTORY.ts new file mode 100644 index 00000000000..c0b1964553e --- /dev/null +++ b/packages/client/lib/commands/LATENCY_HISTORY.ts @@ -0,0 +1,27 @@ +export type EventType = ( + 'active-defrag-cycle' | + 'aof-fsync-always' | + 'aof-stat' | + 'aof-rewrite-diff-write' | + 'aof-rename' | + 'aof-write' | + 'aof-write-active-child' | + 'aof-write-alone' | + 'aof-write-pending-fsync' | + 'command' | + 'expire-cycle' | + 'eviction-cycle' | + 'eviction-del' | + 'fast-command' | + 'fork' | + 'rdb-unlink-temp-file' +); + +export function transformArguments(event: EventType) { + return ['LATENCY', 'HISTORY', event]; +} + +export declare function transformReply(): Array<[ + timestamp: number, + latency: number, +]>;