-
Notifications
You must be signed in to change notification settings - Fork 968
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node | das | libs/header/sync): add total uptime node metrics + …
…totalSampled das metrics + totalSynced sync metrics (#1638) ## Overview This PR introduces node uptime metrics + das total sampled headers metrics to support calculating the uptime index proposed by mustafa on the monitoring side. This PR introduces a new module named `Telemetry` to support node related telemetry. This module can also host all general telemetry and observability that does not interest specific modules. ## Changes - [x] Introduced uptime metrics for node under `nodebuilder/node/uptime.go` - [x] Introduced persistent uptime metrics using datastore to persist node start time - [x] Testing for uptime metrics persistence using the store - [x] Unit testing for uptime metrics - [x] Integration testing for uptime metrics - [ ] e2e testing for uptime metrics ## Checklist - [x] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [x] Required CI checks are passing - [x] Visual proof for any user facing features like CLI or documentation updates - [ ] Linked issues closed with keywords ## Blocked By PR: #1537 --------- Co-authored-by: rene <41963722+renaynay@users.noreply.github.com>
- Loading branch information
Showing
14 changed files
with
306 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package sync | ||
|
||
import ( | ||
"context" | ||
"sync/atomic" | ||
|
||
"go.opentelemetry.io/otel/metric/global" | ||
"go.opentelemetry.io/otel/metric/instrument" | ||
) | ||
|
||
var meter = global.MeterProvider().Meter("header/sync") | ||
|
||
type metrics struct { | ||
totalSynced int64 | ||
} | ||
|
||
func (s *Syncer[H]) InitMetrics() error { | ||
s.metrics = &metrics{} | ||
|
||
totalSynced, err := meter. | ||
AsyncFloat64(). | ||
Gauge( | ||
"total_synced_headers", | ||
instrument.WithDescription("total synced headers"), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return meter.RegisterCallback( | ||
[]instrument.Asynchronous{ | ||
totalSynced, | ||
}, | ||
func(ctx context.Context) { | ||
totalSynced.Observe(ctx, float64(atomic.LoadInt64(&s.metrics.totalSynced))) | ||
}, | ||
) | ||
} | ||
|
||
// recordTotalSynced records the total amount of synced headers. | ||
func (m *metrics) recordTotalSynced(totalSynced int) { | ||
atomic.AddInt64(&m.totalSynced, int64(totalSynced)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package node | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"go.opentelemetry.io/otel/metric/global" | ||
"go.opentelemetry.io/otel/metric/instrument" | ||
) | ||
|
||
var meter = global.MeterProvider().Meter("node") | ||
|
||
var ( | ||
timeStarted time.Time | ||
nodeStarted bool | ||
) | ||
|
||
// WithMetrics registers node metrics. | ||
func WithMetrics() error { | ||
nodeStartTS, err := meter. | ||
AsyncFloat64(). | ||
Gauge( | ||
"node_start_ts", | ||
instrument.WithDescription("timestamp when the node was started"), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
totalNodeRunTime, err := meter. | ||
AsyncFloat64(). | ||
Counter( | ||
"node_runtime_counter_in_seconds", | ||
instrument.WithDescription("total time the node has been running"), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return meter.RegisterCallback( | ||
[]instrument.Asynchronous{nodeStartTS, totalNodeRunTime}, | ||
func(ctx context.Context) { | ||
if !nodeStarted { | ||
// Observe node start timestamp | ||
timeStarted = time.Now() | ||
nodeStartTS.Observe(ctx, float64(timeStarted.Unix())) | ||
nodeStarted = true | ||
} | ||
|
||
totalNodeRunTime.Observe(ctx, time.Since(timeStarted).Seconds()) | ||
}, | ||
) | ||
} |
Oops, something went wrong.