-
Notifications
You must be signed in to change notification settings - Fork 49
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
collectors: collect payment and attempt counts #115
base: master
Are you sure you want to change the base?
collectors: collect payment and attempt counts #115
Conversation
ed0fd64
to
ebd6b23
Compare
ebd6b23
to
0cf9fd4
Compare
I may be able to consolidate the # attempts with the existing HTLC collector. Checking... |
collectors/payments_collector.go
Outdated
prometheus.HistogramOpts{ | ||
Name: "lnd_payment_attempts_per_payment", | ||
Help: "Histogram tracking the number of attempts per payment", | ||
Buckets: prometheus.LinearBuckets(1, 1, 10), // 1 to 10 attempts |
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.
Perhaps let's expand the bucket size here?
One suggestion would be to go with powers of 2, so:
prometheus.LinearBuckets(1, 2, 10)
Which would create buckets of:
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
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.
Sounds good to me. Updated ✅ We'd be really hustling at 500 payment attempts lol.
collectors/payments_collector.go
Outdated
|
||
// Attach macaroon authentication for the router service. | ||
ctx := context.Background() | ||
ctx, err := lnd.WithMacaroonAuthForService(ctx, |
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.
Awkward line wrapping, what about:
ctx, err := lnd.WithMacaroonAuthForService(
ctx, lndclient.RouterServiceMac
)
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.
Updated ✅
collectors/payments_collector.go
Outdated
|
||
paymentLogger.Info("Starting payments monitor...") | ||
|
||
stream, err := p.client.TrackPayments(ctx, |
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.
Rewrap:
stream, err := p.client.TrackPayments(
ctx, &routerrpc.TrackPaymentsRequest{
// NOTE: We only need to know the final result of the
// payment and all attempts.
NoInflightUpdates: true,
},
)
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.
Updated ✅
collectors/payments_collector.go
Outdated
|
||
paymentLogger.Info("Starting payments monitor...") | ||
|
||
stream, err := p.client.TrackPayments(ctx, |
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.
We should also verify that this is using: https://lightning.engineering/api-docs/api/lnd/router/track-payment-v2/
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.
That said, it might not be comparable as TrackPaymentV2
is for a single payment whereas TrackPayments
is for payment events in general
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 we're good to go. Check this out: https://lightning.engineering/api-docs/api/lnd/router/track-payments/. Originally I was looking at using the lndclient library like the rest of the code base, but it doesn't yet support TrackPayments so decided to use raw routerrpc client.
// complete list of all htlc attempts made for this payment. | ||
func processPaymentUpdate(payment *lnrpc.Payment) { | ||
totalPayments.Inc() | ||
attemptCount := len(payment.Htlcs) |
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.
Hmm, I don't think this can quite be used as a proxy for attempts. For that we'd need to watch a payment over time, and increment this counter with each attempt.
We may also want to introspect into the payment state itself: https://lightning.engineering/api-docs/api/lnd/router/track-payment-v2/#lnrpcpaymentpaymentstatus
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.
Double checked, and I think I'm actually wrong about this. We get a new element here for each new attempt, as it isn't just the set of final HTLCs that were settled.
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.
Prior to learning about this TrackPayments
RPC, I had created a draft PR to add these metrics as real time counters in lnd directly. Implemented there, the ChannelRouter can increment counters as each attempt is registered. My hope here was that supplying the NoInflightUpdates
directive to the TrackPayments
call will give us only the final payment update (settle or fail) from which we can make an accurate determination of how many total attempts were made.
// NOTE: It is expected that this receive the *final* payment update with the | ||
// complete list of all htlc attempts made for this payment. | ||
func processPaymentUpdate(payment *lnrpc.Payment) { | ||
totalPayments.Inc() |
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.
We should look at the payment state and only increment this if it's IN_FLIGHT
. That way we won't count a new attempt as a new payment.
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 we might be safe here so long as my comment about NoInflightUpdates
delivering only the terminal payment update (settle/fail) is correct. That way, we'll only process the payment a single time and capture all of the attempts during its life-cycle.
I could add an explicit check that the payment status is terminal to be extra sure though.
0cf9fd4
to
5a38420
Compare
collect raw payment and attempt count information from lnd using the TrackPayments RPC.
5a38420
to
0b15285
Compare
Add support for real time tracking of counters for payments and attempts. These can be used to compute and create visualizations for things like average payment throughput and average # of attempts per payment.
After making payments between two directly connected nodes: