Skip to content

Commit

Permalink
Remove existing metrics library, replace unimplemented metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Djadih committed Oct 4, 2023
1 parent eac02df commit de80a02
Show file tree
Hide file tree
Showing 108 changed files with 277 additions and 8,516 deletions.
5 changes: 0 additions & 5 deletions cmd/go-quai/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"github.com/dominant-strategies/go-quai/crypto"
"github.com/dominant-strategies/go-quai/ethdb"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/metrics"
"github.com/dominant-strategies/go-quai/node"
"gopkg.in/urfave/cli.v1"
)
Expand Down Expand Up @@ -222,10 +221,6 @@ func importChain(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.")
}
// Start metrics export if enabled
utils.SetupMetrics(ctx)
// Start system runtime metrics collection
go metrics.CollectProcessMetrics(3 * time.Second)

stack, _ := makeConfigNode(ctx)
defer stack.Close()
Expand Down
6 changes: 3 additions & 3 deletions cmd/go-quai/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/dominant-strategies/go-quai/eth/ethconfig"
"github.com/dominant-strategies/go-quai/internal/quaiapi"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/metrics"
"github.com/dominant-strategies/go-quai/metrics_config"
"github.com/dominant-strategies/go-quai/node"
"github.com/dominant-strategies/go-quai/p2p/nat"
"github.com/dominant-strategies/go-quai/params"
Expand Down Expand Up @@ -86,7 +86,7 @@ type quaiConfig struct {
Eth ethconfig.Config
Node node.Config
Ethstats quaistatsConfig
Metrics metrics.Config
Metrics metrics_config.Config
}

func loadConfig(file string, cfg *quaiConfig) error {
Expand Down Expand Up @@ -123,7 +123,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, quaiConfig) {
cfg := quaiConfig{
Eth: ethconfig.Defaults,
Node: defaultNodeConfig(ctx),
Metrics: metrics.DefaultConfig,
Metrics: metrics_config.DefaultConfig,
}

// Load config file.
Expand Down
13 changes: 7 additions & 6 deletions cmd/go-quai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"strconv"
"time"

"github.com/dominant-strategies/go-quai/metrics_config"

"github.com/dominant-strategies/go-quai/cmd/utils"
"github.com/dominant-strategies/go-quai/common"
"github.com/dominant-strategies/go-quai/eth"
Expand All @@ -32,7 +34,6 @@ import (
"github.com/dominant-strategies/go-quai/internal/flags"
"github.com/dominant-strategies/go-quai/internal/quaiapi"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/metrics"
"github.com/dominant-strategies/go-quai/node"

"gopkg.in/urfave/cli.v1"
Expand Down Expand Up @@ -246,13 +247,13 @@ func prepare(ctx *cli.Context) {
ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(128))
}

// Start metrics export if enabled
utils.SetupMetrics(ctx)

// Start system runtime metrics collection
if ctx.GlobalBool(utils.MetricsEnabledFlag.Name) {
go metrics.CollectProcessMetrics(3 * time.Second)
if ctx.GlobalIsSet(utils.MetricsEnabledFlag.Name) {
log.Info("Starting metrics")
metrics_config.EnableMetrics()
go metrics_config.StartProcessMetrics()
}

}

// quai is the main entry point into the system if no special subcommand is ran.
Expand Down
34 changes: 2 additions & 32 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"strings"
"text/tabwriter"
"text/template"
"time"

"github.com/dominant-strategies/go-quai/common"
"github.com/dominant-strategies/go-quai/common/fdlimit"
Expand All @@ -51,9 +50,8 @@ import (
"github.com/dominant-strategies/go-quai/internal/flags"
"github.com/dominant-strategies/go-quai/internal/quaiapi"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/metrics"
"github.com/dominant-strategies/go-quai/metrics/exp"
"github.com/dominant-strategies/go-quai/metrics/influxdb"
"github.com/dominant-strategies/go-quai/metrics_config"

"github.com/dominant-strategies/go-quai/node"
"github.com/dominant-strategies/go-quai/p2p"
"github.com/dominant-strategies/go-quai/p2p/enode"
Expand Down Expand Up @@ -1604,34 +1602,6 @@ func RegisterQuaiStatsService(stack *node.Node, backend quaiapi.Backend, url str
}
}

func SetupMetrics(ctx *cli.Context) {
if metrics.Enabled {
log.Info("Enabling metrics collection")

var (
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBFlag.Name)
endpoint = ctx.GlobalString(MetricsInfluxDBEndpointFlag.Name)
database = ctx.GlobalString(MetricsInfluxDBDatabaseFlag.Name)
username = ctx.GlobalString(MetricsInfluxDBUsernameFlag.Name)
password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
)

if enableExport {
tagsMap := SplitTagsFlag(ctx.GlobalString(MetricsInfluxDBTagsFlag.Name))

log.Info("Enabling metrics export to InfluxDB")

go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "quai.", tagsMap)
}

if ctx.GlobalIsSet(MetricsHTTPFlag.Name) {
address := fmt.Sprintf("%s:%d", ctx.GlobalString(MetricsHTTPFlag.Name), ctx.GlobalInt(MetricsPortFlag.Name))
log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address)
exp.Setup(address)
}
}
}

