Skip to content

Commit

Permalink
feat(cosmic-swingset): add metrics for each action type (#10888)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
siarhei-agoric authored Jan 28, 2025
1 parent f047c93 commit 618553b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
25 changes: 25 additions & 0 deletions packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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<string, unknown>} action
* @param {string} inboundNum
* @returns {Promise<void>}
*/
async function performAction(action, inboundNum) {
// blockManagerConsole.error('Performing action', action);
let p;

switch (action.type) {
case ActionType.DELIVER_INBOUND: {
p = deliverInbound(
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions packages/internal/src/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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';

0 comments on commit 618553b

Please sign in to comment.