Skip to content

Commit

Permalink
feat: Integrate EL monitoring stack
Browse files Browse the repository at this point in the history
* feat: Merge DockerManager and ServiceManager interfaces

* feat: integrate dependencies from eigenlayer

* feat: Integrate code from Eigenlayer

* feat: Adjust dependencies

* test: Merged interfaces

* feat: Include monitoring stack

* feat: Adjust monitoring stack dependencies

* feat: Update changelog

* refactor: Update mocks

* tests: Adjust tests file handling for Windows OS

* feat: Update PathMatcher adjustments

* tests: Adjust file handling

* feat: Add monitoring command

* tests: e2e tests for monitoringStack

* feat: Install latest Docker in CI/CD pipeline

* feat: Install latest Docker in CI/CD pipeline for e2e

* fix: Adjust Docker client version

* feat: Adjust docker client API version

* fix: Adjust platfrom issue for Windows

* feat: Update services images

* feat: Update docker-compose script

* fix: Windows error

* fix: File handling for Windows

* feat: Update service versions

* feat: Adjust monitoring clean command

* feat: Update pipeline for Windows docker

* feat: Remove unnecessary files

* fix: Windows error

* feat: Update gomod

* feat: Adjust pipeline for Docker Windows

* feat: Exclude e2e tests from unit-tests workflow

* feat: Update e2e workflow

* feat: Update daemon configuration for workflow

* fix: Pipeline  daemon for Windows

* feat: e2e pipeline for Windows

* feat: Install make for WSL in pipeline

* feat: Update workflow

* feat: Increase timeout for make codecov-test

* feat: Ignore e2e tests in unit-tests workflow

* feat: Install deps for WSL in pipeline

* feat: Skip e2e tests for unit-tests workflow

* feat: Update makefile

* feat: Run e2e tests for unit-tests ubuntu

* feat: Update go version for WSL pipeline

* feat: Update e2e workflow

* fix: Skip e2e in ubuntu unit-tests workflow

* feat: Handle go installation for WSL

* feat: Use actions for WSL in workflow

* feat: Skip e2e monitoringStack test for Windows

* feat: Update Go version

* test: Refactor tests

* refac: ComposeManager and Locker interfaces

* test: Update mocks

* refac: Remove unnecessary files

* refac: Update services versions

* style: Adjust formatting

* tests: Fix errors
  • Loading branch information
khalifaa55 authored Sep 17, 2024
1 parent ea6586f commit 000cc79
Show file tree
Hide file tree
Showing 97 changed files with 36,172 additions and 959 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
matrix:
include:
- os: ubuntu-latest
go: '1.21'
go: '1.22'
- os: macos-latest
go: '1.21'
go: '1.22'
- os: windows-latest
go: '1.21'
go: '1.22'
runs-on: ${{ matrix.os }}

steps:
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/e2e_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
matrix:
include:
- os: ubuntu-latest
go: '1.21'
go: '1.22'
- os: windows-latest
go: '1.21'
go: '1.22'
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -29,6 +29,11 @@ jobs:

- name: Install deps
run: make install-deps

- name: Run e2e tests

- name: Run e2e tests Windows
if: runner.os == 'Windows'
run: make e2e-test-windows

- name: Run e2e tests other
if: runner.os != 'Windows'
run: make e2e-test
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.21.0"
go-version: "1.22.0"

- run: chmod +x ./scripts/build-go-darwin-binaries.sh && ./scripts/build-go-darwin-binaries.sh

Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.21.0"
go-version: "1.22.0"

- run: scripts\build-go-windows-binaries.ps1

Expand All @@ -74,7 +74,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.21.0"
go-version: "1.22.0"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
path: sedge
- uses: actions/setup-go@v5
with:
go-version: "1.21.0"
go-version: "1.22.0"
- name: Run publish PPA script
env:
GOPATH: /home/runner/go
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
matrix:
include:
- os: ubuntu-latest
go: '1.21'
go: '1.22'
- os: windows-latest
go: '1.21'
go: '1.22'
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -36,7 +36,7 @@ jobs:

- name: Run tests other
if: matrix.os != 'ubuntu-latest'
run: make generate && go test ./...
run: make generate && make test-no-e2e

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- New command `lido-status` to display data of Lido Node Operator.
- Monitoring stack setup with Grafana, Prometheus, and Node Exporter.

### Changed
- Update Go version from 1.21 to 1.22.

### Fixed
- Teku and Lighthouse import keys container error on Windows.
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ test: generate ## run tests
e2e-test: generate ## Run e2e tests
@go test -timeout 20m -count=1 ./e2e/...

