generated from valora-inc/typescript-app-starter
-
Notifications
You must be signed in to change notification settings - Fork 11
Capture RPC calls metrics #691
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e850feb
feat: logging transport
pbkompasz aed2440
feat: check if multicall
pbkompasz c05823f
feat: save metrics
pbkompasz 66ba18d
feat: metrics class
pbkompasz 2e76a83
chore: add appName
pbkompasz 73efd18
chore: log metrics
pbkompasz 01246b0
chore: remove export
pbkompasz 285871b
fix: wrong filename
pbkompasz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const fs = require('fs') | ||
|
||
const teardown = () => { | ||
console.log('Tests finished! Running global cleanup...') | ||
const data = fs.readFileSync('.metrics.json', 'utf8') | ||
console.log(JSON.parse(data)) | ||
} | ||
|
||
module.exports = teardown |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import fs from 'fs' | ||
|
||
export class Metrics { | ||
networks: { | ||
'celo-mainnet': number | ||
'ethereum-mainnet': number | ||
'arbitrum-one': number | ||
'op-mainnet': number | ||
'celo-alfajores': number | ||
'ethereum-sepolia': number | ||
'arbitrum-sepolia': number | ||
'op-sepolia': number | ||
'polygon-pos-mainnet': number | ||
'polygon-pos-amoy': number | ||
'base-mainnet': number | ||
'base-sepolia': number | ||
} | ||
apps: { | ||
aave: number | ||
allbridge: number | ||
beefy: number | ||
compound: number | ||
curve: number | ||
gooddollar: number | ||
halofi: number | ||
hedgey: number | ||
'locked-celo': number | ||
mento: number | ||
moola: number | ||
'stake-dao': number | ||
ubeswap: number | ||
uniswap: number | ||
walletconnect: number | ||
} | ||
appNames: string[] | ||
networkNames: string[] | ||
|
||
constructor() { | ||
this.networks = { | ||
'celo-mainnet': 0, | ||
'ethereum-mainnet': 0, | ||
'arbitrum-one': 0, | ||
'op-mainnet': 0, | ||
'celo-alfajores': 0, | ||
'ethereum-sepolia': 0, | ||
'arbitrum-sepolia': 0, | ||
'op-sepolia': 0, | ||
'polygon-pos-mainnet': 0, | ||
'polygon-pos-amoy': 0, | ||
'base-mainnet': 0, | ||
'base-sepolia': 0, | ||
} | ||
this.apps = { | ||
aave: 0, | ||
allbridge: 0, | ||
beefy: 0, | ||
compound: 0, | ||
curve: 0, | ||
gooddollar: 0, | ||
halofi: 0, | ||
hedgey: 0, | ||
'locked-celo': 0, | ||
mento: 0, | ||
moola: 0, | ||
'stake-dao': 0, | ||
ubeswap: 0, | ||
uniswap: 0, | ||
walletconnect: 0, | ||
} | ||
this.appNames = Object.keys(this.apps) | ||
this.networkNames = Object.keys(this.networks) | ||
} | ||
|
||
updateApp(appName: string) { | ||
if (appName && this.appNames.includes(appName)) { | ||
// @ts-expect-error Only app names are allowed | ||
this.apps[appName] += 1 | ||
} | ||
} | ||
|
||
updateNetwork(networkId: string) { | ||
if (networkId && this.networkNames.includes(networkId)) { | ||
// @ts-expect-error Only app names are allowed | ||
this.networks[networkId] += 1 | ||
} | ||
} | ||
|
||
save() { | ||
fs.writeFileSync( | ||
'.metrics.json', | ||
JSON.stringify({ | ||
apps: this.apps, | ||
networks: this.networks, | ||
}), | ||
) | ||
} | ||
} | ||
|
||
export const metrics = new Metrics() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Happy to see you're tackling this! 👍
One early feedback I see in this implementation is that the app won't be correctly reported if there are more than 1 client requested for a given network:
The reason we cache them is because we take advantage of viem clients batching: https://github.com/mobilestack-xyz/hooks/blob/67da2c869492664781f71f6e63f0d40fad747c02/src/runtime/client.ts#L50-L61
And this actually makes it somewhat less clear how to count RPC calls by app.
For instance: 2 apps make an RPC call, but the real final RPC is 1 multicall containing both of them.
i.e. 1 single HTTP request.
The important thing is how many RPC HTTP requests are being made.
I guess if there's no simple way to breakdown by app because of batching, we could omit that breakdown and just count the number of RPC HTTP requests by network.