-
Notifications
You must be signed in to change notification settings - Fork 849
feat: add SAE last executed and last settled height metrics #5362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 10 commits
a3a8190
c32aeaa
169fa3a
dd2efcd
9790179
5e838a6
3fbc3a7
ba38285
984765d
e5ab0ee
3d70de6
988bad6
6357813
ebe2499
6a96724
8543357
e34a81c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
| load("//.bazel:defs.bzl", "go_test") | ||
|
|
||
| go_library( | ||
| name = "metrics", | ||
| srcs = ["metrics.go"], | ||
| importpath = "github.com/ava-labs/avalanchego/vms/saevm/metrics", | ||
| visibility = ["//visibility:public"], | ||
| deps = ["@com_github_prometheus_client_golang//prometheus"], | ||
| ) | ||
|
|
||
| go_test( | ||
| name = "metrics_test", | ||
| srcs = ["metrics_test.go"], | ||
| embed = [":metrics"], | ||
| deps = [ | ||
| "@com_github_prometheus_client_golang//prometheus", | ||
| "@com_github_prometheus_client_golang//prometheus/testutil", | ||
| "@com_github_stretchr_testify//require", | ||
| ], | ||
| ) |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think making a "metrics" package makes sense. This metrics struct IMO should be unexported in whatever package has access to each metric. Do you agree?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I modeled this after What do you think? I could at least unexport the gauge fields so callers can only go through
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We talked in the office about this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this look better? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (C) 2019, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| // metrics defines SAE Prometheus collectors. These lifecycle | ||
| // metrics are useful in their own right for configuring dashboards | ||
| // and alerts and can also be compared with Snowman metrics to derive | ||
| // additional metrics like settlement lag. | ||
| package metrics | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| ) | ||
|
|
||
| // Metrics holds SAE Prometheus collectors and provides update methods. | ||
| type Metrics struct { | ||
| LastExecutedHeight prometheus.Gauge | ||
| LastSettledHeight prometheus.Gauge | ||
| } | ||
|
|
||
| // New constructs and registers SAE metrics. | ||
| func New(reg prometheus.Registerer) (*Metrics, error) { | ||
| m := &Metrics{ | ||
| LastExecutedHeight: prometheus.NewGauge(prometheus.GaugeOpts{ | ||
| Name: "last_executed_height", | ||
| Help: "Height of the latest block that completed async execution.", | ||
| }), | ||
| LastSettledHeight: prometheus.NewGauge(prometheus.GaugeOpts{ | ||
| Name: "last_settled_height", | ||
| Help: "Height of the latest block that has settled.", | ||
| }), | ||
| } | ||
|
|
||
| return m, errors.Join( | ||
| reg.Register(m.LastExecutedHeight), | ||
| reg.Register(m.LastSettledHeight), | ||
| ) | ||
| } | ||
|
|
||
| // MarkBlockExecuted updates metrics for a block that completed async execution. | ||
| func (m *Metrics) MarkBlockExecuted(height uint64) { | ||
| m.LastExecutedHeight.Set(float64(height)) | ||
| } | ||
|
|
||
| // MarkBlockSettled updates metrics for a block that has settled. | ||
| func (m *Metrics) MarkBlockSettled(height uint64) { | ||
| m.LastSettledHeight.Set(float64(height)) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright (C) 2019, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package metrics | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/testutil" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestMetrics(t *testing.T) { | ||
| metrics, err := New(prometheus.NewRegistry()) | ||
| require.NoError(t, err, "New()") | ||
|
|
||
| metrics.MarkBlockExecuted(6) | ||
| metrics.MarkBlockSettled(7) | ||
|
|
||
| require.Equal(t, float64(6), testutil.ToFloat64(metrics.LastExecutedHeight), "last executed height") | ||
| require.Equal(t, float64(7), testutil.ToFloat64(metrics.LastSettledHeight), "last settled height") | ||
| } | ||
|
JonathanOppenheimer marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import ( | |
| "github.com/ava-labs/libevm/params" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
|
|
||
| "github.com/ava-labs/avalanchego/api/metrics" | ||
| "github.com/ava-labs/avalanchego/network/p2p" | ||
| "github.com/ava-labs/avalanchego/network/p2p/gossip" | ||
| "github.com/ava-labs/avalanchego/snow" | ||
|
|
@@ -41,6 +42,7 @@ import ( | |
| "github.com/ava-labs/avalanchego/vms/saevm/txgossip" | ||
|
|
||
| snowcommon "github.com/ava-labs/avalanchego/snow/engine/common" | ||
| saemetrics "github.com/ava-labs/avalanchego/vms/saevm/metrics" | ||
| saetypes "github.com/ava-labs/avalanchego/vms/saevm/types" | ||
| ) | ||
|
|
||
|
|
@@ -52,10 +54,11 @@ type VM struct { | |
| Peers *p2p.Peers | ||
| ValidatorPeers *p2p.Validators | ||
|
|
||
| hooks hook.Points | ||
| config Config | ||
| snowCtx *snow.Context | ||
| metrics *prometheus.Registry | ||
| hooks hook.Points | ||
| config Config | ||
| snowCtx *snow.Context | ||
| metricRegistry *prometheus.Registry | ||
| metrics *saemetrics.Metrics | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an intentional choice to have the |
||
|
|
||
| db ethdb.Database | ||
| xdb saetypes.ExecutionResults | ||
|
|
@@ -123,21 +126,26 @@ func NewVM[T hook.Transaction]( | |
| if cfg.Now == nil { | ||
| cfg.Now = time.Now | ||
| } | ||
| reg, err := metrics.MakeAndRegister(snowCtx.Metrics, "sae") | ||
|
JonathanOppenheimer marked this conversation as resolved.
|
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| vm := &VM{ | ||
| hooks: hooks, | ||
| config: cfg, | ||
| snowCtx: snowCtx, | ||
| metrics: prometheus.NewRegistry(), | ||
| db: db, | ||
| hooks: hooks, | ||
| config: cfg, | ||
| snowCtx: snowCtx, | ||
| metricRegistry: reg, | ||
| db: db, | ||
| } | ||
| defer func() { | ||
| if retErr != nil { | ||
| retErr = errors.Join(retErr, vm.close()) | ||
| } | ||
| }() | ||
|
|
||
| if err := snowCtx.Metrics.Register("sae", vm.metrics); err != nil { | ||
| return nil, err | ||
| vm.metrics, err = saemetrics.New(vm.metricRegistry) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("new metrics: %w", err) | ||
| } | ||
|
|
||
| xdb, err := hooks.ExecutionResultsDB( | ||
|
|
@@ -180,6 +188,7 @@ func NewVM[T hook.Transaction]( | |
| cfg.DBConfig, | ||
| hooks, | ||
| snowCtx.Log, | ||
| vm.metrics, | ||
| ) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("saexec.New(...): %v", err) | ||
|
|
@@ -201,6 +210,8 @@ func NewVM[T hook.Transaction]( | |
| vm.last.settled.Store(lastSettled) | ||
| vm.last.accepted.Store(head) | ||
| vm.preference.Store(head) | ||
| vm.metrics.MarkBlockExecuted(head.Height()) | ||
| vm.metrics.MarkBlockSettled(lastSettled.Height()) | ||
|
JonathanOppenheimer marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| { // ========== Mempool ========== | ||
|
|
@@ -214,11 +225,11 @@ func NewVM[T hook.Transaction]( | |
| } | ||
| vm.toClose = append(vm.toClose, txPool) | ||
|
|
||
| metrics, err := bloom.NewMetrics("mempool", vm.metrics) | ||
| bloomMetrics, err := bloom.NewMetrics("mempool", vm.metricRegistry) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| conf := gossip.BloomSetConfig{Metrics: metrics} | ||
| conf := gossip.BloomSetConfig{Metrics: bloomMetrics} | ||
| pool, err := txgossip.NewSet(txPool, conf) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -239,7 +250,7 @@ func NewVM[T hook.Transaction]( | |
| } | ||
|
|
||
| { // ========== P2P Gossip ========== | ||
| network, peers, validatorPeers, err := newNetwork(snowCtx, sender, vm.metrics) | ||
| network, peers, validatorPeers, err := newNetwork(snowCtx, sender, vm.metricRegistry) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("newNetwork(...): %v", err) | ||
| } | ||
|
|
@@ -253,7 +264,7 @@ func NewVM[T hook.Transaction]( | |
| txgossip.Marshaller{}, | ||
| gossip.SystemConfig{ | ||
| Log: snowCtx.Log, | ||
| Registry: vm.metrics, | ||
| Registry: vm.metricRegistry, | ||
| Namespace: "gossip", | ||
| RequestPeriod: pullGossipPeriod, | ||
| }, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.