Skip to content

Commit

Permalink
attempt to make ts info / info debug backwards cmmpatable
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpotter committed Oct 8, 2024
1 parent 9e8c183 commit 3f65936
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 48 deletions.
73 changes: 48 additions & 25 deletions packages/time-series/lib/commands/INFO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ import { TimeSeriesDuplicatePolicies } from ".";
import { TimeSeriesAggregationType } from "./CREATERULE";
import { transformDoubleReply } from '@redis/client/dist/lib/commands/generic-transformers';

export type InfoRawReply = [
export type InfoRawReplyTypes = SimpleStringReply |
NumberReply |
TimeSeriesDuplicatePolicies | null |
Array<[name: BlobStringReply, value: BlobStringReply]> |
BlobStringReply |
Array<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]> |
DoubleReply

export type InfoRawReply = Array<InfoRawReplyTypes>;

export type InfoRawReplyOld = [
'totalSamples',
NumberReply,
'memoryUsage',
Expand Down Expand Up @@ -54,8 +64,9 @@ export interface InfoReply {
timeBucket: NumberReply;
aggregationType: TimeSeriesAggregationType
}>;
ignoreMaxTimeDiff: NumberReply;
ignoreMaxValDiff: DoubleReply;
/* Added in 7.4 */
ignoreMaxTimeDiff: NumberReply | undefined;
ignoreMaxValDiff: DoubleReply | undefined;
}

export default {
Expand All @@ -66,29 +77,41 @@ export default {
},
transformReply: {
2: (reply: InfoRawReply, _, typeMapping?: TypeMapping): InfoReply => {
return {
totalSamples: reply[1],
memoryUsage: reply[3],
firstTimestamp: reply[5],
lastTimestamp: reply[7],
retentionTime: reply[9],
chunkCount: reply[11],
chunkSize: reply[13],
chunkType: reply[15],
duplicatePolicy: reply[17],
labels: reply[19].map(([name, value]) => ({
name,
value
})),
sourceKey: reply[21],
rules: reply[23].map(([key, timeBucket, aggregationType]) => ({
key,
timeBucket,
aggregationType
})),
ignoreMaxTimeDiff: reply[25],
ignoreMaxValDiff: transformDoubleReply[2](reply[27] as unknown as BlobStringReply, undefined, typeMapping)
const ret: InfoReply = {
totalSamples: reply[1] as NumberReply,
memoryUsage: reply[3] as NumberReply,
firstTimestamp: reply[5] as NumberReply,
lastTimestamp: reply[7] as NumberReply,
retentionTime: reply[9] as NumberReply,
chunkCount: reply[11] as NumberReply,
chunkSize: reply[13] as NumberReply,
chunkType: reply[15] as SimpleStringReply,
duplicatePolicy: reply[17] as TimeSeriesDuplicatePolicies | null,
labels: (reply[19] as Array<[name: BlobStringReply, value: BlobStringReply]>).map(
([name, value]) => ({
name,
value
})
),
sourceKey: reply[21] as BlobStringReply | null,
rules: (reply[23] as Array<[key: BlobStringReply, timeBucket: NumberReply, aggregationType: TimeSeriesAggregationType]>).map(
([key, timeBucket, aggregationType]) => ({
key,
timeBucket,
aggregationType
})
),
ignoreMaxTimeDiff: undefined,
ignoreMaxValDiff: undefined
};

if (reply[24] != null && reply[24].toString() == 'ignoreMaxTimeDiff') {
// > 7.4
ret.ignoreMaxTimeDiff = reply[25] as NumberReply;
ret.ignoreMaxValDiff = transformDoubleReply[2](reply[27] as unknown as BlobStringReply, undefined, typeMapping)
}

return ret;
},
3: undefined as unknown as () => InfoReply
}
Expand Down
56 changes: 33 additions & 23 deletions packages/time-series/lib/commands/INFO_DEBUG.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { BlobStringReply, Command, NumberReply, SimpleStringReply, TypeMapping } from "@redis/client/dist/lib/RESP/types";
import INFO, { InfoRawReply, InfoReply } from "./INFO";
import INFO, { InfoRawReply, InfoRawReplyTypes, InfoReply } from "./INFO";

type chunkType = Array<[
'startTimestamp',
NumberReply,
'endTimestamp',
NumberReply,
'samples',
NumberReply,
'size',
NumberReply,
'bytesPerSample',
SimpleStringReply
]>;

type InfoDebugRawReply = [
...InfoRawReply,
'keySelfName',
BlobStringReply,
'chunks',
Array<[
'startTimestamp',
NumberReply,
'endTimestamp',
NumberReply,
'samples',
NumberReply,
'size',
NumberReply,
'bytesPerSample',
SimpleStringReply
]>
chunkType
];

export type InfoDebugRawReplyType = InfoRawReplyTypes | chunkType

export interface InfoDebugReply extends InfoReply {
keySelfName: BlobStringReply,
chunks: Array<{
Expand All @@ -41,16 +45,22 @@ export default {
},
transformReply: {
2: (rawReply: InfoDebugRawReply, _, typeMapping?: TypeMapping): InfoDebugReply => {
const reply = INFO.transformReply[2](rawReply as unknown as InfoRawReply, _, typeMapping);
(reply as InfoDebugReply).keySelfName = rawReply[29];
(reply as InfoDebugReply).chunks = rawReply[31].map(chunk => ({
startTimestamp: chunk[1],
endTimestamp: chunk[3],
samples: chunk[5],
size: chunk[7],
bytesPerSample: chunk[9]
}));
return reply as InfoDebugReply;
const reply = INFO.transformReply[2](rawReply as unknown as InfoRawReply, _, typeMapping) as unknown as InfoDebugReply;
// decide if > 7.4 or < 7.4
const debugBaseIndex = reply.ignoreMaxTimeDiff === undefined ? 25 : 29;

reply.keySelfName = rawReply[debugBaseIndex] as BlobStringReply;
reply.chunks = (rawReply[debugBaseIndex+2] as chunkType).map(
chunk => ({
startTimestamp: chunk[1],
endTimestamp: chunk[3],
samples: chunk[5],
size: chunk[7],
bytesPerSample: chunk[9]
})
);

return reply;
},
3: undefined as unknown as () => InfoDebugReply
}
Expand Down

0 comments on commit 3f65936

Please sign in to comment.