Skip to content

Commit

Permalink
close #2192 close #2193 close #2194 close #2195 close #2196 close #2197
Browse files Browse the repository at this point in the history
close #2198 - support for TimeSeries 1.8 (#2200)
  • Loading branch information
leibale committed Aug 31, 2022
1 parent b10a656 commit 5dd7d31
Show file tree
Hide file tree
Showing 25 changed files with 369 additions and 181 deletions.
27 changes: 24 additions & 3 deletions packages/time-series/lib/commands/ALTER.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { strict as assert } from 'assert';
import { TimeSeriesDuplicatePolicies } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ALTER';

Expand All @@ -20,6 +21,24 @@ describe('ALTER', () => {
);
});

it('with CHUNK_SIZE', () => {
assert.deepEqual(
transformArguments('key', {
CHUNK_SIZE: 1
}),
['TS.ALTER', 'key', 'CHUNK_SIZE', '1']
);
});

it('with DUPLICATE_POLICY', () => {
assert.deepEqual(
transformArguments('key', {
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK
}),
['TS.ALTER', 'key', 'DUPLICATE_POLICY', 'BLOCK']
);
});

it('with LABELS', () => {
assert.deepEqual(
transformArguments('key', {
Expand All @@ -29,19 +48,21 @@ describe('ALTER', () => {
);
});

it('with RETENTION, LABELS', () => {
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
assert.deepEqual(
transformArguments('key', {
RETENTION: 1,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,
LABELS: { label: 'value' }
}),
['TS.ALTER', 'key', 'RETENTION', '1', 'LABELS', 'label', 'value']
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
);
});
});

testUtils.testWithClient('client.ts.alter', async client => {
await client.ts.create('key');
await client.ts.create('key');

assert.equal(
await client.ts.alter('key', { RETENTION: 1 }),
Expand Down
8 changes: 7 additions & 1 deletion packages/time-series/lib/commands/ALTER.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { pushRetentionArgument, Labels, pushLabelsArgument } from '.';
import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy } from '.';

export const FIRST_KEY_INDEX = 1;

interface AlterOptions {
RETENTION?: number;
CHUNK_SIZE?: number;
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
LABELS?: Labels;
}

Expand All @@ -12,6 +14,10 @@ export function transformArguments(key: string, options?: AlterOptions): Array<s

pushRetentionArgument(args, options?.RETENTION);

pushChunkSizeArgument(args, options?.CHUNK_SIZE);

pushDuplicatePolicy(args, options?.DUPLICATE_POLICY);

pushLabelsArgument(args, options?.LABELS);

return args;
Expand Down
10 changes: 3 additions & 7 deletions packages/time-series/lib/commands/CREATE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
pushChunkSizeArgument,
TimeSeriesDuplicatePolicies,
Labels,
pushLabelsArgument
pushLabelsArgument,
pushDuplicatePolicy
} from '.';

export const FIRST_KEY_INDEX = 1;
Expand All @@ -27,12 +28,7 @@ export function transformArguments(key: string, options?: CreateOptions): Array<

pushChunkSizeArgument(args, options?.CHUNK_SIZE);

if (options?.DUPLICATE_POLICY) {
args.push(
'DUPLICATE_POLICY',
options.DUPLICATE_POLICY
);
}
pushDuplicatePolicy(args, options?.DUPLICATE_POLICY);

pushLabelsArgument(args, options?.LABELS);

Expand Down
19 changes: 14 additions & 5 deletions packages/time-series/lib/commands/CREATERULE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './CREATERULE';

describe('CREATERULE', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1),
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'avg', '1']
);
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1),
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1']
);
});

it('with alignTimestamp', () => {
assert.deepEqual(
transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1, 1),
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1', '1']
);
});
});

testUtils.testWithClient('client.ts.createRule', async client => {
Expand Down
13 changes: 10 additions & 3 deletions packages/time-series/lib/commands/CREATERULE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@ export function transformArguments(
sourceKey: string,
destinationKey: string,
aggregationType: TimeSeriesAggregationType,
timeBucket: number
bucketDuration: number,
alignTimestamp?: number
): Array<string> {
return [
const args = [
'TS.CREATERULE',
sourceKey,
destinationKey,
'AGGREGATION',
aggregationType,
timeBucket.toString()
bucketDuration.toString()
];

if (alignTimestamp) {
args.push(alignTimestamp.toString());
}

return args;
}

export declare function transformReply(): 'OK';
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/DELETERULE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function transformArguments(sourceKey: string, destinationKey: string): A
return [
'TS.DELETERULE',
sourceKey,
destinationKey,
destinationKey
];
}

Expand Down
21 changes: 16 additions & 5 deletions packages/time-series/lib/commands/GET.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './GET';

describe('GET', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
['TS.GET', 'key']
);
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
transformArguments('key'),
['TS.GET', 'key']
);
});

