Skip to content
Merged
2 changes: 1 addition & 1 deletion dot/state/block_finalisation.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (bs *BlockState) GetHighestFinalisedHeader() (*types.Header, error) {
return header, nil
}

// SetFinalisedHash sets the latest finalised block header
// SetFinalisedHash sets the latest finalised block hash
func (bs *BlockState) SetFinalisedHash(hash common.Hash, round, setID uint64) error {
bs.Lock()
defer bs.Unlock()
Expand Down
10 changes: 10 additions & 0 deletions dot/state/block_notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"sync"

"github.com/ChainSafe/gossamer/dot/telemetry"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/runtime"
Expand Down Expand Up @@ -111,6 +112,15 @@ func (bs *BlockState) notifyFinalized(hash common.Hash, round, setID uint64) {
go func(ch chan *types.FinalisationInfo) {
select {
case ch <- info:
err := telemetry.GetInstance().SendMessage(
telemetry.NewNotifyFinalizedTM(
info.Header.Hash(),
info.Header.Number,
),
)
if err != nil {
logger.Error("could not send 'notify.finalized' telemetry message", "error", err)
}
Comment thread
kishansagathiya marked this conversation as resolved.
Outdated
default:
}
}(ch)
Expand Down
45 changes: 45 additions & 0 deletions dot/telemetry/block_import.go
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
}
66 changes: 66 additions & 0 deletions dot/telemetry/network_state.go
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{}
Comment thread
kishansagathiya marked this conversation as resolved.
Outdated
for _, v := range host.Addrs() {
hostAddrs = append(hostAddrs, v.String())
}
netState["externalAddressess"] = hostAddrs
listAddrs := []string{}
Comment thread
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
}
46 changes: 46 additions & 0 deletions dot/telemetry/notify_finalized.go
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",
Comment thread
kishansagathiya marked this conversation as resolved.
Outdated
}
}

func (tm *NotifyFinalizedTM) messageType() string {
return tm.Msg
}
52 changes: 52 additions & 0 deletions dot/telemetry/system_connected.go
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",
Comment thread
kishansagathiya marked this conversation as resolved.
Outdated
Name: name,
NetworkID: networkID,
StartupTime: startupTime,
Version: version,
}
}

func (tm *SystemConnectedTM) messageType() string {
return tm.Msg
}
65 changes: 65 additions & 0 deletions dot/telemetry/system_interval.go
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",
Comment thread
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",
Comment thread
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
}
Loading