Skip to content

Commit

Permalink
Merge pull request #4073 from organise-network/configure-mongo-min-po…
Browse files Browse the repository at this point in the history
…ol-size

feat(dal): Configure minimum connection pool size by env var
  • Loading branch information
Pablo Fernández authored Oct 9, 2023
2 parents 178edf3 + 39747e8 commit 291efe6
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apps/api/src/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ MAIL_SERVER_DOMAIN=
MAX_NOVU_INTEGRATION_MAIL_REQUESTS=300
NOVU_EMAIL_INTEGRATION_API_KEY=

MONGO_MIN_POOL_SIZE=200

MAX_NOVU_INTEGRATION_SMS_REQUESTS=20
NOVU_SMS_INTEGRATION_ACCOUNT_SID=
NOVU_SMS_INTEGRATION_TOKEN=
Expand Down
3 changes: 3 additions & 0 deletions apps/api/src/config/env-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const validators: { [K in keyof any]: ValidatorSpec<any[K]> } = {
default: '',
}),
MONGO_URL: str(),
MONGO_MIN_POOL_SIZE: num({
default: 10,
}),
MONGO_MAX_POOL_SIZE: num({
default: 500,
}),
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ declare namespace NodeJS {
// eslint-disable-next-line @typescript-eslint/naming-convention
export interface ProcessEnv {
MONGO_URL: string;
MONGO_MIN_POOL_SIZE: number;
MONGO_MAX_POOL_SIZE: number;
REDIS_URL: string;
SYNC_PATH: string;
Expand Down
1 change: 1 addition & 0 deletions apps/webhook/src/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ WIDGET_BASE_URL=https://widget.novu.co
NEW_RELIC_ENABLED=true
NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED=true
LOGGING_LEVEL=info
MONGO_MIN_POOL_SIZE=200
1 change: 1 addition & 0 deletions apps/worker/src/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ REDIS_CLUSTER_KEY_PREFIX=

# MongoDB
# MONGO_URL=
MONGO_MIN_POOL_SIZE=200

# Storage
# S3_LOCAL_STACK=http://localhost:4566
Expand Down
3 changes: 3 additions & 0 deletions apps/worker/src/config/env-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const validators: { [K in keyof any]: ValidatorSpec<any[K]> } = {
}),
REDIS_DB_INDEX: num(),
MONGO_URL: str(),
MONGO_MIN_POOL_SIZE: num({
default: 10,
}),
MONGO_MAX_POOL_SIZE: num({
default: 500,
}),
Expand Down
1 change: 1 addition & 0 deletions apps/worker/src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare global {
REDIS_CACHE_KEY_PREFIX?: string;
REDIS_CACHE_SERVICE_TLS?: ConnectionOptions;
MONGO_URL: string;
MONGO_MIN_POOL_SIZE: number;
MONGO_MAX_POOL_SIZE: number;
NEW_RELIC_APP_NAME: string;
NEW_RELIC_LICENSE_KEY: string;
Expand Down
1 change: 1 addition & 0 deletions apps/ws/src/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ WS_CONTEXT_PATH=
NEW_RELIC_ENABLED=true
NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED=true
LOGGING_LEVEL=info
MONGO_MIN_POOL_SIZE=200
1 change: 1 addition & 0 deletions docker/kubernetes/helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ The command removes all the Kubernetes components associated with the chart and
| `api.env.API_ROOT_URL` | Define the required env for novu | `http://novu-api:3000` |
| `api.env.DISABLE_USER_REGISTRATION` | If users should not be able to create new accounts. Possible values are: true, false | `true` |
| `api.env.FRONT_BASE_URL` | The base url on which your frontend is accessible for the user. (e.g. web.novu.co) | `http://novu-web:4200` |
| `api.env.MONGO_MIN_POOL_SIZE` | The min pool size of the MongoDB connection | `10` |
| `api.env.MONGO_MAX_POOL_SIZE` | The max pool size of the MongoDB connection | `50` |
| `api.ingress.enabled` | Enable ingress record generation for novu api | `false` |
| `api.ingress.pathType` | Ingress path type | `ImplementationSpecific` |
Expand Down
2 changes: 2 additions & 0 deletions docker/kubernetes/helm/templates/api/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ spec:
value : {{print .Values.api.port | quote }}
- name: FRONT_BASE_URL
value : {{print .Values.api.env.FRONT_BASE_URL | quote }}
- name: MONGO_MIN_POOL_SIZE
value : {{print .Values.api.env.MONGO_MIN_POOL_SIZE | quote }}
- name: MONGO_MAX_POOL_SIZE
value : {{print .Values.api.env.MONGO_MAX_POOL_SIZE | quote }}
- name: REDIS_HOST
Expand Down
2 changes: 2 additions & 0 deletions docker/kubernetes/helm/templates/worker/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ spec:
value : {{print .Values.api.env.NODE_ENV | quote }}
- name: PORT
value : {{ print .Values.worker.port | quote }}
- name: MONGO_MIN_POOL_SIZE
value : {{print .Values.api.env.MONGO_MIN_POOL_SIZE | quote }}
- name: MONGO_MAX_POOL_SIZE
value : {{print .Values.api.env.MONGO_MAX_POOL_SIZE | quote }}
- name: REDIS_HOST
Expand Down
2 changes: 2 additions & 0 deletions docker/kubernetes/helm/templates/ws/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ spec:
value : {{print .Values.api.env.NODE_ENV | quote }}
- name: PORT
value : {{print .Values.ws.port | quote }}
- name: MONGO_MIN_POOL_SIZE
value : {{print .Values.api.env.MONGO_MIN_POOL_SIZE | quote }}
- name: MONGO_MAX_POOL_SIZE
value : {{print .Values.api.env.MONGO_MAX_POOL_SIZE | quote }}
- name: REDIS_HOST
Expand Down
3 changes: 3 additions & 0 deletions docker/kubernetes/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ api:
## @param api.env.FRONT_BASE_URL The base url on which your frontend is accessible for the user. (e.g. web.novu.co)
##
FRONT_BASE_URL: http://novu-web:4200
## @param api.env.MONGO_MIN_POOL_SIZE The min pool size of the MongoDB connection
##
MONGO_MIN_POOL_SIZE: 10
## @param api.env.MONGO_MAX_POOL_SIZE The max pool size of the MongoDB connection
##
MONGO_MAX_POOL_SIZE: 50
Expand Down
1 change: 1 addition & 0 deletions docker/kubernetes/kustomize/env-dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ STORE_ENCRYPTION_KEY=ekwUKf9yLjGPLOz939Y1GM0nJckVoVyF
## General
NODE_ENV=dev
MONGO_URL=mongodb://novu-mongodb-dev:27017/novu-db
MONGO_MIN_POOL_SIZE=200
MONGO_MAX_POOL_SIZE=500
REDIS_HOST=novu-redis-dev
REDIS_CACHE_SERVICE_HOST=novu-redis-dev
Expand Down
1 change: 1 addition & 0 deletions docker/local/deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ services:
PORT: ${API_PORT}
FRONT_BASE_URL: ${FRONT_BASE_URL}
MONGO_URL: ${MONGO_URL}
MONGO_MIN_POOL_SIZE: ${MONGO_MIN_POOL_SIZE}
MONGO_MAX_POOL_SIZE: ${MONGO_MAX_POOL_SIZE}
REDIS_HOST: ${REDIS_HOST}
REDIS_PORT: ${REDIS_PORT}
Expand Down
2 changes: 1 addition & 1 deletion libs/dal/src/dal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class DalService {
async connect(url: string, config: ConnectOptions = {}) {
const baseConfig: ConnectOptions = {
maxPoolSize: process.env.MONGO_MAX_POOL_SIZE || 500,
minPoolSize: process.env.NODE_ENV === 'production' ? 50 : 10,
minPoolSize: process.env.MONGO_MIN_POOL_SIZE || 10,
autoIndex: process.env.AUTO_CREATE_INDEXES === 'true',
maxIdleTimeMS: 1000 * 60 * 10,
};
Expand Down
1 change: 1 addition & 0 deletions libs/dal/src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare namespace NodeJS {
REDIS_URL: string;
REDIS_ARENA_PORT: string;
NODE_ENV: 'test' | 'production' | 'dev';
MONGO_MIN_POOL_SIZE: number;
MONGO_MAX_POOL_SIZE: number;
}
}

1 comment on commit 291efe6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.