Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@
- Avoid more than one piece of information in one tag
*/
var (
once sync.Once
rep *reporter = nil
once sync.Once

Check failure on line 72 in pkg/metrics/metrics.go

View workflow job for this annotation

GitHub Actions / ubuntu

once is a global variable (gochecknoglobals)

Check failure on line 72 in pkg/metrics/metrics.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

once is a global variable (gochecknoglobals)
rep *reporter = nil

Check failure on line 73 in pkg/metrics/metrics.go

View workflow job for this annotation

GitHub Actions / ubuntu

var-declaration: should drop = nil from declaration of var rep; it is the zero value (revive)

Check failure on line 73 in pkg/metrics/metrics.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

var-declaration: should drop = nil from declaration of var rep; it is the zero value (revive)
DefaultUtxSampler *RangeSampler

Check failure on line 74 in pkg/metrics/metrics.go

View workflow job for this annotation

GitHub Actions / ubuntu

DefaultUtxSampler is a global variable (gochecknoglobals)

Check failure on line 74 in pkg/metrics/metrics.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

DefaultUtxSampler is a global variable (gochecknoglobals)
)

func MicroBlockInv(mb *proto.MicroBlockInv, source string) {
Expand Down Expand Up @@ -211,12 +212,13 @@
reportBlock(t, f)
}

func Utx(utxCount int) {
func UtxCollect() {
if rep == nil {
return
}
curV, minV, maxV := DefaultUtxSampler.Sample()
t := emptyTags().node().withEvent(eventUtx)
f := emptyFields().withUtxCount(utxCount)
f := emptyFields().withUtxCount(curV, minV, maxV)
reportUtx(t, f)
}

Expand Down Expand Up @@ -311,8 +313,10 @@
return f
}

func (f fields) withUtxCount(utxCount int) fields {
f["utx_count"] = utxCount
func (f fields) withUtxCount(currentValue, minValue, maxValue int) fields {
f["utx_current"] = currentValue
f["utx_min"] = minValue
f["utx_max"] = maxValue
return f
}

Expand Down Expand Up @@ -379,6 +383,7 @@
interval: reportInterval,
in: make(chan *influx.Point, bufferSize),
}
DefaultUtxSampler = NewRangeSampler(0)
go rep.run(ctx)
})
return nil
Expand All @@ -397,6 +402,7 @@
}
return
case <-ticker.C:
UtxCollect()
err := r.report()
if err != nil {
zap.S().Warnf("Failed to report metrics: %v", err)
Expand Down Expand Up @@ -473,3 +479,39 @@
func shortID(id proto.BlockID) string {
return id.String()[:6]
}

type RangeSampler struct {
sync.Mutex
current int
min int
max int
}

func NewRangeSampler(initial int) *RangeSampler {
return &RangeSampler{
current: initial,
min: initial,
max: initial,
}
}

func (r *RangeSampler) Update(value int) {
r.Lock()
defer r.Unlock()
r.current = value
if value < r.min {
r.min = value
}
if value > r.max {
r.max = value
}
}

func (r *RangeSampler) Sample() (int, int, int) {
r.Lock()
defer r.Unlock()
curV, minV, maxV := r.current, r.min, r.max
r.min = r.current
r.max = r.current
return curV, minV, maxV
}
9 changes: 8 additions & 1 deletion pkg/miner/utxpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/mr-tron/base58"
"github.com/pkg/errors"
"github.com/wavesplatform/gowaves/pkg/crypto"
"github.com/wavesplatform/gowaves/pkg/metrics"
"github.com/wavesplatform/gowaves/pkg/proto"
"github.com/wavesplatform/gowaves/pkg/settings"
"github.com/wavesplatform/gowaves/pkg/types"
Expand Down Expand Up @@ -74,7 +75,13 @@ func (a *UtxImpl) Add(t proto.Transaction) error {
}
a.mu.Lock()
defer a.mu.Unlock()
return a.addWithBytes(t, bts)

errAdd := a.addWithBytes(t, bts)
if errAdd != nil {
return errAdd
}
metrics.DefaultUtxSampler.Update(a.Count())
return nil
}

