diff --git a/cmd/tasks.go b/cmd/tasks.go index d1a5d5e..383011b 100644 --- a/cmd/tasks.go +++ b/cmd/tasks.go @@ -7,7 +7,7 @@ import ( "fmt" "log" - "github.com/ethpandaops/minccino/pkg/coordinator/task/tasks" + "github.com/ethpandaops/minccino/pkg/coordinator/tasks" "github.com/spf13/cobra" "gopkg.in/yaml.v2" ) diff --git a/pkg/coordinator/coordinator.go b/pkg/coordinator/coordinator.go index 8b3ec85..0b1cc08 100644 --- a/pkg/coordinator/coordinator.go +++ b/pkg/coordinator/coordinator.go @@ -9,6 +9,7 @@ import ( "github.com/ethpandaops/minccino/pkg/coordinator/buildinfo" "github.com/ethpandaops/minccino/pkg/coordinator/clients" "github.com/ethpandaops/minccino/pkg/coordinator/test" + "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/ethpandaops/minccino/pkg/coordinator/web/server" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/sirupsen/logrus" @@ -18,7 +19,9 @@ type Coordinator struct { // Config is the coordinator configuration. Config *Config log logrus.FieldLogger + clientPool *clients.ClientPool webserver *server.WebServer + tests []types.Test metricsPort int lameDuckSeconds int } @@ -27,6 +30,7 @@ func NewCoordinator(config *Config, log logrus.FieldLogger, metricsPort, lameDuc return &Coordinator{ log: log, Config: config, + tests: []types.Test{}, metricsPort: metricsPort, lameDuckSeconds: lameDuckSeconds, } @@ -45,6 +49,7 @@ func (c *Coordinator) Run(ctx context.Context) error { if err != nil { return err } + c.clientPool = clientPool for idx := range c.Config.Endpoints { err = clientPool.AddClient(&c.Config.Endpoints[idx]) if err != nil { @@ -59,15 +64,16 @@ func (c *Coordinator) Run(ctx context.Context) error { return err } if c.Config.Web.Frontend != nil { - c.webserver.StartFrontend(c.Config.Web.Frontend, clientPool) + c.webserver.StartFrontend(c.Config.Web.Frontend, c) } } // run test - testToRun, err := test.CreateRunnable(ctx, c.log, clientPool, c.Config.Test) + testToRun, err := test.CreateRunnable(ctx, c, c.Config.Test) if err != nil { return err } + c.tests = append(c.tests, testToRun) if err := testToRun.Validate(); err != nil { return err @@ -97,6 +103,20 @@ func (c *Coordinator) Run(ctx context.Context) error { return nil } +func (c *Coordinator) Logger() logrus.FieldLogger { + return c.log +} + +func (c *Coordinator) ClientPool() *clients.ClientPool { + return c.clientPool +} + +func (c *Coordinator) GetTests() []types.Test { + tests := make([]types.Test, len(c.tests)) + copy(tests, c.tests) + return tests +} + func (c *Coordinator) startMetrics() error { c.log. Info(fmt.Sprintf("Starting metrics server on :%v", c.metricsPort)) diff --git a/pkg/coordinator/task/tasks/check_clients_are_healthy/config.go b/pkg/coordinator/tasks/check_clients_are_healthy/config.go similarity index 100% rename from pkg/coordinator/task/tasks/check_clients_are_healthy/config.go rename to pkg/coordinator/tasks/check_clients_are_healthy/config.go diff --git a/pkg/coordinator/task/tasks/check_clients_are_healthy/task.go b/pkg/coordinator/tasks/check_clients_are_healthy/task.go similarity index 94% rename from pkg/coordinator/task/tasks/check_clients_are_healthy/task.go rename to pkg/coordinator/tasks/check_clients_are_healthy/task.go index 1f3d1b0..138e76e 100644 --- a/pkg/coordinator/task/tasks/check_clients_are_healthy/task.go +++ b/pkg/coordinator/tasks/check_clients_are_healthy/task.go @@ -8,7 +8,7 @@ import ( "github.com/ethpandaops/minccino/pkg/coordinator/clients" "github.com/ethpandaops/minccino/pkg/coordinator/clients/consensus" "github.com/ethpandaops/minccino/pkg/coordinator/clients/execution" - "github.com/ethpandaops/minccino/pkg/coordinator/task/types" + "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/imdario/mergo" "github.com/sirupsen/logrus" ) @@ -96,7 +96,7 @@ func (t *Task) processCheck(ctx context.Context) error { expectedResult := !t.config.ExpectUnhealthy allResultsPass := true failedClients := []string{} - for _, client := range t.ctx.Scheduler.GetClientPool().GetClientsByNamePatterns(t.config.ClientNamePatterns) { + for _, client := range t.ctx.Scheduler.GetCoordinator().ClientPool().GetClientsByNamePatterns(t.config.ClientNamePatterns) { checkResult := t.processClientCheck(ctx, client) if checkResult != expectedResult { allResultsPass = false diff --git a/pkg/coordinator/task/tasks/check_consensus_sync_status/config.go b/pkg/coordinator/tasks/check_consensus_sync_status/config.go similarity index 100% rename from pkg/coordinator/task/tasks/check_consensus_sync_status/config.go rename to pkg/coordinator/tasks/check_consensus_sync_status/config.go diff --git a/pkg/coordinator/task/tasks/check_consensus_sync_status/task.go b/pkg/coordinator/tasks/check_consensus_sync_status/task.go similarity index 95% rename from pkg/coordinator/task/tasks/check_consensus_sync_status/task.go rename to pkg/coordinator/tasks/check_consensus_sync_status/task.go index 468e0b3..44e77e8 100644 --- a/pkg/coordinator/task/tasks/check_consensus_sync_status/task.go +++ b/pkg/coordinator/tasks/check_consensus_sync_status/task.go @@ -6,7 +6,7 @@ import ( "time" "github.com/ethpandaops/minccino/pkg/coordinator/clients" - "github.com/ethpandaops/minccino/pkg/coordinator/task/types" + "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/imdario/mergo" "github.com/sirupsen/logrus" ) @@ -95,7 +95,7 @@ func (t *Task) Execute(ctx context.Context) error { func (t *Task) processCheck(ctx context.Context) error { allResultsPass := true failedClients := []string{} - for _, client := range t.ctx.Scheduler.GetClientPool().GetClientsByNamePatterns(t.config.ClientNamePatterns) { + for _, client := range t.ctx.Scheduler.GetCoordinator().ClientPool().GetClientsByNamePatterns(t.config.ClientNamePatterns) { checkResult := t.processClientCheck(ctx, client) if !checkResult { allResultsPass = false diff --git a/pkg/coordinator/task/tasks/check_execution_sync_status/config.go b/pkg/coordinator/tasks/check_execution_sync_status/config.go similarity index 100% rename from pkg/coordinator/task/tasks/check_execution_sync_status/config.go rename to pkg/coordinator/tasks/check_execution_sync_status/config.go diff --git a/pkg/coordinator/task/tasks/check_execution_sync_status/task.go b/pkg/coordinator/tasks/check_execution_sync_status/task.go similarity index 95% rename from pkg/coordinator/task/tasks/check_execution_sync_status/task.go rename to pkg/coordinator/tasks/check_execution_sync_status/task.go index 36eab2f..0d8da60 100644 --- a/pkg/coordinator/task/tasks/check_execution_sync_status/task.go +++ b/pkg/coordinator/tasks/check_execution_sync_status/task.go @@ -6,7 +6,7 @@ import ( "time" "github.com/ethpandaops/minccino/pkg/coordinator/clients" - "github.com/ethpandaops/minccino/pkg/coordinator/task/types" + "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/imdario/mergo" "github.com/sirupsen/logrus" ) @@ -95,7 +95,7 @@ func (t *Task) Execute(ctx context.Context) error { func (t *Task) processCheck(ctx context.Context) error { allResultsPass := true failedClients := []string{} - for _, client := range t.ctx.Scheduler.GetClientPool().GetClientsByNamePatterns(t.config.ClientNamePatterns) { + for _, client := range t.ctx.Scheduler.GetCoordinator().ClientPool().GetClientsByNamePatterns(t.config.ClientNamePatterns) { checkResult := t.processClientCheck(ctx, client) if !checkResult { allResultsPass = false diff --git a/pkg/coordinator/task/tasks/info.go b/pkg/coordinator/tasks/info.go similarity index 100% rename from pkg/coordinator/task/tasks/info.go rename to pkg/coordinator/tasks/info.go diff --git a/pkg/coordinator/task/tasks/run_command/config.go b/pkg/coordinator/tasks/run_command/config.go similarity index 100% rename from pkg/coordinator/task/tasks/run_command/config.go rename to pkg/coordinator/tasks/run_command/config.go diff --git a/pkg/coordinator/task/tasks/run_command/task.go b/pkg/coordinator/tasks/run_command/task.go similarity index 97% rename from pkg/coordinator/task/tasks/run_command/task.go rename to pkg/coordinator/tasks/run_command/task.go index fa444d0..c6b2ce9 100644 --- a/pkg/coordinator/task/tasks/run_command/task.go +++ b/pkg/coordinator/tasks/run_command/task.go @@ -6,7 +6,7 @@ import ( "os/exec" "time" - "github.com/ethpandaops/minccino/pkg/coordinator/task/types" + "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/imdario/mergo" "github.com/sirupsen/logrus" ) diff --git a/pkg/coordinator/task/tasks/run_tasks/config.go b/pkg/coordinator/tasks/run_tasks/config.go similarity index 100% rename from pkg/coordinator/task/tasks/run_tasks/config.go rename to pkg/coordinator/tasks/run_tasks/config.go diff --git a/pkg/coordinator/task/tasks/run_tasks/task.go b/pkg/coordinator/tasks/run_tasks/task.go similarity index 97% rename from pkg/coordinator/task/tasks/run_tasks/task.go rename to pkg/coordinator/tasks/run_tasks/task.go index 2503fd8..4607dab 100644 --- a/pkg/coordinator/task/tasks/run_tasks/task.go +++ b/pkg/coordinator/tasks/run_tasks/task.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/ethpandaops/minccino/pkg/coordinator/task/types" + "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/imdario/mergo" "github.com/sirupsen/logrus" ) diff --git a/pkg/coordinator/task/tasks/run_tasks_concurrent/config.go b/pkg/coordinator/tasks/run_tasks_concurrent/config.go similarity index 100% rename from pkg/coordinator/task/tasks/run_tasks_concurrent/config.go rename to pkg/coordinator/tasks/run_tasks_concurrent/config.go diff --git a/pkg/coordinator/task/tasks/run_tasks_concurrent/task.go b/pkg/coordinator/tasks/run_tasks_concurrent/task.go similarity index 98% rename from pkg/coordinator/task/tasks/run_tasks_concurrent/task.go rename to pkg/coordinator/tasks/run_tasks_concurrent/task.go index de716da..5dd2258 100644 --- a/pkg/coordinator/task/tasks/run_tasks_concurrent/task.go +++ b/pkg/coordinator/tasks/run_tasks_concurrent/task.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/ethpandaops/minccino/pkg/coordinator/task/types" + "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/imdario/mergo" "github.com/sirupsen/logrus" ) diff --git a/pkg/coordinator/task/tasks/sleep/config.go b/pkg/coordinator/tasks/sleep/config.go similarity index 100% rename from pkg/coordinator/task/tasks/sleep/config.go rename to pkg/coordinator/tasks/sleep/config.go diff --git a/pkg/coordinator/task/tasks/sleep/task.go b/pkg/coordinator/tasks/sleep/task.go similarity index 96% rename from pkg/coordinator/task/tasks/sleep/task.go rename to pkg/coordinator/tasks/sleep/task.go index af0c46b..00e7f3a 100644 --- a/pkg/coordinator/task/tasks/sleep/task.go +++ b/pkg/coordinator/tasks/sleep/task.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/ethpandaops/minccino/pkg/coordinator/task/types" + "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/imdario/mergo" "github.com/sirupsen/logrus" ) diff --git a/pkg/coordinator/task/tasks/tasks.go b/pkg/coordinator/tasks/tasks.go similarity index 60% rename from pkg/coordinator/task/tasks/tasks.go rename to pkg/coordinator/tasks/tasks.go index 5e138d8..c024a82 100644 --- a/pkg/coordinator/task/tasks/tasks.go +++ b/pkg/coordinator/tasks/tasks.go @@ -1,15 +1,15 @@ package tasks import ( - "github.com/ethpandaops/minccino/pkg/coordinator/task/types" + "github.com/ethpandaops/minccino/pkg/coordinator/types" - checkclientsarehealthy "github.com/ethpandaops/minccino/pkg/coordinator/task/tasks/check_clients_are_healthy" - checkconsensussyncstatus "github.com/ethpandaops/minccino/pkg/coordinator/task/tasks/check_consensus_sync_status" - checkexecutionsyncstatus "github.com/ethpandaops/minccino/pkg/coordinator/task/tasks/check_execution_sync_status" - runcommand "github.com/ethpandaops/minccino/pkg/coordinator/task/tasks/run_command" - runtasks "github.com/ethpandaops/minccino/pkg/coordinator/task/tasks/run_tasks" - runtasksconcurrent "github.com/ethpandaops/minccino/pkg/coordinator/task/tasks/run_tasks_concurrent" - sleep "github.com/ethpandaops/minccino/pkg/coordinator/task/tasks/sleep" + checkclientsarehealthy "github.com/ethpandaops/minccino/pkg/coordinator/tasks/check_clients_are_healthy" + checkconsensussyncstatus "github.com/ethpandaops/minccino/pkg/coordinator/tasks/check_consensus_sync_status" + checkexecutionsyncstatus "github.com/ethpandaops/minccino/pkg/coordinator/tasks/check_execution_sync_status" + runcommand "github.com/ethpandaops/minccino/pkg/coordinator/tasks/run_command" + runtasks "github.com/ethpandaops/minccino/pkg/coordinator/tasks/run_tasks" + runtasksconcurrent "github.com/ethpandaops/minccino/pkg/coordinator/tasks/run_tasks_concurrent" + sleep "github.com/ethpandaops/minccino/pkg/coordinator/tasks/sleep" ) var AvailableTaskDescriptors = []*types.TaskDescriptor{ diff --git a/pkg/coordinator/task/scheduler/scheduler.go b/pkg/coordinator/test/scheduler.go similarity index 95% rename from pkg/coordinator/task/scheduler/scheduler.go rename to pkg/coordinator/test/scheduler.go index a86d0cb..c8403a2 100644 --- a/pkg/coordinator/task/scheduler/scheduler.go +++ b/pkg/coordinator/test/scheduler.go @@ -1,4 +1,4 @@ -package scheduler +package test import ( "context" @@ -6,14 +6,14 @@ import ( "sync" "time" - "github.com/ethpandaops/minccino/pkg/coordinator/clients" "github.com/ethpandaops/minccino/pkg/coordinator/helper" - "github.com/ethpandaops/minccino/pkg/coordinator/task/tasks" - "github.com/ethpandaops/minccino/pkg/coordinator/task/types" + "github.com/ethpandaops/minccino/pkg/coordinator/tasks" + "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/sirupsen/logrus" ) type TaskScheduler struct { + coordinator types.Coordinator logger logrus.FieldLogger taskCount uint64 allTasks []types.Task @@ -22,8 +22,6 @@ type TaskScheduler struct { rootCleanupTasks []types.Task taskStateMutex sync.RWMutex taskStateMap map[types.Task]*taskExecutionState - - clientPool *clients.ClientPool } type taskExecutionState struct { @@ -37,13 +35,13 @@ type taskExecutionState struct { resultMutex sync.RWMutex } -func NewTaskScheduler(logger logrus.FieldLogger, clientPool *clients.ClientPool) *TaskScheduler { +func NewTaskScheduler(logger logrus.FieldLogger, coordinator types.Coordinator) *TaskScheduler { return &TaskScheduler{ logger: logger, rootTasks: make([]types.Task, 0), allTasks: make([]types.Task, 0), taskStateMap: make(map[types.Task]*taskExecutionState), - clientPool: clientPool, + coordinator: coordinator, } } @@ -55,8 +53,8 @@ func (ts *TaskScheduler) GetTaskCount() int { return len(ts.allTasks) } -func (ts *TaskScheduler) GetClientPool() *clients.ClientPool { - return ts.clientPool +func (ts *TaskScheduler) GetCoordinator() types.Coordinator { + return ts.coordinator } func (ts *TaskScheduler) ParseTaskOptions(rawtask *helper.RawMessage) (*types.TaskOptions, error) { diff --git a/pkg/coordinator/test/test.go b/pkg/coordinator/test/test.go index 1af0a83..4bac734 100644 --- a/pkg/coordinator/test/test.go +++ b/pkg/coordinator/test/test.go @@ -5,21 +5,13 @@ import ( "fmt" "time" - "github.com/ethpandaops/minccino/pkg/coordinator/clients" - "github.com/ethpandaops/minccino/pkg/coordinator/task/scheduler" + "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/sirupsen/logrus" ) -type Runnable interface { - Validate() error - Run(ctx context.Context) error - Name() string - Percent() float64 -} - type Test struct { name string - taskScheduler *scheduler.TaskScheduler + taskScheduler *TaskScheduler log logrus.FieldLogger config Config @@ -27,45 +19,45 @@ type Test struct { metrics Metrics } -func CreateRunnable(ctx context.Context, log logrus.FieldLogger, clientPool *clients.ClientPool, config Config) (Runnable, error) { - runnable := &Test{ +func CreateRunnable(ctx context.Context, coordinator types.Coordinator, config Config) (types.Test, error) { + test := &Test{ name: config.Name, - log: log.WithField("component", "test").WithField("test", config.Name), + log: coordinator.Logger().WithField("component", "test").WithField("test", config.Name), config: config, metrics: NewMetrics("sync_test_coordinator", config.Name), } // parse tasks - runnable.taskScheduler = scheduler.NewTaskScheduler(runnable.log, clientPool) + test.taskScheduler = NewTaskScheduler(test.log, coordinator) for _, rawtask := range config.Tasks { - taskOptions, err := runnable.taskScheduler.ParseTaskOptions(&rawtask) + taskOptions, err := test.taskScheduler.ParseTaskOptions(&rawtask) if err != nil { return nil, err } - _, err = runnable.taskScheduler.AddRootTask(taskOptions) + _, err = test.taskScheduler.AddRootTask(taskOptions) if err != nil { return nil, err } } for _, rawtask := range config.CleanupTasks { - taskOptions, err := runnable.taskScheduler.ParseTaskOptions(&rawtask) + taskOptions, err := test.taskScheduler.ParseTaskOptions(&rawtask) if err != nil { return nil, err } - _, err = runnable.taskScheduler.AddCleanupTask(taskOptions) + _, err = test.taskScheduler.AddCleanupTask(taskOptions) if err != nil { return nil, err } } // setup metrics - runnable.metrics.Register() + test.metrics.Register() - runnable.metrics.SetTestInfo(config.Name) - runnable.metrics.SetTotalTasks(float64(len(config.Tasks))) + test.metrics.SetTestInfo(config.Name) + test.metrics.SetTotalTasks(float64(len(config.Tasks))) - return runnable, nil + return test, nil } func (t *Test) Name() string { diff --git a/pkg/coordinator/types/coordinator.go b/pkg/coordinator/types/coordinator.go new file mode 100644 index 0000000..39851ef --- /dev/null +++ b/pkg/coordinator/types/coordinator.go @@ -0,0 +1,12 @@ +package types + +import ( + "github.com/ethpandaops/minccino/pkg/coordinator/clients" + "github.com/sirupsen/logrus" +) + +type Coordinator interface { + Logger() logrus.FieldLogger + ClientPool() *clients.ClientPool + GetTests() []Test +} diff --git a/pkg/coordinator/task/types/task.go b/pkg/coordinator/types/task.go similarity index 100% rename from pkg/coordinator/task/types/task.go rename to pkg/coordinator/types/task.go diff --git a/pkg/coordinator/task/types/taskctx.go b/pkg/coordinator/types/taskctx.go similarity index 89% rename from pkg/coordinator/task/types/taskctx.go rename to pkg/coordinator/types/taskctx.go index 1bff02d..62b71dc 100644 --- a/pkg/coordinator/task/types/taskctx.go +++ b/pkg/coordinator/types/taskctx.go @@ -3,14 +3,13 @@ package types import ( "context" - "github.com/ethpandaops/minccino/pkg/coordinator/clients" "github.com/ethpandaops/minccino/pkg/coordinator/helper" "github.com/sirupsen/logrus" ) type TaskScheduler interface { GetLogger() logrus.FieldLogger - GetClientPool() *clients.ClientPool + GetCoordinator() Coordinator ParseTaskOptions(rawtask *helper.RawMessage) (*TaskOptions, error) ExecuteTask(ctx context.Context, task Task, taskWatchFn func(task Task, ctx context.Context, cancelFn context.CancelFunc)) error WatchTaskPass(task Task, ctx context.Context, cancelFn context.CancelFunc) diff --git a/pkg/coordinator/types/test.go b/pkg/coordinator/types/test.go new file mode 100644 index 0000000..a9be298 --- /dev/null +++ b/pkg/coordinator/types/test.go @@ -0,0 +1,10 @@ +package types + +import "context" + +type Test interface { + Validate() error + Run(ctx context.Context) error + Name() string + Percent() float64 +} diff --git a/pkg/coordinator/web/handlers/clients.go b/pkg/coordinator/web/handlers/clients.go index 94b2315..f951f3e 100644 --- a/pkg/coordinator/web/handlers/clients.go +++ b/pkg/coordinator/web/handlers/clients.go @@ -63,7 +63,7 @@ func (fh *FrontendHandler) getClientsPageData() (*ClientsPage, error) { } // get clients - for _, client := range fh.pool.GetAllClients() { + for _, client := range fh.coordinator.ClientPool().GetAllClients() { clientData := fh.getClientsPageClientData(client) pageData.Clients = append(pageData.Clients, clientData) } @@ -73,6 +73,7 @@ func (fh *FrontendHandler) getClientsPageData() (*ClientsPage, error) { } func (fh *FrontendHandler) getClientsPageClientData(client *clients.PoolClient) *ClientsPageClient { + clientPool := fh.coordinator.ClientPool() headSlot, headRoot := client.ConsensusClient.GetLastHead() blockNum, blockHash := client.ExecutionClient.GetLastHead() clientData := &ClientsPageClient{ @@ -83,13 +84,13 @@ func (fh *FrontendHandler) getClientsPageClientData(client *clients.PoolClient) CLHeadSlot: uint64(headSlot), CLHeadRoot: headRoot[:], CLLastRefresh: client.ConsensusClient.GetLastEventTime(), - CLIsReady: fh.pool.GetConsensusPool().GetCanonicalFork(2).IsClientReady(client.ConsensusClient), + CLIsReady: clientPool.GetConsensusPool().GetCanonicalFork(2).IsClientReady(client.ConsensusClient), ELVersion: client.ExecutionClient.GetVersion(), ELType: uint64(client.ExecutionClient.GetClientType()), ELHeadNumber: uint64(blockNum), ELHeadHash: blockHash[:], ELLastRefresh: client.ExecutionClient.GetLastEventTime(), - ELIsReady: fh.pool.GetExecutionPool().GetCanonicalFork(2).IsClientReady(client.ExecutionClient), + ELIsReady: clientPool.GetExecutionPool().GetCanonicalFork(2).IsClientReady(client.ExecutionClient), } if lastError := client.ConsensusClient.GetLastError(); lastError != nil { clientData.CLLastError = lastError.Error() diff --git a/pkg/coordinator/web/handlers/handler.go b/pkg/coordinator/web/handlers/handler.go index 375c641..1ae2ac7 100644 --- a/pkg/coordinator/web/handlers/handler.go +++ b/pkg/coordinator/web/handlers/handler.go @@ -1,15 +1,15 @@ package handlers import ( - "github.com/ethpandaops/minccino/pkg/coordinator/clients" + "github.com/ethpandaops/minccino/pkg/coordinator/types" ) type FrontendHandler struct { - pool *clients.ClientPool + coordinator types.Coordinator } -func NewFrontendHandler(clientPool *clients.ClientPool) *FrontendHandler { +func NewFrontendHandler(coordinator types.Coordinator) *FrontendHandler { return &FrontendHandler{ - pool: clientPool, + coordinator: coordinator, } } diff --git a/pkg/coordinator/web/handlers/index.go b/pkg/coordinator/web/handlers/index.go index 423c303..74a6c58 100644 --- a/pkg/coordinator/web/handlers/index.go +++ b/pkg/coordinator/web/handlers/index.go @@ -40,16 +40,17 @@ func (fh *FrontendHandler) Index(w http.ResponseWriter, r *http.Request) { func (fh *FrontendHandler) getIndexPageData() (*IndexPage, error) { pageData := &IndexPage{} - allClients := fh.pool.GetAllClients() + clientPool := fh.coordinator.ClientPool() + allClients := clientPool.GetAllClients() pageData.ClientCount = uint64(len(allClients)) - canonicalClFork := fh.pool.GetConsensusPool().GetCanonicalFork(2) + canonicalClFork := clientPool.GetConsensusPool().GetCanonicalFork(2) if canonicalClFork != nil { pageData.CLReadyCount = uint64(len(canonicalClFork.ReadyClients)) pageData.CLHeadSlot = uint64(canonicalClFork.Slot) pageData.CLHeadRoot = canonicalClFork.Root[:] } - canonicalElFork := fh.pool.GetExecutionPool().GetCanonicalFork(2) + canonicalElFork := clientPool.GetExecutionPool().GetCanonicalFork(2) if canonicalElFork != nil { pageData.ELReadyCount = uint64(len(canonicalElFork.ReadyClients)) pageData.ELHeadNumber = uint64(canonicalElFork.Number) diff --git a/pkg/coordinator/web/server/server.go b/pkg/coordinator/web/server/server.go index ff8191b..eb624d3 100644 --- a/pkg/coordinator/web/server/server.go +++ b/pkg/coordinator/web/server/server.go @@ -4,7 +4,7 @@ import ( "net" "net/http" - "github.com/ethpandaops/minccino/pkg/coordinator/clients" + coordinator_types "github.com/ethpandaops/minccino/pkg/coordinator/types" "github.com/ethpandaops/minccino/pkg/coordinator/web" "github.com/ethpandaops/minccino/pkg/coordinator/web/handlers" "github.com/ethpandaops/minccino/pkg/coordinator/web/types" @@ -62,7 +62,7 @@ func NewWebServer(config *types.ServerConfig, logger logrus.FieldLogger) (*WebSe return ws, nil } -func (ws *WebServer) StartFrontend(config *types.FrontendConfig, clientPool *clients.ClientPool) error { +func (ws *WebServer) StartFrontend(config *types.FrontendConfig, coordinator coordinator_types.Coordinator) error { if config.Pprof { // add pprof handler ws.router.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux) @@ -74,7 +74,7 @@ func (ws *WebServer) StartFrontend(config *types.FrontendConfig, clientPool *cli } // register frontend routes - frontendHandler := handlers.NewFrontendHandler(clientPool) + frontendHandler := handlers.NewFrontendHandler(coordinator) ws.router.HandleFunc("/", frontendHandler.Index).Methods("GET") ws.router.HandleFunc("/clients", frontendHandler.Clients).Methods("GET")