From 556e3c85443f51e52a9c780f81eda8df9531aa6f Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Tue, 4 Jun 2024 22:56:46 -0400 Subject: [PATCH] fix(metrics): version wasn't being properly reported (#1321) * bet * bet * bet * bet --- mod/execution/pkg/client/client.go | 3 ++- .../pkg/services/version/metrics.go | 9 +++++-- .../pkg/services/version/version.go | 25 ++++++++++--------- mod/storage/pkg/manager/manager.go | 2 +- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/mod/execution/pkg/client/client.go b/mod/execution/pkg/client/client.go index 92935e3d76..8285b3d2bf 100644 --- a/mod/execution/pkg/client/client.go +++ b/mod/execution/pkg/client/client.go @@ -343,8 +343,9 @@ func (s *EngineClient[ExecutionPayloadT]) buildJWTHeader() (http.Header, error) return header, nil } +// Name returns the name of the engine client. func (s *EngineClient[ExecutionPayloadT]) Name() string { - return "EngineClient" + return "engine-client" } // ================================ Info ================================ diff --git a/mod/node-builder/pkg/services/version/metrics.go b/mod/node-builder/pkg/services/version/metrics.go index 3eaf81a2c1..3909dde0b7 100644 --- a/mod/node-builder/pkg/services/version/metrics.go +++ b/mod/node-builder/pkg/services/version/metrics.go @@ -43,7 +43,12 @@ func newVersionMetrics( // reportVersion increments the versionReported counter. func (vm *versionMetrics) reportVersion(version string) { - vm.logger.Info("this node is running", "version", version) + vm.logger.Info( + "this node is running beacon-kit software", + "version", + version, + ) vm.sink.IncrementCounter( - "beacon_kit.runtime.version.reported", "version", version) + "beacon_kit.runtime.version.reported", "version", version, + ) } diff --git a/mod/node-builder/pkg/services/version/version.go b/mod/node-builder/pkg/services/version/version.go index e53519cd77..94f41a10d5 100644 --- a/mod/node-builder/pkg/services/version/version.go +++ b/mod/node-builder/pkg/services/version/version.go @@ -38,8 +38,8 @@ type ReportingService struct { logger log.Logger[any] // version represents the current version of the running chain. version string - // ticker is used to trigger periodic logging at specified intervals. - ticker *time.Ticker + // reportingInterval is the interval at which the version is reported. + reportingInterval time.Duration // metrics contains the metrics for the version service. metrics *versionMetrics } @@ -51,30 +51,31 @@ func NewReportingService( version string, ) *ReportingService { return &ReportingService{ - logger: logger, - version: version, - ticker: time.NewTicker( - defaultReportingInterval, - ), - metrics: newVersionMetrics(logger, telemetrySink), + logger: logger, + version: version, + reportingInterval: defaultReportingInterval, + metrics: newVersionMetrics(logger, telemetrySink), } } // Name returns the name of the service. func (*ReportingService) Name() string { - return "ReportingService" + 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) go func() { for { select { + case <-ticker.C: + v.metrics.reportVersion(v.version) + continue case <-ctx.Done(): - v.ticker.Stop() + ticker.Stop() return - case <-v.ticker.C: - v.metrics.reportVersion(v.version) } } }() diff --git a/mod/storage/pkg/manager/manager.go b/mod/storage/pkg/manager/manager.go index bb0d62ef29..e075780714 100644 --- a/mod/storage/pkg/manager/manager.go +++ b/mod/storage/pkg/manager/manager.go @@ -73,7 +73,7 @@ func NewDBManager[ func (m *DBManager[ BeaconBlockT, BlockEventT, SubscriptionT, ]) Name() string { - return "DBManager" + return "db-manager" } // TODO: fr implementation