Skip to content

Commit

Permalink
uuid validation
Browse files Browse the repository at this point in the history
  • Loading branch information
maamalama committed Sep 19, 2024
1 parent d0fec42 commit c789bfe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion valhalla/jawn/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if (KAFKA_ENABLED) {
dlqCount: DLQ_WORKER_COUNT,
normalCount: NORMAL_WORKER_COUNT,
scoresCount: SCORES_WORKER_COUNT,
scoresDlqCount: SCORES_WORKER_COUNT,
scoresDlqCount: 0,
backFillCount: 0,
});
}
Expand Down
6 changes: 5 additions & 1 deletion valhalla/jawn/src/managers/score/ScoreManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { dataDogClient } from "../../lib/clients/DataDogClient";
import { KafkaProducer } from "../../lib/clients/KafkaProducer";
import { HeliconeScoresMessage } from "../../lib/handlers/HandlerContext";
import * as Sentry from "@sentry/node";
import { validate as uuidValidate } from "uuid";

type Scores = Record<string, number | boolean>;

Expand Down Expand Up @@ -80,9 +81,12 @@ export class ScoreManager extends BaseManager {
if (scoresMessages.length === 0) {
return ok(null);
}
const validScoresMessages = scoresMessages.filter((message) =>
uuidValidate(message.requestId)
);
// Filter out duplicate scores messages and only keep the latest one
const filteredMessages = Array.from(
scoresMessages
validScoresMessages
.reduce((map, message) => {
const key = `${message.requestId}-${message.organizationId}`;
const existingMessage = map.get(key);
Expand Down

0 comments on commit c789bfe

Please sign in to comment.