mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package diagnostics
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
|
diaglib "github.com/ledgerwatch/erigon-lib/diagnostics"
|
|
"github.com/ledgerwatch/erigon/turbo/node"
|
|
"github.com/ledgerwatch/log/v3"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
type DiagnosticClient struct {
|
|
ctx *cli.Context
|
|
metricsMux *http.ServeMux
|
|
node *node.ErigonNode
|
|
|
|
snapshotDownload map[string]diaglib.DownloadStatistics
|
|
}
|
|
|
|
func NewDiagnosticClient(ctx *cli.Context, metricsMux *http.ServeMux, node *node.ErigonNode) *DiagnosticClient {
|
|
return &DiagnosticClient{ctx: ctx, metricsMux: metricsMux, node: node, snapshotDownload: map[string]diaglib.DownloadStatistics{}}
|
|
}
|
|
|
|
func (d *DiagnosticClient) Setup() {
|
|
d.runSnapshotListener()
|
|
}
|
|
|
|
func (d *DiagnosticClient) runSnapshotListener() {
|
|
go func() {
|
|
ctx, ch, cancel := diaglib.Context[diaglib.DownloadStatistics](context.Background(), 1)
|
|
defer cancel()
|
|
|
|
rootCtx, _ := common.RootContext()
|
|
|
|
diaglib.StartProviders(ctx, diaglib.TypeOf(diaglib.DownloadStatistics{}), log.Root())
|
|
for {
|
|
select {
|
|
case <-rootCtx.Done():
|
|
cancel()
|
|
return
|
|
case info := <-ch:
|
|
d.snapshotDownload[info.StagePrefix] = info
|
|
if info.DownloadFinished {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
}()
|
|
}
|
|
|
|
func (d *DiagnosticClient) SnapshotDownload() map[string]diaglib.DownloadStatistics {
|
|
return d.snapshotDownload
|
|
}
|