Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion manifest-vars.beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ instances: 2
environment: beta
host: api-easey-beta.app.cloud.gov
apiHost: api.epa.gov/easey/beta
matsImportBucket: cg-4e77a460-aab1-4070-a67c-9debdc58a516
matsImportBucket: cg-4e77a460-aab1-4070-a67c-9debdc58a516
maxConnectionPool: 15
idleTimeout: 30000
connectionTimeout: 10000
acquireConnectionFromPoolTimeout: 15000
statementTimeout: 300000
idleInTransactionSessionTimeout: 300000
maxUsesBeforeRecreatingConnection: 500
sqlLogging: ['error']
maxQueryExecutionTime: 30000
11 changes: 10 additions & 1 deletion manifest-vars.perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ instances: 2
environment: performance
host: api-easey-perf.app.cloud.gov
apiHost: api.epa.gov/easey/perf
matsImportBucket: cg-313e2894-003b-4eda-88ca-ce57b954a57d
matsImportBucket: cg-313e2894-003b-4eda-88ca-ce57b954a57d
maxConnectionPool: 15
idleTimeout: 30000
connectionTimeout: 10000
acquireConnectionFromPoolTimeout: 15000
statementTimeout: 300000
idleInTransactionSessionTimeout: 300000
maxUsesBeforeRecreatingConnection: 500
sqlLogging: ['error']
maxQueryExecutionTime: 30000
11 changes: 10 additions & 1 deletion manifest-vars.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ instances: 2
environment: production
host: api-easey.app.cloud.gov
apiHost: api.epa.gov/easey
matsImportBucket:
matsImportBucket:
maxConnectionPool: 15
idleTimeout: 30000
connectionTimeout: 10000
acquireConnectionFromPoolTimeout: 15000
statementTimeout: 300000
idleInTransactionSessionTimeout: 300000
maxUsesBeforeRecreatingConnection: 500
sqlLogging: ['error']
maxQueryExecutionTime: 30000
11 changes: 10 additions & 1 deletion manifest-vars.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ instances: 2
environment: staging
host: api-easey-stg.app.cloud.gov
apiHost: api.epa.gov/easey/staging
matsImportBucket:
matsImportBucket:
maxConnectionPool: 5
idleTimeout: 5000
connectionTimeout: 5000
acquireConnectionFromPoolTimeout: 3000
statementTimeout: 200000
idleInTransactionSessionTimeout: 60000
maxUsesBeforeRecreatingConnection: 500
sqlLogging: ['error']
maxQueryExecutionTime: 5000
11 changes: 10 additions & 1 deletion manifest-vars.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ instances: 1
environment: testing
host: api-easey-tst.app.cloud.gov
apiHost: api.epa.gov/easey/test
matsImportBucket: cg-4f56c44b-64ff-45e7-b346-87ee77ca1dad
matsImportBucket: cg-4f56c44b-64ff-45e7-b346-87ee77ca1dad
maxConnectionPool: 5
idleTimeout: 5000
connectionTimeout: 5000
acquireConnectionFromPoolTimeout: 3000
statementTimeout: 200000
idleInTransactionSessionTimeout: 60000
maxUsesBeforeRecreatingConnection: 500
sqlLogging: ['error']
maxQueryExecutionTime: 5000
9 changes: 9 additions & 0 deletions manifest-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ apiHost: api.epa.gov/easey/dev
dbSvc: camd-pg-db
awsRegion: us-gov-west-1
matsImportBucket: cg-a5287c70-6f5f-4b41-acd4-a82bbb633f55
maxConnectionPool: 15
idleTimeout: 30000
connectionTimeout: 10000
acquireConnectionFromPoolTimeout: 15000
statementTimeout: 300000
idleInTransactionSessionTimeout: 300000
maxUsesBeforeRecreatingConnection: 500
sqlLogging: ['error']
maxQueryExecutionTime: 30000
10 changes: 10 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ applications:
EASEY_API_GATEWAY_HOST: ((apiHost))
EASEY_AUTH_API: https://((apiHost))/auth-mgmt
TZ: America/New_York
EASEY_DB_MAX_CONNECTION_POOL: ((maxConnectionPool))
EASEY_DB_IDLE_TIMEOUT: ((idleTimeout))
EASEY_DB_CONNECTION_TIMEOUT: ((connectionTimeout))
EASEY_DB_IDLE_CONNECTION_TIMEOUT: ((acquireConnectionFromPoolTimeout))
EASEY_DB_STATEMENT_TIMEOUT: ((statementTimeout))
EASEY_DB_IDLE_TRANS_SESSION_TIMEOUT: ((idleInTransactionSessionTimeout))
EASEY_DB_MAX_USES_BEFORE_CONN_RECREATE: ((maxUsesBeforeRecreatingConnection))
EASEY_DB_SQL_LOGGING: ((sqlLogging))
EASEY_DB_MAX_QUERY_EXECUTION_TIMEOUT: ((maxQueryExecutionTime))

