Skip to content

Commit

Permalink
changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlamz committed Apr 1, 2024
1 parent 87a0973 commit 277fd9d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions common/lib/connection_plugin_chain_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand All @@ -35,7 +35,7 @@ export class ConnectionPluginChainBuilder {
static readonly PLUGIN_FACTORIES = new Map<string, FactoryClass>([
["iam", IamAuthenticationPluginFactory],
["failover", FailoverPluginFactory],
["connectTime", ConnectTimeConnectionPluginFactory]
["connectTime", ConnectTimePluginFactory]
]);

getPlugins(pluginService: PluginService, props: Map<string, any>): ConnectionPlugin[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = new Set<string>(["connect", "forceConnect"]);
private static connectTime: number = 0;
private static connectTime: bigint = 0n;

public override getSubscribedMethods(): Set<string> {
return ConnectTimeConnectionPlugin.subscribedMethods;
return ConnectTimePlugin.subscribedMethods;
}

public override async connect<T>(hostInfo: HostInfo, props: Map<string, any>, isInitialConnection: boolean, connectFunc: () => Promise<T>): Promise<T> {
Expand All @@ -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;
}

Expand All @@ -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<string, any>): ConnectionPlugin {
return new ConnectTimeConnectionPlugin();
return new ConnectTimePlugin();
}
}
}
2 changes: 1 addition & 1 deletion common/lib/utils/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 1 addition & 2 deletions common/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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<string, any>) {
Expand Down

0 comments on commit 277fd9d

Please sign in to comment.