Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LATENCY LATEST #2514

Merged
merged 7 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/client/lib/client/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -290,6 +291,8 @@ export default {
latencyDoctor: LATENCY_DOCTOR,
LATENCY_GRAPH,
latencyGraph: LATENCY_GRAPH,
LATENCY_LATEST,
latencyLatest: LATENCY_LATEST,
LOLWUT,
lolwut: LOLWUT,
MEMORY_DOCTOR,
Expand Down
6 changes: 1 addition & 5 deletions packages/client/lib/commands/LATENCY_GRAPH.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
27 changes: 27 additions & 0 deletions packages/client/lib/commands/LATENCY_LATEST.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 => {
await Promise.all([
client.configSet('latency-monitor-threshold', '100'),
client.sendCommand(['DEBUG', 'SLEEP', '1'])
]);
const latency = await client.latencyLatest();
assert.ok(Array.isArray(latency));
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);
});
12 changes: 12 additions & 0 deletions packages/client/lib/commands/LATENCY_LATEST.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RedisCommandArguments } from '.';

export function transformArguments(): RedisCommandArguments {
return ['LATENCY', 'LATEST'];
}

export declare function transformReply(): Array<[
name: string,
timestamp: number,
latestLatency: number,
allTimeLatency: number
]>;
22 changes: 14 additions & 8 deletions packages/client/lib/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,43 @@ 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'
}
}
},
CLUSTERS: {
OPEN: {
serverArguments: []
serverArguments: [...DEBUG_MODE_ARGS]
},
PASSWORD: {
serverArguments: ['--requirepass', 'password'],
serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS],
clusterConfiguration: {
defaults: {
password: 'password'
}
}
},
WITH_REPLICAS: {
serverArguments: [],
serverArguments: [...DEBUG_MODE_ARGS],
numberOfMasters: 2,
numberOfReplicas: 1,
clusterConfiguration: {
Expand Down