-
Notifications
You must be signed in to change notification settings - Fork 850
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
Open
JonathanOppenheimer
wants to merge
17
commits into
master
Choose a base branch
from
JonathanOppenheimer/sae-lifecycle-frontier-metrics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+165
−25
Open
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a3a8190
feat: add SAE last executed and last settled height metrics
JonathanOppenheimer c32aeaa
test: add integration test
JonathanOppenheimer 169fa3a
chore: use MakeAndRegister
JonathanOppenheimer dd2efcd
docs: update release notes
JonathanOppenheimer 9790179
Merge branch 'master' into JonathanOppenheimer/sae-lifecycle-frontier…
JonathanOppenheimer 5e838a6
chore: copilot comments
JonathanOppenheimer 3fbc3a7
docs: copilot nit
JonathanOppenheimer ba38285
chore: bazel
JonathanOppenheimer 984765d
Merge branch 'master' into JonathanOppenheimer/sae-lifecycle-frontier…
JonathanOppenheimer e5ab0ee
docs: tighten comments
JonathanOppenheimer 3d70de6
refactor: Austin suggestion
JonathanOppenheimer 988bad6
chore: simplify gaugeValue
JonathanOppenheimer 6357813
Merge branch 'master' into JonathanOppenheimer/sae-lifecycle-frontier…
JonathanOppenheimer ebe2499
Merge branch 'master' into JonathanOppenheimer/sae-lifecycle-frontier…
JonathanOppenheimer 6a96724
Update vms/saevm/saexec/metrics.go
JonathanOppenheimer 8543357
docs: correct metrics docs
JonathanOppenheimer e34a81c
Merge branch 'master' into JonathanOppenheimer/sae-lifecycle-frontier…
JonathanOppenheimer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,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", | ||
| ], | ||
| ) |
This file contains hidden or 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,48 @@ | ||
| // Copyright (C) 2019, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| // Package metrics defines SAE Prometheus collectors. These lifecycle frontier | ||
| // metrics can be compared with Snowman accepted height to derive execution and | ||
| // settlement lag. | ||
| package metrics | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| ) | ||
|
|
||
| // Metrics holds SAE Prometheus collectors and provides semantic 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)) | ||
| } |
This file contains hidden or 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,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
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -41,6 +41,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 +53,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 | ||
|
|
@@ -124,21 +126,26 @@ func NewVM[T hook.Transaction]( | |
| cfg.Now = time.Now | ||
| } | ||
| vm := &VM{ | ||
| hooks: hooks, | ||
| config: cfg, | ||
| snowCtx: snowCtx, | ||
| metrics: prometheus.NewRegistry(), | ||
| db: db, | ||
| hooks: hooks, | ||
| config: cfg, | ||
| snowCtx: snowCtx, | ||
| metricRegistry: prometheus.NewRegistry(), | ||
| db: db, | ||
| } | ||
| defer func() { | ||
| if retErr != nil { | ||
| retErr = errors.Join(retErr, vm.close()) | ||
| } | ||
| }() | ||
|
|
||
| if err := snowCtx.Metrics.Register("sae", vm.metrics); err != nil { | ||
| if err := snowCtx.Metrics.Register("sae", vm.metricRegistry); err != nil { | ||
| return nil, err | ||
| } | ||
| metrics, err := saemetrics.New(vm.metricRegistry) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("new metrics: %w", err) | ||
| } | ||
| vm.metrics = metrics | ||
|
|
||
| xdb, err := hooks.ExecutionResultsDB( | ||
| filepath.Join(snowCtx.ChainDataDir, "sae_execution_results"), | ||
|
|
@@ -180,6 +187,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 +209,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 +224,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 +249,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 +263,7 @@ func NewVM[T hook.Transaction]( | |
| txgossip.Marshaller{}, | ||
| gossip.SystemConfig{ | ||
| Log: snowCtx.Log, | ||
| Registry: vm.metrics, | ||
| Registry: vm.metricRegistry, | ||
| Namespace: "gossip", | ||
| RequestPeriod: pullGossipPeriod, | ||
| }, | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modeled this after
avalanchego/avm/metrics. I don't think it's as simple as unexporting it in whatever package has access to each metric --saeandsaeexec-- we need host it, and then export it somewhere. This package will also grow over time as we add more metrics, all of which not be as tightly coupled to an individual package.What do you think?
I could at least unexport the gauge fields so callers can only go through
MarkBlockExecuted/MarkBlockSettled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talked in the office about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this look better?