Skip to content

Commit

Permalink
feat: Integrate lido-exporter into the monitoring stack
Browse files Browse the repository at this point in the history
* feat: Integrate lido-exporter into the monitoring stack

* test: e2e tests for monitoring init  lido

* chore: Update go.mod

* feat: Add method Name to ServiceAPI

* feat: Add lido-exporter as target

* refac: Port conversion

* test: Unit tests for AddService method

* test: Adjust mocks order

* feat: Set network name for monitoring stack
  • Loading branch information
khalifaa55 authored Sep 30, 2024
1 parent d45ab87 commit 9eb8d61
Show file tree
Hide file tree
Showing 34 changed files with 1,264 additions and 253 deletions.
54 changes: 38 additions & 16 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import (
"strings"
"time"

eth2 "github.com/protolambda/zrnt/eth2/configs"

"github.com/NethermindEth/sedge/internal/pkg/clients"
"github.com/NethermindEth/sedge/internal/pkg/dependencies"
"github.com/NethermindEth/sedge/internal/pkg/generate"
sedgeOpts "github.com/NethermindEth/sedge/internal/pkg/options"
"github.com/NethermindEth/sedge/internal/ui"
eth2 "github.com/protolambda/zrnt/eth2/configs"

"github.com/NethermindEth/sedge/cli/actions"
"github.com/NethermindEth/sedge/configs"
Expand Down Expand Up @@ -84,9 +83,10 @@ type CliCmdOptions struct {
numberOfValidators int64
existingValidators int64
installDependencies bool
enableMonitoring bool
}

func CliCmd(p ui.Prompter, actions actions.SedgeActions, depsMgr dependencies.DependenciesManager) *cobra.Command {
func CliCmd(p ui.Prompter, actions actions.SedgeActions, depsMgr dependencies.DependenciesManager, monitoringMgr MonitoringManager) *cobra.Command {
o := new(CliCmdOptions)
cmd := &cobra.Command{
Use: "cli",
Expand Down Expand Up @@ -116,21 +116,21 @@ using docker compose command behind the scenes.
}
switch o.nodeType {
case NodeTypeFullNode:
return setupFullNode(p, o, actions, depsMgr)
return setupFullNode(p, o, actions, depsMgr, monitoringMgr)
case NodeTypeExecution:
return setupExecutionNode(p, o, actions, depsMgr)
return setupExecutionNode(p, o, actions, depsMgr, monitoringMgr)
case NodeTypeConsensus:
return setupConsensusNode(p, o, actions, depsMgr)
return setupConsensusNode(p, o, actions, depsMgr, monitoringMgr)
case NodeTypeValidator:
return setupValidatorNode(p, o, actions, depsMgr)
return setupValidatorNode(p, o, actions, depsMgr, monitoringMgr)
}
return nil
},
}
return cmd
}

func setupFullNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsManager dependencies.DependenciesManager) (err error) {
func setupFullNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsManager dependencies.DependenciesManager, monitoringMgr MonitoringManager) (err error) {
o.genData.Services = []string{"execution", "consensus"}
if err := confirmWithValidator(p, o); err != nil {
return err
Expand Down Expand Up @@ -193,6 +193,9 @@ func setupFullNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, deps
if err := setupJWT(p, o, false); err != nil {
return err
}
if err := confirmEnableMonitoring(p, o); err != nil {
return err
}
// Call generate action
o.genData, err = a.Generate(actions.GenerateOptions{
GenerationData: o.genData,
Expand All @@ -201,10 +204,10 @@ func setupFullNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, deps
if err != nil {
return err
}
return postGenerate(p, o, a, depsManager)
return postGenerate(p, o, a, depsManager, monitoringMgr)
}

func setupExecutionNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsManager dependencies.DependenciesManager) (err error) {
func setupExecutionNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsManager dependencies.DependenciesManager, monitoringMgr MonitoringManager) (err error) {
o.genData.Services = []string{"execution"}
if err := selectExecutionClient(p, o); err != nil {
return err
Expand All @@ -223,17 +226,20 @@ func setupExecutionNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions,
if err := setupJWT(p, o, true); err != nil {
return err
}
if err := confirmEnableMonitoring(p, o); err != nil {
return err
}
o.genData, err = a.Generate(actions.GenerateOptions{
GenerationData: o.genData,
GenerationPath: o.generationPath,
})
if err != nil {
return err
}
return postGenerate(p, o, a, depsManager)
return postGenerate(p, o, a, depsManager, monitoringMgr)
}

func setupConsensusNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsManager dependencies.DependenciesManager) (err error) {
func setupConsensusNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsManager dependencies.DependenciesManager, monitoringMgr MonitoringManager) (err error) {
o.genData.Services = []string{"consensus"}
if err := selectConsensusClient(p, o); err != nil {
return err
Expand Down Expand Up @@ -268,17 +274,20 @@ func setupConsensusNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions,
if err := setupJWT(p, o, true); err != nil {
return err
}
if err := confirmEnableMonitoring(p, o); err != nil {
return err
}
o.genData, err = a.Generate(actions.GenerateOptions{
GenerationData: o.genData,
GenerationPath: o.generationPath,
})
if err != nil {
return err
}
return postGenerate(p, o, a, depsManager)
return postGenerate(p, o, a, depsManager, monitoringMgr)
}

func setupValidatorNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsManager dependencies.DependenciesManager) (err error) {
func setupValidatorNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsManager dependencies.DependenciesManager, monitoringMgr MonitoringManager) (err error) {
o.genData.Services = []string{"validator"}
if err := selectValidatorClient(p, o); err != nil {
return err
Expand Down Expand Up @@ -306,14 +315,17 @@ func setupValidatorNode(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions,
}
o.genData.MevBoostOnValidator = o.withMevBoost
}
if err := confirmEnableMonitoring(p, o); err != nil {
return err
}
o.genData, err = a.Generate(actions.GenerateOptions{
GenerationData: o.genData,
GenerationPath: o.generationPath,
})
if err != nil {
return err
}
return postGenerate(p, o, a, depsManager)
return postGenerate(p, o, a, depsManager, monitoringMgr)
}

func setupJWT(p ui.Prompter, o *CliCmdOptions, skip bool) error {
Expand Down Expand Up @@ -345,7 +357,7 @@ func setupJWT(p ui.Prompter, o *CliCmdOptions, skip bool) error {
return nil
}

func postGenerate(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsMgr dependencies.DependenciesManager) error {
func postGenerate(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsMgr dependencies.DependenciesManager, monitoringMgr MonitoringManager) error {
if o.withValidator || o.nodeType == NodeTypeValidator {
if err := generateKeystore(p, o, a, depsMgr); err != nil {
return err
Expand Down Expand Up @@ -385,6 +397,11 @@ func postGenerate(p ui.Prompter, o *CliCmdOptions, a actions.SedgeActions, depsM
}); err != nil {
return err
}
if o.enableMonitoring {
if err := InitMonitoring(true, true, monitoringMgr, nil); err != nil {
return err
}
}
if o.withValidator {
log.Info(configs.HappyStakingRun)
} else {
Expand Down Expand Up @@ -818,6 +835,11 @@ func confirmEnableMEVBoost(p ui.Prompter, o *CliCmdOptions) (err error) {
return
}

func confirmEnableMonitoring(p ui.Prompter, o *CliCmdOptions) (err error) {
o.enableMonitoring, err = p.Confirm("Do you want to enable the monitoring stack?", false)
return
}

func inputCustomNetworkConfig(p ui.Prompter, o *CliCmdOptions) (err error) {
o.genData.CustomNetworkConfigPath, err = p.InputFilePath("Custom network config file path", "", true, ".yml", ".yaml")
if err != nil {
Expand Down
14 changes: 13 additions & 1 deletion cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().EthAddress("Please enter the Fee Recipient address", "", true).Return("0x2d07a21ebadde0c13e6b91022a7e5722eb6bf5d5", nil),
prompter.EXPECT().Confirm("Do you want to expose all ports?", false).Return(true, nil),
prompter.EXPECT().Select("Select JWT source", "", []string{SourceTypeCreate, SourceTypeExisting}).Return(0, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -182,6 +183,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().EthAddress("Please enter the Fee Recipient address (press enter to skip it)", "", false).Return("0x2d07a21ebadde0c13e6b91022a7e5722eb6bf5d5", nil),
prompter.EXPECT().Confirm("Do you want to expose all ports?", false).Return(true, nil),
prompter.EXPECT().Select("Select JWT source", "", []string{SourceTypeCreate, SourceTypeExisting}).Return(0, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -226,6 +228,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().EthAddress("Please enter the Fee Recipient address (press enter to skip it)", "", false).Return("0x2d07a21ebadde0c13e6b91022a7e5722eb6bf5d5", nil),
prompter.EXPECT().Confirm("Do you want to expose all ports?", false).Return(true, nil),
prompter.EXPECT().Select("Select JWT source", "", []string{SourceTypeCreate, SourceTypeExisting}).Return(0, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -259,6 +262,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().Select("Select execution client", "", ETHClients["execution"]).Return(0, nil),
prompter.EXPECT().Confirm("Do you want to expose all ports?", false).Return(true, nil),
prompter.EXPECT().Select("Select JWT source", "", []string{SourceTypeCreate, SourceTypeExisting, SourceTypeSkip}).Return(2, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -303,6 +307,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().Select("Select execution client", "", ETHClients["execution"]).Return(0, nil),
prompter.EXPECT().Confirm("Do you want to expose all ports?", false).Return(true, nil),
prompter.EXPECT().Select("Select JWT source", "", []string{SourceTypeCreate, SourceTypeExisting, SourceTypeSkip}).Return(2, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -358,6 +363,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().EthAddress("Please enter the Fee Recipient address (press enter to skip it)", "", false).Return("0x2d07a21ebadde0c13e8b91022a7e5732eb6bf5d5", nil),
prompter.EXPECT().Confirm("Do you want to expose all ports?", false).Return(true, nil),
prompter.EXPECT().Select("Select JWT source", "", []string{SourceTypeCreate, SourceTypeExisting, SourceTypeSkip}).Return(0, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -402,6 +408,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().EthAddress("Please enter the Fee Recipient address (press enter to skip it)", "", false).Return("0x2d07a21ebadde0c13e8b91022a7e5732eb6bf5d5", nil),
prompter.EXPECT().Confirm("Do you want to expose all ports?", false).Return(false, nil),
prompter.EXPECT().Select("Select JWT source", "", []string{SourceTypeCreate, SourceTypeExisting, SourceTypeSkip}).Return(0, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -444,6 +451,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().InputInt64("Validator grace period. This is the number of epochs the validator will wait for security reasons before starting", int64(1)).Return(int64(2), nil),
prompter.EXPECT().EthAddress("Please enter the Fee Recipient address", "", true).Return("0x2d07a31ebadce0a13e8a91022a5e5732eb6bf5d5", nil),
prompter.EXPECT().Confirm("Enable MEV Boost?", true).Return(true, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -509,6 +517,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().EthAddress("Please enter the Fee Recipient address (press enter to skip it)", "", false).Return("0x2d07a21ebadde0c13e8b91022a7e5732eb6bf5d5", nil),
prompter.EXPECT().Confirm("Do you want to expose all ports?", false).Return(true, nil),
prompter.EXPECT().Select("Select JWT source", "", []string{SourceTypeCreate, SourceTypeExisting, SourceTypeSkip}).Return(0, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -567,6 +576,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().InputURL("Checkpoint sync URL", configs.NetworksConfigs()[genData.Network].CheckpointSyncURL, false).Return("http://checkpoint.sync", nil),
prompter.EXPECT().Confirm("Do you want to expose all ports?", false).Return(true, nil),
prompter.EXPECT().Select("Select JWT source", "", []string{SourceTypeCreate, SourceTypeExisting}).Return(0, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -645,6 +655,7 @@ func TestCli(t *testing.T) {
prompter.EXPECT().InputURL("Checkpoint sync URL", configs.NetworksConfigs()[genData.Network].CheckpointSyncURL, false).Return("http://checkpoint.sync", nil),
prompter.EXPECT().Confirm("Do you want to expose all ports?", false).Return(true, nil),
prompter.EXPECT().Select("Select JWT source", "", []string{SourceTypeCreate, SourceTypeExisting}).Return(0, nil),
prompter.EXPECT().Confirm("Do you want to enable the monitoring stack?", false).Return(false, nil),
sedgeActions.EXPECT().Generate(gomock.Eq(actions.GenerateOptions{
GenerationPath: generationPath,
GenerationData: genData,
Expand Down Expand Up @@ -681,11 +692,12 @@ func TestCli(t *testing.T) {
sedgeActions := sedge_mocks.NewMockSedgeActions(ctrl)
prompter := sedge_mocks.NewMockPrompter(ctrl)
depsMgr := sedge_mocks.NewMockDependenciesManager(ctrl)
monitoringMgr := sedge_mocks.NewMockMonitoringManager(ctrl)
defer ctrl.Finish()

tt.setup(t, sedgeActions, prompter, depsMgr)

c := CliCmd(prompter, sedgeActions, depsMgr)
c := CliCmd(prompter, sedgeActions, depsMgr, monitoringMgr)
c.Execute()
})
}
Expand Down
Loading

0 comments on commit 9eb8d61

Please sign in to comment.