-
Notifications
You must be signed in to change notification settings - Fork 129
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
Merged
+289
−120
Merged
Changes from 7 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
fd1024c
refactor telemetry messages to map format
edwardmack d867d2f
add basic network state telemetry message
edwardmack 17aba94
Merge branch 'development' into ed/tel_msg_network_state
edwardmack cd3abbb
Merge branch 'development' into ed/tel_msg_network_state
edwardmack 74abc1b
refactor message sender to handle interface{} types
edwardmack 6997fa1
refactor telemetry messages to be structs
edwardmack 90506c0
Merge branch 'development' into ed/tel_msg_network_state
edwardmack 9b4eb7a
Merge branch 'development' into ed/tel_msg_network_state
edwardmack 7c00e1e
lint
edwardmack 5ceddd9
go fmt
edwardmack 266c3dd
Merge branch 'development' into ed/tel_msg_network_state
edwardmack 529bac0
lint
edwardmack 6eb7b63
move msg building logic outside msg sending loop
edwardmack 4e1f92b
Merge branch 'development' into ed/tel_msg_network_state
edwardmack 13024dd
make telemetry messages an interface
edwardmack 7263912
Lookup transactions count from TransactionsState
edwardmack 6f07942
address comments
edwardmack 545c25c
fix mocks for tests
edwardmack 17bd211
lint
edwardmack ac904b0
refactor TelemetryMessage to Message
edwardmack b0e43fa
update mock handler to return result
edwardmack 3247f7e
add TransactionsCount to mockhandler
edwardmack ffc8428
Merge branch 'development' into ed/tel_msg_network_state
edwardmack cf87b93
Merge branch 'development' into ed/tel_msg_network_state
edwardmack 9ab5339
move logic to build new network state message
edwardmack 08fd38a
lint
edwardmack e5c4de9
fix interface
edwardmack 02f03db
update mockhandler
edwardmack 0428696
Merge branch 'development' into ed/tel_msg_network_state
edwardmack a160f58
Merge branch 'development' into ed/tel_msg_network_state
edwardmack a257def
Merge branch 'development' into ed/tel_msg_network_state
edwardmack 0321eca
lint
edwardmack 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 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 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 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -19,6 +19,7 @@ package telemetry | |||||
import ( | ||||||
"encoding/json" | ||||||
"errors" | ||||||
"fmt" | ||||||
"math/big" | ||||||
"sync" | ||||||
"time" | ||||||
|
@@ -27,6 +28,7 @@ import ( | |||||
"github.com/ChainSafe/gossamer/lib/genesis" | ||||||
log "github.com/ChainSafe/log15" | ||||||
"github.com/gorilla/websocket" | ||||||
libp2phost "github.com/libp2p/go-libp2p-core/host" | ||||||
) | ||||||
|
||||||
type telemetryConnection struct { | ||||||
|
@@ -95,7 +97,7 @@ func (h *Handler) startListening() { | |||||
msg := <-h.msg | ||||||
go func() { | ||||||
msgBytes, err := h.msgToJSON(msg) | ||||||
if err != nil || len(msgBytes) == 0 { | ||||||
if err != nil { | ||||||
h.log.Debug("issue decoding telemetry message", "error", err) | ||||||
return | ||||||
} | ||||||
|
@@ -236,17 +238,47 @@ func (tm *SystemIntervalTM) messageType() string { | |||||
return tm.Msg | ||||||
} | ||||||
|
||||||
type peerInfo struct { | ||||||
Roles byte `json:"roles"` | ||||||
BestHash string `json:"bestHash"` | ||||||
BestNumber uint64 `json:"bestNumber"` | ||||||
} | ||||||
|
||||||
// NetworkStateTM struct to hold network state telemetry messages | ||||||
type NetworkStateTM struct { | ||||||
Msg string `json:"msg"` | ||||||
State map[string]interface{} `json:"state"` | ||||||
} | ||||||
|
||||||
// NewNetworkStateTM function to create new Network State Telemetry Message | ||||||
func NewNetworkStateTM(state map[string]interface{}) *NetworkStateTM { | ||||||
func NewNetworkStateTM(host libp2phost.Host, peerInfos []common.PeerInfo) *NetworkStateTM { | ||||||
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.
Suggested change
|
||||||
netState := make(map[string]interface{}) | ||||||
netState["peerId"] = host.ID() | ||||||
hostAddrs := []string{} | ||||||
for _, v := range host.Addrs() { | ||||||
hostAddrs = append(hostAddrs, v.String()) | ||||||
} | ||||||
netState["externalAddressess"] = hostAddrs | ||||||
listAddrs := []string{} | ||||||
for _, v := range host.Network().ListenAddresses() { | ||||||
listAddrs = append(listAddrs, fmt.Sprintf("%s/p2p/%s", v, host.ID())) | ||||||
} | ||||||
netState["listenedAddressess"] = listAddrs | ||||||
|
||||||
peers := make(map[string]interface{}) | ||||||
for _, v := range peerInfos { | ||||||
p := &peerInfo{ | ||||||
Roles: v.Roles, | ||||||
BestHash: v.BestHash.String(), | ||||||
BestNumber: v.BestNumber, | ||||||
} | ||||||
peers[v.PeerID] = *p | ||||||
} | ||||||
netState["connectedPeers"] = peers | ||||||
|
||||||
return &NetworkStateTM{ | ||||||
Msg: "system.network_state", | ||||||
State: state, | ||||||
State: netState, | ||||||
} | ||||||
} | ||||||
func (tm *NetworkStateTM) messageType() string { | ||||||
|
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.
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)