e2e-test-windows: generate ## Run e2e tests on Windows
@go test -timeout 20m -count=1 -skip TestE2E_MonitoringStack ./e2e/...

test-no-e2e: generate ## run tests excluding e2e
@mkdir -p coverage
@go test -coverprofile=coverage/coverage.out -covermode=count ./... -skip TestE2E

codecov-test: generate ## unit tests with coverage using the courtney tool
@mkdir -p coverage
@courtney/courtney -v -o coverage/coverage.out ./...
@courtney/courtney -v -o coverage/coverage.out -t="-skip=TestE2E" ./...
@go tool cover -html=coverage/coverage.out -o coverage/coverage.html

install-gofumpt: ## install gofumpt
Expand Down
19 changes: 9 additions & 10 deletions cli/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package actions
import (
"github.com/NethermindEth/sedge/internal/pkg/commands"
"github.com/NethermindEth/sedge/internal/pkg/generate"
"github.com/NethermindEth/sedge/internal/pkg/services"
"github.com/docker/docker/client"
)

Expand All @@ -37,22 +36,22 @@ type SedgeActions interface {
}

type sedgeActions struct {
dockerClient client.APIClient
serviceManager services.ServiceManager
commandRunner commands.CommandRunner
dockerClient client.APIClient
dockerServiceManager DockerServiceManager
commandRunner commands.CommandRunner
}

type SedgeActionsOptions struct {
DockerClient client.APIClient
ServiceManager services.ServiceManager
CommandRunner commands.CommandRunner
DockerClient client.APIClient
DockerServiceManager DockerServiceManager
CommandRunner commands.CommandRunner
}

func NewSedgeActions(options SedgeActionsOptions) SedgeActions {
return &sedgeActions{
dockerClient: options.DockerClient,
serviceManager: options.ServiceManager,
commandRunner: options.CommandRunner,
dockerClient: options.DockerClient,
dockerServiceManager: options.DockerServiceManager,
commandRunner: options.CommandRunner,
}
}

Expand Down
14 changes: 14 additions & 0 deletions cli/actions/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package actions

import "github.com/docker/docker/api/types/container"

