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

feat: record when an anchor is taking longer than x minutes #1230

Merged
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
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"schedulerIntervalMS": 300000,
"schedulerStopAfterNoOp": false,
"pubsubResponderWindowMs": 8035200000,
"alertOnLongAnchorMs": 1200000,
"carStorage": {
"mode": "inmemory",
"s3BucketName": "myS3Bucket",
Expand Down
1 change: 1 addition & 0 deletions config/env/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"schedulerIntervalMS": "@@SCHEDULER_INTERVAL_MS",
"schedulerStopAfterNoOp": "@@SCHEDULER_STOP_AFTER_NO_OP",
"pubsubResponderWindowMs": "@@PUBSUB_RESPONDER_WINDOW_MS",
"alertOnLongAnchorMs": "@@ALERT_ON_LONG_ANCHOR_MS",
"carStorage": {
"mode": "@@MERKLE_CAR_STORAGE_MODE",
"s3BucketName": "@@S3_BUCKET_NAME",
Expand Down
1 change: 1 addition & 0 deletions config/env/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"schedulerIntervalMS": "@@SCHEDULER_INTERVAL_MS",
"schedulerStopAfterNoOp": "@@SCHEDULER_STOP_AFTER_NO_OP",
"pubsubResponderWindowMs": "@@PUBSUB_RESPONDER_WINDOW_MS",
"alertOnLongAnchorMs": "@@ALERT_ON_LONG_ANCHOR_MS",
"carStorage": {
"mode": "@@MERKLE_CAR_STORAGE_MODE",
"s3BucketName": "@@S3_BUCKET_NAME",
Expand Down
15 changes: 14 additions & 1 deletion src/services/anchor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class AnchorService {
private readonly maxStreamLimit: number
private readonly minStreamLimit: number
private readonly merkleCarFactory: MerkleCarFactory
private readonly alertOnLongAnchorMs: number

static inject = [
'blockchainService',
Expand Down Expand Up @@ -167,6 +168,7 @@ export class AnchorService {
this.merkleDepthLimit = config.merkleDepthLimit
this.useSmartContractAnchors = config.useSmartContractAnchors
this.useQueueBatches = Boolean(config.queue.sqsQueueUrl)
this.alertOnLongAnchorMs = Number(config.alertOnLongAnchorMs || 1200000) // default 20 minutes

const minStreamCount = Number(config.minStreamCount)
this.maxStreamLimit = this.merkleDepthLimit > 0 ? Math.pow(2, this.merkleDepthLimit) : 0
Expand All @@ -179,8 +181,18 @@ export class AnchorService {
*/
// TODO: Remove for CAS V2 as we won't need to move PENDING requests to ready. Switch to using anchorReadyRequests.
async anchorRequests(abortOptions?: AbortOptions): Promise<boolean> {
const timeout = setTimeout(() => {
Metrics.count(METRIC_NAMES.ANCHOR_TAKING_TOO_LONG, 1)
}, this.alertOnLongAnchorMs)

abortOptions?.signal?.addEventListener('abort', () => {
clearTimeout(timeout)
})

if (this.useQueueBatches) {
return this.anchorNextQueuedBatch(abortOptions)
const batchAnchored = await this.anchorNextQueuedBatch(abortOptions)
clearTimeout(timeout)
return batchAnchored
} else {
const readyRequestsCount = await this.requestRepository.countByStatus(RS.READY)

Expand All @@ -190,6 +202,7 @@ export class AnchorService {
}

await this.anchorReadyRequests()
clearTimeout(timeout)
return true
}
}
Expand Down
1 change: 1 addition & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum METRIC_NAMES {
MERKLE_CAR_STORAGE_FAILURE_IPFS = 'merkle_car_storage_failure_ipfs',
MERKLE_CAR_STORAGE_FAILURE_S3 = 'merkle_car_storage_failure_s3',
WITNESS_CAR_STORAGE_FAILURE = 'witness_car_storage_failure',
ANCHOR_TAKING_TOO_LONG = 'anchor_taking_too_long',

// Transaction repository
MANY_ATTEMPTS_TO_ACQUIRE_MUTEX = 'many_attempts_to_acquire_mutex',
Expand Down