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

Added substrate_number_leaves metrics #1926

Merged
merged 12 commits into from
Nov 1, 2021
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.idea
*.vscode
*.sublime
*.devcontainer

# Output of go coverage tool when used with LiteIDE
*.out
Expand Down
6 changes: 4 additions & 2 deletions dot/metrics/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func (c *Collector) AddGauge(g GaugeMetrics) {
}

func (c *Collector) startCollectGauges() {
t := time.NewTicker(Refresh)
//TODO: Should we better add individual RefreshInterval for each `GaugeMetrics`or `label inside the gauges map`?
omar391 marked this conversation as resolved.
Show resolved Hide resolved
t := time.NewTicker(RefreshInterval)
defer func() {
t.Stop()
c.wg.Done()
Expand All @@ -89,6 +90,7 @@ func (c *Collector) startCollectGauges() {
}

func (c *Collector) startCollectProccessMetrics() {
//TODO: Should we better add individual RefreshInterval for each `GaugeMetrics`or `label inside the gauges map`?
cpuStats := make([]*ethmetrics.CPUStats, 2)
memStats := make([]*runtime.MemStats, 2)
for i := 0; i < len(memStats); i++ {
Expand All @@ -110,7 +112,7 @@ func (c *Collector) startCollectProccessMetrics() {
memUsed = ethmetrics.GetOrRegisterGauge("system/memory/used", ethmetrics.DefaultRegistry)
)

t := time.NewTicker(Refresh)
t := time.NewTicker(RefreshInterval)
defer func() {
t.Stop()
c.wg.Done()
Expand Down
6 changes: 3 additions & 3 deletions dot/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
var logger = log.New("pkg", "metrics")

const (
// Refresh is the refresh time for publishing metrics.
Refresh = time.Second * 10
refreshFreq = int64(Refresh / time.Second)
// RefreshInterval is the refresh time for publishing metrics.
RefreshInterval = time.Second * 10
refreshFreq = int64(RefreshInterval / time.Second)
)

// PublishMetrics function will export the /metrics endpoint to prometheus process
Expand Down
4 changes: 2 additions & 2 deletions dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (s *Service) collectNetworkMetrics() {
syncedBlocks.Update(num.Int64())
}

time.Sleep(gssmrmetrics.Refresh)
time.Sleep(gssmrmetrics.RefreshInterval)
}
}

Expand Down Expand Up @@ -713,7 +713,7 @@ func (s *Service) NodeRoles() byte {
return s.cfg.Roles
}

// CollectGauge will be used to collect coutable metrics from network service
// CollectGauge will be used to collect countable metrics from network service
func (s *Service) CollectGauge() map[string]int64 {
var isSynced int64
omar391 marked this conversation as resolved.
Show resolved Hide resolved
if !s.syncer.IsSynced() {
Expand Down
2 changes: 1 addition & 1 deletion dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func LoadGlobalNodeName(basepath string) (nodename string, err error) {
// NewNode creates a new dot node from a dot node configuration
func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node, error) {
// set garbage collection percent to 10%
// can be overwritten by setting the GOGC env veriable, which defaults to 100
// can be overwritten by setting the GOGC env variable, which defaults to 100
prev := debug.SetGCPercent(10)
if prev != 100 {
debug.SetGCPercent(prev)
Expand Down
8 changes: 6 additions & 2 deletions dot/state/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ import (
log "github.com/ChainSafe/log15"
)

const readyPoolTransactionsMetrics = "gossamer/ready/pool/transaction/metrics"
const readyPriorityQueueTransactions = "gossamer/ready/queue/transaction/metrics"
const (
readyPoolTransactionsMetrics = "gossamer/ready/pool/transaction/metrics"
readyPriorityQueueTransactions = "gossamer/ready/queue/transaction/metrics"
substrateNumberLeaves = "gossamer/substrate_number_leaves/metrics"
)

var logger = log.New("pkg", "state")

Expand Down Expand Up @@ -358,5 +361,6 @@ func (s *Service) CollectGauge() map[string]int64 {
return map[string]int64{
readyPoolTransactionsMetrics: int64(s.Transaction.pool.Len()),
readyPriorityQueueTransactions: int64(s.Transaction.queue.Len()),
substrateNumberLeaves: int64(len(s.Block.Leaves())),
}
}
4 changes: 2 additions & 2 deletions dot/state/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func TestStateServiceMetrics(t *testing.T) {
hashes[i] = h
}

time.Sleep(time.Second + metrics.Refresh)
time.Sleep(time.Second + metrics.RefreshInterval)
gpool := ethmetrics.GetOrRegisterGauge(readyPoolTransactionsMetrics, nil)
gqueue := ethmetrics.GetOrRegisterGauge(readyPriorityQueueTransactions, nil)

Expand All @@ -444,7 +444,7 @@ func TestStateServiceMetrics(t *testing.T) {
serv.Transaction.pool.Remove(hashes[0])
serv.Transaction.queue.Pop()

time.Sleep(time.Second + metrics.Refresh)
time.Sleep(time.Second + metrics.RefreshInterval)
require.Equal(t, int64(1), gpool.Value())
require.Equal(t, int64(1), gqueue.Value())
}
2 changes: 1 addition & 1 deletion lib/grandpa/grandpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ func TestFinalRoundGaugeMetric(t *testing.T) {

go coll.Start()

time.Sleep(metrics.Refresh + time.Second)
time.Sleep(metrics.RefreshInterval + time.Second)
gauge := ethmetrics.GetOrRegisterGauge(finalityGrandpaRoundMetrics, nil)
require.Equal(t, gauge.Value(), int64(180))
}
1 change: 1 addition & 0 deletions scripts/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// 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/>.

//go:build none
// +build none

package main
Expand Down