Skip to content

Commit

Permalink
Add telemetry for beacon and eth version (#2176)
Browse files Browse the repository at this point in the history
Co-authored-by: Cal Bera <calbera@berachain.com>
  • Loading branch information
fridrik01 and calbera authored Nov 29, 2024
1 parent fcdcb35 commit 9409929
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 97 deletions.
4 changes: 3 additions & 1 deletion beacond/cmd/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ func DefaultComponents() []any {
*BeaconBlockHeader, *BeaconState, *BeaconStateMarshallable,
*ExecutionPayload, *ExecutionPayloadHeader, *KVStore, *Logger,
],
components.ProvideReportingService[*Logger],
components.ProvideReportingService[
*ExecutionPayload, *PayloadAttributes, *Logger,
],
components.ProvideCometBFTService[*Logger],
components.ProvideServiceRegistry[
*AvailabilityStore,
Expand Down
5 changes: 4 additions & 1 deletion beacond/cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ type (
NodeAPIServer = server.Server[NodeAPIContext]

// ReportingService is a type alias for the reporting service.
ReportingService = version.ReportingService
ReportingService = version.ReportingService[
*ExecutionPayload,
*PayloadAttributes,
]

// SidecarFactory is a type alias for the sidecar factory.
SidecarFactory = dablob.SidecarFactory[
Expand Down
20 changes: 20 additions & 0 deletions mod/execution/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"context"
"math/big"
"strings"
"sync"
"time"

"github.com/berachain/beacon-kit/mod/errors"
Expand Down Expand Up @@ -51,6 +52,10 @@ type EngineClient[
metrics *clientMetrics
// capabilities is a map of capabilities that the execution client has.
capabilities map[string]struct{}
// connected will be set to true when we have successfully connected
// to the execution client.
connectedMu sync.RWMutex
connected bool
}

// New creates a new engine client EngineClient.
Expand Down Expand Up @@ -82,6 +87,7 @@ func New[
capabilities: make(map[string]struct{}),
eth1ChainID: eth1ChainID,
metrics: newClientMetrics(telemetrySink, logger),
connected: false,
}
}

Expand Down Expand Up @@ -130,11 +136,25 @@ func (s *EngineClient[
}
continue
}
s.connectedMu.Lock()
s.connected = true
s.connectedMu.Unlock()
return nil
}
}
}

func (s *EngineClient[_, _]) IsConnected() bool {
s.connectedMu.RLock()
defer s.connectedMu.RUnlock()
return s.connected
}

func (s *EngineClient[_, _]) HasCapability(capability string) bool {
_, ok := s.capabilities[capability]
return ok
}

