Skip to content

Commit 45ec608

Browse files
authored
Merge pull request #7901 from devbugging/gregor/callbacks/metrics
[Scheduled Callbacks] Add scheduled transaction metrics
2 parents 33d6951 + 02b7e1d commit 45ec608

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed

engine/execution/computation/computer/computer.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,21 @@ func (e *blockComputer) executeProcessCallback(
650650
return nil, 0, err
651651
}
652652

653+
if len(callbackTxs) > 0 {
654+
// calculate total computation limits for execute callback transactions
655+
var totalExecuteComputationLimits uint64
656+
for _, tx := range callbackTxs {
657+
totalExecuteComputationLimits += tx.GasLimit
658+
}
659+
660+
// report metrics for callbacks executed
661+
e.metrics.ExecutionCallbacksExecuted(
662+
len(callbackTxs),
663+
txn.Output().ComputationUsed,
664+
totalExecuteComputationLimits,
665+
)
666+
}
667+
653668
return callbackTxs, txnIndex, nil
654669
}
655670

engine/execution/computation/computer/computer_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,16 @@ func testScheduledCallbackWithError(t *testing.T, chain flow.Chain, callbackEven
15291529
Return(nil).
15301530
Times(1)
15311531

1532+
// expect callback execution metrics if there are callbacks
1533+
if len(callbackEvents) > 0 {
1534+
exemetrics.On("ExecutionCallbacksExecuted",
1535+
mock.Anything,
1536+
mock.Anything,
1537+
mock.Anything).
1538+
Return(nil).
1539+
Times(1)
1540+
}
1541+
15321542
bservice := requesterunit.MockBlobService(blockstore.NewBlockstore(dssync.MutexWrap(datastore.NewMapDatastore())))
15331543
trackerStorage := mocktracker.NewMockStorage()
15341544

module/metrics.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,9 @@ type ExecutionMetrics interface {
10271027
// ExecutionScriptExecuted reports the time and memory spent on executing an script
10281028
ExecutionScriptExecuted(dur time.Duration, compUsed, memoryUsed, memoryEstimate uint64)
10291029

1030+
// ExecutionCallbacksExecuted reports the number of callbacks executed, computation used by process transaction, and total computation limits for execute transactions
1031+
ExecutionCallbacksExecuted(callbackCount int, processComputationUsed, executeComputationLimits uint64)
1032+
10301033
// ExecutionCollectionRequestSent reports when a request for a collection is sent to a collection node
10311034
ExecutionCollectionRequestSent()
10321035

module/metrics/execution.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ type ExecutionCollector struct {
9898
evmTransactionGasUsed prometheus.Histogram
9999
evmBlockTxCount prometheus.Histogram
100100
evmBlockGasUsed prometheus.Histogram
101+
callbacksExecutedCount prometheus.Histogram
102+
callbacksExecutedTotal prometheus.Counter
103+
callbacksProcessComputationUsed prometheus.Histogram
104+
callbacksExecuteComputationLimits prometheus.Histogram
101105
}
102106

103107
func NewExecutionCollector(tracer module.Tracer) *ExecutionCollector {
@@ -793,6 +797,37 @@ func NewExecutionCollector(tracer module.Tracer) *ExecutionCollector {
793797
Name: "evm_block_total_supply",
794798
Help: "the total amount of flow deposited to EVM (in FLOW)",
795799
}),
800+
801+
callbacksExecutedCount: promauto.NewHistogram(prometheus.HistogramOpts{
802+
Namespace: namespaceExecution,
803+
Subsystem: subsystemRuntime,
804+
Name: "callbacks_executed_count",
805+
Help: "the number of callbacks executed",
806+
Buckets: prometheus.ExponentialBuckets(1, 2, 8),
807+
}),
808+
809+
callbacksExecutedTotal: promauto.NewCounter(prometheus.CounterOpts{
810+
Namespace: namespaceExecution,
811+
Subsystem: subsystemRuntime,
812+
Name: "callbacks_executed_total",
813+
Help: "the total number of callbacks executed",
814+
}),
815+
816+
callbacksProcessComputationUsed: promauto.NewHistogram(prometheus.HistogramOpts{
817+
Namespace: namespaceExecution,
818+
Subsystem: subsystemRuntime,
819+
Name: "callbacks_process_computation_used",
820+
Help: "the computation used by the process callback transaction",
821+
Buckets: prometheus.ExponentialBuckets(10_000, 2, 12),
822+
}),
823+
824+
callbacksExecuteComputationLimits: promauto.NewHistogram(prometheus.HistogramOpts{
825+
Namespace: namespaceExecution,
826+
Subsystem: subsystemRuntime,
827+
Name: "callbacks_execute_computation_limits",
828+
Help: "the total computation limits for execute callback transactions",
829+
Buckets: prometheus.ExponentialBuckets(10_000, 2, 12),
830+
}),
796831
}
797832

798833
return ec
@@ -883,6 +918,14 @@ func (ec *ExecutionCollector) ExecutionScriptExecuted(dur time.Duration, compUse
883918
ec.scriptMemoryDifference.Observe(float64(memoryEstimated) - float64(memoryUsed))
884919
}
885920

921+
// ExecutionCallbacksExecuted reports callback execution metrics
922+
func (ec *ExecutionCollector) ExecutionCallbacksExecuted(callbackCount int, processComputationUsed, executeComputationLimits uint64) {
923+
ec.callbacksExecutedCount.Observe(float64(callbackCount))
924+
ec.callbacksExecutedTotal.Add(float64(callbackCount))
925+
ec.callbacksProcessComputationUsed.Observe(float64(processComputationUsed))
926+
ec.callbacksExecuteComputationLimits.Observe(float64(executeComputationLimits))
927+
}
928+
886929
// ExecutionStateStorageDiskTotal reports the total storage size of the execution state on disk in bytes
887930
func (ec *ExecutionCollector) ExecutionStateStorageDiskTotal(bytes int64) {
888931
ec.stateStorageDiskTotal.Set(float64(bytes))

module/metrics/noop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func (nc *NoopCollector) ExecutionTransactionExecuted(_ time.Duration, _ module.
181181
}
182182
func (nc *NoopCollector) ExecutionChunkDataPackGenerated(_, _ int) {}
183183
func (nc *NoopCollector) ExecutionScriptExecuted(dur time.Duration, compUsed, _, _ uint64) {}
184+
func (nc *NoopCollector) ExecutionCallbacksExecuted(int, uint64, uint64) {}
184185
func (nc *NoopCollector) ForestApproxMemorySize(bytes uint64) {}
185186
func (nc *NoopCollector) ForestNumberOfTrees(number uint64) {}
186187
func (nc *NoopCollector) LatestTrieRegCount(number uint64) {}

module/mock/execution_metrics.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)