Skip to content

Commit db1b5a5

Browse files
committed
feat: configuration types
1 parent 823371e commit db1b5a5

File tree

5 files changed

+198
-29
lines changed

5 files changed

+198
-29
lines changed

common/lib/aws_client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,23 @@ export abstract class AwsClient extends EventEmitter implements SessionStateClie
154154

155155
abstract setReadOnly(readOnly: boolean): Promise<any | void>;
156156

157-
abstract isReadOnly(): boolean;
157+
abstract isReadOnly(): boolean | undefined;
158158

159159
abstract setAutoCommit(autoCommit: boolean): Promise<any | void>;
160160

161-
abstract getAutoCommit(): boolean;
161+
abstract getAutoCommit(): boolean | undefined;
162162

163163
abstract setTransactionIsolation(level: TransactionIsolationLevel): Promise<any | void>;
164164

165-
abstract getTransactionIsolation(): TransactionIsolationLevel;
165+
abstract getTransactionIsolation(): TransactionIsolationLevel | undefined;
166166

167167
abstract setSchema(schema: any): Promise<any | void>;
168168

169-
abstract getSchema(): string;
169+
abstract getSchema(): string | undefined;
170170

171171
abstract setCatalog(catalog: string): Promise<any | void>;
172172

173-
abstract getCatalog(): string;
173+
abstract getCatalog(): string | undefined;
174174

175175
abstract end(): Promise<any>;
176176

common/lib/session_state_client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ import { TransactionIsolationLevel } from "./utils/transaction_isolation_level";
1919
export interface SessionStateClient {
2020
setReadOnly(readOnly: boolean): Promise<any | void>;
2121

22-
isReadOnly(): boolean;
22+
isReadOnly(): boolean | undefined;
2323

2424
setAutoCommit(autoCommit: boolean): Promise<any | void>;
2525

26-
getAutoCommit(): boolean;
26+
getAutoCommit(): boolean | undefined;
2727

2828
setTransactionIsolation(level: TransactionIsolationLevel): Promise<any | void>;
2929

30-
getTransactionIsolation(): TransactionIsolationLevel;
30+
getTransactionIsolation(): TransactionIsolationLevel | undefined;
3131

3232
setSchema(schema: any): Promise<any | void>;
3333

34-
getSchema(): string;
34+
getSchema(): string | undefined;
3535

3636
setCatalog(catalog: string): Promise<any | void>;
3737

38-
getCatalog(): string;
38+
getCatalog(): string | undefined;
3939
}

common/lib/wrapper_property.ts

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,173 @@ import { DatabaseDialect } from "./database_dialect/database_dialect";
1919
import { ClusterTopologyMonitorImpl } from "./host_list_provider/monitoring/cluster_topology_monitor";
2020
import { BlueGreenStatusProvider } from "./plugins/bluegreen/blue_green_status_provider";
2121