/* -------------------------------------------------------------------------- */
/* Helpers */
/* -------------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion mod/execution/pkg/client/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (s *EngineClient[

// Log the capabilities that the execution client does not have.
for _, capability := range ethclient.BeaconKitSupportedCapabilities() {
if _, exists := s.capabilities[capability]; !exists {
if !s.HasCapability(capability) {
s.logger.Warn(
"Your execution client may require an update 🚸",
"unsupported_capability", capability,
Expand Down
7 changes: 6 additions & 1 deletion mod/execution/pkg/client/ethclient/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/eip4844"
"github.com/berachain/beacon-kit/mod/primitives/pkg/version"
"github.com/ethereum/go-ethereum/beacon/engine"
)

/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -180,8 +181,12 @@ func (s *Client[ExecutionPayloadT]) GetClientVersionV1(
ctx context.Context,
) ([]engineprimitives.ClientVersionV1, error) {
result := make([]engineprimitives.ClientVersionV1, 0)

// NOTE: although the ethereum spec does not require us passing a
// clientversion as param, it seems some clients require it and even
// enforce a valid Code.
if err := s.Call(
ctx, &result, GetClientVersionV1, nil,
ctx, &result, GetClientVersionV1, engine.ClientVersionV1{Code: "GE"},
); err != nil {
return nil, err
}
Expand Down
19 changes: 16 additions & 3 deletions mod/node-core/pkg/components/reporting_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,41 @@ package components

import (
"cosmossdk.io/depinject"
"github.com/berachain/beacon-kit/mod/execution/pkg/client"
"github.com/berachain/beacon-kit/mod/log"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/metrics"
"github.com/berachain/beacon-kit/mod/node-core/pkg/services/version"
"github.com/berachain/beacon-kit/mod/primitives/pkg/constraints"
sdkversion "github.com/cosmos/cosmos-sdk/version"
)

type ReportingServiceInput[
ExecutionPayloadT constraints.EngineType[ExecutionPayloadT],
PayloadAttributesT client.PayloadAttributes,
LoggerT log.AdvancedLogger[LoggerT],
] struct {
depinject.In
Logger LoggerT
TelemetrySink *metrics.TelemetrySink
EngineClient *client.EngineClient[
ExecutionPayloadT,
PayloadAttributesT,
]
}

func ProvideReportingService[
ExecutionPayloadT constraints.EngineType[ExecutionPayloadT],
PayloadAttributesT client.PayloadAttributes,
LoggerT log.AdvancedLogger[LoggerT],
](
in ReportingServiceInput[LoggerT],
) *ReportingService {
return version.NewReportingService(
in ReportingServiceInput[ExecutionPayloadT, PayloadAttributesT, LoggerT],
) *version.ReportingService[ExecutionPayloadT, PayloadAttributesT] {
return version.NewReportingService[
ExecutionPayloadT, PayloadAttributesT,
](
in.Logger.With("service", "reporting"),
in.TelemetrySink,
sdkversion.Version,
in.EngineClient,
)
}
6 changes: 5 additions & 1 deletion mod/node-core/pkg/components/service_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/berachain/beacon-kit/mod/node-api/server"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/metrics"
service "github.com/berachain/beacon-kit/mod/node-core/pkg/services/registry"
"github.com/berachain/beacon-kit/mod/node-core/pkg/services/version"
"github.com/berachain/beacon-kit/mod/observability/pkg/telemetry"
)

Expand Down Expand Up @@ -101,7 +102,10 @@ type ServiceRegistryInput[
]
Logger LoggerT
NodeAPIServer *server.Server[NodeAPIContextT]
ReportingService *ReportingService
ReportingService *version.ReportingService[
ExecutionPayloadT,
*engineprimitives.PayloadAttributes[WithdrawalT],
]
TelemetrySink *metrics.TelemetrySink
TelemetryService *telemetry.Service
ValidatorService *validator.Service[
Expand Down
4 changes: 0 additions & 4 deletions mod/node-core/pkg/components/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
consruntimetypes "github.com/berachain/beacon-kit/mod/consensus/pkg/types"
engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/signer"
"github.com/berachain/beacon-kit/mod/node-core/pkg/services/version"
"github.com/berachain/beacon-kit/mod/primitives/pkg/async"
"github.com/berachain/beacon-kit/mod/primitives/pkg/transition"
"github.com/berachain/beacon-kit/mod/storage/pkg/manager"
Expand All @@ -40,9 +39,6 @@ import (
type (
// DBManager is a type alias for the database manager.
DBManager = manager.DBManager

// ReportingService is a type alias for the reporting service.
ReportingService = version.ReportingService
)

/* -------------------------------------------------------------------------- */
Expand Down
73 changes: 0 additions & 73 deletions mod/node-core/pkg/services/version/metrics.go

This file was deleted.

3 changes: 3 additions & 0 deletions mod/node-core/pkg/services/version/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ type TelemetrySink interface {
// IncrementCounter increments a counter metric identified by the provided
// keys.
IncrementCounter(key string, args ...string)
// SetGauge sets a gauge metric to the specified value, identified by the
// provided keys.
SetGauge(key string, value int64, args ...string)
}
Loading

0 comments on commit 9409929

Please sign in to comment.