Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeouts to ddb client, add logs #306

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 lib/handlers/get-orders/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ContainerInjected {
export class GetOrdersInjector extends ApiInjector<ContainerInjected, RequestInjected, void, RawGetOrdersQueryParams> {
public async buildContainerInjected(): Promise<ContainerInjected> {
return {
dbInterface: DynamoOrdersRepository.create(new DynamoDB.DocumentClient()),
dbInterface: DynamoOrdersRepository.create(new DynamoDB.DocumentClient({ maxRetries: 3, httpOptions: { timeout: 1000 } })),
}
}

Expand Down
10 changes: 8 additions & 2 deletions lib/handlers/post-order/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
containerInjected: { dbInterface, orderValidator, onchainValidatorByChainId },
} = params

log.info('Handling POST order request', params)
log.info({ params }, 'Handling POST order request')
log.info(
{
onchainValidatorByChainId: Object.keys(onchainValidatorByChainId).map(
Expand All @@ -57,6 +57,7 @@
...(e instanceof Error && { detail: e.message }),
}
}
log.info({ decodedOrder: decodedOrder.toJSON() }, 'Parsed order')

const validationResponse = orderValidator.validate(decodedOrder)
if (!validationResponse.valid) {
Expand All @@ -83,12 +84,15 @@
detail: `Onchain validation failed: ${OrderValidation[validation]}`,
}
}
log.info({ validation }, 'Onchain validation succeeded')

const order: OrderEntity = formatOrderEntity(decodedOrder, signature, OrderType.Dutch, ORDER_STATUS.OPEN, quoteId)
const id = order.orderHash

try {
const orderCount = await dbInterface.countOrdersByOffererAndStatus(order.offerer, ORDER_STATUS.OPEN)
log.info({ offerer: order.offerer, orderCount }, `Counted open orders for ${order.offerer}: ${orderCount}`)

if (orderCount > getMaxOpenOrders(order.offerer)) {
log.info(orderCount, `${order.offerer} has too many open orders`)
return {
Expand All @@ -109,7 +113,7 @@

try {
await dbInterface.putOrderAndUpdateNonceTransaction(order)
log.info(`Successfully inserted Order ${id} into DB`)
log.info({ order }, `Successfully inserted Order ${id} into DB`)
} catch (e: unknown) {
log.error(e, `Failed to insert order ${id} into DB`)
return {
Expand Down Expand Up @@ -146,6 +150,8 @@
stateMachineArn,
log
)
log.info(`Successfully kicked off SFN order with name: ${id}`)

return {
statusCode: 201,
body: { hash: id },
Expand Down Expand Up @@ -182,7 +188,7 @@
// Try and extract the chain id from the raw json.
let chainId = '0'
try {
const rawBody = JSON.parse(event.body!)

Check warning on line 191 in lib/handlers/post-order/handler.ts

View workflow job for this annotation

GitHub Actions / lint-and-test

Forbidden non-null assertion
chainId = rawBody.chainId ?? chainId
} catch (err) {
// no-op. If we can't get chainId still log the metric as chain 0
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/post-order/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class PostOrderInjector extends ApiInjector<ContainerInjected, ApiRInj, P
}
})
return {
dbInterface: DynamoOrdersRepository.create(new DynamoDB.DocumentClient()),
dbInterface: DynamoOrdersRepository.create(new DynamoDB.DocumentClient({ maxRetries: 3, httpOptions: { timeout: 1000 } })),
orderValidator: new OrderValidator(() => new Date().getTime() / 1000),
onchainValidatorByChainId,
}
Expand Down
Loading