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 HISTOGRAM #2819

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -86,6 +86,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_HISTOGRAM from '../commands/LATENCY_HISTOGRAM';
import * as LATENCY_HISTORY from '../commands/LATENCY_HISTORY';
import * as LATENCY_LATEST from '../commands/LATENCY_LATEST';
import * as LOLWUT from '../commands/LOLWUT';
Expand Down Expand Up @@ -299,6 +300,8 @@ export default {
latencyDoctor: LATENCY_DOCTOR,
LATENCY_GRAPH,
latencyGraph: LATENCY_GRAPH,
LATENCY_HISTOGRAM,
latencyHistogram: LATENCY_HISTOGRAM,
LATENCY_HISTORY,
latencyHistory: LATENCY_HISTORY,
LATENCY_LATEST,
Expand Down
28 changes: 28 additions & 0 deletions packages/client/lib/commands/LATENCY_HISTOGRAM.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {strict as assert} from 'assert';
import testUtils, {GLOBAL} from '../test-utils';
import { transformArguments } from './LATENCY_HISTOGRAM';

describe('LATENCY HISTOGRAM', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('command'),
['LATENCY', 'HISTOGRAM', 'command']
);
});

testUtils.testWithClient('client.latencyHistory', async client => {
await Promise.all([
client.set('sample-key', 'sample-value'),
client.get('sample-key')
]);

const commandNames = ['set', 'get'];
const latencyHistograms = await client.latencyHistogram(...commandNames);

for (const commandName of commandNames) {
const commandInfo = latencyHistograms[commandName];
assert.ok(Number.isInteger(commandInfo['calls']));
assert.ok(Array.isArray(commandInfo['histogram_usec']));
}
}, GLOBAL.SERVERS.OPEN);
});
34 changes: 34 additions & 0 deletions packages/client/lib/commands/LATENCY_HISTOGRAM.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { RedisCommandArgument, RedisCommandArguments } from '.';

export type LatencyHistogram = Record<string, {
calls: number;
histogram_usec: HistogramData;
}>;

export type HistogramData = number[];

export type CommandInfo = [
string,
number,
string,
HistogramData
]

export type RawReply = (string | CommandInfo)[];

export function transformArguments(...commands: RedisCommandArgument[]): RedisCommandArguments {
return ['LATENCY', 'HISTOGRAM', ...commands];
}

export function transformReply(rawReply: RawReply): LatencyHistogram {
const result: LatencyHistogram = {};

for (let i = 0; i < rawReply.length; i += 2) {
const [command, [_, calls, __, histogram]] = [rawReply[i] as string, rawReply[i + 1] as CommandInfo];
result[command] = {
calls,
histogram_usec: histogram
};
}
return result;
};