-
Notifications
You must be signed in to change notification settings - Fork 21
OEV-832 Ingest block_history_estimator and fee_history_estimator metrics into Beholder #393
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
Merged
cll-gg
merged 9 commits into
develop
from
OEV-832-ingest-gas_updater_set_gas_price-in-Beholder
Mar 20, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
56156f0
OEV-832 Ingest gas_updater_set_gas_price and gas_updater_set_tip_cap …
cll-gg c2ecda1
Separate metrics block
cll-gg e8801e7
Potential fix for pull request finding
cll-gg e3a3784
Introduce otel metrics for the other block_history_estimator metrics …
cll-gg 9a704a3
Extract metrics into its own file for readability + encapsulation
cll-gg 481fae6
Can't have prom metrics per struct
cll-gg 992d2fe
Fix ctx handling for setLatest()
cll-gg 9e6b05a
Do the same thing for existing prom metrics in fee_history_estimator
cll-gg 59b01b0
Small comment update
cll-gg 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| package gas | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/big" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/promauto" | ||
| "go.opentelemetry.io/otel/attribute" | ||
| "go.opentelemetry.io/otel/metric" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-common/pkg/beholder" | ||
| "github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
| ) | ||
|
|
||
| var ( | ||
| promBlockHistoryEstimatorAllGasPricePercentiles = promauto.NewGaugeVec(prometheus.GaugeOpts{ | ||
| Name: "gas_updater_all_gas_price_percentiles", | ||
| Help: "Gas price at given percentile", | ||
| }, []string{"percentile", "evmChainID"}) | ||
| promBlockHistoryEstimatorAllTipCapPercentiles = promauto.NewGaugeVec(prometheus.GaugeOpts{ | ||
| Name: "gas_updater_all_tip_cap_percentiles", | ||
| Help: "Tip cap at given percentile", | ||
| }, []string{"percentile", "evmChainID"}) | ||
| promBlockHistoryEstimatorSetGasPrice = promauto.NewGaugeVec(prometheus.GaugeOpts{ | ||
| Name: "gas_updater_set_gas_price", | ||
| Help: "Gas updater set gas price (in Wei)", | ||
| }, []string{"percentile", "evmChainID"}) | ||
| promBlockHistoryEstimatorSetTipCap = promauto.NewGaugeVec(prometheus.GaugeOpts{ | ||
| Name: "gas_updater_set_tip_cap", | ||
| Help: "Gas updater set gas tip cap (in Wei)", | ||
| }, []string{"percentile", "evmChainID"}) | ||
| promBlockHistoryEstimatorCurrentBaseFee = promauto.NewGaugeVec(prometheus.GaugeOpts{ | ||
| Name: "gas_updater_current_base_fee", | ||
| Help: "Gas updater current block base fee in Wei", | ||
| }, []string{"evmChainID"}) | ||
| promBlockHistoryEstimatorConnectivityFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "block_history_estimator_connectivity_failure_count", | ||
| Help: "Counter is incremented every time a gas bump is prevented due to a detected network propagation/connectivity issue", | ||
| }, []string{"evmChainID", "mode"}) | ||
| ) | ||
|
|
||
| // blockHistoryEstimatorMetrics dual-writes to Prometheus and optional Beholder OTel instruments. | ||
| // All Record* methods are safe to call when Beholder instruments are nil (no-op for OTel side). | ||
| type blockHistoryEstimatorMetrics struct { | ||
| chainID string | ||
|
|
||
| gasPriceGauge metric.Float64Gauge | ||
| tipCapGauge metric.Float64Gauge | ||
| allGasPricePercentilesGauge metric.Float64Gauge | ||
| allTipCapPercentilesGauge metric.Float64Gauge | ||
| currentBaseFeeGauge metric.Float64Gauge | ||
| connectivityFailureCountCounter metric.Int64Counter | ||
| } | ||
|
|
||
| func newBlockHistoryEstimatorMetrics(lggr logger.SugaredLogger, chainID *big.Int) *blockHistoryEstimatorMetrics { | ||
| m := &blockHistoryEstimatorMetrics{chainID: chainID.String()} | ||
|
|
||
| // otel | ||
| if g, err := beholder.GetMeter().Float64Gauge("gas_updater_set_gas_price"); err != nil { | ||
| lggr.Errorw("Failed to register Beholder gas_updater_set_gas_price gauge", "err", err) | ||
| } else { | ||
| m.gasPriceGauge = g | ||
| } | ||
| if g, err := beholder.GetMeter().Float64Gauge("gas_updater_set_tip_cap"); err != nil { | ||
| lggr.Errorw("Failed to register Beholder gas_updater_set_tip_cap gauge", "err", err) | ||
| } else { | ||
| m.tipCapGauge = g | ||
| } | ||
| if g, err := beholder.GetMeter().Float64Gauge("gas_updater_all_gas_price_percentiles"); err != nil { | ||
| lggr.Errorw("Failed to register Beholder gas_updater_all_gas_price_percentiles gauge", "err", err) | ||
| } else { | ||
| m.allGasPricePercentilesGauge = g | ||
| } | ||
| if g, err := beholder.GetMeter().Float64Gauge("gas_updater_all_tip_cap_percentiles"); err != nil { | ||
| lggr.Errorw("Failed to register Beholder gas_updater_all_tip_cap_percentiles gauge", "err", err) | ||
| } else { | ||
| m.allTipCapPercentilesGauge = g | ||
| } | ||
| if g, err := beholder.GetMeter().Float64Gauge("gas_updater_current_base_fee"); err != nil { | ||
| lggr.Errorw("Failed to register Beholder gas_updater_current_base_fee gauge", "err", err) | ||
| } else { | ||
| m.currentBaseFeeGauge = g | ||
| } | ||
| if c, err := beholder.GetMeter().Int64Counter("block_history_estimator_connectivity_failure_count"); err != nil { | ||
| lggr.Errorw("Failed to register Beholder block_history_estimator_connectivity_failure_count counter", "err", err) | ||
| } else { | ||
| m.connectivityFailureCountCounter = c | ||
| } | ||
|
cll-gg marked this conversation as resolved.
|
||
|
|
||
| return m | ||
| } | ||
|
|
||
| func (m *blockHistoryEstimatorMetrics) RecordSetGasPrice(ctx context.Context, percentileLabel string, value float64) { | ||
| promBlockHistoryEstimatorSetGasPrice.WithLabelValues(percentileLabel, m.chainID).Set(value) | ||
| if m.gasPriceGauge != nil { | ||
| m.gasPriceGauge.Record(ctx, value, metric.WithAttributes( | ||
| attribute.String("chainID", m.chainID), | ||
| attribute.String("percentile", percentileLabel), | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| func (m *blockHistoryEstimatorMetrics) RecordSetTipCap(ctx context.Context, percentileLabel string, value float64) { | ||
| promBlockHistoryEstimatorSetTipCap.WithLabelValues(percentileLabel, m.chainID).Set(value) | ||
| if m.tipCapGauge != nil { | ||
| m.tipCapGauge.Record(ctx, value, metric.WithAttributes( | ||
| attribute.String("chainID", m.chainID), | ||
| attribute.String("percentile", percentileLabel), | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| func (m *blockHistoryEstimatorMetrics) RecordAllGasPricePercentile(ctx context.Context, percentileLabel string, value float64) { | ||
| promBlockHistoryEstimatorAllGasPricePercentiles.WithLabelValues(percentileLabel, m.chainID).Set(value) | ||
| if m.allGasPricePercentilesGauge != nil { | ||
| m.allGasPricePercentilesGauge.Record(ctx, value, metric.WithAttributes( | ||
| attribute.String("chainID", m.chainID), | ||
| attribute.String("percentile", percentileLabel), | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| func (m *blockHistoryEstimatorMetrics) RecordAllTipCapPercentile(ctx context.Context, percentileLabel string, value float64) { | ||
| promBlockHistoryEstimatorAllTipCapPercentiles.WithLabelValues(percentileLabel, m.chainID).Set(value) | ||
| if m.allTipCapPercentilesGauge != nil { | ||
| m.allTipCapPercentilesGauge.Record(ctx, value, metric.WithAttributes( | ||
| attribute.String("chainID", m.chainID), | ||
| attribute.String("percentile", percentileLabel), | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| func (m *blockHistoryEstimatorMetrics) RecordCurrentBaseFee(ctx context.Context, value float64) { | ||
| promBlockHistoryEstimatorCurrentBaseFee.WithLabelValues(m.chainID).Set(value) | ||
| if m.currentBaseFeeGauge != nil { | ||
| m.currentBaseFeeGauge.Record(ctx, value, metric.WithAttributes( | ||
| attribute.String("chainID", m.chainID), | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| func (m *blockHistoryEstimatorMetrics) RecordConnectivityFailure(ctx context.Context, mode string) { | ||
| promBlockHistoryEstimatorConnectivityFailureCount.WithLabelValues(m.chainID, mode).Inc() | ||
| if m.connectivityFailureCountCounter != nil { | ||
| m.connectivityFailureCountCounter.Add(ctx, 1, metric.WithAttributes( | ||
| attribute.String("chainID", m.chainID), | ||
| attribute.String("mode", mode), | ||
| )) | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.