From 618553b8ea0ea736a1406e2c8dae4378315547e9 Mon Sep 17 00:00:00 2001 From: siarhei-agoric Date: Tue, 28 Jan 2025 14:57:55 -0500 Subject: [PATCH] feat(cosmic-swingset): add metrics for each action type (#10888) closes: #10883 refs: #10882 ## Description Add metrics for the following action types: - CORE_EVAL - DELIVER_INBOUND - IBC_EVENT - INSTALL_BUNDLE - PLEASE_PROVISION - VBANK_BALANCE_UPDATE - WALLET_ACTION - WALLET_SPEND_ACTION - VTRANSFER_IBC_EVENT - KERNEL_UPGRADE_EVENTS ### Security Considerations Metrics may expose inner state which could be used to mount an effective attack. ### Scaling Considerations No impact on a local node performance expected. ### Documentation Considerations Metric names and their meaning need to be documented as now available via standard reporting interface. ### Testing Considerations manual testing? ### Upgrade Considerations This will roll out as part of standard release. --- packages/cosmic-swingset/src/launch-chain.js | 25 ++++++++++++++++++++ packages/internal/src/action-types.js | 8 +++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/cosmic-swingset/src/launch-chain.js b/packages/cosmic-swingset/src/launch-chain.js index eccfbbc2a65..73f090bf64f 100644 --- a/packages/cosmic-swingset/src/launch-chain.js +++ b/packages/cosmic-swingset/src/launch-chain.js @@ -413,6 +413,21 @@ export async function launch({ // Not to be confused with the gas model, this meter is for OpenTelemetry. const metricMeter = metricsProvider.getMeter('ag-chain-cosmos'); + + const knownActionTypes = new Set(Object.values(ActionType.QueuedActionType)); + + const processedInboundActionCounter = metricMeter.createCounter( + 'cosmic_swingset_inbound_actions', + { description: 'Processed inbound action counts by type' }, + ); + + /** @type {(actionType: ActionType.QueuedActionType) => void} */ + const countInboundAction = actionType => { + if (!knownActionTypes.has(actionType)) { + console.warn(`unknown inbound action type ${JSON.stringify(actionType)}`); + } + processedInboundActionCounter.add(1, { actionType }); + }; const slogCallbacks = makeSlogCallbacks({ metricMeter, }); @@ -637,9 +652,18 @@ export async function launch({ let decohered; let afterCommitWorkDone = Promise.resolve(); + /** + * Dispatch an action from an inbound queue to an appropriate handler based on + * action type. + * + * @param {{ type: ActionType.QueuedActionType } & Record} action + * @param {string} inboundNum + * @returns {Promise} + */ async function performAction(action, inboundNum) { // blockManagerConsole.error('Performing action', action); let p; + switch (action.type) { case ActionType.DELIVER_INBOUND: { p = deliverInbound( @@ -717,6 +741,7 @@ export async function launch({ for await (const { action, context } of inboundQueue.consumeAll()) { const inboundNum = `${context.blockHeight}-${context.txHash}-${context.msgIdx}`; inboundQueueMetrics.decStat(); + countInboundAction(action.type); await performAction(action, inboundNum); keepGoing = await runSwingset(phase); if (!keepGoing) { diff --git a/packages/internal/src/action-types.js b/packages/internal/src/action-types.js index 837059d9b52..18d4ad2b8a9 100644 --- a/packages/internal/src/action-types.js +++ b/packages/internal/src/action-types.js @@ -56,6 +56,8 @@ export const QueuedActionType = /** @type {const} */ ({ VBANK_BALANCE_UPDATE: 'VBANK_BALANCE_UPDATE', WALLET_ACTION: 'WALLET_ACTION', WALLET_SPEND_ACTION: 'WALLET_SPEND_ACTION', + VTRANSFER_IBC_EVENT: 'VTRANSFER_IBC_EVENT', + KERNEL_UPGRADE_EVENTS: 'KERNEL_UPGRADE_EVENTS', }); harden(QueuedActionType); @@ -69,8 +71,6 @@ export const { VBANK_BALANCE_UPDATE, WALLET_ACTION, WALLET_SPEND_ACTION, + VTRANSFER_IBC_EVENT, + KERNEL_UPGRADE_EVENTS, } = QueuedActionType; - -export const CALCULATE_FEES_IN_BEANS = 'CALCULATE_FEES_IN_BEANS'; -export const VTRANSFER_IBC_EVENT = 'VTRANSFER_IBC_EVENT'; -export const KERNEL_UPGRADE_EVENTS = 'KERNEL_UPGRADE_EVENTS';