// DockerServiceManager is an interface for managing Docker containers.
type DockerServiceManager interface {
Image(service string) (string, error)
Stop(service string) error
Start(service string) error
IsRunning(service string) (bool, error)
Wait(service string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
ContainerID(service string) (string, error)
ContainerLogs(ctID, service string) (string, error)
}
6 changes: 3 additions & 3 deletions cli/actions/generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import (
func newAction(t *testing.T, ctrl *gomock.Controller) actions.SedgeActions {
t.Helper()
dockerClient := sedge_mocks.NewMockAPIClient(ctrl)
serviceManager := services.NewServiceManager(dockerClient)
dockerServiceManager := services.NewDockerServiceManager(dockerClient)
return actions.NewSedgeActions(actions.SedgeActionsOptions{
DockerClient: dockerClient,
ServiceManager: serviceManager,
DockerClient: dockerClient,
DockerServiceManager: dockerServiceManager,
})
}

Expand Down
6 changes: 3 additions & 3 deletions cli/actions/getContainers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ func getMockActions(

return actions.NewSedgeActions(
actions.SedgeActionsOptions{
DockerClient: dockerClient,
ServiceManager: nil,
CommandRunner: nil,
DockerClient: dockerClient,
DockerServiceManager: nil,
CommandRunner: nil,
},
)
}
Expand Down
31 changes: 15 additions & 16 deletions cli/actions/importKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/NethermindEth/sedge/internal/images/validator-import/teku"
"github.com/NethermindEth/sedge/internal/pkg/commands"
"github.com/NethermindEth/sedge/internal/pkg/services"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
Expand Down Expand Up @@ -70,18 +69,18 @@ func (s *sedgeActions) ImportValidatorKeys(options ImportValidatorKeysOptions) e
}
validatorCtName := services.ContainerNameWithTag(services.DefaultSedgeValidatorClient, options.ContainerTag)
// Check validator container exists
_, err := s.serviceManager.ContainerId(validatorCtName)
_, err := s.dockerServiceManager.ContainerID(validatorCtName)
if err != nil {
return err
}
previouslyRunning, err := s.serviceManager.IsRunning(validatorCtName)
previouslyRunning, err := s.dockerServiceManager.IsRunning(validatorCtName)
if err != nil {
return err
}
// Stop validator
if previouslyRunning {
log.Info("Stopping validator client")
if err := s.serviceManager.Stop(validatorCtName); err != nil {
if err := s.dockerServiceManager.Stop(validatorCtName); err != nil {
return err
}
}
Expand All @@ -106,13 +105,13 @@ func (s *sedgeActions) ImportValidatorKeys(options ImportValidatorKeysOptions) e
var ctID string
switch options.ValidatorClient {
case "prysm":
prysmCtID, err := setupPrysmValidatorImportContainer(s.dockerClient, s.serviceManager, options)
prysmCtID, err := setupPrysmValidatorImportContainer(s.dockerClient, s.dockerServiceManager, options)
if err != nil {
return err
}
ctID = prysmCtID
case "lodestar":
lodestarCtID, err := setupLodestarValidatorImport(s.dockerClient, s.serviceManager, options)
lodestarCtID, err := setupLodestarValidatorImport(s.dockerClient, s.dockerServiceManager, options)
if err != nil {
return err
}
Expand All @@ -133,11 +132,11 @@ func (s *sedgeActions) ImportValidatorKeys(options ImportValidatorKeysOptions) e
return fmt.Errorf("%w: %s", ErrUnsupportedValidatorClient, options.ValidatorClient)
}
log.Info("Importing validator keys")
runErr := runAndWaitImportKeys(s.dockerClient, s.serviceManager, ctID)
runErr := runAndWaitImportKeys(s.dockerClient, s.dockerServiceManager, ctID)
// Run validator again
if (previouslyRunning && !options.StopValidator) || options.StartValidator {
log.Info("The validator container is being restarted")
if err := s.serviceManager.Start(validatorCtName); err != nil {
if err := s.dockerServiceManager.Start(validatorCtName); err != nil {
return err
}
}
Expand All @@ -151,12 +150,12 @@ func isDefaultKeysPath(generationPath, from string) bool {
return from == filepath.Join(generationPath, "keystore")
}

func setupPrysmValidatorImportContainer(dockerClient client.APIClient, serviceManager services.ServiceManager, options ImportValidatorKeysOptions) (string, error) {
func setupPrysmValidatorImportContainer(dockerClient client.APIClient, dockerServiceManager DockerServiceManager, options ImportValidatorKeysOptions) (string, error) {
var (
validatorCtName = services.ContainerNameWithTag(services.DefaultSedgeValidatorClient, options.ContainerTag)
validatorImportCtName = services.ContainerNameWithTag(services.ServiceCtValidatorImport, options.ContainerTag)
)
validatorImage, err := serviceManager.Image(validatorCtName)
validatorImage, err := dockerServiceManager.Image(validatorCtName)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -209,12 +208,12 @@ func setupPrysmValidatorImportContainer(dockerClient client.APIClient, serviceMa
return ct.ID, nil
}

func setupLodestarValidatorImport(dockerClient client.APIClient, serviceManager services.ServiceManager, options ImportValidatorKeysOptions) (string, error) {
func setupLodestarValidatorImport(dockerClient client.APIClient, dockerServiceManager DockerServiceManager, options ImportValidatorKeysOptions) (string, error) {
var (
validatorCtName = services.ContainerNameWithTag(services.DefaultSedgeValidatorClient, options.ContainerTag)
validatorImportCtName = services.ContainerNameWithTag(services.ServiceCtValidatorImport, options.ContainerTag)
)
validatorImage, err := serviceManager.Image(validatorCtName)
validatorImage, err := dockerServiceManager.Image(validatorCtName)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -402,19 +401,19 @@ func setupTekuValidatorImport(dockerClient client.APIClient, commandRunner comma
return ct.ID, nil
}

func runAndWaitImportKeys(dockerClient client.APIClient, serviceManager services.ServiceManager, ctID string) error {
func runAndWaitImportKeys(dockerClient client.APIClient, dockerServiceManager DockerServiceManager, ctID string) error {
log.Debugf("import keys container id: %s", ctID)
ctExit, errChan := serviceManager.Wait(ctID, container.WaitConditionNextExit)
ctExit, errChan := dockerServiceManager.Wait(ctID, container.WaitConditionNextExit)
log.Info("The keys import container is starting")
if err := dockerClient.ContainerStart(context.Background(), ctID, types.ContainerStartOptions{}); err != nil {
if err := dockerClient.ContainerStart(context.Background(), ctID, container.StartOptions{}); err != nil {
return err
}
osSignals := make(chan os.Signal, 1)
signal.Notify(osSignals, os.Interrupt)
for {
select {
case exitResult := <-ctExit:
logs, err := serviceManager.ContainerLogs(ctID, "Import keys")
logs, err := dockerServiceManager.ContainerLogs(ctID, "Import keys")
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 000cc79

Please sign in to comment.