Skip to content

Commit 847de6a

Browse files
omar391timwu20
authored andcommitted
feat(dot/telemetry): implement substrate_number_leaves metrics (ChainSafe#1926)
1 parent 154d6e2 commit 847de6a

File tree

9 files changed

+22
-15
lines changed

9 files changed

+22
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.idea
66
*.vscode
77
*.sublime
8+
*.devcontainer
89

910
# Output of go coverage tool when used with LiteIDE
1011
*.out

dot/metrics/collector.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ func (c *Collector) AddGauge(g GaugeMetrics) {
6565
}
6666

6767
func (c *Collector) startCollectGauges() {
68-
t := time.NewTicker(Refresh)
68+
//TODO: Should we better add individual RefreshInterval for each `GaugeMetrics`or `label inside the gauges map`?
69+
t := time.NewTicker(RefreshInterval)
6970
defer func() {
7071
t.Stop()
7172
c.wg.Done()
@@ -89,6 +90,7 @@ func (c *Collector) startCollectGauges() {
8990
}
9091

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

113-
t := time.NewTicker(Refresh)
115+
t := time.NewTicker(RefreshInterval)
114116
defer func() {
115117
t.Stop()
116118
c.wg.Done()

dot/metrics/metrics.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import (
2929
var logger = log.New("pkg", "metrics")
3030

3131
const (
32-
// Refresh is the refresh time for publishing metrics.
33-
Refresh = time.Second * 10
34-
refreshFreq = int64(Refresh / time.Second)
32+
// RefreshInterval is the refresh time for publishing metrics.
33+
RefreshInterval = time.Second * 10
34+
refreshFreq = int64(RefreshInterval / time.Second)
3535
)
3636

3737
// PublishMetrics function will export the /metrics endpoint to prometheus process

dot/network/service.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (s *Service) collectNetworkMetrics() {
301301
syncedBlocks.Update(num.Int64())
302302
}
303303

304-
time.Sleep(gssmrmetrics.Refresh)
304+
time.Sleep(gssmrmetrics.RefreshInterval)
305305
}
306306
}
307307

@@ -713,13 +713,11 @@ func (s *Service) NodeRoles() byte {
713713
return s.cfg.Roles
714714
}
715715

716-
// CollectGauge will be used to collect coutable metrics from network service
716+
// CollectGauge will be used to collect countable metrics from network service
717717
func (s *Service) CollectGauge() map[string]int64 {
718718
var isSynced int64
719719
if !s.syncer.IsSynced() {
720720
isSynced = 1
721-
} else {
722-
isSynced = 0
723721
}
724722

725723
return map[string]int64{

dot/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func LoadGlobalNodeName(basepath string) (nodename string, err error) {
212212
// NewNode creates a new dot node from a dot node configuration
213213
func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node, error) {
214214
// set garbage collection percent to 10%
215-
// can be overwritten by setting the GOGC env veriable, which defaults to 100
215+
// can be overwritten by setting the GOGC env variable, which defaults to 100
216216
prev := debug.SetGCPercent(10)
217217
if prev != 100 {
218218
debug.SetGCPercent(prev)

dot/state/service.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ import (
3232
log "github.com/ChainSafe/log15"
3333
)
3434

35-
const readyPoolTransactionsMetrics = "gossamer/ready/pool/transaction/metrics"
36-
const readyPriorityQueueTransactions = "gossamer/ready/queue/transaction/metrics"
35+
const (
36+
readyPoolTransactionsMetrics = "gossamer/ready/pool/transaction/metrics"
37+
readyPriorityQueueTransactions = "gossamer/ready/queue/transaction/metrics"
38+
substrateNumberLeaves = "gossamer/substrate_number_leaves/metrics"
39+
)
3740

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

@@ -358,5 +361,6 @@ func (s *Service) CollectGauge() map[string]int64 {
358361
return map[string]int64{
359362
readyPoolTransactionsMetrics: int64(s.Transaction.pool.Len()),
360363
readyPriorityQueueTransactions: int64(s.Transaction.queue.Len()),
364+
substrateNumberLeaves: int64(len(s.Block.Leaves())),
361365
}
362366
}

dot/state/service_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ func TestStateServiceMetrics(t *testing.T) {
416416
ethmetrics.Enabled = true
417417
serv := NewService(config)
418418
serv.Transaction = NewTransactionState()
419+
serv.Block = newTestBlockState(t, testGenesisHeader)
419420

420421
m := metrics.NewCollector(context.Background())
421422
m.AddGauge(serv)
@@ -440,7 +441,7 @@ func TestStateServiceMetrics(t *testing.T) {
440441
hashes[i] = h
441442
}
442443

443-
time.Sleep(time.Second + metrics.Refresh)
444+
time.Sleep(time.Second + metrics.RefreshInterval)
444445
gpool := ethmetrics.GetOrRegisterGauge(readyPoolTransactionsMetrics, nil)
445446
gqueue := ethmetrics.GetOrRegisterGauge(readyPriorityQueueTransactions, nil)
446447

@@ -450,7 +451,7 @@ func TestStateServiceMetrics(t *testing.T) {
450451
serv.Transaction.pool.Remove(hashes[0])
451452
serv.Transaction.queue.Pop()
452453

453-
time.Sleep(time.Second + metrics.Refresh)
454+
time.Sleep(time.Second + metrics.RefreshInterval)
454455
require.Equal(t, int64(1), gpool.Value())
455456
require.Equal(t, int64(1), gqueue.Value())
456457
}

lib/grandpa/grandpa_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ func TestFinalRoundGaugeMetric(t *testing.T) {
12741274

12751275
go coll.Start()
12761276

1277-
time.Sleep(metrics.Refresh + time.Second)
1277+
time.Sleep(metrics.RefreshInterval + time.Second)
12781278
gauge := ethmetrics.GetOrRegisterGauge(finalityGrandpaRoundMetrics, nil)
12791279
require.Equal(t, gauge.Value(), int64(180))
12801280
}

scripts/ci.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.
1616

17+
//go:build none
1718
// +build none
1819

1920
package main

0 commit comments

Comments
 (0)