From 277fd9d42b367c3244cf8a00d205eba9ce47dd24 Mon Sep 17 00:00:00 2001 From: jasonlamz Date: Mon, 1 Apr 2024 14:30:03 -0700 Subject: [PATCH] changes from review --- common/lib/connection_plugin_chain_builder.ts | 4 ++-- ...ction_plugin.ts => connect_time_plugin.ts} | 24 +++++++++---------- common/lib/utils/locales/en.json | 2 +- common/lib/utils/utils.ts | 3 +-- 4 files changed, 16 insertions(+), 17 deletions(-) rename common/lib/plugins/{connect_time_connection_plugin.ts => connect_time_plugin.ts} (73%) diff --git a/common/lib/connection_plugin_chain_builder.ts b/common/lib/connection_plugin_chain_builder.ts index f00aede8..9204ebfe 100644 --- a/common/lib/connection_plugin_chain_builder.ts +++ b/common/lib/connection_plugin_chain_builder.ts @@ -22,7 +22,7 @@ import { WrapperProperties } from "./wrapper_property"; import { AwsWrapperError } from "./utils/aws_wrapper_error"; import { Messages } from "./utils/messages"; import { DefaultPlugin } from "./plugins/default_plugin"; -import { ConnectTimeConnectionPluginFactory } from './plugins/connect_time_connection_plugin'; +import { ConnectTimePluginFactory } from './plugins/connect_time_plugin'; export class PluginFactoryInfo {} @@ -35,7 +35,7 @@ export class ConnectionPluginChainBuilder { static readonly PLUGIN_FACTORIES = new Map([ ["iam", IamAuthenticationPluginFactory], ["failover", FailoverPluginFactory], - ["connectTime", ConnectTimeConnectionPluginFactory] + ["connectTime", ConnectTimePluginFactory] ]); getPlugins(pluginService: PluginService, props: Map): ConnectionPlugin[] { diff --git a/common/lib/plugins/connect_time_connection_plugin.ts b/common/lib/plugins/connect_time_plugin.ts similarity index 73% rename from common/lib/plugins/connect_time_connection_plugin.ts rename to common/lib/plugins/connect_time_plugin.ts index 5d27d187..cd82b2d5 100644 --- a/common/lib/plugins/connect_time_connection_plugin.ts +++ b/common/lib/plugins/connect_time_plugin.ts @@ -23,12 +23,12 @@ import { ConnectionPluginFactory } from "../plugin_factory"; import { ConnectionPlugin } from "../connection_plugin"; import { PluginService } from '../plugin_service'; -export class ConnectTimeConnectionPlugin extends AbstractConnectionPlugin { +export class ConnectTimePlugin extends AbstractConnectionPlugin { private static subscribedMethods: Set = new Set(["connect", "forceConnect"]); - private static connectTime: number = 0; + private static connectTime: bigint = 0n; public override getSubscribedMethods(): Set { - return ConnectTimeConnectionPlugin.subscribedMethods; + return ConnectTimePlugin.subscribedMethods; } public override async connect(hostInfo: HostInfo, props: Map, isInitialConnection: boolean, connectFunc: () => Promise): Promise { @@ -37,8 +37,8 @@ export class ConnectTimeConnectionPlugin extends AbstractConnectionPlugin { let result = await connectFunc(); let elapsedTimeNanos = getTimeInNanos() - startTime; - ConnectTimeConnectionPlugin.connectTime += elapsedTimeNanos; - logger.debug(Messages.get("ConnectTimeConnectionPlugin.connectTime", elapsedTimeNanos.toString())); + ConnectTimePlugin.connectTime += elapsedTimeNanos; + logger.debug(Messages.get("ConnectTimePlugin.connectTime", elapsedTimeNanos.toString())); return result; } @@ -48,22 +48,22 @@ export class ConnectTimeConnectionPlugin extends AbstractConnectionPlugin { let result = await forceConnectFunc(); let elapsedTimeNanos = getTimeInNanos() - startTime; - ConnectTimeConnectionPlugin.connectTime += elapsedTimeNanos; - logger.debug(Messages.get("ConnectTimeConnectionPlugin.connectTime", elapsedTimeNanos.toString())); + ConnectTimePlugin.connectTime += elapsedTimeNanos; + logger.debug(Messages.get("ConnectTimePlugin.connectTime", elapsedTimeNanos.toString())); return result; } public static resetConnectTime(): void { - this.connectTime = 0; + this.connectTime = 0n; } - public static getTotalConnectTime(): number { + public static getTotalConnectTime(): bigint { return this.connectTime; } } -export class ConnectTimeConnectionPluginFactory implements ConnectionPluginFactory { +export class ConnectTimePluginFactory implements ConnectionPluginFactory { getInstance(pluginService: PluginService, properties: Map): ConnectionPlugin { - return new ConnectTimeConnectionPlugin(); + return new ConnectTimePlugin(); } -} \ No newline at end of file +} diff --git a/common/lib/utils/locales/en.json b/common/lib/utils/locales/en.json index 1de07053..a25f8dee 100644 --- a/common/lib/utils/locales/en.json +++ b/common/lib/utils/locales/en.json @@ -34,5 +34,5 @@ "ClusterAwareWriterFailoverHandler.standaloneNode": "[TaskB] Host %s is not yet connected to a cluster. The cluster is still being reconfigured.", "ClusterAwareWriterFailoverHandler.taskBAttemptConnectionToNewWriter": "[TaskB] Trying to connect to a new writer: '%s'", "ClusterAwareWriterFailoverHandler.alreadyWriter": "Current reader connection is actually a new writer connection.", - "ConnectTimeConnectionPlugin.connectTime": "Connected in %s nanos." + "ConnectTimePlugin.connectTime": "Connected in %s nanos." } diff --git a/common/lib/utils/utils.ts b/common/lib/utils/utils.ts index 30c00054..553fcdcf 100644 --- a/common/lib/utils/utils.ts +++ b/common/lib/utils/utils.ts @@ -17,7 +17,6 @@ import { HostInfo } from "../host_info"; import { Messages } from "./messages"; import { WrapperProperties } from "../wrapper_property"; -import { performance } from 'perf_hooks'; export function sleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); @@ -39,7 +38,7 @@ export function logTopology(hosts: HostInfo[], msgPrefix: string) { } export function getTimeInNanos() { - return performance.now() * 1000000; + return process.hrtime.bigint(); } export function maskProperties(props: Map) {