22+
export interface AwsClientConfig {
23+
/** Comma separated list of connection plugin codes */
24+
plugins?: string;
25+
/** This flag is enabled by default, meaning that the plugins order will be automatically adjusted. Disable it at your own risk or if you really need plugins to be executed in a particular order. */
26+
autoSortWrapperPluginOrder?: boolean;
27+
/** A unique identifier for the supported database dialect. */
28+
dialect?: string;
29+
/** The connection provider used to create connections. */
30+
connectionProvider?: ConnectionProvider;
31+
/** Timeout in milliseconds for the wrapper to execute queries against MySQL database engines */
32+
mysqlQueryTimeout?: number;
33+
/** Timeout in milliseconds for the wrapper to create a connection. */
34+
wrapperConnectTimeout?: number;
35+
/** Timeout in milliseconds for the wrapper to execute queries. */
36+
wrapperQueryTimeout?: number;
37+
/** Enables session state transfer to a new connection. */
38+
transferSessionStateOnSwitch?: boolean;
39+
/** Enables resetting a connection's session state before closing it. */
40+
resetSessionStateOnClose?: boolean;
41+
/** Enables to rollback a current transaction being in progress when switching to a new connection. */
42+
rollbackOnSwitch?: boolean;
43+
/** An override for specifying the default host availability change strategy. */
44+
defaultHostAvailabilityStrategy?: string;
45+
/** Max number of retries for checking a host's availability. */
46+
hostAvailabilityStrategyMaxRetries?: number;
47+
/** The initial backoff time in seconds. */
48+
hostAvailabilityStrategyInitialBackoffTimeSec?: number;
49+
/** Interval in millis between measuring response time to a database host. */
50+
responseMeasurementIntervalMs?: number;
51+
/** Overrides the host that is used to generate the IAM token */
52+
iamHost?: string;
53+
/** Overrides default port that is used to generate the IAM token */
54+
iamDefaultPort?: number;
55+
/** Overrides AWS region that is used to generate the IAM token */
56+
iamRegion?: string;
57+
/** The ARN of the IAM Role that is to be assumed. */
58+
iamRoleArn?: string;
59+
/** The ARN of the identity provider */
60+
iamIdpArn?: string;
61+
/** IAM token cache expiration in seconds */
62+
iamTokenExpiration?: number;
63+
/** The federated user name */
64+
idpUsername?: string;
65+
/** The federated user password */
66+
idpPassword?: string;
67+
/** The hosting URL of the Identity Provider */
68+
idpEndpoint?: string;
69+
/** The hosting port of the Identity Provider */
70+
idpPort?: number;
71+
/** The ID of the AWS application configured on Okta */
72+
appId?: string;
73+
/** The relaying party identifier */
74+
rpIdentifier?: string;
75+
/** The IAM user used to access the database */
76+
dbUser?: string;
77+
/** The options to be passed into the httpsAgent */
78+
httpsAgentOptions?: Record<string, any>;
79+
/** The name or the ARN of the secret to retrieve. */
80+
secretId?: string;
81+
/** The region of the secret to retrieve. */
82+
secretRegion?: string;
83+
/** The endpoint of the secret to retrieve. */
84+
secretEndpoint?: string;
85+
/** Cluster topology refresh rate in millis during a writer failover process. During the writer failover process, cluster topology may be refreshed at a faster pace than normal to speed up discovery of the newly promoted writer. */
86+
failoverClusterTopologyRefreshRateMs?: number;
87+
/** Maximum allowed time for the failover process. */
88+
failoverTimeoutMs?: number;
89+
/** Interval of time to wait between attempts to reconnect to a failed writer during a writer failover process. */
90+
failoverWriterReconnectIntervalMs?: number;
91+
/** Reader connection attempt timeout during a reader failover process. */
92+
failoverReaderConnectTimeoutMs?: number;
93+
/** Enable/disable cluster-aware failover logic. */
94+
enableClusterAwareFailover?: boolean;
95+
/** Set host role to follow during failover. */
96+
failoverMode?: string;
97+
/** The strategy that should be used to select a new reader host while opening a new connection. */
98+
failoverReaderHostSelectorStrategy?: string;
99+
/** Cluster topology refresh rate in millis. The cached topology for the cluster will be invalidated after the specified time, after which it will be updated during the next interaction with the connection. */
100+
clusterTopologyRefreshRateMs?: number;
101+
/** Cluster topology high refresh rate in millis. */
102+
clusterTopologyHighRefreshRateMs?: number;
103+
/** A unique identifier for the cluster. Connections with the same cluster id share a cluster topology cache. If unspecified, a cluster id is automatically created for AWS RDS clusters. */
104+
clusterId?: string;
105+
/** The cluster instance DNS pattern that will be used to build a complete instance endpoint. A "?" character in this pattern should be used as a placeholder for cluster instance names. This pattern is required to be specified for IP address or custom domain connections to AWS RDS clusters. Otherwise, if unspecified, the pattern will be automatically created for AWS RDS clusters. */
106+
clusterInstanceHostPattern?: string;
107+
/** Set to true if you are providing a connection string with multiple comma-delimited hosts and your cluster has only one writer. The writer must be the first host in the connection string */
108+
singleWriterConnectionString?: boolean;
109+
/** The strategy that should be used to select a new reader host. */
110+
readerHostSelectorStrategy?: string;
111+
/** Maximum allowed time for the retries opening a connection. */
112+
openConnectionRetryTimeoutMs?: number;
113+
/** Time between each retry of opening a connection. */
114+
openConnectionRetryIntervalMs?: number;
115+
/** Interval in millis between sending SQL to the server and the first probe to database host. */
116+
failureDetectionTime?: number;
117+
/** Enable enhanced failure detection logic. */
118+
failureDetectionEnabled?: boolean;
119+
/** Interval in millis between probes to database host. */
120+
failureDetectionInterval?: number;
121+
/** Number of failed connection checks before considering database host unhealthy. */
122+
failureDetectionCount?: number;
123+
/** Interval in milliseconds for a monitor to be considered inactive and to be disposed. */
124+
monitorDisposalTime?: number;
125+
/** Comma separated list of database host-weight pairs in the format of `<host>:<weight>`. */
126+
roundRobinHostWeightPairs?: string;
127+
/** The default weight for any hosts that have not been configured with the `roundRobinHostWeightPairs` parameter. */
128+
roundRobinDefaultWeight?: number;
129+
/** Enables telemetry and observability of the wrapper */
130+
enableTelemetry?: boolean;
131+
/** Force submitting traces related to calls as top level traces. */
132+
telemetrySubmitToplevel?: boolean;
133+
/** Method to export telemetry traces of the wrapper. */
134+
telemetryTracesBackend?: string;
135+
/** Method to export telemetry metrics of the wrapper. */
136+
telemetryMetricsBackend?: string;
137+
/** Post an additional top-level trace for failover process. */
138+
telemetryFailoverAdditionalTopTrace?: boolean;
139+
/** If the cache of transaction router info is empty and a new connection is made, this property toggles whether the plugin will wait and synchronously fetch transaction router info before selecting a transaction router to connect to, or to fall back to using the provided DB Shard Group endpoint URL. */
140+
limitlessWaitForTransactionRouterInfo?: boolean;
141+
/** Interval in millis between retries fetching Limitless Transaction Router information. */
142+
limitlessGetTransactionRouterInfoRetryIntervalMs?: number;
143+
/** Max number of connection retries fetching Limitless Transaction Router information. */
144+
limitlessGetTransactionRouterInfoMaxRetries?: number;
145+
/** Interval in millis between polling for Limitless Transaction Routers to the database. */
146+
limitlessTransactionRouterMonitorIntervalMs?: number;
147+
/** Max number of connection retries the Limitless Connection Plugin will attempt. */
148+
limitlessConnectMaxRetries?: number;
149+
/** Interval in milliseconds for an Limitless router monitor to be considered inactive and to be disposed. */
150+
limitlessTransactionRouterMonitorDisposalTimeMs?: number;
151+
/** Map containing any keepAlive properties that the target driver accepts in the client configuration. */
152+
wrapperKeepAliveProperties?: Map<string, any>;
153+
/** A reference to a custom database dialect object. */
154+
customDatabaseDialect?: DatabaseDialect;
155+
/** A reference to a custom AwsCredentialsProviderHandler object. */
156+
customAwsCredentialProviderHandler?: any;
157+
/** Name of the AWS Profile to use for IAM or SecretsManager auth. */
158+
awsProfile?: string;
159+
/** Driver configuration profile name */
160+
profileName?: string;
161+
/** Controls how frequently custom endpoint monitors fetch custom endpoint info, in milliseconds. */
162+
customEndpointInfoRefreshRateMs?: number;
163+
/** Controls whether to wait for custom endpoint info to become available before connecting or executing a method. Waiting is only necessary if a connection to a given custom endpoint has not been opened or used recently. Note that disabling this may result in occasional connections to instances outside of the custom endpoint. */
164+
waitForCustomEndpointInfo?: boolean;
165+
/** Controls the maximum amount of time that the plugin will wait for custom endpoint info to be made available by the custom endpoint monitor, in milliseconds. */
166+
waitForCustomEndpointInfoTimeoutMs?: number;
167+
/** Controls how long a monitor should run without use before expiring and being removed, in milliseconds. */
168+
customEndpointMonitorExpirationMs?: number;
169+
/** The region of the cluster's custom endpoints. If not specified, the region will be parsed from the URL. */
170+
customEndpointRegion?: string;
171+
/** Enables replacing a green host name with the original hostname after a blue/green switchover and the green name no longer resolves. */
172+
enableGreenHostReplacement?: boolean;
173+
/** Connect timeout in milliseconds during Blue/Green Deployment switchover. */
174+
bgConnectTimeoutMs?: number;
175+
/** Blue/Green Deployment ID */
176+
bgdId?: string;
177+
/** Baseline Blue/Green Deployment status checking interval in milliseconds. */
178+
bgBaselineMs?: number;
179+
/** Increased Blue/Green Deployment status checking interval in milliseconds. */
180+
bgIncreasedMs?: number;
181+
/** High Blue/Green Deployment status checking interval in milliseconds. */
182+
bgHighMs?: number;
183+
/** Blue/Green Deployment switchover timeout in milliseconds. */
184+
bgSwitchoverTimeoutMs?: number;
185+
/** Enables Blue/Green Deployment switchover to suspend new blue connection requests while the switchover process is in progress. */
186+
bgSuspendNewBlueConnections?: boolean;
187+
}
188+
22189
export class WrapperProperty<T> {
23190
name: string;
24191
description: string;

mysql/lib/client.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ import { MySQL2DriverDialect } from "./dialect/mysql2_driver_dialect";
4242
import { isDialectTopologyAware } from "../../common/lib/utils/utils";
4343
import { MySQLClient, MySQLPoolClient } from "./mysql_client";
4444
import { DriverConnectionProvider } from "../../common/lib/driver_connection_provider";
45+
import { AwsClientConfig } from "../../common/lib/wrapper_property";
46+
47+
export interface AwsMySQLClientConfig extends ConnectionOptions, AwsClientConfig {}
4548

4649
class BaseAwsMySQLClient extends AwsClient implements MySQLClient {
4750
private static readonly knownDialectsByCode: Map<string, DatabaseDialect> = new Map([
@@ -51,7 +54,7 @@ class BaseAwsMySQLClient extends AwsClient implements MySQLClient {
5154
[DatabaseDialectCodes.RDS_MULTI_AZ_MYSQL, new RdsMultiAZClusterMySQLDatabaseDialect()]
5255
]);
5356

54-
constructor(config: any, connectionProvider?: ConnectionProvider) {
57+
constructor(config: AwsMySQLClientConfig, connectionProvider?: ConnectionProvider) {
5558
super(
5659
config,
5760
DatabaseType.MYSQL,
@@ -113,7 +116,7 @@ class BaseAwsMySQLClient extends AwsClient implements MySQLClient {
113116
return result;
114117
}
115118

116-
isReadOnly(): boolean {
119+
isReadOnly(): boolean | undefined {
117120
return this.pluginService.getSessionStateService().getReadOnly();
118121
}
119122

@@ -129,7 +132,7 @@ class BaseAwsMySQLClient extends AwsClient implements MySQLClient {
129132
return result;
130133
}
131134

132-
getAutoCommit(): boolean {
135+
getAutoCommit(): boolean | undefined {
133136
return this.pluginService.getSessionStateService().getAutoCommit();
134137
}
135138

@@ -142,15 +145,15 @@ class BaseAwsMySQLClient extends AwsClient implements MySQLClient {
142145
this.pluginService.getSessionStateService().setCatalog(catalog);
143146
}
144147

145-
getCatalog(): string {
148+
getCatalog(): string | undefined {
146149
return this.pluginService.getSessionStateService().getCatalog();
147150
}
148151

149152
async setSchema(schema: string): Promise<Query | void> {
150153
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported", "setSchema"));
151154
}
152155

153-
getSchema(): string {
156+
getSchema(): string | undefined {
154157
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported", "getSchema"));
155158
}
156159

@@ -181,7 +184,7 @@ class BaseAwsMySQLClient extends AwsClient implements MySQLClient {
181184
this.pluginService.getSessionStateService().setTransactionIsolation(level);
182185
}
183186

184-
getTransactionIsolation(): TransactionIsolationLevel {
187+
getTransactionIsolation(): TransactionIsolationLevel | undefined {
185188
return this.pluginService.getSessionStateService().getTransactionIsolation();
186189
}
187190

@@ -198,6 +201,10 @@ class BaseAwsMySQLClient extends AwsClient implements MySQLClient {
198201
"end",
199202
() => {
200203
this.pluginService.removeErrorListener(this.targetClient);
204+
if (!this.targetClient) {
205+
this.isConnected = false;
206+
return Promise.resolve();
207+
}
201208
const res = ClientUtils.queryWithTimeout(this.targetClient.end(), this.properties);
202209
this.targetClient = undefined;
203210
this.isConnected = false;

pg/lib/client.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
import {
18-
QueryArrayConfig,
19-
QueryArrayResult,
20-
QueryConfig,
21-
QueryConfigValues,
22-
QueryResult,
23-
QueryResultRow,
24-
Submittable
25-
} from "pg";
17+
import { ClientConfig, QueryArrayConfig, QueryArrayResult, QueryConfig, QueryConfigValues, QueryResult, QueryResultRow, Submittable } from "pg";
2618
import { AwsClient } from "../../common/lib/aws_client";
2719
import { PgConnectionUrlParser } from "./pg_connection_url_parser";
2820
import { DatabaseDialect, DatabaseType } from "../../common/lib/database_dialect/database_dialect";
@@ -49,6 +41,9 @@ import { NodePostgresDriverDialect } from "./dialect/node_postgres_driver_dialec
4941
import { isDialectTopologyAware } from "../../common/lib/utils/utils";
5042
import { PGClient, PGPoolClient } from "./pg_client";
5143
import { DriverConnectionProvider } from "../../common/lib/driver_connection_provider";
44+
import { AwsClientConfig } from "../../common/lib/wrapper_property";
45+
46+
export interface AwsPgClientConfig extends ClientConfig, AwsClientConfig {}
5247

5348
class BaseAwsPgClient extends AwsClient implements PGClient {
5449
private static readonly knownDialectsByCode: Map<string, DatabaseDialect> = new Map([
@@ -58,7 +53,7 @@ class BaseAwsPgClient extends AwsClient implements PGClient {
5853
[DatabaseDialectCodes.RDS_MULTI_AZ_PG, new RdsMultiAZClusterPgDatabaseDialect()]
5954
]);
6055

61-
constructor(config: any, connectionProvider?: ConnectionProvider) {
56+
constructor(config: AwsPgClientConfig, connectionProvider?: ConnectionProvider) {
6257
super(
6358
config,
6459
DatabaseType.POSTGRES,
@@ -90,7 +85,7 @@ class BaseAwsPgClient extends AwsClient implements PGClient {
9085
return result;
9186
}
9287

93-
isReadOnly(): boolean {
88+
isReadOnly(): boolean | undefined {
9489
return this.pluginService.getSessionStateService().getReadOnly();
9590
}
9691

@@ -128,7 +123,7 @@ class BaseAwsPgClient extends AwsClient implements PGClient {
128123
this.pluginService.getSessionStateService().setTransactionIsolation(level);
129124
}
130125

131-
getTransactionIsolation(): TransactionIsolationLevel {
126+
getTransactionIsolation(): TransactionIsolationLevel | undefined {
132127
return this.pluginService.getSessionStateService().getTransactionIsolation();
133128
}
134129

@@ -155,7 +150,7 @@ class BaseAwsPgClient extends AwsClient implements PGClient {
155150
return result;
156151
}
157152

158-
getSchema(): string {
153+
getSchema(): string | undefined {
159154
return this.pluginService.getSessionStateService().getSchema();
160155
}
161156

0 commit comments

Comments
 (0)