-
Notifications
You must be signed in to change notification settings - Fork 23
feat: show remaining CDN & cache-miss egress #538
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: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Miroslav Bajtoš <[email protected]>
Signed-off-by: Miroslav Bajtoš <[email protected]>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ⛔ Deployment terminated View logs |
synapse-dev | c0bbd0e | Commit Preview URL Branch Preview URL |
Jan 07 2026, 12:14 PM |
| </TooltipTrigger> | ||
| <TooltipContent> | ||
| <p>Cache miss egress quota remaining</p> | ||
| </TooltipContent> |
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.
The icons aren't clear to me, at first I assumed the globe would stand for global traffic. Otoh, this is just a demo app, so we don't have to get the UX exaclty right.
Proposals:
- Use icon ⬇️ for egress
- Replace icons with text
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.
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.
I think I prefered the previous version, but don't have a strong opinion
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.
Icons, "folder sync" one in particular, definitely seem a bit confusing.
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.
Done in ac134f7.
🌐 Egress remaining: 98.42 GiB delivery · 43.31 GiB cache-miss
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.
Would you like me to add tooltips for "delivery" and "cache-miss" to explain what these labels mean (traffic from the client to Filbeam, traffic from FilBeam to the SP).
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.
I think it's fine like this
Signed-off-by: Miroslav Bajtoš <[email protected]>
Signed-off-by: Miroslav Bajtoš <[email protected]>
Signed-off-by: Miroslav Bajtoš <[email protected]>
Signed-off-by: Miroslav Bajtoš <[email protected]>
| function getFilBeamStatsBaseUrl(chainId: number): string { | ||
| return chainId === 314 ? 'https://stats.filbeam.com' : 'https://calibration.stats.filbeam.com' | ||
| } |
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.
Should we move this helper to synapse-core, to avoid duplication between synapse-react and synapse-sdk?
synapse-sdk/packages/synapse-sdk/src/filbeam/service.ts
Lines 71 to 76 in 87ac7a8
| /** | |
| * Get the base stats URL for the current network | |
| */ | |
| private _getStatsBaseUrl(): string { | |
| return this._network === 'mainnet' ? 'https://stats.filbeam.com' : 'https://calibration.stats.filbeam.com' | |
| } |
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.
yes make a filbeam file or folder in core and move this there
|
This seems fine to me and I appreciate the AGENTS.md edits but I'm going to leave it to @hugomrdias to review |
- Change format to "Egress remaining: X GiB delivery · Y GiB cache-miss" - Remove FolderSync icon, keep Globe icon with tooltip "This data set is using CDN" - Use binary units (KiB, MiB, GiB, TiB) instead of decimal units Co-Authored-By: Claude Code <[email protected]> Signed-off-by: Miroslav Bajtoš <[email protected]>
|
I addressed the review comments, this PR is ready for another round of reviews. 🙏🏻 |
pyropy
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 👍🏻
| export function formatBytes(bytes: bigint | number): string { | ||
| const num = typeof bytes === 'bigint' ? Number(bytes) : bytes | ||
| if (num === 0) return '0 B' | ||
|
|
||
| const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'] | ||
| const k = 1024 | ||
| const i = Math.floor(Math.log(num) / Math.log(k)) | ||
| const value = num / k ** i | ||
|
|
||
| return `${value.toFixed(2).replace(/\.?0+$/, '')} ${units[i]}` | ||
| } |
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.
| function getFilBeamStatsBaseUrl(chainId: number): string { | ||
| return chainId === 314 ? 'https://stats.filbeam.com' : 'https://calibration.stats.filbeam.com' | ||
| } |
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.
yes make a filbeam file or folder in core and move this there
| async function fetchDataSetEgressQuota(chainId: number, dataSetId: bigint): Promise<DataSetEgressQuota | undefined> { | ||
| const baseUrl = getFilBeamStatsBaseUrl(chainId) | ||
| const url = `${baseUrl}/data-set/${dataSetId}` | ||
|
|
||
| try { | ||
| const response = await fetch(url) | ||
| if (!response.ok) { | ||
| console.error(`Failed to fetch data set egress quota: ${response.status} ${response.statusText}`) | ||
| return undefined | ||
| } | ||
|
|
||
| const data = (await response.json()) as Record<string, unknown> | ||
|
|
||
| if (typeof data.cdnEgressQuota !== 'string' || typeof data.cacheMissEgressQuota !== 'string') { | ||
| console.error('Unexpected response body from FilBeam Stats API:', data) | ||
| return undefined | ||
| } | ||
|
|
||
| return { | ||
| cdnEgressQuota: BigInt(data.cdnEgressQuota), | ||
| cacheMissEgressQuota: BigInt(data.cacheMissEgressQuota), | ||
| } | ||
| } catch (err) { | ||
| console.error('Cannot fetch data set egress quotas from FilBeam Stats API', err) | ||
| return undefined | ||
| } |
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.
same move to core pls use the request lib we use for sp client and make proper error
| const egressQuota = dataSet.cdn ? await fetchDataSetEgressQuota(chainId, dataSet.dataSetId) : undefined | ||
|
|
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.
im not sold on put this inside useDataSets its already pretty heavy and we are rethinking the apis for costs and balances right now.
| </TooltipContent> | ||
| </Tooltip> | ||
| <span className="flex items-center gap-1 text-sm text-muted-foreground"> | ||
| <Tooltip> |
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.
i would make a custom tooltip component wrapping the globe icon with all the cdn info, using a hook to fetch the data.
check the other hooks that use tanstack query to wrap fetchDataSetEgressQuota

Update the demo app to show remaining egress allowances for each data set where the FilBeam service is enabled.
Screenshot showing the new version in practice:
version 2 using FolderSync icon
version 1 using RefreshCw icon