func SplitTagsFlag(tagsFlag string) map[string]string {
tags := strings.Split(tagsFlag, ",")
tagsMap := map[string]string{}
Expand Down
8 changes: 2 additions & 6 deletions consensus/blake3pow/blake3pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/dominant-strategies/go-quai/common/hexutil"
"github.com/dominant-strategies/go-quai/consensus"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/metrics"

"github.com/dominant-strategies/go-quai/rpc"
)

Expand Down Expand Up @@ -62,7 +62,6 @@ type Blake3pow struct {
rand *rand.Rand // Properly seeded random source for nonces
threads int // Number of threads to mine on if mining
update chan struct{} // Notification channel to update mining parameters
hashrate metrics.Meter // Meter tracking the average hashrate
remote *remoteSealer

// The fields below are hooks for testing
Expand All @@ -84,7 +83,6 @@ func New(config Config, notify []string, noverify bool) *Blake3pow {
blake3pow := &Blake3pow{
config: config,
update: make(chan struct{}),
hashrate: metrics.NewMeterForced(),
}
if config.PowMode == ModeShared {
blake3pow.shared = sharedBlake3pow
Expand Down Expand Up @@ -205,19 +203,17 @@ func (blake3pow *Blake3pow) SetThreads(threads int) {
func (blake3pow *Blake3pow) Hashrate() float64 {
// Short circuit if we are run the blake3pow in normal/test mode.
if blake3pow.config.PowMode != ModeNormal && blake3pow.config.PowMode != ModeTest {
return blake3pow.hashrate.Rate1()
}
var res = make(chan uint64, 1)

select {
case blake3pow.remote.fetchRateCh <- res:
case <-blake3pow.remote.exitCh:
// Return local hashrate only if blake3pow is stopped.
return blake3pow.hashrate.Rate1()
}

// Gather total submitted hash rate of remote sealers.
return blake3pow.hashrate.Rate1() + float64(<-res)
return -1
}

// SubmitHashrate can be used for remote miners to submit their hash rate.
Expand Down
2 changes: 0 additions & 2 deletions consensus/blake3pow/sealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,12 @@ search:
case <-abort:
// Mining terminated, update stats and abort
logger.Trace("Blake3pow nonce search aborted", "attempts", nonce-seed)
blake3pow.hashrate.Mark(attempts)
break search

default:
// We don't have to update hash rate on every nonce, so update after after 2^X nonces
attempts++
if (attempts % (1 << 15)) == 0 {
blake3pow.hashrate.Mark(attempts)
attempts = 0
}
// Compute the PoW value of this nonce
Expand Down
23 changes: 10 additions & 13 deletions consensus/progpow/progpow.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/dominant-strategies/go-quai/common/hexutil"
"github.com/dominant-strategies/go-quai/consensus"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/metrics"
"github.com/dominant-strategies/go-quai/rpc"
mmap "github.com/edsrzf/mmap-go"
"github.com/hashicorp/golang-lru/simplelru"
Expand Down Expand Up @@ -174,11 +173,10 @@ type Progpow struct {
caches *lru // In memory caches to avoid regenerating too often

// Mining related fields
rand *rand.Rand // Properly seeded random source for nonces
threads int // Number of threads to mine on if mining
update chan struct{} // Notification channel to update mining parameters
hashrate metrics.Meter // Meter tracking the average hashrate
remote *remoteSealer
rand *rand.Rand // Properly seeded random source for nonces
threads int // Number of threads to mine on if mining
update chan struct{} // Notification channel to update mining parameters
remote *remoteSealer

// The fields below are hooks for testing
shared *Progpow // Shared PoW verifier to avoid cache regeneration
Expand All @@ -204,10 +202,9 @@ func New(config Config, notify []string, noverify bool) *Progpow {
config.Log.Info("Disk storage enabled for ethash caches", "dir", config.CacheDir, "count", config.CachesOnDisk)
}
progpow := &Progpow{
config: config,
caches: newlru("cache", config.CachesInMem, newCache),
update: make(chan struct{}),
hashrate: metrics.NewMeterForced(),
config: config,
caches: newlru("cache", config.CachesInMem, newCache),
update: make(chan struct{}),
}
if config.PowMode == ModeShared {
progpow.shared = sharedProgpow
Expand Down Expand Up @@ -482,19 +479,19 @@ func (progpow *Progpow) SetThreads(threads int) {
func (progpow *Progpow) Hashrate() float64 {
// Short circuit if we are run the progpow in normal/test mode.
if progpow.config.PowMode != ModeNormal && progpow.config.PowMode != ModeTest {
return progpow.hashrate.Rate1()
return -1
}
var res = make(chan uint64, 1)

select {
case progpow.remote.fetchRateCh <- res:
case <-progpow.remote.exitCh:
// Return local hashrate only if progpow is stopped.
return progpow.hashrate.Rate1()
return -1
}

// Gather total submitted hash rate of remote sealers.
return progpow.hashrate.Rate1() + float64(<-res)
return -1
}

// SubmitHashrate can be used for remote miners to submit their hash rate.
Expand Down
2 changes: 0 additions & 2 deletions consensus/progpow/sealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,12 @@ search:
select {
case <-abort:
// Mining terminated, update stats and abort
progpow.hashrate.Mark(attempts)
break search

default:
// We don't have to update hash rate on every nonce, so update after after 2^X nonces
attempts++
if (attempts % (1 << 15)) == 0 {
progpow.hashrate.Mark(attempts)
attempts = 0
}
powLight := func(size uint64, cache []uint32, hash []byte, nonce uint64, blockNumber uint64) ([]byte, []byte) {
Expand Down
2 changes: 0 additions & 2 deletions core/rawdb/accessors_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ func WritePreimages(db ethdb.KeyValueWriter, preimages map[common.Hash][]byte) {
log.Fatal("Failed to store trie preimage", "err", err)
}
}
preimageCounter.Inc(int64(len(preimages)))
preimageHitCounter.Inc(int64(len(preimages)))
}

// ReadCode retrieves the contract code of the provided code hash.
Expand Down
7 changes: 2 additions & 5 deletions core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/dominant-strategies/go-quai/common"
"github.com/dominant-strategies/go-quai/ethdb"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/metrics"

"github.com/dominant-strategies/go-quai/params"
"github.com/prometheus/tsdb/fileutil"
)
Expand Down Expand Up @@ -93,9 +93,6 @@ type freezer struct {
func newFreezer(datadir string, namespace string, readonly bool) (*freezer, error) {
// Create the initial freezer object
var (
readMeter = metrics.NewRegisteredMeter(namespace+"ancient/read", nil)
writeMeter = metrics.NewRegisteredMeter(namespace+"ancient/write", nil)
sizeGauge = metrics.NewRegisteredGauge(namespace+"ancient/size", nil)
)
// Ensure the datadir is not a symbolic link if it exists.
if info, err := os.Lstat(datadir); !os.IsNotExist(err) {
Expand All @@ -120,7 +117,7 @@ func newFreezer(datadir string, namespace string, readonly bool) (*freezer, erro
quit: make(chan struct{}),
}
for name, disableSnappy := range FreezerNoSnappy {
table, err := newTable(datadir, name, readMeter, writeMeter, sizeGauge, disableSnappy)
table, err := newTable(datadir, name, disableSnappy)
if err != nil {
for _, table := range freezer.tables {
table.Close()
Expand Down
Loading

0 comments on commit de80a02

Please sign in to comment.