Skip to content

Commit

Permalink
fix: Avoid writing misleading failed/skipped duration metrics (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley authored Aug 29, 2023
1 parent 67164c4 commit 2e64d52
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ const processStream = async (streamKey: string): Promise<void> => {
console.log('Started processing stream: ', streamKey);

let indexerName = '';
let startTime = 0;
let streamType = '';

while (true) {
try {
startTime = performance.now();
streamType = redisClient.getStreamType(streamKey);
const startTime = performance.now();
const streamType = redisClient.getStreamType(streamKey);

const messages = await redisClient.getNextStreamMessage(streamKey);
const indexerConfig = await redisClient.getStreamStorage(streamKey);
Expand Down Expand Up @@ -50,13 +48,13 @@ const processStream = async (streamKey: string): Promise<void> => {
await redisClient.deleteStreamMessage(streamKey, id);

const unprocessedMessages = await redisClient.getUnprocessedStreamMessages(streamKey);

metrics.UNPROCESSED_STREAM_MESSAGES.labels({ indexer: indexerName, type: streamType }).set(unprocessedMessages?.length ?? 0);
metrics.EXECUTION_DURATION.labels({ indexer: indexerName, type: streamType }).set(performance.now() - startTime);

console.log(`Success: ${indexerName}`);
} catch (err) {
console.log(`Failed: ${indexerName}`, err);
} finally {
metrics.EXECUTION_DURATION.labels({ indexer: indexerName, type: streamType }).set(performance.now() - startTime);
}
}
};
Expand Down

0 comments on commit 2e64d52

Please sign in to comment.