From e393a92aad9273925160684eae6483b1aede228e Mon Sep 17 00:00:00 2001 From: Matt Rice Date: Thu, 5 Dec 2024 05:10:31 -0500 Subject: [PATCH] fix: make datadog logs more digestible in datadog (#1937) --- src/monitor/Monitor.ts | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/monitor/Monitor.ts b/src/monitor/Monitor.ts index 1122f8c5a..0b488694e 100644 --- a/src/monitor/Monitor.ts +++ b/src/monitor/Monitor.ts @@ -8,8 +8,6 @@ import { L1Token, RelayerBalanceReport, RelayerBalanceTable, - RelayerBalanceColumns, - RelayerBalanceCell, TokenTransfer, } from "../interfaces"; import { @@ -44,14 +42,13 @@ import { resolveTokenDecimals, sortEventsDescending, getWidestPossibleExpectedBlockRange, + utils, } from "../utils"; import { MonitorClients, updateMonitorClients } from "./MonitorClientHelper"; import { MonitorConfig } from "./MonitorConfig"; import { CombinedRefunds } from "../dataworker/DataworkerUtils"; -import lodash from "lodash"; - // 60 minutes, which is the length of the challenge window, so if a rebalance takes longer than this to finalize, // then its finalizing after the subsequent challenge period has started, which is sub-optimal. export const REBALANCE_FINALIZE_GRACE_PERIOD = Number(process.env.REBALANCE_FINALIZE_GRACE_PERIOD ?? 60 * 60); @@ -301,22 +298,30 @@ export class Monitor { }); // Note: types are here for clarity, not necessity. - const machineReadableReport = lodash.mapValues(reports, (table: RelayerBalanceTable) => - lodash.mapValues(table, (columns: RelayerBalanceColumns, tokenSymbol: string) => { + + Object.entries(reports).forEach(([relayer, balanceTable]) => { + Object.entries(balanceTable).forEach(([tokenSymbol, columns]) => { const decimals = allL1Tokens.find((token) => token.symbol === tokenSymbol)?.decimals; if (!decimals) { throw new Error(`No decimals found for ${tokenSymbol}`); } - return lodash.mapValues(columns, (cell: RelayerBalanceCell) => - lodash.mapValues(cell, (balance: BigNumber) => Number(convertFromWei(balance.toString(), decimals))) - ); - }) - ); - - this.logger.debug({ - at: "Monitor#reportRelayerBalances", - message: "Machine-readable balance report", - report: machineReadableReport, + Object.entries(columns).forEach(([chainName, cell]) => { + Object.entries(cell).forEach(([balanceType, balance]) => { + this.logger.debug({ + at: "Monitor#reportRelayerBalances", + message: "Machine-readable single balance report", + relayer, + tokenSymbol, + decimals, + chainName, + balanceType, + balanceInWei: balance.toString(), + balance: Number(utils.formatUnits(balance, decimals)), + datadog: true, + }); + }); + }); + }); }); } }