Skip to content

Commit

Permalink
Structured logging for checkpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkistner committed Jul 17, 2024
1 parent f2d6473 commit 6143b06
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/service-core/src/sync/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ async function* streamResponseInner(
});

if (allBuckets.length > 1000) {
logger.error(`Too many buckets`, {
checkpoint,
user_id: syncParams.user_id,
buckets: allBuckets.length
});
// TODO: Limit number of buckets even before we get to this point
throw new Error(`Too many buckets: ${allBuckets.length}`);
}
Expand Down Expand Up @@ -141,13 +146,18 @@ async function* streamResponseInner(
}
bucketsToFetch = diff.updatedBuckets.map((c) => c.bucket);

let message = `Updated checkpoint | user: ${syncParams.user_id} | `;
message += `op: ${checkpoint} | `;
let message = `Updated checkpoint: ${checkpoint} | `;
message += `write: ${writeCheckpoint} | `;
message += `buckets: ${allBuckets.length} | `;
message += `updated: ${limitedBuckets(diff.updatedBuckets, 20)} | `;
message += `removed: ${limitedBuckets(diff.removedBuckets, 20)}`;
logger.info(message);
logger.info(message, {
checkpoint,
user_id: syncParams.user_id,
buckets: allBuckets.length,
updated: diff.updatedBuckets.length,
removed: diff.removedBuckets.length
});

const checksum_line: util.StreamingSyncCheckpointDiff = {
checkpoint_diff: {
Expand All @@ -162,7 +172,7 @@ async function* streamResponseInner(
} else {
let message = `New checkpoint: ${checkpoint} | write: ${writeCheckpoint} | `;
message += `buckets: ${allBuckets.length} ${limitedBuckets(allBuckets, 20)}`;
logger.info(message);
logger.info(message, { checkpoint, user_id: syncParams.user_id, buckets: allBuckets.length });
bucketsToFetch = allBuckets;
const checksum_line: util.StreamingSyncCheckpoint = {
checkpoint: {
Expand Down

0 comments on commit 6143b06

Please sign in to comment.