Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/middleware/withEgressClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ async function record (space, resource, bytes, servedAt, env, ctx) {
nb: {
resource,
bytes,
servedAt: Math.floor(servedAt.getTime() / 1000)
servedAt: servedAt.getTime()
},
expiration: Infinity, // Don't expire the invocation, so we can record egress any time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is necessary, and I don't think the upload service should be able to record egress for this resource forever...just when it receives this invocation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to include this here explicitly because I was thinking about the rollout for Phase 2 (storacha/project-tracking#192). In this phase, I plan to integrate a queue in Cloudflare worker to receive the egress events, with consumers responsible for signing and forwarding these requests to the Upload-API. This setup would allow us to fine-tune the duration for which these events are recorded, likely based on the throughput of the consumers. Also, this code would probably be moved to the consumer.

nonce: process.hrtime().toString(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the partition key is now milliseconds precision we should probably also use that here right? At the moment we'd end up with multiple invocations recorded but only a single row in the DB (in the same millisecond). Using Date.now() here would mean we'd see the same number of invocations as DB rows (i.e. one in the same millisecond).

Copy link
Member Author

@fforbeck fforbeck Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alanshaw I'm not sure I fully understand. My assumption was that in the context of generating a nonce, process.hrtime() would provide a more precise and unique value, particularly in a high-frequency execution environment. Does it need to align with the servedAt field (using Date.now())? I guess they are intended to function independently, no?

proofs: ctx.delegationProofs
})
const res = await invocation.execute(connection)
Expand Down