func (a *UtxImpl) AddBytes(bts []byte) error {
Expand Down
6 changes: 4 additions & 2 deletions pkg/node/fsm/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ func (a *BaseInfo) BroadcastTransaction(t proto.Transaction, receivedFrom peer.P
}

func (a *BaseInfo) CleanUtx() {
utxpool.NewCleaner(a.storage, a.utx, a.tm).Clean()
metrics.Utx(a.utx.Count())
go func() {
utxpool.NewCleaner(a.storage, a.utx, a.tm).Clean()
metrics.DefaultUtxSampler.Update(a.utx.Count())
}()
}

// States.
Expand Down
2 changes: 0 additions & 2 deletions pkg/node/fsm/fsm_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/wavesplatform/gowaves/pkg/libs/signatures"
"github.com/wavesplatform/gowaves/pkg/logging"
"github.com/wavesplatform/gowaves/pkg/metrics"
"github.com/wavesplatform/gowaves/pkg/node/fsm/sync_internal"
"github.com/wavesplatform/gowaves/pkg/node/fsm/tasks"
"github.com/wavesplatform/gowaves/pkg/p2p/peer"
Expand Down Expand Up @@ -152,7 +151,6 @@ func tryBroadcastTransaction(
return fsm, nil, err
}
baseInfo.BroadcastTransaction(t, p)
metrics.Utx(baseInfo.utx.Count())
return fsm, nil, nil
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/node/fsm/ng_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func (a *NGState) Block(peer peer.Peer, block *proto.Block) (State, Async, error
return a, nil, a.Errorf(errors.Wrapf(err, "failed to apply block %s", block.BlockID()))
}
metrics.BlockApplied(block, height+1)
metrics.Utx(a.baseInfo.utx.Count())
a.blocksCache.Clear()
a.blocksCache.AddBlockState(block)
a.baseInfo.scheduler.Reschedule()
Expand Down Expand Up @@ -235,7 +234,6 @@ func (a *NGState) MinedBlock(
return a, nil, a.Errorf(err)
}
metrics.BlockApplied(block, height+1)
metrics.Utx(a.baseInfo.utx.Count())
zap.S().Infof("[%s] Generated key block '%s' successfully applied to state", a, block.ID.String())

a.blocksCache.Clear()
Expand Down Expand Up @@ -308,7 +306,6 @@ func (a *NGState) mineMicro(
a.blocksCache.AddBlockState(block)
a.baseInfo.scheduler.Reschedule()
metrics.MicroBlockApplied(micro)
metrics.Utx(a.baseInfo.utx.Count())
a.baseInfo.CleanUtx()
inv := proto.NewUnsignedMicroblockInv(
micro.SenderPK,
Expand Down Expand Up @@ -392,7 +389,6 @@ func (a *NGState) checkAndAppendMicroBlock(
return nil, errors.Wrap(err, "failed to apply created from micro block")
}
metrics.MicroBlockApplied(micro)
metrics.Utx(a.baseInfo.utx.Count())
a.baseInfo.CleanUtx()
return newBlock, nil
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/node/fsm/sync_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ func (a *SyncState) MinedBlock(
return a, nil, nil // We've failed to apply mined block, it's not an error
}
metrics.BlockAppliedFromExtension(block, height+1)
metrics.Utx(a.baseInfo.utx.Count())
a.baseInfo.scheduler.Reschedule()

// first we should send block
Expand Down Expand Up @@ -285,7 +284,6 @@ func (a *SyncState) applyBlocksWithSnapshots(
}
for _, b := range blocks {
metrics.BlockAppliedFromExtension(b, height+1)
metrics.Utx(a.baseInfo.utx.Count())
height++
}
a.baseInfo.scheduler.Reschedule()
Expand Down
1 change: 0 additions & 1 deletion pkg/node/fsm/wait_micro_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ func (a *WaitMicroSnapshotState) checkAndAppendMicroBlock(
return nil, errors.Wrap(err, "failed to apply created from micro block")
}
metrics.MicroBlockApplied(micro)
metrics.Utx(a.baseInfo.utx.Count())
a.baseInfo.CleanUtx()
return newBlock, nil
}
Expand Down
1 change: 0 additions & 1 deletion pkg/node/fsm/wait_snapshot_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func (a *WaitSnapshotState) BlockSnapshot(
return processScoreAfterApplyingOrReturnToNG(a, a.baseInfo, a.receivedScores, a.blocksCache)
}
metrics.SnapshotBlockApplied(a.blockWaitingForSnapshot, height+1)
metrics.Utx(a.baseInfo.utx.Count())
zap.S().Named(logging.FSMNamespace).Debugf("[%s] Handle received key block message: block '%s' applied to state",
a, blockID)

Expand Down
Loading