Skip to content

Commit

Permalink
chore: add computeRoutes/SplitRoutes latency metrics (#835)
Browse files Browse the repository at this point in the history
* chore: add computeRoutes/SplitRoutes latency metrics

* per split metrics
  • Loading branch information
xrsv authored Mar 4, 2025
1 parent 2459ed3 commit 166b25f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uniswap/smart-order-router",
"version": "4.19.2",
"version": "4.19.3",
"description": "Uniswap Smart Order Router",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
20 changes: 20 additions & 0 deletions src/routers/alpha-router/functions/best-swap-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export async function getBestSwapRoute(
);

// Given all the valid quotes for each percentage find the optimal route.
const getBestSwapRouteByStartTime = Date.now();
const swapRoute = await getBestSwapRouteBy(
routeType,
percentToQuotes,
Expand All @@ -104,6 +105,19 @@ export async function getBestSwapRoute(
swapConfig,
providerConfig
);
const getBestSwapRouteByLatencyMs = Date.now() - getBestSwapRouteByStartTime;

// Add latency metrics.
metric.putMetric(
'GetBestSwapRouteByLatency',
getBestSwapRouteByLatencyMs,
MetricLoggerUnit.Milliseconds
);
metric.putMetric(
`GetBestSwapRouteByLatency_Chain${chainId}`,
getBestSwapRouteByLatencyMs,
MetricLoggerUnit.Milliseconds
);

// It is possible we were unable to find any valid route given the quotes.
if (!swapRoute) {
Expand Down Expand Up @@ -287,6 +301,12 @@ export async function getBestSwapRouteBy(
MetricLoggerUnit.Milliseconds
);

metric.putMetric(
`Split${splits}Done_Chain${chainId}`,
Date.now() - startedSplit,
MetricLoggerUnit.Milliseconds
);

startedSplit = Date.now();

log.info(
Expand Down
6 changes: 6 additions & 0 deletions src/routers/alpha-router/quoters/mixed-quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ export class MixedQuoter extends BaseQuoter<
MetricLoggerUnit.Milliseconds
);

metric.putMetric(
`MixedGetRoutesLoad_Chain${this.chainId}`,
Date.now() - beforeGetRoutes,
MetricLoggerUnit.Milliseconds
);

return {
routes: routes,
candidatePools,
Expand Down
6 changes: 6 additions & 0 deletions src/routers/alpha-router/quoters/v2-quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ export class V2Quoter extends BaseQuoter<V2CandidatePools, V2Route, Token> {
MetricLoggerUnit.Milliseconds
);

metric.putMetric(
`V2GetRoutesLoad_Chain${this.chainId}`,
Date.now() - beforeGetRoutes,
MetricLoggerUnit.Milliseconds
);

return {
routes,
candidatePools,
Expand Down
6 changes: 6 additions & 0 deletions src/routers/alpha-router/quoters/v3-quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export class V3Quoter extends BaseQuoter<V3CandidatePools, V3Route, Token> {
MetricLoggerUnit.Milliseconds
);

metric.putMetric(
`V3GetRoutesLoad_Chain${this.chainId}`,
Date.now() - beforeGetRoutes,
MetricLoggerUnit.Milliseconds
);

return {
routes,
candidatePools,
Expand Down
6 changes: 6 additions & 0 deletions src/routers/alpha-router/quoters/v4-quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ export class V4Quoter extends BaseQuoter<V4CandidatePools, V4Route, Currency> {
MetricLoggerUnit.Milliseconds
);

metric.putMetric(
`V4GetRoutesLoad_Chain${this.chainId}`,
Date.now() - beforeGetRoutes,
MetricLoggerUnit.Milliseconds
);

return {
routes,
candidatePools,
Expand Down

0 comments on commit 166b25f

Please sign in to comment.