Skip to content

Commit

Permalink
Track record staleness (#499)
Browse files Browse the repository at this point in the history
* Track record staleness

* bump up provisioned concurrency

* bump up provisioned concurrency
  • Loading branch information
codyborn authored Dec 16, 2024
1 parent 56fcc61 commit 0c4578b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
20 changes: 20 additions & 0 deletions bin/stacks/dashboard-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,26 @@ export class DashboardStack extends cdk.NestedStack {
stat: 'Sum',
},
},
{
height: 6,
width: 12,
y: 68,
x: 0,
type: 'metric',
properties: {
metrics: _.flatMap(SUPPORTED_CHAINS, (chainId) => [
['Uniswap', `NotificationRecordStaleness-chain-${chainId}`, 'Service', `UniswapXService`],
['.', '.', '.', `.`, { stat: 'p99' }],
['.', '.', '.', `.`, { stat: 'p50' }],
['.', '.', '.', `.`, { stat: 'Average' }],
]),
view: 'timeSeries',
region,
title: 'DutchV2 Notification Record Staleness',
period: 300,
stat: 'p90',
},
},
{
height: 1,
width: 24,
Expand Down
4 changes: 2 additions & 2 deletions bin/stacks/lambda-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class LambdaStack extends cdk.NestedStack {
const { provisionedConcurrency, kmsKey, tableCapacityConfig, indexCapacityConfig, chatbotSNSArn } = props

const lambdaName = `${SERVICE_NAME}Lambda`
const orderNotificationProvisionedConcurrency = 10
const orderNotificationProvisionedConcurrency = 50

const lambdaRole = new aws_iam.Role(this, `${lambdaName}-LambdaRole`, {
assumedBy: new aws_iam.ServicePrincipal('lambda.amazonaws.com'),
Expand Down Expand Up @@ -165,7 +165,7 @@ export class LambdaStack extends cdk.NestedStack {

const notificationConfig = {
startingPosition: aws_lambda.StartingPosition.TRIM_HORIZON,
batchSize: 10,
batchSize: 1,
retryAttempts: 0,
bisectBatchOnError: true,
reportBatchItemFailures: true,
Expand Down
15 changes: 10 additions & 5 deletions lib/handlers/order-notification/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ export class OrderNotificationHandler extends DynamoStreamLambdaHandler<Containe
const order = CosignedV2DutchOrder.parse(newOrder.encodedOrder, newOrder.chainId)
const decayStartTime = order.info.cosignerData.decayStartTime
const currentTime = Math.floor(Date.now() / 1000) // Convert to seconds
const timeDifference = Number(decayStartTime) - currentTime
const decayTimeDifference = Number(decayStartTime) - currentTime
if (record.dynamodb && record.dynamodb.ApproximateCreationDateTime) {
const recordTimeDifference = record.dynamodb.ApproximateCreationDateTime - currentTime
const staleRecordMetricName = `NotificationRecordStaleness-chain-${newOrder.chainId.toString()}`
metrics.putMetric(staleRecordMetricName, recordTimeDifference)
}

// GPA currentlys sets mainnet decay start to 24 secs into the future
if (newOrder.chainId == ChainId.MAINNET && timeDifference > DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC) {
// GPA currently sets mainnet decay start to 24 secs into the future
if (newOrder.chainId == ChainId.MAINNET && decayTimeDifference > DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC) {
const staleOrderMetricName = `NotificationStaleOrder-chain-${newOrder.chainId.toString()}`
metrics.putMetric(staleOrderMetricName, 1, Unit.Count)
}
const staleOrderMetricName = `NotificationOrderStaleness-chain-${newOrder.chainId.toString()}`
metrics.putMetric(staleOrderMetricName, timeDifference)
const orderStalenessMetricName = `NotificationOrderStaleness-chain-${newOrder.chainId.toString()}`
metrics.putMetric(orderStalenessMetricName, decayTimeDifference)
}

const registeredEndpoints = await webhookProvider.getEndpoints({
Expand Down

0 comments on commit 0c4578b

Please sign in to comment.