-
Notifications
You must be signed in to change notification settings - Fork 13
feat: egress tracker middleware #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f21680e to
b99bf75
Compare
b99bf75 to
232c5fc
Compare
| write: (block) => { blocks.push(block) } | ||
| })) | ||
|
|
||
| // expect(blocks[0].bytes).to.deep.equal(carBytes) - FIXME (fforbeck): how to get the correct byte count? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to figure out how to check the byte count of the returned CAR file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Peeja / @hannahhoward, any advice on comparing the total bytes of the returned CAR file with expectedTotalBytes? I suspect I'm not converting the file correctly. Any tips would be helpful!
Peeja
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Some suggestions:
hannahhoward
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but agree with @Peeja 's comments
6bad2ac to
67cb972
Compare
67cb972 to
f0fca41
Compare
f0fca41 to
50383a6
Compare
50383a6 to
25982f4
Compare
Peeja
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woohoo! Looking even better!
I dug into the tests a bit more. My main concern is that they're a bit hard to follow when you don't have all the context loaded in your brain. Hopefully these suggestions improve that?
| expect(accountingRecordMethodStub.args[0][1], 'second argument should be the total bytes').to.equal(totalBytes) | ||
| }) | ||
|
|
||
| it('should record egress bytes for a CAR file request', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Is this testing anything in particular about withEgressTracker? It seems to me like it's just the same as any wrapped response.
suggestion: If I'm not missing something here, I'd remove this test and the setup complexity that comes with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving so test changes can happen in #123
🤖 I have created a release *beep* *boop* --- ## [2.21.0](v2.20.2...v2.21.0) (2024-11-06) ### Features * **blob-fetcher:** use updated blob fetcher ([#124](#124)) ([90bb605](90bb605)) * egress tracker middleware ([#120](#120)) ([847829b](847829b)) * rate limiter + unit tests + readme ([#115](#115)) ([7bc4c6d](7bc4c6d)) ### Bug Fixes * **test:** enable nodejs compat for miniflare ([#127](#127)) ([0165521](0165521)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Egress Tracker Middleware
Summary:
This PR introduces an egress tracking middleware for the Freeway project, enabling accurate measurement and recording of egress data for served content. The middleware tracks the bytes sent in each response body and logs them with the accounting service tied to each content ID (CID).
Key Changes:
Egress Middleware (
withEgressHandler):FF_EGRESS_TRACKER_ENABLEDfeature flag, enabling or disabling egress tracking as needed. It is disabled by default.Accounting Service Integration:
ACCOUNTING_SERVICEfrom the context or a new instance based on theACCOUNTING_SERVICE_URLenvironment variable.w3up-clientfor the newusage/recordcapability, will follow in a separate PR.)Efficient Byte Counting via
TransformStream:TransformStream(createEgressPassThroughStream) to passively count bytes in the response body without altering content.flushmethod records total egress to the accounting service usingctx.waitUntil()for non-blocking calls.Error Handling:
Testing:
Next Steps:
w3up-clientintegration to execute the newusage/recordcapability in subsequent development.