@@ -20,11 +20,12 @@ import { PluginService } from "../../plugin_service";
2020import { logger } from "../../../logutils" ;
2121import { Messages } from "../../utils/messages" ;
2222import { ClientWrapper } from "../../client_wrapper" ;
23- import { sleep } from "../../utils/utils" ;
24- import { WrapperProperties } from "../../wrapper_property" ;
23+ import { getCurrentTimeNano , sleep } from "../../utils/utils" ;
2524import { TelemetryFactory } from "../../utils/telemetry/telemetry_factory" ;
2625import { TelemetryCounter } from "../../utils/telemetry/telemetry_counter" ;
2726import { TelemetryTraceLevel } from "../../utils/telemetry/telemetry_trace_level" ;
27+ import { HostResponseTimeMonitor } from "../strategy/fastest_response/host_response_time_monitor" ;
28+ import { WrapperProperties } from "../../wrapper_property" ;
2829
2930export interface Monitor {
3031 startMonitoring ( context : MonitorConnectionContext ) : void ;
@@ -79,7 +80,7 @@ export class MonitorImpl implements Monitor {
7980 this . properties = properties ;
8081 this . hostInfo = hostInfo ;
8182 this . monitorDisposalTimeMillis = monitorDisposalTimeMillis ;
82- this . contextLastUsedTimestampNanos = this . getCurrentTimeNano ( ) ;
83+ this . contextLastUsedTimestampNanos = getCurrentTimeNano ( ) ;
8384 const instanceId = this . hostInfo . hostId ?? this . hostInfo . host ;
8485 this . instanceInvalidCounter = this . telemetryFactory . createCounter ( `efm.hostUnhealthy.count.${ instanceId } ` ) ;
8586 }
@@ -94,7 +95,7 @@ export class MonitorImpl implements Monitor {
9495 logger . warn ( Messages . get ( "MonitorImpl.monitorIsStopped" , this . hostInfo . host ) ) ;
9596 }
9697
97- const currentTimeNanos : number = this . getCurrentTimeNano ( ) ;
98+ const currentTimeNanos : number = getCurrentTimeNano ( ) ;
9899 context . startMonitorTimeNano = currentTimeNanos ;
99100 this . contextLastUsedTimestampNanos = currentTimeNanos ;
100101 this . newContexts . push ( context ) ;
@@ -110,7 +111,7 @@ export class MonitorImpl implements Monitor {
110111 }
111112
112113 context . isActiveContext = false ;
113- this . contextLastUsedTimestampNanos = this . getCurrentTimeNano ( ) ;
114+ this . contextLastUsedTimestampNanos = getCurrentTimeNano ( ) ;
114115 }
115116
116117 async run ( ) : Promise < void > {
@@ -121,7 +122,7 @@ export class MonitorImpl implements Monitor {
121122 try {
122123 let newMonitorContext : MonitorConnectionContext | undefined ;
123124 let firstAddedNewMonitorContext : MonitorConnectionContext | null = null ;
124- const currentTimeNano : number = this . getCurrentTimeNano ( ) ;
125+ const currentTimeNano : number = getCurrentTimeNano ( ) ;
125126
126127 while ( ( newMonitorContext = this . newContexts . shift ( ) ) != null ) {
127128 if ( firstAddedNewMonitorContext === newMonitorContext ) {
@@ -140,9 +141,9 @@ export class MonitorImpl implements Monitor {
140141 }
141142
142143 if ( this . activeContexts . length > 0 ) {
143- this . contextLastUsedTimestampNanos = this . getCurrentTimeNano ( ) ;
144+ this . contextLastUsedTimestampNanos = getCurrentTimeNano ( ) ;
144145
145- const statusCheckStartTimeNanos : number = this . getCurrentTimeNano ( ) ;
146+ const statusCheckStartTimeNanos : number = getCurrentTimeNano ( ) ;
146147 this . contextLastUsedTimestampNanos = statusCheckStartTimeNanos ;
147148
148149 const status : ConnectionStatus = await this . checkConnectionStatus ( ) ;
@@ -199,7 +200,7 @@ export class MonitorImpl implements Monitor {
199200 this . delayMillisTimeoutId = setTimeout ( resolve , delayMillis ) ;
200201 } ) ;
201202 } else {
202- if ( this . getCurrentTimeNano ( ) - this . contextLastUsedTimestampNanos >= this . monitorDisposalTimeMillis * 1_000_000 ) {
203+ if ( getCurrentTimeNano ( ) - this . contextLastUsedTimestampNanos >= this . monitorDisposalTimeMillis * 1_000_000 ) {
203204 break ;
204205 }
205206 await new Promise ( ( resolve ) => {
@@ -229,36 +230,33 @@ export class MonitorImpl implements Monitor {
229230 const connectContext = this . telemetryFactory . openTelemetryContext ( "Connection status check" , TelemetryTraceLevel . FORCE_TOP_LEVEL ) ;
230231 connectContext . setAttribute ( "url" , this . hostInfo . host ) ;
231232 return await connectContext . start ( async ( ) => {
232- const startNanos = this . getCurrentTimeNano ( ) ;
233+ const startNanos = getCurrentTimeNano ( ) ;
233234 try {
234235 const clientIsValid = this . monitoringClient && ( await this . pluginService . isClientValid ( this . monitoringClient ) ) ;
235236
236237 if ( this . monitoringClient !== null && clientIsValid ) {
237- return Promise . resolve ( new ConnectionStatus ( clientIsValid , this . getCurrentTimeNano ( ) - startNanos ) ) ;
238+ return Promise . resolve ( new ConnectionStatus ( clientIsValid , getCurrentTimeNano ( ) - startNanos ) ) ;
238239 }
239240
240241 await this . endMonitoringClient ( ) ;
241-
242242 // Open a new connection.
243243 const monitoringConnProperties : Map < string , any > = new Map ( this . properties ) ;
244-
245- for ( const key of this . properties . keys ( ) ) {
244+ for ( const key of monitoringConnProperties . keys ( ) ) {
246245 if ( ! key . startsWith ( WrapperProperties . MONITORING_PROPERTY_PREFIX ) ) {
247246 continue ;
248247 }
249-
250248 monitoringConnProperties . set ( key . substring ( WrapperProperties . MONITORING_PROPERTY_PREFIX . length ) , this . properties . get ( key ) ) ;
251249 monitoringConnProperties . delete ( key ) ;
252250 }
253251
254252 logger . debug ( `Opening a monitoring connection to ${ this . hostInfo . url } ` ) ;
255253 this . monitoringClient = await this . pluginService . forceConnect ( this . hostInfo , monitoringConnProperties ) ;
256254 logger . debug ( `Successfully opened monitoring connection to ${ this . monitoringClient . id } - ${ this . hostInfo . url } ` ) ;
257- return Promise . resolve ( new ConnectionStatus ( true , this . getCurrentTimeNano ( ) - startNanos ) ) ;
255+ return Promise . resolve ( new ConnectionStatus ( true , getCurrentTimeNano ( ) - startNanos ) ) ;
258256 } catch ( error : any ) {
259257 this . instanceInvalidCounter . inc ( ) ;
260258 await this . endMonitoringClient ( ) ;
261- return Promise . resolve ( new ConnectionStatus ( false , this . getCurrentTimeNano ( ) - startNanos ) ) ;
259+ return Promise . resolve ( new ConnectionStatus ( false , getCurrentTimeNano ( ) - startNanos ) ) ;
262260 }
263261 } ) ;
264262 }
@@ -272,10 +270,6 @@ export class MonitorImpl implements Monitor {
272270 return this . stopped || this . cancelled ;
273271 }
274272
275- protected getCurrentTimeNano ( ) {
276- return Number ( process . hrtime . bigint ( ) ) ;
277- }
278-
279273 async releaseResources ( ) {
280274 this . cancelled = true ;
281275 clearTimeout ( this . delayMillisTimeoutId ) ;
0 commit comments