From f78a02c6c62176d0d3f02f8aa65008a2d31c731a Mon Sep 17 00:00:00 2001 From: mfw78 Date: Fri, 6 Oct 2023 05:11:29 +0000 Subject: [PATCH] chore: metrics todo --- src/domain/checkForAndPlaceOrder.ts | 18 ++++++++++++------ src/utils/metrics.ts | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/domain/checkForAndPlaceOrder.ts b/src/domain/checkForAndPlaceOrder.ts index a4fcd77..66600f8 100644 --- a/src/domain/checkForAndPlaceOrder.ts +++ b/src/domain/checkForAndPlaceOrder.ts @@ -32,6 +32,7 @@ import { import { ChainContext } from "./chainContext"; import { pollingOnChainDurationSeconds, + totalPollingOnChainInvalidInterfaces, totalActiveOrders, totalActiveOwners, totalOrderBookDiscreteOrders, @@ -39,6 +40,7 @@ import { totalPollingOnChainChecks, totalPollingRuns, totalPollingUnexpectedErrors, + totalPollingOnChainEthersErrors, } from "../utils/metrics"; const GPV2SETTLEMENT = "0x9008D19f58AAbD9eD0D60971565AA8510560ab41"; @@ -527,7 +529,8 @@ async function _pollLegacy( offchainInput: string, orderRef: string ): Promise { - const { contract, multicall } = context; + const { contract, multicall, chainId } = context; + const { handler } = conditionalOrder.params; // as we going to use multicall, with `aggregate3Value`, there is no need to do any simulation as the // calls are guaranteed to pass, and will return the results, or the reversion within the ABI-encoded data. // By not using `populateTransaction`, we avoid an `eth_estimateGas` RPC call. @@ -536,6 +539,8 @@ async function _pollLegacy( "getTradeableOrderWithSignature", [owner, conditionalOrder.params, offchainInput, proof] ); + const id = ConditionalOrderSDK.leafToId(conditionalOrder.params); + const metricLabels = [chainId.toString(), owner, handler, id]; try { const lowLevelCall = await multicall.callStatic.aggregate3Value([ @@ -573,7 +578,8 @@ async function _pollLegacy( orderRef, context, to, - data + data, + metricLabels ); } } @@ -584,7 +590,8 @@ function _handleGetTradableOrderWithSignatureCall( orderRef: string, context: ChainContext, to: string, - data: string + data: string, + metricLabels: string[] ): PollResultErrors { const logPrefix = `checkForAndPlaceOrder:_handleGetTradableOrderCall:${orderRef}`; const log = getLogger(logPrefix); @@ -636,7 +643,6 @@ function _handleGetTradableOrderWithSignatureCall( result: PollResultCode.DONT_TRY_AGAIN, reason: `${selector}: The safe has swap guard enabled`, }; - // TODO: Add metrics to track this case "ORDER_NOT_VALID": case "POLL_TRY_NEXT_BLOCK": // OrderNotValid: With the revised custom errors, `OrderNotValid` is generally returned when elements @@ -684,10 +690,10 @@ function _handleGetTradableOrderWithSignatureCall( } catch (err: any) { // Any errors thrown here can _ONLY_ come from non-compliant interfaces (ie. bad revert ABI encoding). // We log the error, and return a DONT_TRY_AGAIN result. - // TODO: Add metrics to track this log.error( `Contract returned non-interface compliant revert via getTradeableOrderWithSignature. Simulate: https://dashboard.tenderly.co/gp-v2/watch-tower-prod/simulator/new?network=${chainId}&contractAddress=${to}&rawFunctionInput=${data}` ); + totalPollingOnChainInvalidInterfaces.labels(...metricLabels).inc(); return { result: PollResultCode.DONT_TRY_AGAIN, reason: @@ -698,9 +704,9 @@ function _handleGetTradableOrderWithSignatureCall( } log.error(`${logPrefix} ethers/call Unexpected error`, error); + totalPollingOnChainEthersErrors.labels(...metricLabels).inc(); // We can only get here from some provider / ethers failure. As the contract hasn't had it's say // we will defer to try again. - // TODO: Add metrics to track this return { result: PollResultCode.TRY_NEXT_BLOCK, reason: diff --git a/src/utils/metrics.ts b/src/utils/metrics.ts index c753b6e..c3b7ded 100644 --- a/src/utils/metrics.ts +++ b/src/utils/metrics.ts @@ -108,6 +108,18 @@ const pollingOnChainDurationSeconds = new client.Histogram({ labelNames: ["chain_id", "handler", "owner", "id"], }); +const totalPollingOnChainInvalidInterfaces = new client.Counter({ + name: "watch_tower_polling_onchain_invalid_interface_total", + help: "Total number of invalid on-chain hint interface", + labelNames: ["chain_id", "handler", "owner", "id"], +}); + +const totalPollingOnChainEthersErrors = new client.Counter({ + name: "watch_tower_polling_onchain_ethers_errors_total", + help: "Total number of ethers on-chain hint errors", + labelNames: ["chain_id", "handler", "owner", "id"], +}); + const totalPollingUnexpectedErrors = new client.Counter({ name: "watch_tower_polling_unexpected_errors_total", help: "Total number of unexpected polling errors", @@ -132,6 +144,8 @@ export { totalOrderBookErrors, totalPollingRuns, totalPollingOnChainChecks, + totalPollingOnChainInvalidInterfaces, + totalPollingOnChainEthersErrors, pollingOnChainDurationSeconds, totalPollingUnexpectedErrors, };