Skip to content

Commit

Permalink
refactor: switch to using Batching datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
derrandz committed Jan 27, 2023
1 parent 50c1db3 commit 32d965b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions nodebuilder/node/uptime.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ type UptimeMetrics struct {
// totalNodeUptime is the total time the node has been running.
totalNodeUptime asyncfloat64.Counter

// totalNodeUpTimeTicks is the total time the node has been running
// counted in units of 1 second.
totalNodeUpTimeTicks int

// store is the datastore used to store the node uptime metrics.
store datastore.Datastore
store datastore.Batching
}

var (
Expand All @@ -40,7 +44,7 @@ var (

// NewUptimeMetrics creates a new UptimeMetrics
// and registers a callback to re-meter the totalNodeUptime metric.
func NewUptimeMetrics(ds datastore.Datastore) (*UptimeMetrics, error) {
func NewUptimeMetrics(ds datastore.Batching) (*UptimeMetrics, error) {
nodeStartTS, err := meter.
AsyncFloat64().
Gauge(
Expand All @@ -62,17 +66,19 @@ func NewUptimeMetrics(ds datastore.Datastore) (*UptimeMetrics, error) {
}

m := &UptimeMetrics{
nodeStartTS: nodeStartTS,
totalNodeUptime: totalNodeUptime,
store: namespace.Wrap(ds, storePrefix),
nodeStartTS: nodeStartTS,
totalNodeUptime: totalNodeUptime,
store: namespace.Wrap(ds, storePrefix),
totalNodeUpTimeTicks: 1,
}

err = meter.RegisterCallback(
[]instrument.Asynchronous{
totalNodeUptime,
},
func(ctx context.Context) {
totalNodeUptime.Observe(ctx, 1)
m.totalNodeUpTimeTicks++
totalNodeUptime.Observe(ctx, float64(m.totalNodeUpTimeTicks))
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func WithMetrics(metricOpts []otlpmetrichttp.Option, nodeType node.Type) fx.Opti
fx.Invoke(header.WithMetrics),
fx.Invoke(state.WithMetrics),
fx.Invoke(fraud.WithMetrics),
fx.Invoke(func(ctx context.Context, ds datastore.Datastore) error {
fx.Invoke(func(ctx context.Context, ds datastore.Batching) error {
m, err := node.NewUptimeMetrics(ds)
if err != nil {
return err
Expand Down

0 comments on commit 32d965b

Please sign in to comment.