-
Notifications
You must be signed in to change notification settings - Fork 122
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
feat(dot/telemetry): implement telemetry message network_state #1618
Changes from 23 commits
fd1024c
d867d2f
17aba94
cd3abbb
74abc1b
6997fa1
90506c0
9b4eb7a
7c00e1e
5ceddd9
266c3dd
529bac0
6eb7b63
4e1f92b
13024dd
7263912
6f07942
545c25c
17bd211
ac904b0
b0e43fa
3247f7e
ffc8428
cf87b93
9ab5339
08fd38a
e5c4de9
02f03db
0428696
a160f58
a257def
0321eca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,9 @@ package network | |
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"math/big" | ||
"os" | ||
"sync" | ||
"time" | ||
|
@@ -304,6 +306,12 @@ func (s *Service) logPeerCount() { | |
} | ||
} | ||
|
||
type peerInfo struct { | ||
Roles byte `json:"roles"` | ||
BestHash string `json:"bestHash"` | ||
BestNumber uint64 `json:"bestNumber"` | ||
} | ||
|
||
func (s *Service) publishNetworkTelemetry(done chan interface{}) { | ||
ticker := time.NewTicker(s.telemetryInterval) | ||
defer ticker.Stop() | ||
|
@@ -316,11 +324,36 @@ main: | |
|
||
case <-ticker.C: | ||
o := s.host.bwc.GetBandwidthTotals() | ||
err := telemetry.GetInstance().SendMessage(telemetry.NewTelemetryMessage( | ||
telemetry.NewKeyValue("bandwidth_download", o.RateIn), | ||
telemetry.NewKeyValue("bandwidth_upload", o.RateOut), | ||
telemetry.NewKeyValue("msg", "system.interval"), | ||
telemetry.NewKeyValue("peers", s.host.peerCount()))) | ||
err := telemetry.GetInstance().SendMessage(telemetry.NewBandwidthTM(o.RateIn, o.RateOut, s.host.peerCount())) | ||
|
||
if err != nil { | ||
logger.Debug("problem sending system.interval telemetry message", "error", err) | ||
} | ||
netState := make(map[string]interface{}) | ||
netState["peerId"] = s.host.h.ID() | ||
hostAddrs := []string{} | ||
for _, v := range s.host.h.Addrs() { | ||
hostAddrs = append(hostAddrs, v.String()) | ||
} | ||
netState["externalAddressess"] = hostAddrs | ||
listAddrs := []string{} | ||
for _, v := range s.host.h.Network().ListenAddresses() { | ||
listAddrs = append(listAddrs, fmt.Sprintf("%s/p2p/%s", v, s.host.h.ID())) | ||
} | ||
netState["listenedAddressess"] = listAddrs | ||
|
||
peers := make(map[string]interface{}) | ||
for _, v := range s.Peers() { | ||
p := &peerInfo{ | ||
Roles: v.Roles, | ||
BestHash: v.BestHash.String(), | ||
BestNumber: v.BestNumber, | ||
} | ||
peers[v.PeerID] = *p | ||
} | ||
netState["connectedPeers"] = peers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this code be moved into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it would make more sense there, moved. |
||
|
||
err = telemetry.GetInstance().SendMessage(telemetry.NewNetworkStateTM(netState)) | ||
if err != nil { | ||
logger.Debug("problem sending system.interval telemetry message", "error", err) | ||
} | ||
|
@@ -334,19 +367,22 @@ func (s *Service) sentBlockIntervalTelemetry() { | |
if err != nil { | ||
continue | ||
} | ||
bestHash := best.Hash() | ||
|
||
finalized, err := s.blockState.GetFinalizedHeader(0, 0) //nolint | ||
if err != nil { | ||
continue | ||
} | ||
|
||
err = telemetry.GetInstance().SendMessage(telemetry.NewTelemetryMessage( | ||
telemetry.NewKeyValue("best", best.Hash().String()), | ||
telemetry.NewKeyValue("finalized_hash", finalized.Hash().String()), //nolint | ||
telemetry.NewKeyValue("finalized_height", finalized.Number), //nolint | ||
telemetry.NewKeyValue("height", best.Number), | ||
telemetry.NewKeyValue("msg", "system.interval"), | ||
telemetry.NewKeyValue("txcount", 0), // todo (ed) determine where to get tx count | ||
telemetry.NewKeyValue("used_state_cache_size", 0))) // todo (ed) determine where to get used_state_cache_size | ||
finalizedHash := finalized.Hash() | ||
|
||
err = telemetry.GetInstance().SendMessage(telemetry.NewBlockIntervalTM( | ||
&bestHash, | ||
best.Number, | ||
&finalizedHash, | ||
finalized.Number, | ||
big.NewInt(int64(s.transactionHandler.TransactionsCount())), | ||
big.NewInt(0), // todo (ed) determine where to get used_state_cache_size | ||
)) | ||
if err != nil { | ||
logger.Debug("problem sending system.interval telemetry message", "error", err) | ||
} | ||
|
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.
wondering why this uses
done chan
instead of the servicectx
?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 was following suggestions from this thread: #1528 (comment)