Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

feat: Log QuoteReport to Kibana #298

Merged
merged 24 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
},
"dependencies": {
"@0x/assert": "^3.0.4",
"@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-ae2a6fb68",
"@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-766888ec4",
steveklebanoff marked this conversation as resolved.
Show resolved Hide resolved
"@0x/connect": "^6.0.4",
"@0x/contract-addresses": "^4.11.0",
"@0x/contract-wrappers": "^13.7.0",
Expand Down
32 changes: 30 additions & 2 deletions src/handlers/swap_handlers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { RfqtRequestOpts, SwapQuoterError } from '@0x/asset-swapper';
import { QuoteReport, RfqtRequestOpts, SwapQuoterError } from '@0x/asset-swapper';
import { BigNumber, NULL_ADDRESS } from '@0x/utils';
import * as express from 'express';
import * as HttpStatus from 'http-status-codes';
import _ = require('lodash');

import { CHAIN_ID, RFQT_API_KEY_WHITELIST } from '../config';
import {
Expand Down Expand Up @@ -61,8 +62,12 @@ export class SwapHandlers {
makers: quote.orders.map(order => order.makerAddress),
},
});
if (quote.quoteReport) {
logQuoteReport(quote.quoteReport);
}
}
res.status(HttpStatus.OK).send(quote);
const cleanedQuote = _.omit(quote, 'quoteReport');
res.status(HttpStatus.OK).send(cleanedQuote);
}
// tslint:disable-next-line:prefer-function-over-method
public async getSwapTokensAsync(_req: express.Request, res: express.Response): Promise<void> {
Expand Down Expand Up @@ -273,6 +278,29 @@ export class SwapHandlers {
}
}

const logQuoteReport = (qr: QuoteReport) => {
// tslint:disable-next-line:custom-no-magic-numbers
const sourcesConsideredChunks = _.chunk(qr.sourcesConsidered, 12);
// tslint:disable-next-line:custom-no-magic-numbers
const sourcesDeliveredChunks = _.chunk(qr.sourcesDelivered, 12);
sourcesConsideredChunks.forEach((chunk, i) => {
logger.info({
firmQuoteReport: true,
sourcesConsideredChunkIndex: i,
sourcesConsideredChunkLength: sourcesConsideredChunks.length,
sourcesConsidered: chunk,
});
});
sourcesDeliveredChunks.forEach((chunk, i) => {
logger.info({
firmQuoteReport: true,
sourcesDeliveredChunkIndex: i,
sourcesDeliveredChunkLength: sourcesDeliveredChunks.length,
sourcesDelivered: chunk,
});
});
};

const parseGetSwapQuoteRequestParams = (
req: express.Request,
endpoint: 'price' | 'quote',
Expand Down
3 changes: 2 additions & 1 deletion src/services/swap_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class SwapService {
protocolFeeInWeiAmount: bestCaseProtocolFee,
} = attributedSwapQuote.bestCaseQuoteInfo;
const { protocolFeeInWeiAmount: protocolFee, gas: worstCaseGas } = attributedSwapQuote.worstCaseQuoteInfo;
const { orders, gasPrice, sourceBreakdown } = attributedSwapQuote;
const { orders, gasPrice, sourceBreakdown, quoteReport } = attributedSwapQuote;

const { to, value, data } = await this._getSwapQuotePartialTransactionAsync(
swapQuote,
Expand Down Expand Up @@ -208,6 +208,7 @@ export class SwapService {
sources: serviceUtils.convertSourceBreakdownToArray(sourceBreakdown),
orders: serviceUtils.cleanSignedOrderFields(orders),
allowanceTarget,
quoteReport,
steveklebanoff marked this conversation as resolved.
Show resolved Hide resolved
};
return apiSwapQuote;
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ERC20BridgeSource,
MarketBuySwapQuote,
MarketSellSwapQuote,
QuoteReport,
RfqtRequestOpts,
SupportedProvider,
} from '@0x/asset-swapper';
Expand Down Expand Up @@ -411,6 +412,7 @@ export interface GetSwapQuoteResponse extends SwapQuoteResponsePartialTransactio
estimatedGas: BigNumber;
estimatedGasTokenRefund: BigNumber;
allowanceTarget?: string;
quoteReport?: QuoteReport;
}

export interface Price {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
lodash "^4.17.11"
valid-url "^1.0.9"

"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-ae2a6fb68":
"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-766888ec4":
version "4.6.0"
resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/209c8324412173f5aa1c4b65fbe5494ea648205e"
resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/c89fa41b593c3c28f024a588865ec9ffb25068ca"
dependencies:
"@0x/assert" "^3.0.9"
"@0x/contract-addresses" "^4.11.0"
Expand Down