-
Notifications
You must be signed in to change notification settings - Fork 146
feat(dot/telemetry): implement notify.finalized telemetry interface #1877
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1f54614
Implement notify.finalized Telemetry Interface
kishansagathiya c257366
Merge branch 'development' into issue-1835
kishansagathiya 11f2626
Added tests for notify.finalized telemetry message
kishansagathiya f6b1f10
Fixing some linting issues
kishansagathiya 98279c1
Send telemetry message from SetFinalisedHash instead
kishansagathiya 39cd90d
Make NotifyFinalizedTM.Height string
kishansagathiya 1bb3f5b
Fix telemetry test
kishansagathiya 4ad7591
Addressed some reviews
kishansagathiya 9f31279
return Message interface
kishansagathiya cf1facc
Omit the reciever name when unused
kishansagathiya c1f561d
Merge branch 'development' into issue-1835
kishansagathiya 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright 2021 ChainSafe Systems (ON) Corp. | ||
| // This file is part of gossamer. | ||
| // | ||
| // The gossamer library is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Lesser General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // The gossamer library is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Lesser General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the gossamer library. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package telemetry | ||
|
|
||
| import ( | ||
| "math/big" | ||
|
|
||
| "github.com/ChainSafe/gossamer/lib/common" | ||
| ) | ||
|
|
||
| // BlockImportTM struct to hold block import telemetry messages | ||
| type BlockImportTM struct { | ||
| BestHash *common.Hash `json:"best"` | ||
| Height *big.Int `json:"height"` | ||
| Msg string `json:"msg"` | ||
| Origin string `json:"origin"` | ||
| } | ||
|
|
||
| // NewBlockImportTM function to create new Block Import Telemetry Message | ||
| func NewBlockImportTM(bestHash *common.Hash, height *big.Int, origin string) *BlockImportTM { | ||
| return &BlockImportTM{ | ||
| BestHash: bestHash, | ||
| Height: height, | ||
| Msg: "block.import", | ||
| Origin: origin, | ||
| } | ||
| } | ||
|
|
||
| func (tm *BlockImportTM) messageType() string { | ||
| return tm.Msg | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright 2021 ChainSafe Systems (ON) Corp. | ||
| // This file is part of gossamer. | ||
| // | ||
| // The gossamer library is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Lesser General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // The gossamer library is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Lesser General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the gossamer library. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package telemetry | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/ChainSafe/gossamer/lib/common" | ||
| libp2phost "github.com/libp2p/go-libp2p-core/host" | ||
| ) | ||
|
|
||
| // 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(host libp2phost.Host, peerInfos []common.PeerInfo) *NetworkStateTM { | ||
| netState := make(map[string]interface{}) | ||
| netState["peerId"] = host.ID() | ||
| hostAddrs := []string{} | ||
|
kishansagathiya marked this conversation as resolved.
Outdated
|
||
| for _, v := range host.Addrs() { | ||
| hostAddrs = append(hostAddrs, v.String()) | ||
| } | ||
| netState["externalAddressess"] = hostAddrs | ||
| listAddrs := []string{} | ||
|
kishansagathiya marked this conversation as resolved.
Outdated
|
||
| 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: netState, | ||
| } | ||
| } | ||
|
|
||
| func (tm *NetworkStateTM) messageType() string { | ||
| return tm.Msg | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright 2021 ChainSafe Systems (ON) Corp. | ||
| // This file is part of gossamer. | ||
| // | ||
| // The gossamer library is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Lesser General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // The gossamer library is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Lesser General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the gossamer library. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package telemetry | ||
|
|
||
| import ( | ||
| "math/big" | ||
|
|
||
| "github.com/ChainSafe/gossamer/lib/common" | ||
| ) | ||
|
|
||
| //nolint | ||
| // NotifyFinalizedTM holds `notify.finalized` telemetry message, which is | ||
| // supposed to be send when a new block gets finalized. | ||
| type NotifyFinalizedTM struct { | ||
| Best common.Hash `json:"best"` | ||
| // Height is same as block.Header.Number | ||
| Height *big.Int `json:"height"` | ||
| Msg string `json:"msg"` | ||
| } | ||
|
|
||
| // NewNotifyFinalizedTM gets a new NotifyFinalizedTM struct. | ||
| func NewNotifyFinalizedTM(best common.Hash, height *big.Int) *NotifyFinalizedTM { | ||
| return &NotifyFinalizedTM{ | ||
| Best: best, | ||
| Height: height, | ||
| Msg: "notify.finalized", | ||
|
kishansagathiya marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| func (tm *NotifyFinalizedTM) messageType() string { | ||
| return tm.Msg | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright 2021 ChainSafe Systems (ON) Corp. | ||
| // This file is part of gossamer. | ||
| // | ||
| // The gossamer library is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Lesser General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // The gossamer library is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Lesser General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the gossamer library. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package telemetry | ||
|
|
||
| import "github.com/ChainSafe/gossamer/lib/common" | ||
|
|
||
| // SystemConnectedTM struct to hold system connected telemetry messages | ||
| type SystemConnectedTM struct { | ||
| Authority bool `json:"authority"` | ||
| Chain string `json:"chain"` | ||
| GenesisHash *common.Hash `json:"genesis_hash"` | ||
| Implementation string `json:"implementation"` | ||
| Msg string `json:"msg"` | ||
| Name string `json:"name"` | ||
| NetworkID string `json:"network_id"` | ||
| StartupTime string `json:"startup_time"` | ||
| Version string `json:"version"` | ||
| } | ||
|
|
||
| // NewSystemConnectedTM function to create new System Connected Telemetry Message | ||
| func NewSystemConnectedTM(authority bool, chain string, genesisHash *common.Hash, | ||
| implementation, name, networkID, startupTime, version string) *SystemConnectedTM { | ||
| return &SystemConnectedTM{ | ||
| Authority: authority, | ||
| Chain: chain, | ||
| GenesisHash: genesisHash, | ||
| Implementation: implementation, | ||
| Msg: "system.connected", | ||
|
kishansagathiya marked this conversation as resolved.
Outdated
|
||
| Name: name, | ||
| NetworkID: networkID, | ||
| StartupTime: startupTime, | ||
| Version: version, | ||
| } | ||
| } | ||
|
|
||
| func (tm *SystemConnectedTM) messageType() string { | ||
| return tm.Msg | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright 2021 ChainSafe Systems (ON) Corp. | ||
| // This file is part of gossamer. | ||
| // | ||
| // The gossamer library is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Lesser General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // The gossamer library is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Lesser General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the gossamer library. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package telemetry | ||
|
|
||
| import ( | ||
| "math/big" | ||
|
|
||
| "github.com/ChainSafe/gossamer/lib/common" | ||
| ) | ||
|
|
||
| // SystemIntervalTM struct to hold system interval telemetry messages | ||
| type SystemIntervalTM struct { | ||
| BandwidthDownload float64 `json:"bandwidth_download,omitempty"` | ||
| BandwidthUpload float64 `json:"bandwidth_upload,omitempty"` | ||
| Msg string `json:"msg"` | ||
| Peers int `json:"peers,omitempty"` | ||
| BestHash *common.Hash `json:"best,omitempty"` | ||
| BestHeight *big.Int `json:"height,omitempty"` | ||
| FinalisedHash *common.Hash `json:"finalized_hash,omitempty"` // nolint | ||
| FinalisedHeight *big.Int `json:"finalized_height,omitempty"` // nolint | ||
| TxCount *big.Int `json:"txcount,omitempty"` | ||
| UsedStateCacheSize *big.Int `json:"used_state_cache_size,omitempty"` | ||
| } | ||
|
|
||
| // NewBandwidthTM function to create new Bandwidth Telemetry Message | ||
| func NewBandwidthTM(bandwidthDownload, bandwidthUpload float64, peers int) *SystemIntervalTM { | ||
| return &SystemIntervalTM{ | ||
| BandwidthDownload: bandwidthDownload, | ||
| BandwidthUpload: bandwidthUpload, | ||
| Msg: "system.interval", | ||
|
kishansagathiya marked this conversation as resolved.
Outdated
|
||
| Peers: peers, | ||
| } | ||
| } | ||
|
|
||
| // NewBlockIntervalTM function to create new Block Interval Telemetry Message | ||
| func NewBlockIntervalTM(beshHash *common.Hash, bestHeight *big.Int, finalisedHash *common.Hash, | ||
| finalisedHeight, txCount, usedStateCacheSize *big.Int) *SystemIntervalTM { | ||
| return &SystemIntervalTM{ | ||
| Msg: "system.interval", | ||
|
kishansagathiya marked this conversation as resolved.
Outdated
|
||
| BestHash: beshHash, | ||
| BestHeight: bestHeight, | ||
| FinalisedHash: finalisedHash, | ||
| FinalisedHeight: finalisedHeight, | ||
| TxCount: txCount, | ||
| UsedStateCacheSize: usedStateCacheSize, | ||
| } | ||
| } | ||
|
|
||
| func (tm *SystemIntervalTM) messageType() string { | ||
| return tm.Msg | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.