Skip to content

Commit

Permalink
fix: measure time usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mfw78 committed Oct 10, 2023
1 parent caf8812 commit 4f7a036
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/domain/addContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ export async function addContract(
event: ConditionalOrderCreatedEvent
) {
const { chainId } = context;
await measureTime(
() => _addContract(context, event),
[chainId.toString()],
addContractsRunDurationSeconds,
addContractRunsTotal,
handleExecutionError,
addContractsErrorsTotal
);
await measureTime({
action: () => _addContract(context, event),
labelValues: [chainId.toString()],
durationMetric: addContractsRunDurationSeconds,
totalRunsMetric: addContractRunsTotal,
errorHandler: handleExecutionError,
errorMetric: addContractsErrorsTotal,
});
}

async function _addContract(
Expand Down
17 changes: 11 additions & 6 deletions src/domain/checkForAndPlaceOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ async function _processConditionalOrder(
// Unsupported Order Type (unknown handler)
// For now, fallback to legacy behavior
// TODO: Decide in the future what to do. Probably, move the error handling to the SDK and kill the poll Legacy
pollResult = await measureTime(
() =>
pollResult = await measureTime({
action: () =>
_pollLegacy(
context,
owner,
Expand All @@ -269,10 +269,15 @@ async function _processConditionalOrder(
offchainInput,
orderRef
),
metricLabels,
pollingOnChainDurationSeconds,
pollingOnChainChecksTotal
);
labelValues: metricLabels,
durationMetric: pollingOnChainDurationSeconds,
totalRunsMetric: pollingOnChainChecksTotal,
});
}

// This should be impossible to reach, but satisfies the compiler
if (pollResult === undefined) {
throw new Error("Unexpected error: pollResult is undefined");
}

// Error polling
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe("handle on-chain custom errors", () => {
revertData: abiToSelector(
CUSTOM_ERROR_ABI_MAP[CustomErrorSelectors.SINGLE_ORDER_NOT_AUTHED]
),
metricLabels: [],
metricLabels: ["chain_id", "handler", "owner", "id"],
};

it("should pass a known selector correctly", () => {
Expand Down

0 comments on commit 4f7a036

Please sign in to comment.