Skip to content
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

feat(cosmic-swingset): add metrics for each action type #10888

Merged
merged 14 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Loading