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

[Networking] Adds metrics to GossipSub router #3501

Merged
merged 43 commits into from
Nov 23, 2022

Conversation

yhassanzadeh13
Copy link
Contributor

@yhassanzadeh13 yhassanzadeh13 commented Nov 3, 2022

This PR implements an ObservableGossipSubRouter component that wraps an actual GossipSubRouter and adds metrics and logging observability on it in terms of control message exchanges.

@@ -48,7 +48,7 @@ require (
github.com/libp2p/go-libp2p v0.22.0
github.com/libp2p/go-libp2p-kad-dht v0.18.0
github.com/libp2p/go-libp2p-kbucket v0.4.7
github.com/libp2p/go-libp2p-pubsub v0.8.1-0.20220908052023-8866ca88a105
github.com/libp2p/go-libp2p-pubsub v0.8.2-0.20221102045350-1e161006c43f
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We upgrade our libp2p-pubsub to enable the recent refactoring we upstreamed: libp2p/go-libp2p-pubsub#503

@codecov-commenter
Copy link

codecov-commenter commented Nov 3, 2022

Codecov Report

Merging #3501 (c15f315) into master (8f8e12f) will decrease coverage by 5.44%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #3501      +/-   ##
==========================================
- Coverage   55.27%   49.83%   -5.45%     
==========================================
  Files         754      430     -324     
  Lines       69207    39553   -29654     
==========================================
- Hits        38257    19711   -18546     
+ Misses      27808    18060    -9748     
+ Partials     3142     1782    -1360     
Flag Coverage Δ
unittests 49.83% <ø> (-5.45%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...s/hotstuff/votecollector/staking_vote_processor.go 83.87% <0.00%> (-3.23%) ⬇️
consensus/hotstuff/eventloop/event_loop.go 74.82% <0.00%> (-1.37%) ⬇️
engine/access/rest/network.go
module/executiondatasync/execution_data/store.go
module/dkg/instance.go
engine/consensus/approvals/approvals_lru_cache.go
engine/access/rest/handler.go
engine/errors.go
engine/access/rest/request/create_transaction.go
...ngine/execution/computation/committer/committer.go
... and 316 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2022

FVM Benchstat comparison

This branch with compared with the base branch onflow:master commit a60e306

The command (for i in {1..10}; do go test ./fvm ./engine/execution/computation --bench . --tags relic -shuffle=on --benchmem --run ^$; done) was used.

Collapsed results for better readability

old.txtnew.txt
time/opdelta
pkg:github.com/onflow/flow-go/engine/execution/computation goos:linux goarch:amd64
ComputeBlock/16/cols/128/txes-25.32s ± 3%5.47s ± 4%+2.87%(p=0.015 n=10+10)
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/copy_array_from_storage-2167ms ± 4%172ms ± 5%+2.86%(p=0.007 n=10+10)
RuntimeTransaction/get_account_and_get_balance-2362ms ± 2%370ms ± 4%+2.33%(p=0.028 n=9+10)
RuntimeTransaction/reference_tx-237.1ms ± 4%37.3ms ± 4%~(p=0.356 n=10+9)
RuntimeTransaction/convert_int_to_string-239.4ms ±13%40.5ms ± 3%~(p=0.077 n=9+9)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-241.1ms ± 7%41.2ms ± 5%~(p=0.815 n=8+9)
RuntimeTransaction/get_signer_address-238.2ms ± 2%38.2ms ± 5%~(p=1.000 n=9+10)
RuntimeTransaction/get_public_account-240.9ms ± 3%41.3ms ± 4%~(p=0.340 n=9+9)
RuntimeTransaction/get_account_and_get_available_balance-2323ms ± 3%326ms ± 3%~(p=0.315 n=10+10)
RuntimeTransaction/get_account_and_get_storage_used-242.8ms ± 7%43.5ms ± 4%~(p=0.182 n=10+9)
RuntimeTransaction/get_account_and_get_storage_capacity-2288ms ± 3%289ms ± 6%~(p=0.853 n=10+10)
RuntimeTransaction/get_signer_vault-246.4ms ± 4%46.8ms ± 7%~(p=0.436 n=10+10)
RuntimeTransaction/get_signer_receiver-258.5ms ± 7%59.3ms ± 9%~(p=0.481 n=10+10)
RuntimeTransaction/transfer_tokens-2248ms ± 4%249ms ± 5%~(p=0.684 n=10+10)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-244.8ms ± 5%44.8ms ± 6%~(p=0.905 n=10+9)
RuntimeTransaction/load_and_save_long_string_on_signers_address-291.5ms ± 7%91.4ms ± 7%~(p=0.905 n=10+9)
RuntimeTransaction/create_new_account-21.00s ± 2%1.01s ± 3%~(p=0.280 n=10+10)
RuntimeTransaction/call_empty_contract_function-240.6ms ± 4%41.1ms ± 3%~(p=0.218 n=10+10)
RuntimeTransaction/emit_event-255.8ms ± 3%57.7ms ± 9%~(p=0.079 n=9+10)
RuntimeTransaction/borrow_array_from_storage-2164ms ± 1%166ms ± 3%~(p=0.278 n=9+10)
RuntimeNFTBatchTransfer-2139ms ± 4%141ms ± 5%~(p=0.156 n=10+9)
 
computationdelta
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/reference_tx-2202 ± 0%202 ± 0%~(all equal)
RuntimeTransaction/convert_int_to_string-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-2502 ± 0%502 ± 0%~(all equal)
RuntimeTransaction/get_signer_address-2302 ± 0%302 ± 0%~(all equal)
RuntimeTransaction/get_public_account-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_balance-21.00k ± 0%1.00k ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_available_balance-22.60k ± 0%2.60k ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_storage_used-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_storage_capacity-21.30k ± 0%1.30k ± 0%~(all equal)
RuntimeTransaction/get_signer_vault-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/get_signer_receiver-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/transfer_tokens-23.50k ± 0%3.50k ± 0%~(all equal)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/load_and_save_long_string_on_signers_address-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/create_new_account-2202 ± 0%202 ± 0%~(all equal)
RuntimeTransaction/call_empty_contract_function-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/emit_event-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/borrow_array_from_storage-22.60k ± 0%2.60k ± 0%~(all equal)
RuntimeTransaction/copy_array_from_storage-22.60k ± 0%2.60k ± 0%~(all equal)
 
interactionsdelta
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/reference_tx-244.3k ± 0%44.3k ± 0%~(all equal)
RuntimeTransaction/convert_int_to_string-244.3k ± 0%44.3k ± 0%~(all equal)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-244.3k ± 0%44.3k ± 0%~(all equal)
RuntimeTransaction/get_signer_address-244.3k ± 0%44.3k ± 0%~(all equal)
RuntimeTransaction/get_public_account-244.3k ± 0%44.3k ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_balance-216.7M ± 0%16.7M ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_available_balance-25.13M ± 0%5.13M ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_storage_used-244.3k ± 0%44.3k ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_storage_capacity-25.13M ± 0%5.13M ± 0%~(all equal)
RuntimeTransaction/get_signer_vault-244.5k ± 0%44.5k ± 0%~(all equal)
RuntimeTransaction/get_signer_receiver-244.9k ± 0%44.9k ± 0%~(all equal)
RuntimeTransaction/transfer_tokens-245.2k ± 0%45.2k ± 0%~(all equal)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-244.4k ± 0%44.4k ± 0%~(all equal)
RuntimeTransaction/load_and_save_long_string_on_signers_address-247.2k ± 0%47.2k ± 0%~(all equal)
RuntimeTransaction/create_new_account-28.39M ± 0%8.39M ± 0%~(all equal)
RuntimeTransaction/call_empty_contract_function-244.5k ± 0%44.5k ± 0%~(all equal)
RuntimeTransaction/emit_event-244.5k ± 0%44.5k ± 0%~(all equal)
RuntimeTransaction/borrow_array_from_storage-249.7k ± 0%49.7k ± 0%~(all equal)
RuntimeTransaction/copy_array_from_storage-249.7k ± 0%49.7k ± 0%~(all equal)
 
alloc/opdelta
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/reference_tx-234.1MB ± 3%34.3MB ± 5%~(p=0.631 n=10+10)
RuntimeTransaction/convert_int_to_string-234.0MB ± 3%34.2MB ± 4%~(p=0.497 n=9+10)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-235.0MB ± 4%34.6MB ± 3%~(p=0.315 n=10+10)
RuntimeTransaction/get_signer_address-234.0MB ± 5%34.4MB ± 1%~(p=0.065 n=10+9)
RuntimeTransaction/get_public_account-235.5MB ± 2%35.3MB ± 5%~(p=0.631 n=10+10)
RuntimeTransaction/get_account_and_get_balance-2121MB ± 2%119MB ± 0%~(p=0.088 n=10+7)
RuntimeTransaction/get_account_and_get_available_balance-2104MB ± 2%103MB ± 3%~(p=0.481 n=10+10)
RuntimeTransaction/get_account_and_get_storage_used-236.0MB ± 2%36.0MB ± 4%~(p=0.780 n=9+10)
RuntimeTransaction/get_account_and_get_storage_capacity-299.2MB ± 4%98.5MB ± 5%~(p=0.218 n=10+10)
RuntimeTransaction/get_signer_vault-236.3MB ± 3%36.1MB ± 3%~(p=0.481 n=10+10)
RuntimeTransaction/get_signer_receiver-239.9MB ± 5%40.0MB ± 8%~(p=0.796 n=10+10)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-235.0MB ± 3%35.0MB ± 5%~(p=0.912 n=10+10)
RuntimeTransaction/load_and_save_long_string_on_signers_address-251.4MB ± 3%51.3MB ± 5%~(p=0.739 n=10+10)
RuntimeTransaction/create_new_account-2183MB ± 3%182MB ± 1%~(p=0.436 n=10+10)
RuntimeTransaction/call_empty_contract_function-234.4MB ± 3%34.7MB ± 3%~(p=0.280 n=10+10)
RuntimeTransaction/emit_event-239.6MB ± 8%39.7MB ± 3%~(p=0.661 n=10+9)
RuntimeTransaction/borrow_array_from_storage-269.3MB ± 1%70.0MB ± 2%~(p=0.436 n=9+9)
RuntimeTransaction/copy_array_from_storage-280.1MB ± 3%81.2MB ± 3%~(p=0.247 n=10+10)
RuntimeNFTBatchTransfer-252.1MB ± 8%53.2MB ± 6%~(p=0.218 n=10+10)
pkg:github.com/onflow/flow-go/engine/execution/computation goos:linux goarch:amd64
ComputeBlock/16/cols/128/txes-21.11GB ± 1%1.11GB ± 1%~(p=0.353 n=10+10)
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/transfer_tokens-284.2MB ± 1%83.0MB ± 2%−1.43%(p=0.028 n=8+8)
 
allocs/opdelta
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/get_account_and_get_available_balance-21.19M ± 0%1.19M ± 0%+0.00%(p=0.008 n=10+9)
RuntimeTransaction/reference_tx-274.6k ± 0%74.6k ± 0%~(p=0.209 n=10+10)
RuntimeTransaction/convert_int_to_string-286.7k ± 0%86.7k ± 0%~(p=0.321 n=10+10)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-298.0k ± 0%98.0k ± 0%~(p=0.752 n=10+10)
RuntimeTransaction/get_signer_address-278.7k ± 0%78.7k ± 0%~(p=0.071 n=10+10)
RuntimeTransaction/get_public_account-2100k ± 0%100k ± 0%~(p=0.233 n=9+9)
RuntimeTransaction/get_account_and_get_balance-21.31M ± 0%1.31M ± 0%~(p=0.968 n=10+9)
RuntimeTransaction/get_account_and_get_storage_used-2110k ± 0%110k ± 0%~(p=0.868 n=10+10)
RuntimeTransaction/get_signer_vault-2117k ± 0%117k ± 0%~(p=0.514 n=10+10)
RuntimeTransaction/get_signer_receiver-2189k ± 0%189k ± 0%~(p=0.897 n=10+10)
RuntimeTransaction/transfer_tokens-2840k ± 0%840k ± 0%~(p=0.669 n=10+10)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-2117k ± 0%117k ± 0%~(p=0.527 n=10+8)
RuntimeTransaction/call_empty_contract_function-289.0k ± 0%89.0k ± 0%~(p=0.342 n=8+10)
RuntimeTransaction/emit_event-2127k ± 0%127k ± 0%~(p=0.949 n=8+10)
RuntimeTransaction/borrow_array_from_storage-2330k ± 0%330k ± 0%~(p=0.956 n=10+10)
RuntimeTransaction/copy_array_from_storage-2287k ± 0%287k ± 0%~(p=0.305 n=10+10)
RuntimeNFTBatchTransfer-2260k ± 0%260k ± 0%~(p=0.350 n=9+7)
pkg:github.com/onflow/flow-go/engine/execution/computation goos:linux goarch:amd64
ComputeBlock/16/cols/128/txes-216.0M ± 0%15.9M ± 0%~(p=0.113 n=9+10)
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/get_account_and_get_storage_capacity-21.07M ± 0%1.07M ± 0%−0.00%(p=0.017 n=10+9)
RuntimeTransaction/load_and_save_long_string_on_signers_address-2192k ± 0%192k ± 0%−0.00%(p=0.033 n=10+10)
RuntimeTransaction/create_new_account-22.27M ± 0%2.27M ± 0%−0.00%(p=0.016 n=9+10)
 
us/txdelta
pkg:github.com/onflow/flow-go/engine/execution/computation goos:linux goarch:amd64
ComputeBlock/16/cols/128/txes-22.60k ± 3%2.67k ± 4%+2.87%(p=0.012 n=10+10)
 

@yhassanzadeh13 yhassanzadeh13 marked this pull request as ready for review November 3, 2022 20:56
@yhassanzadeh13 yhassanzadeh13 requested review from kc1116 and peterargue and removed request for vishalchangrani November 3, 2022 20:56
Copy link
Contributor

@kc1116 kc1116 left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Contributor

@peterargue peterargue left a comment

Choose a reason for hiding this comment

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

Looks good besides the comments about log level.

🚩 An important flag you noted is that the log message will not contain the peerID of the sender because it's not available in the router. That means operators will need to use other means to identify the source of these control messages.

lg := o.logger.With().Str("peer", id.String()).Logger()
switch acceptStatus {
case pubsub.AcceptAll:
lg.Debug().Msg("accepting all messages from peer")
Copy link
Contributor

Choose a reason for hiding this comment

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

should these be Trace? If this method is called on all incoming messages, this could get spammy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

includedMessages := len(rpc.GetPublish())

// TODO: add peer id of the sender to the log (currently unavailable in the RPC).
o.logger.Debug().
Copy link
Contributor

Choose a reason for hiding this comment

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

this will result in one log event per gossip message received right? Probably should make it Trace level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yhassanzadeh13 yhassanzadeh13 merged commit 74105c9 into master Nov 23, 2022
@yhassanzadeh13 yhassanzadeh13 deleted the yahya/6422-adding-observability-to-gossipsub branch November 23, 2022 19:46
peterargue pushed a commit that referenced this pull request Nov 23, 2022
* [temporary] replaces libp2p gossipsub

* make tidy

* adds observable gossipsub router

* implements gossipsub metrics

* adds metrics

* Revert "make tidy"

This reverts commit c4906b3.

* Revert "[temporary] replaces libp2p gossipsub"

This reverts commit 60377e2.

* tidy

* upgrades pubsub version

* small refactor

* fmt

* mocks

* adds topic to constructor of metrics for gossipsub

* regenerates mocks

* wires in metrics

* wip

* adds with default tag tracer to pubsub router

* adds metrics to libp2p node

* adds documentation to gossipsub router

* regenerates mocks

* adds gossipsub received rpc count

* refactors logging

* adds metrics for tracking rpcs

* adds accept rpc metrics

* fixes build error

* tidy

* fixes noop collector

* generates mocks

* wires in accept from metrics

* adds included publish messages

* generates mocks

* lint fix

* make tidy

* disables observable gossipsub

* switches log level

* switching log level
peterargue pushed a commit that referenced this pull request Dec 1, 2022
* [temporary] replaces libp2p gossipsub

* make tidy

* adds observable gossipsub router

* implements gossipsub metrics

* adds metrics

* Revert "make tidy"

This reverts commit c4906b3.

* Revert "[temporary] replaces libp2p gossipsub"

This reverts commit 60377e2.

* tidy

* upgrades pubsub version

* small refactor

* fmt

* mocks

* adds topic to constructor of metrics for gossipsub

* regenerates mocks

* wires in metrics

* wip

* adds with default tag tracer to pubsub router

* adds metrics to libp2p node

* adds documentation to gossipsub router

* regenerates mocks

* adds gossipsub received rpc count

* refactors logging

* adds metrics for tracking rpcs

* adds accept rpc metrics

* fixes build error

* tidy

* fixes noop collector

* generates mocks

* wires in accept from metrics

* adds included publish messages

* generates mocks

* lint fix

* make tidy

* disables observable gossipsub

* switches log level

* switching log level
peterargue pushed a commit that referenced this pull request Dec 9, 2022
* [temporary] replaces libp2p gossipsub

* make tidy

* adds observable gossipsub router

* implements gossipsub metrics

* adds metrics

* Revert "make tidy"

This reverts commit c4906b3.

* Revert "[temporary] replaces libp2p gossipsub"

This reverts commit 60377e2.

* tidy

* upgrades pubsub version

* small refactor

* fmt

* mocks

* adds topic to constructor of metrics for gossipsub

* regenerates mocks

* wires in metrics

* wip

* adds with default tag tracer to pubsub router

* adds metrics to libp2p node

* adds documentation to gossipsub router

* regenerates mocks

* adds gossipsub received rpc count

* refactors logging

* adds metrics for tracking rpcs

* adds accept rpc metrics

* fixes build error

* tidy

* fixes noop collector

* generates mocks

* wires in accept from metrics

* adds included publish messages

* generates mocks

* lint fix

* make tidy

* disables observable gossipsub

* switches log level

* switching log level
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.

4 participants