This repository was archived by the owner on May 7, 2025. It is now read-only.
generated from rollkit/template-da-repo
-
Notifications
You must be signed in to change notification settings - Fork 4
feat(da): metrics #11
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5b6cdac
feat(da): add metrics
tuxcanfly 29d2c63
feat(da): review
tuxcanfly 0e67700
feat(da): lint
tuxcanfly f04fcf6
feat(da): fix init
tuxcanfly b9b6f2a
feat(da): status gauge
tuxcanfly b9b824c
feat(da): error
tuxcanfly 63ee054
feat(da): lint
tuxcanfly baadccf
feat(da): graceful shutdown
tuxcanfly 36a37b7
feat(da): gosec lint
tuxcanfly f815474
feat(da): review
tuxcanfly 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package sequencing | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/go-kit/kit/metrics" | ||
"github.com/go-kit/kit/metrics/discard" | ||
"github.com/go-kit/kit/metrics/prometheus" | ||
stdprometheus "github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const ( | ||
// MetricsSubsystem is a subsystem shared by all metrics exposed by this | ||
// package. | ||
MetricsSubsystem = "sequencer" | ||
) | ||
|
||
// MetricsProvider returns sequencing Metrics. | ||
type MetricsProvider func(chainID string) (*Metrics, error) | ||
|
||
// DefaultMetricsProvider returns Metrics build using Prometheus client library | ||
// if Prometheus is enabled. Otherwise, it returns no-op Metrics. | ||
func DefaultMetricsProvider(enabled bool) MetricsProvider { | ||
return func(chainID string) (*Metrics, error) { | ||
if enabled { | ||
return PrometheusMetrics("chain_id", chainID) | ||
} | ||
return NopMetrics() | ||
} | ||
} | ||
|
||
// Metrics contains metrics exposed by this package. | ||
type Metrics struct { | ||
// GasPrice | ||
GasPrice metrics.Gauge | ||
// Last submitted blob size | ||
LastBlobSize metrics.Gauge | ||
// cost / byte | ||
// CostPerByte metrics.Gauge | ||
// Wallet Balance | ||
// WalletBalance metrics.Gauge | ||
tuxcanfly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Transaction Status | ||
TransactionStatus metrics.Counter | ||
// Number of pending blocks. | ||
NumPendingBlocks metrics.Gauge | ||
// Last included block height | ||
IncludedBlockHeight metrics.Gauge | ||
} | ||
|
||
// PrometheusMetrics returns Metrics build using Prometheus client library. | ||
// Optionally, labels can be provided along with their values ("foo", | ||
// "fooValue"). | ||
func PrometheusMetrics(labelsAndValues ...string) (*Metrics, error) { | ||
if len(labelsAndValues)%2 != 0 { | ||
return nil, errors.New("uneven number of labels and values; labels and values should be provided in pairs") | ||
} | ||
labels := []string{} | ||
for i := 0; i < len(labelsAndValues); i += 2 { | ||
labels = append(labels, labelsAndValues[i]) | ||
} | ||
tuxcanfly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return &Metrics{ | ||
GasPrice: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ | ||
Subsystem: MetricsSubsystem, | ||
Name: "gas_price", | ||
Help: "The gas price of DA.", | ||
}, labels).With(labelsAndValues...), | ||
LastBlobSize: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ | ||
Subsystem: MetricsSubsystem, | ||
Name: "last_blob_size", | ||
Help: "The size in bytes of the last DA blob.", | ||
}, labels).With(labelsAndValues...), | ||
TransactionStatus: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ | ||
Subsystem: MetricsSubsystem, | ||
Name: "transaction_status", | ||
Help: "Count of transaction statuses for DA submissions", | ||
}, labels).With(labelsAndValues...), | ||
NumPendingBlocks: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ | ||
Subsystem: MetricsSubsystem, | ||
Name: "num_pending_blocks", | ||
Help: "The number of pending blocks for DA submission.", | ||
}, labels).With(labelsAndValues...), | ||
IncludedBlockHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ | ||
Subsystem: MetricsSubsystem, | ||
Name: "included_block_height", | ||
Help: "The last DA included block height.", | ||
}, labels).With(labelsAndValues...), | ||
}, nil | ||
} | ||
|
||
// NopMetrics returns no-op Metrics. | ||
func NopMetrics() (*Metrics, error) { | ||
return &Metrics{ | ||
GasPrice: discard.NewGauge(), | ||
LastBlobSize: discard.NewGauge(), | ||
TransactionStatus: discard.NewCounter(), | ||
NumPendingBlocks: discard.NewGauge(), | ||
IncludedBlockHeight: discard.NewGauge(), | ||
}, nil | ||
} |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.