routes:
- route: ((host))/((path))
services:
Expand Down
10 changes: 10 additions & 0 deletions src/config/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,14 @@ export default registerAs('app', () => ({
matsImportBucketSecretAccessKey: getConfigValue(
'EASEY_MATS_BULK_FILES_IMPORT_AWS_SECRET_ACCESS_KEY',
),

maxConnectionPool: getConfigValueNumber('EASEY_DB_MAX_CONNECTION_POOL',15),
idleTimeout: getConfigValueNumber( 'EASEY_DB_IDLE_TIMEOUT', 30000, ),
connectionTimeout: getConfigValueNumber('EASEY_DB_CONNECTION_TIMEOUT',10000),
acquireConnectionFromPoolTimeout: getConfigValueNumber('EASEY_DB_IDLE_CONNECTION_TIMEOUT',15000),
statementTimeout: getConfigValueNumber('EASEY_DB_STATEMENT_TIMEOUT',300000),
idleInTransactionSessionTimeout: getConfigValueNumber('EASEY_DB_IDLE_TRANS_SESSION_TIMEOUT',300000),
sqlLogging: getConfigValue('EASEY_DB_SQL_LOGGING', ['error']),
maxQueryExecutionTime: getConfigValueNumber('EASEY_DB_MAX_QUERY_EXECUTION_TIMEOUT',30000),
maxUsesBeforeRecreatingConnection: getConfigValueNumber('EASEY_DB_MAX_USES_BEFORE_CONN_RECREATE',500),
}));
18 changes: 18 additions & 0 deletions src/config/typeorm.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LoggerOptions } from 'typeorm';

require('dotenv').config();
import { TlsOptions } from 'tls';
import { readFileSync } from 'fs';
Expand Down Expand Up @@ -35,6 +37,22 @@ export class TypeOrmConfigService implements TypeOrmOptionsFactory {
entities: [__dirname + '/../**/*.entity.{js,ts}'],
synchronize: false,
ssl: this.tlsOptions,

// Database specific (Postgres) settings.
extra: {
max: this.configService.get<number>('app.maxConnectionPool'), // Max connections in pool
idleTimeoutMillis: this.configService.get<number>('app.idleTimeout'), // Close idle connections
connectionTimeoutMillis: this.configService.get<number>('app.connectionTimeout'), // Maximum time (ms) to wait for a new connection before timing out.
acquireTimeoutMillis: this.configService.get<number>('app.acquireConnectionFromPoolTimeout'), // Fail if a connection is not acquired from the pool within timeframe
statement_timeout: this.configService.get<number>('app.statementTimeout'), // Terminates queries that exceed the timeout (in ms).
idle_in_transaction_session_timeout: this.configService.get<number>('app.idleInTransactionSessionTimeout'), // Terminates idle transactions after the specified time (in ms).
maxUses: this.configService.get<number>('app.maxUsesBeforeRecreatingConnection'), //Recreate connections after 'n' uses
},
// Enable SQL Logging. Values are: true | false | 'all' | ['query', 'error', 'schema', 'warn', 'info', 'log']
logging: this.configService.get<LoggerOptions>('app.sqlLogging', ),
// Logs queries exceeding this limit (does not terminate, 'statement_timeout' terminates them).
maxQueryExecutionTime: this.configService.get<number>('app.maxQueryExecutionTime'),

};
}
}