it('with LATEST', () => {
assert.deepEqual(
transformArguments('key', {
LATEST: true
}),
['TS.GET', 'key', 'LATEST']
);
});
});

describe('client.ts.get', () => {
Expand Down
11 changes: 8 additions & 3 deletions packages/time-series/lib/commands/GET.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { SampleRawReply, SampleReply, transformSampleReply } from '.';
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
import { pushLatestArgument, SampleRawReply, SampleReply, transformSampleReply } from '.';

export const FIRST_KEY_INDEX = 1;

export const IS_READ_ONLY = true;

export function transformArguments(key: string): Array<string> {
return ['TS.GET', key];
interface GetOptions {
LATEST?: boolean;
}

export function transformArguments(key: string, options?: GetOptions): RedisCommandArguments {
return pushLatestArgument(['TS.GET', key], options?.LATEST);
}

export function transformReply(reply: [] | SampleRawReply): null | SampleReply {
Expand Down
55 changes: 29 additions & 26 deletions packages/time-series/lib/commands/INFO.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'assert';
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './INFO';
import { InfoReply, transformArguments } from './INFO';

describe('INFO', () => {
it('transformArguments', () => {
Expand All @@ -14,37 +14,40 @@ describe('INFO', () => {
testUtils.testWithClient('client.ts.info', async client => {
await Promise.all([
client.ts.create('key', {
LABELS: { id: "2" },
LABELS: { id: '1' },
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.LAST
}),
client.ts.create('key2'),
client.ts.createRule('key', 'key2', TimeSeriesAggregationType.COUNT, 5),
client.ts.add('key', 1, 10)
]);

assert.deepEqual(
await client.ts.info('key'),
{
totalSamples: 1,
memoryUsage: 4261,
firstTimestamp: 1,
lastTimestamp: 1,
retentionTime: 0,
chunkCount: 1,
chunkSize: 4096,
chunkType: 'compressed',
duplicatePolicy: 'last',
labels: [{
name: 'id',
value: '2'
}],
rules: [{
aggregationType: 'COUNT',
key: 'key2',
timeBucket: 5
}],
sourceKey: null
}
);
assertInfo(await client.ts.info('key'));
}, GLOBAL.SERVERS.OPEN);
});

export function assertInfo(info: InfoReply): void {
assert.equal(typeof info.totalSamples, 'number');
assert.equal(typeof info.memoryUsage, 'number');
assert.equal(typeof info.firstTimestamp, 'number');
assert.equal(typeof info.lastTimestamp, 'number');
assert.equal(typeof info.retentionTime, 'number');
assert.equal(typeof info.chunkCount, 'number');
assert.equal(typeof info.chunkSize, 'number');
assert.equal(typeof info.chunkType, 'string');
assert.equal(typeof info.duplicatePolicy, 'string');
assert.ok(Array.isArray(info.labels));
for (const label of info.labels) {
assert.equal(typeof label, 'object');
assert.equal(typeof label.name, 'string');
assert.equal(typeof label.value, 'string');
}
assert.ok(Array.isArray(info.rules));
for (const rule of info.rules) {
assert.equal(typeof rule, 'object');
assert.equal(typeof rule.aggregationType, 'string');
assert.equal(typeof rule.key, 'string');
assert.equal(typeof rule.timeBucket, 'number');
}
assert.ok(info.sourceKey === null || typeof info.sourceKey === 'string');
}
48 changes: 24 additions & 24 deletions packages/time-series/lib/commands/INFO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ export function transformArguments(key: string): Array<string> {
}

export type InfoRawReply = [
_: string,
totalSamples: number,
_: string,
memoryUsage: number,
_: string,
firstTimestamp: number,
_: string,
lastTimestamp: number,
_: string,
retentionTime: number,
_: string,
chunkCount: number,
_: string,
chunkSize: number,
_: string,
chunkType: string,
_: string,
duplicatePolicy: TimeSeriesDuplicatePolicies | null,
_: string,
labels: Array<[name: string, value: string]>,
_: string,
sourceKey: string | null,
_: string,
rules: Array<[key: string, timeBucket: number, aggregationType: TimeSeriesAggregationType]>
'totalSamples',
number,
'memoryUsage',
number,
'firstTimestamp',
number,
'lastTimestamp',
number,
'retentionTime',
number,
'chunkCount',
number,
'chunkSize',
number,
'chunkType',
string,
'duplicatePolicy',
TimeSeriesDuplicatePolicies | null,
'labels',
Array<[name: string, value: string]>,
'sourceKey',
string | null,
'rules',
Array<[key: string, timeBucket: number, aggregationType: TimeSeriesAggregationType]>
];

export interface InfoReply {
Expand Down

0 comments on commit 5dd7d31

Please sign in to comment.