Skip to content

Commit

Permalink
rotor: count each multiplied event sent to destination as additional …
Browse files Browse the repository at this point in the history
…"active event"
  • Loading branch information
absorbb committed Jan 24, 2025
1 parent 4d48edc commit 901c174
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libs/core-functions/src/functions/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export type FuncChainResult = {
};

export type FunctionExecRes = {
receivedAt?: any;
receivedAt?: Date;
eventIndex: number;
event?: any;
metricsMeta?: MetricsMeta;
Expand Down
4 changes: 2 additions & 2 deletions services/rotor/src/lib/functions-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ export async function runChain(
const event = events[i];
let result: FuncReturn = undefined;
const sw = stopwatch();
const rat = new Date(event.receivedAt) as any;
const rat = new Date(event.receivedAt);
const execLogMeta = {
eventIndex: i,
receivedAt: rat && rat != "Invalid Date" ? rat : new Date(),
receivedAt: !isNaN(rat.getTime()) ? rat : new Date(),
functionId: f.id,
metricsMeta: metricsMeta,
};
Expand Down
5 changes: 3 additions & 2 deletions services/rotor/src/lib/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export function createMetrics(
value: JSON.stringify({
timestamp: d,
workspaceId: m.workspaceId,
messageId: m.messageId,
// to count active events use composed key: messageId_eventIndex_receivedAt
messageId: m.key,
}),
};
}),
Expand Down Expand Up @@ -183,7 +184,7 @@ export function createMetrics(
return prefix + status;
})(el);
buffer.push({
key: crypto.randomUUID(),
key: el.metricsMeta.messageId + "_" + el.eventIndex + "_" + d.getTime(),
timestamp: d,
...omit(el.metricsMeta, "retries"),
functionId: el.functionId,
Expand Down

0 comments on commit 901c174

Please sign in to comment.