Skip to content

Commit

Permalink
Add telemetry for beacon and eth version
Browse files Browse the repository at this point in the history
  • Loading branch information
fridrik01 committed Nov 25, 2024
1 parent 86b41a4 commit 64a27ae
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 96 deletions.
2 changes: 1 addition & 1 deletion beacond/cmd/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ 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
2 changes: 1 addition & 1 deletion beacond/cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ 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
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 enfore
// 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,
)
}
3 changes: 2 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,7 @@ 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)
}
91 changes: 79 additions & 12 deletions mod/node-core/pkg/services/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ package version

import (
"context"
"fmt"
"runtime"
"time"

"github.com/berachain/beacon-kit/mod/execution/pkg/client"
"github.com/berachain/beacon-kit/mod/log"
"github.com/berachain/beacon-kit/mod/primitives/pkg/constraints"
)

// defaultReportingInterval is the default interval at which the version is
Expand All @@ -33,46 +37,60 @@ const defaultReportingInterval = 5 * time.Minute

// ReportingService is a service that periodically logs the running chain
// version.
type ReportingService struct {
type ReportingService[
ExecutionPayloadT constraints.EngineType[ExecutionPayloadT],
PayloadAttributesT client.PayloadAttributes,
] struct {
// logger is used to log information about the running chain version.
logger log.Logger
// version represents the current version of the running chain.
version string
// reportingInterval is the interval at which the version is reported.
reportingInterval time.Duration
// metrics contains the metrics for the version service.
metrics *versionMetrics
// sink is the telemetry sink used to report metrics.
sink TelemetrySink
// client to query the execution layer
client *client.EngineClient[ExecutionPayloadT, PayloadAttributesT]
}

// NewReportingService creates a new VersionReporterService.
func NewReportingService(
func NewReportingService[
ExecutionPayloadT constraints.EngineType[ExecutionPayloadT],
PayloadAttributesT client.PayloadAttributes,
](
logger log.Logger,
telemetrySink TelemetrySink,
version string,
) *ReportingService {
return &ReportingService{
engineClient *client.EngineClient[ExecutionPayloadT, PayloadAttributesT],
) *ReportingService[
ExecutionPayloadT, PayloadAttributesT,
] {
return &ReportingService[
ExecutionPayloadT, PayloadAttributesT,
]{
logger: logger,
version: version,
reportingInterval: defaultReportingInterval,
metrics: newVersionMetrics(logger, telemetrySink),
sink: telemetrySink,
client: engineClient,
}
}

// Name returns the name of the service.
func (*ReportingService) Name() string {
func (*ReportingService[_, _]) Name() string {
return "reporting"
}

// Start begins the periodic logging of the chain version.
func (v *ReportingService) Start(ctx context.Context) error {
ticker := time.NewTicker(v.reportingInterval)
v.metrics.reportVersion(v.version)
func (rs *ReportingService[_, _]) Start(ctx context.Context) error {
ticker := time.NewTicker(rs.reportingInterval)
rs.handleReport(ctx)
go func() {
defer ticker.Stop()
for {
select {
case <-ticker.C:
v.metrics.reportVersion(v.version)
rs.handleReport(ctx)
continue
case <-ctx.Done():
return
Expand All @@ -81,3 +99,52 @@ func (v *ReportingService) Start(ctx context.Context) error {
}()
return nil
}

func (rs *ReportingService[_, _]) handleReport(ctx context.Context) {
systemInfo := runtime.GOOS + "/" + runtime.GOARCH

rs.logger.Info(fmt.Sprintf(`
+==========================================================================+
+ ⭐️ Star BeaconKit on GitHub @ https://github.com/berachain/beacon-kit +
+ 🧩 Your node is running version: %-40s+
+ 💾 Your system: %-57s+
+ 🦺 Please report issues @ https://github.com/berachain/beacon-kit/issues +
+==========================================================================+
`,
rs.version,
systemInfo,
))

// TODO: Delete this counter as it should be included in the new beacon_kit.runtime.version metric.
rs.sink.IncrementCounter(
"beacon_kit.runtime.version.reported",
"version", rs.version, "system", systemInfo,
)

// Get the client version from the execution layer.
info, err := rs.client.GetClientVersionV1(ctx)
if err != nil {
rs.logger.Error("Failed to get client version", "err", err)
return
}
rs.logger.Info("GetClientVersionV1", "info", info)

// the spec says we should have at least one client version
if len(info) == 0 {
rs.logger.Warn("No client version returned")
return
}

// Report the version to the telemetry sink and include labels for beacon node version and eth name and version
var args = [8]string{
"version", rs.version,
"system", systemInfo,
"eth_version", info[0].Version,
"eth_name", info[0].Name,
}
rs.sink.SetGauge("beacon_kit.runtime.version", 1, args[:]...)
}

0 comments on commit 64a27ae

Please sign in to comment.