Skip to content
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

[Faucet] Add balance metric #19681

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

stefan-mysten
Copy link
Contributor

Description

Added a balance metric for alerting when we need to top it up.

Test plan

How did you test the new or updated feature?


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • REST API:

Copy link

vercel bot commented Oct 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 2:26am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Oct 4, 2024 2:26am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Oct 4, 2024 2:26am
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Oct 4, 2024 2:26am

Copy link
Contributor

@amnn amnn left a comment

Choose a reason for hiding this comment

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

I don't think this works too well, for a couple of reasons:

  • I think you've only covered the non-batched case.
  • The request is happening before you execute the transaction.
  • You're asking RPC what it thinks the balance is, but that may account for coins that are not in the faucet's queue (imagine someone transfers a giant coin to the faucet after it starts -- it won't know about it, but the balance will report a large number).
  • We are now making a non-trivial number of extra requests to RPC.

Here is what I would do instead:

  • Don't add any more RPC calls, just track the balances of the coins you are already reading.
  • Instrument the paths where coins enter and leave the queue to hit both endpoints.

@jordanjennings-mysten
Copy link
Contributor

jordanjennings-mysten commented Oct 3, 2024

Don't add any more RPC calls, just track the balances of the coins you are already reading.

thoughts about this :

  • this would end up measuring the balance before the send (via get_coin()) so you'd end up with a number that is always slightly off, small thing but figured I'd call it out.
  • avoid storing the balance of each coin but instead store the aggregate since the alternative (storing the balance of each coin in prometheus) would cause "high cardinality" and slow down prometheus since each coin has a unique id which could accumulate unique labels over time.

at best if you wanted to avoid that "high cardinality" problem each coin amount you could use its position in nth largest sorted so labels don't become unique:

  • 1st largest
  • 2nd largest coin
  • etc

you would get some flexibility in querying, could make a bar chart showing the distribution of balances across each coin, seems unnecessary to me, since coin merging should make coin distribution flat? but its an idea and could help debug coin merging.

@amnn
Copy link
Contributor

amnn commented Oct 3, 2024

Yes, sorry I should have been clearer, clarifications follow:

this would end up measuring the balance before the send (via get_coin()) so you'd end up with a number that is always slightly off, small thing but figured I'd call it out

That's right, in particular what I want to measure is the total balance in the coin queue, so it's not going to include coins that are committed to transactions in flight, but I think that's okay because we want to know what the size of our "reservoir" is and if it consistently dips below some threshold, we know we need to fill it back up.

this would end up measuring the balance before the send (via get_coin()) so you'd end up with a number that is always slightly off, small thing but figured I'd call it out

yes, this is what I had in mind -- a single gauge in prometheus that tracks the total balance of all the coins in the in-memory queue.

@stefan-mysten
Copy link
Contributor Author

Thanks @amnn and @jordanjennings-mysten, I will revise it later today.

@stefan-mysten
Copy link
Contributor Author

@amnn @jordanjennings-mysten I went with the following solution

  • read the balance at the start of the service
  • decrement the amount of SUI that was transferred after a transfer gas transaction is successful, for both endpoints. I thought this might be easier to reason about.

Let me know your thoughts.

let metrics = FaucetMetrics::new(prometheus_registry);
// set initial balance when faucet starts
metrics.balance.set(balance as i64);
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of interest, is it possible to sum it as an i64 to begin with?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does not work unfortunately as balance.value() in the lines above is u64, so I can only sum it to u64.

@@ -520,6 +523,7 @@ impl SimpleFaucet {
.sign_and_execute_txn(uuid, recipient, coin_id, tx_data, false)
.await?;
self.metrics.total_coin_requests_succeeded.inc();
self.metrics.balance.add(-(total_amount as i64));
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't match the actual SUI spent by the transaction (e.g. the amount sent, but also the amount spent on the transaction for computation, storage etc), so it will diverge over time.

One way to handle this is to request balance changes when executing the transaction. The balance change for the faucet's address, should match the balance change on the coin, and can be applied to the metric as a delta. I would suggest moving that logic into sign_and_execute_txn so you only need to handle it in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants