@@ -10,8 +10,11 @@ import {
10
10
} from '@aztec/circuit-types' ;
11
11
import { createDebugLogger } from '@aztec/foundation/log' ;
12
12
import { RunningPromise } from '@aztec/foundation/running-promise' ;
13
+ import { Timer } from '@aztec/foundation/timer' ;
14
+ import { type TelemetryClient } from '@aztec/telemetry-client' ;
13
15
14
16
import { type ProofStore } from './proof_store.js' ;
17
+ import { ProvingAgentInstrumentation } from './proving_agent_instrumentation.js' ;
15
18
import { ProvingJobController , ProvingJobControllerStatus } from './proving_job_controller.js' ;
16
19
17
20
/**
@@ -20,6 +23,8 @@ import { ProvingJobController, ProvingJobControllerStatus } from './proving_job_
20
23
export class ProvingAgent {
21
24
private currentJobController ?: ProvingJobController ;
22
25
private runningPromise : RunningPromise ;
26
+ private instrumentation : ProvingAgentInstrumentation ;
27
+ private idleTimer : Timer | undefined ;
23
28
24
29
constructor (
25
30
/** The source of proving jobs */
@@ -28,12 +33,15 @@ export class ProvingAgent {
28
33
private proofStore : ProofStore ,
29
34
/** The prover implementation to defer jobs to */
30
35
private circuitProver : ServerCircuitProver ,
36
+ /** A telemetry client through which to emit metrics */
37
+ client : TelemetryClient ,
31
38
/** Optional list of allowed proof types to build */
32
39
private proofAllowList : Array < ProvingRequestType > = [ ] ,
33
40
/** How long to wait between jobs */
34
41
private pollIntervalMs = 1000 ,
35
42
private log = createDebugLogger ( 'aztec:prover-client:proving-agent' ) ,
36
43
) {
44
+ this . instrumentation = new ProvingAgentInstrumentation ( client ) ;
37
45
this . runningPromise = new RunningPromise ( this . safeWork , this . pollIntervalMs ) ;
38
46
}
39
47
@@ -46,6 +54,7 @@ export class ProvingAgent {
46
54
}
47
55
48
56
public start ( ) : void {
57
+ this . idleTimer = new Timer ( ) ;
49
58
this . runningPromise . start ( ) ;
50
59
}
51
60
@@ -114,6 +123,11 @@ export class ProvingAgent {
114
123
) ;
115
124
}
116
125
126
+ if ( this . idleTimer ) {
127
+ this . instrumentation . recordIdleTime ( this . idleTimer ) ;
128
+ }
129
+ this . idleTimer = undefined ;
130
+
117
131
this . currentJobController . start ( ) ;
118
132
} catch ( err ) {
119
133
this . log . error ( `Error in ProvingAgent: ${ String ( err ) } ` ) ;
@@ -126,6 +140,7 @@ export class ProvingAgent {
126
140
err : Error | undefined ,
127
141
result : ProvingJobResultsMap [ T ] | undefined ,
128
142
) => {
143
+ this . idleTimer = new Timer ( ) ;
129
144
if ( err ) {
130
145
const retry = err . name === ProvingError . NAME ? ( err as ProvingError ) . retry : false ;
131
146
this . log . error ( `Job id=${ jobId } type=${ ProvingRequestType [ type ] } failed err=${ err . message } retry=${ retry } ` , err ) ;
0 commit comments