Skip to content

Commit

Permalink
fix: standardise metric variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
mfw78 committed Oct 9, 2023
1 parent 19f1c0d commit 60250e4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions src/domain/addContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {
merkleRootTotal,
newContractsTotal,
singleOrdersTotal,
totalActiveOrders,
totalActiveOwners,
activeOrdersTotal,
activeOwnersTotal,
} from "../utils/metrics";

/**
Expand Down Expand Up @@ -234,7 +234,7 @@ export function add(
orders: new Map(),
composableCow,
});
totalActiveOrders.labels(registry.network).inc();
activeOrdersTotal.labels(registry.network).inc();
}
} else {
log.info(`Adding conditional order to new owner contract ${owner}:`, {
Expand All @@ -247,8 +247,8 @@ export function add(
owner,
new Set([{ tx, params, proof, orders: new Map(), composableCow }])
);
totalActiveOwners.labels(registry.network).inc();
totalActiveOrders.labels(registry.network).inc();
activeOwnersTotal.labels(registry.network).inc();
activeOrdersTotal.labels(registry.network).inc();
}
}

Expand Down
32 changes: 16 additions & 16 deletions src/domain/checkForAndPlaceOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ import {
import { ChainContext } from "./chainContext";
import {
pollingOnChainDurationSeconds,
totalActiveOrders,
totalActiveOwners,
totalOrderBookDiscreteOrders,
totalOrderBookErrors,
totalPollingOnChainChecks,
totalPollingRuns,
totalPollingUnexpectedErrors,
totalPollingOnChainEthersErrors,
activeOrdersTotal,
activeOwnersTotal,
orderBookDiscreteOrdersTotal,
orderBookErrorsTotal,
pollingOnChainChecksTotal,
pollingRunsTotal,
pollingUnexpectedErrorsTotal,
pollingOnChainEthersErrorsTotal,
measureTime,
} from "../utils/metrics";

Expand Down Expand Up @@ -189,7 +189,7 @@ export async function checkForAndPlaceOrder(
const action = deleted ? "Stop Watching" : "Failed to stop watching";

log.debug(`${action} conditional order from TX ${conditionalOrder.tx}`);
totalActiveOrders.labels(chainId.toString()).dec();
activeOrdersTotal.labels(chainId.toString()).dec();
}
}

Expand All @@ -198,7 +198,7 @@ export async function checkForAndPlaceOrder(
for (const [owner, conditionalOrders] of Array.from(ownerOrders.entries())) {
if (conditionalOrders.size === 0) {
ownerOrders.delete(owner);
totalActiveOwners.labels(chainId.toString()).dec();
activeOwnersTotal.labels(chainId.toString()).dec();
}
}

Expand Down Expand Up @@ -231,7 +231,7 @@ async function _processConditionalOrder(
const id = ConditionalOrderSDK.leafToId(conditionalOrder.params);
const metricLabels = [chainId.toString(), handler, owner, id];
try {
totalPollingRuns.labels(...metricLabels).inc();
pollingRunsTotal.labels(...metricLabels).inc();

const proof = conditionalOrder.proof
? conditionalOrder.proof.path.map((c) => c.toString())
Expand Down Expand Up @@ -271,7 +271,7 @@ async function _processConditionalOrder(
),
metricLabels,
pollingOnChainDurationSeconds,
totalPollingOnChainChecks
pollingOnChainChecksTotal
);
const timer = pollingOnChainDurationSeconds
.labels(...metricLabels)
Expand Down Expand Up @@ -342,7 +342,7 @@ async function _processConditionalOrder(
signature,
};
} catch (e: any) {
totalPollingUnexpectedErrors.labels(...metricLabels).inc();
pollingUnexpectedErrorsTotal.labels(...metricLabels).inc();
return {
result: PollResultCode.UNEXPECTED_ERROR,
error: e,
Expand Down Expand Up @@ -431,7 +431,7 @@ async function _placeOrder(params: {
log.debug(`Order`, postOrder);
if (!dryRun) {
const orderUid = await orderBook.sendOrder(postOrder);
totalOrderBookDiscreteOrders.labels(...metricLabels).inc();
orderBookDiscreteOrdersTotal.labels(...metricLabels).inc();
log.info(`API response`, { orderUid });
}
} catch (error: any) {
Expand Down Expand Up @@ -492,7 +492,7 @@ function _handleOrderBookError(
metricLabels: string[]
): Omit<PollResultSuccess, "order" | "signature"> | PollResultErrors {
const apiError = body?.errorType as OrderPostError.errorType;
totalOrderBookErrors
orderBookErrorsTotal
.labels(...metricLabels, status.toString(), apiError)
.inc();
if (status === 400) {
Expand Down Expand Up @@ -598,7 +598,7 @@ async function _pollLegacy(
// 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.
log.error(`${logPrefix} ethers/call Unexpected error`, error);
totalPollingOnChainEthersErrors.labels(...metricLabels).inc();
pollingOnChainEthersErrorsTotal.labels(...metricLabels).inc();
return {
result: PollResultCode.TRY_NEXT_BLOCK,
reason:
Expand Down
6 changes: 3 additions & 3 deletions src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BytesLike } from "ethers";
import type { ConditionalOrderCreatedEvent } from "./generated/ComposableCoW";
import { ConditionalOrderParams, PollResult } from "@cowprotocol/cow-sdk";
import { DBService } from "../utils";
import { totalActiveOrders, totalActiveOwners } from "../utils/metrics";
import { activeOrdersTotal, activeOwnersTotal } from "../utils/metrics";

// Standardise the storage key
const LAST_NOTIFIED_ERROR_STORAGE_KEY = "LAST_NOTIFIED_ERROR";
Expand Down Expand Up @@ -160,12 +160,12 @@ export class Registry {
.catch(() => null);

// Return registry (on its latest version)
totalActiveOwners.labels(network).set(ownerOrders.size);
activeOwnersTotal.labels(network).set(ownerOrders.size);
const numOrders = Array.from(ownerOrders.values()).reduce(
(acc, o) => acc + o.size,
0
);
totalActiveOrders.labels(network).set(numOrders);
activeOrdersTotal.labels(network).set(numOrders);

return new Registry(
ownerOrders,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SupportedChainId,
} from "@cowprotocol/cow-sdk";
import { getLogger } from "./logging";
import { totalPollingOnChainInvalidInterfaces } from "./metrics";
import { pollingOnChainInvalidInterfacesTotal } from "./metrics";

// Selectors that are required to be part of the contract's bytecode in order to be considered compatible
const REQUIRED_SELECTORS = [
Expand Down Expand Up @@ -289,7 +289,7 @@ export function handleOnChainCustomError(params: {
log.debug(
`Contract returned a non-compliant interface revert via getTradeableOrderWithSignature. Simulate: https://dashboard.tenderly.co/gp-v2/watch-tower-prod/simulator/new?network=${chainId}&contractAddress=${target}&rawFunctionInput=${callData}`
);
totalPollingOnChainInvalidInterfaces.labels(...metricLabels).inc();
pollingOnChainInvalidInterfacesTotal.labels(...metricLabels).inc();
return {
result: PollResultCode.DONT_TRY_AGAIN,
reason: "Order returned a non-compliant (invalid/erroneous) revert hint",
Expand Down
18 changes: 9 additions & 9 deletions src/utils/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,37 +102,37 @@ export const processBlockDurationSeconds = new client.Histogram({
labelNames: ["chain_id"],
});

export const totalActiveOwners = new client.Gauge({
export const activeOwnersTotal = new client.Gauge({
name: "watch_tower_active_owners_total",
help: "Total number of owners with active orders",
labelNames: ["chain_id"],
});

export const totalActiveOrders = new client.Gauge({
export const activeOrdersTotal = new client.Gauge({
name: "watch_tower_active_orders_total",
help: "Total number of active orders",
labelNames: ["chain_id"],
});

export const totalOrderBookDiscreteOrders = new client.Counter({
export const orderBookDiscreteOrdersTotal = new client.Counter({
name: "watch_tower_orderbook_discrete_orders_total",
help: "Total number of discrete orders posted to the orderbook",
labelNames: ["chain_id", "handler", "owner", "id"],
});

export const totalOrderBookErrors = new client.Counter({
export const orderBookErrorsTotal = new client.Counter({
name: "watch_tower_orderbook_errors_total",
help: "Total number of errors when interacting with the orderbook",
labelNames: ["chain_id", "handler", "owner", "id", "status", "error"],
});

export const totalPollingRuns = new client.Counter({
export const pollingRunsTotal = new client.Counter({
name: "watch_tower_polling_runs_total",
help: "Total number of polling runs",
labelNames: ["chain_id", "handler", "owner", "id"],
});

export const totalPollingOnChainChecks = new client.Counter({
export const pollingOnChainChecksTotal = new client.Counter({
name: "watch_tower_polling_onchain_checks_total",
help: "Total number of on-chain hint checks",
labelNames: ["chain_id", "handler", "owner", "id"],
Expand All @@ -144,19 +144,19 @@ export const pollingOnChainDurationSeconds = new client.Histogram({
labelNames: ["chain_id", "handler", "owner", "id"],
});

export const totalPollingOnChainInvalidInterfaces = new client.Counter({
export const pollingOnChainInvalidInterfacesTotal = 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"],
});

export const totalPollingOnChainEthersErrors = new client.Counter({
export const pollingOnChainEthersErrorsTotal = 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"],
});

export const totalPollingUnexpectedErrors = new client.Counter({
export const pollingUnexpectedErrorsTotal = new client.Counter({
name: "watch_tower_polling_unexpected_errors_total",
help: "Total number of unexpected polling errors",
labelNames: ["chain_id", "handler", "owner", "id"],
Expand Down

0 comments on commit 60250e4

Please sign in to comment.