-
Notifications
You must be signed in to change notification settings - Fork 6
feat: report remaining egress quotas #583
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
base: main
Are you sure you want to change the base?
Changes from 18 commits
cccc2e7
7a6e01c
c30b39c
e2515ff
2f28238
fc9a4b5
11e36f7
7193801
de090e0
200c7f7
91a488e
a0ebbe4
760fca9
3bbe611
d288566
7ac7e62
5e16c99
7ff29ee
e9ea5b6
73a1452
9c6307c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,7 +169,7 @@ export default { | |
| { | ||
| status: 502, | ||
| headers: new Headers({ | ||
| 'X-Data-Set-ID': retrievalAttempts | ||
| 'FB-Data-Set-ID': retrievalAttempts | ||
| .map((a) => a.dataSetId) | ||
| .join(','), | ||
| }), | ||
|
|
@@ -200,15 +200,22 @@ export default { | |
| retrievalResult.response, | ||
| ) | ||
| setContentSecurityPolicy(response) | ||
| response.headers.set('X-Data-Set-ID', retrievalCandidate.dataSetId) | ||
| response.headers.set('FB-Data-Set-ID', retrievalCandidate.dataSetId) | ||
| response.headers.set( | ||
| 'Cache-Control', | ||
| `public, max-age=${env.CLIENT_CACHE_TTL}`, | ||
| ) | ||
| response.headers.set( | ||
| 'FB-Cdn-Egress-Remaining', | ||
| String(retrievalCandidate.cdnEgressQuota), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we confident it's good enough to respond with the quota for this one retrieval candidate? This means if you have stored with multiple SPs, you will get different responses randomly. What about instead summing up the quotas of all retrieval candidates, since that's effectively how much you have left?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, got it. There can be multiple retrieval candidates, so we should sum up the quotas from all of them. I'll make the change.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I propose returning two sets of headers: one with the remaining quotas for the selected data-set (as indicated in the If we feel the per-data-set quotas are not needed, then I am okay to not implement such response headers. Either way, let's rename the headers returning the sum of all quotas to clearly indicate that the value is a sum across all datasets. |
||
| ) | ||
| response.headers.set( | ||
| 'FB-Cache-Miss-Egress-Remaining', | ||
| String(retrievalCandidate.cacheMissEgressQuota), | ||
| ) | ||
| return response | ||
| } | ||
|
|
||
| // Stream, count bytes and validate (a cache miss) | ||
|
akronim26 marked this conversation as resolved.
|
||
| let egressBytes = 0 | ||
| /** @type {number | null} */ | ||
| let firstByteAt = null | ||
|
|
@@ -320,18 +327,25 @@ export default { | |
| })(), | ||
| ) | ||
|
|
||
| // Return immediately, proxying the transformed response | ||
|
akronim26 marked this conversation as resolved.
|
||
| const response = new Response(returnedStream.readable, { | ||
| status: retrievalResult.response.status, | ||
| statusText: retrievalResult.response.statusText, | ||
| headers: retrievalResult.response.headers, | ||
| }) | ||
| setContentSecurityPolicy(response) | ||
| response.headers.set('X-Data-Set-ID', retrievalCandidate.dataSetId) | ||
| response.headers.set('FB-Data-Set-ID', retrievalCandidate.dataSetId) | ||
| response.headers.set( | ||
| 'Cache-Control', | ||
| `public, max-age=${env.CLIENT_CACHE_TTL}`, | ||
| ) | ||
| response.headers.set( | ||
| 'FB-Cdn-Egress-Remaining', | ||
| String(retrievalCandidate.cdnEgressQuota), | ||
| ) | ||
| response.headers.set( | ||
| 'FB-Cache-Miss-Egress-Remaining', | ||
| String(retrievalCandidate.cacheMissEgressQuota), | ||
| ) | ||
|
akronim26 marked this conversation as resolved.
Outdated
|
||
| return response | ||
| } catch (error) { | ||
| const { status } = getErrorHttpStatusMessage(error) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.