@mimik/configuration 5.0.5 → 5.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -199,8 +199,12 @@ When `redis` is used the following environement variables are used for the confi
199
199
 
200
200
  | Env variable name | Description | Default | Comments |
201
201
  | ----------------- | ----------- | ------- | -------- |
202
- | CACHE_IP | domain of the redis server to use | localhost:6379 |
203
- | CACHE_PASSWORD | password if the redis service is protected (requirepass in redis.conf) | null |
202
+ | CACHE_IP | domain of the redis server to use with port, a comma seperated list if using cluster | localhost:6379 |
203
+ | CACHE_USER | redis user if the redis service is auth protected | null |
204
+ | CACHE_PASSWORD | redis password for the user if the redis service is auth protected | null |
205
+ | CACHE_CLUSTER_SET | set on, when using redis in a cluster. | off |
206
+ | CACHE_CLUSTER_USE_REPLICAS | When set on, distribute load by executing readonly commands (such as GET) across all cluster nodes. When false, only use master nodes | off |
207
+ | CACHE_CLUSTER_MINIMIZE_CONNECTION | When set on, .connect() will only discover the cluster topology, without actually connecting to all the nodes. Useful for short-term or Pub/Sub-only connections. | off |
204
208
  | CACHE_CONNECTION_TIMEOUT | time the server will wait at start to connect to the cache | 30 | in seconds
205
209
  | CACHE_VALIDATION_CHECK | the delay before checking for connection | 1000 | in ms
206
210
  | CACHE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
@@ -211,8 +215,8 @@ When `redis` is used the following environement variables are used for the confi
211
215
  | REDIS_RECONNECT_INTERVAL | time to wait before retry | 500 | in milliseconds
212
216
  | REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache | 10 | in megabytes
213
217
  | REDIS_REQUEST_MAX_MEMORY_POLICY | eviction policy of the request cache | allkeys-lru |
214
- | REDIS_SOCKET_KEEPALIVE | keep alive for long running connections | yes |
215
- | REDIS_ENABLE_OFFLINE_QUEUE | queuing event when not connected | yes |
218
+ | REDIS_SOCKET_KEEPALIVE | keep long running connections alive for x seconds | 5000 | in seconds
219
+ | REDIS_DISABLE_OFFLINE_QUEUE | queuing event when not connected | no |
216
220
 
217
221
  **Requires**: <code>module:@mimik/sumologic-winston-logger</code>
218
222
 
package/index.js CHANGED
@@ -35,7 +35,6 @@ const {
35
35
  DEFAULT_CLOUD_PROVIDER,
36
36
  DEFAULT_CUSTOMER_CODE,
37
37
  DEFAULT_CACHE_IP,
38
- DEFAULT_CACHE_PASSWORD,
39
38
  DEFAULT_CACHE_CONNECTION_TIMEOUT,
40
39
  DEFAULT_CACHE_RECONNECTION_OFFSET,
41
40
  DEFAULT_CACHE_VALIDATION_CHECK,
@@ -47,7 +46,7 @@ const {
47
46
  DEFAULT_REDIS_REQUEST_MAX_MEMORY,
48
47
  DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
49
48
  DEFAULT_REDIS_SOCKET_KEEPALIVE,
50
- DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE,
49
+ DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE,
51
50
  DEFAULT_AWS_REGION,
52
51
  DEFAULT_AWS_LOCAL_PROPERTIES,
53
52
  DEFAULT_DYNAMODB_LOCAL_URL,
@@ -104,37 +103,49 @@ const isMSTSet = process.env.MST_SET !== SET_OFF;
104
103
 
105
104
  const setupRedis = () => {
106
105
  const domain = process.env.CACHE_IP || DEFAULT_CACHE_IP;
107
- const password = process.env.CACHE_PASSWORD || DEFAULT_CACHE_PASSWORD;
106
+ const username = process.env.CACHE_USER;
107
+ const password = process.env.CACHE_PASSWORD;
108
108
  const reconnectTries = parseInt(process.env.REDIS_RECONNECT_TRIES, 10) || DEFAULT_REDIS_RECONNECT_TRIES;
109
109
  const reconnectInterval = parseInt(process.env.REDIS_RECONNECT_INTERVAL, 10) || DEFAULT_REDIS_RECONNECT_INTERVAL;
110
- let url = `${REDIS_BASE_URL}${domain}`;
110
+ let url = REDIS_BASE_URL;
111
+ if (username && password) url += `${username}:${password}@`;
112
+ url += domain;
113
+
114
+ const clusterConfig = {
115
+ set: process.env.CACHE_CLUSTER_SET || SET_OFF,
116
+ useReplicas: process.env.CACHE_CLUSTER_USE_REPLICAS || SET_OFF,
117
+ minimizeConnections: process.env.CACHE_CLUSTER_MINIMIZE_CONNECTION || SET_OFF,
118
+ };
111
119
 
112
- if (password) url = `${url}?password=${password}`;
113
120
  return {
114
121
  domain,
122
+ username,
115
123
  password,
116
124
  connectTimeout: parseInt(process.env.CACHE_CONNECTION_TIMEOUT, 10) || DEFAULT_CACHE_CONNECTION_TIMEOUT,
117
125
  validationCheck: parseInt(process.env.CACHE_VALIDATION_CHECK, 10) || DEFAULT_CACHE_VALIDATION_CHECK,
118
126
  reconnectOffset: parseInt(process.env.CACHE_RECONNECTION_OFFSET, 10) || DEFAULT_CACHE_RECONNECTION_OFFSET,
119
127
  url,
128
+ cluster: clusterConfig,
120
129
  options: {
121
- maxMemory: process.env.REDIS_REQUEST_MAX_MEMORY || DEFAULT_REDIS_REQUEST_MAX_MEMORY,
122
- maxMemoryPolicy: process.env.REDIS_REQUEST_MAX_MEMORY_POLICY || DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
123
- socket_keepalive: process.env.REDIS_SOCKET_KEEPALIVE || DEFAULT_REDIS_SOCKET_KEEPALIVE,
124
- enable_offline_queue: process.env.REDIS_ENABLE_OFFLINE_QUEUE || DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE,
125
- retry_strategy: function retryStrategy(opts) {
126
- if (opts.timesConnected > 0 && opts.attempt < reconnectTries) {
127
- return reconnectInterval;
128
- }
129
- if (opts.error && opts.error.code === 'ECONNREFUSED') {
130
- if (display) {
131
- logger.error('Fatal error: Could not connect to cache', { type: 'redis', error: opts.error.code }, `redis-cache-start@0/${new Date().toISOString()}`);
132
- logger.flushAndExit(1);
130
+ socket: {
131
+ keepAlive: process.env.REDIS_SOCKET_KEEPALIVE || DEFAULT_REDIS_SOCKET_KEEPALIVE,
132
+ reconnectStrategy: function retryStrategy(opts) {
133
+ if (opts.timesConnected > 0 && opts.attempt < reconnectTries) {
134
+ return reconnectInterval;
133
135
  }
134
- display = false;
135
- }
136
- return undefined;
136
+ if (opts.error && opts.error.code === 'ECONNREFUSED') {
137
+ if (display) {
138
+ logger.error('Fatal error: Could not connect to cache', { type: 'redis', error: opts.error.code }, `redis-cache-start@0/${new Date().toISOString()}`);
139
+ logger.flushAndExit(1);
140
+ }
141
+ display = false;
142
+ }
143
+ return undefined;
144
+ },
145
+ disableOfflineQueue: (process.env.REDIS_DISABLE_OFFLINE_QUEUE === 'yes') || DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE,
137
146
  },
147
+ maxMemory: process.env.REDIS_REQUEST_MAX_MEMORY || DEFAULT_REDIS_REQUEST_MAX_MEMORY,
148
+ maxMemoryPolicy: process.env.REDIS_REQUEST_MAX_MEMORY_POLICY || DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
138
149
  },
139
150
  retryStrategyOptions: {
140
151
  reconnectTries,
@@ -642,8 +653,12 @@ configuration.locationProvider = setupLocationProvider();
642
653
  *
643
654
  * | Env variable name | Description | Default | Comments |
644
655
  * | ----------------- | ----------- | ------- | -------- |
645
- * | CACHE_IP | domain of the redis server to use | localhost:6379 |
646
- * | CACHE_PASSWORD | password if the redis service is protected (requirepass in redis.conf) | null |
656
+ * | CACHE_IP | domain of the redis server to use with port, a comma seperated list if using cluster | localhost:6379 |
657
+ * | CACHE_USER | redis user if the redis service is auth protected | null |
658
+ * | CACHE_PASSWORD | redis password for the user if the redis service is auth protected | null |
659
+ * | CACHE_CLUSTER_SET | set on, when using redis in a cluster. | off |
660
+ * | CACHE_CLUSTER_USE_REPLICAS | When set on, distribute load by executing readonly commands (such as GET) across all cluster nodes. When false, only use master nodes | off |
661
+ * | CACHE_CLUSTER_MINIMIZE_CONNECTION | When set on, .connect() will only discover the cluster topology, without actually connecting to all the nodes. Useful for short-term or Pub/Sub-only connections. | off |
647
662
  * | CACHE_CONNECTION_TIMEOUT | time the server will wait at start to connect to the cache | 30 | in seconds
648
663
  * | CACHE_VALIDATION_CHECK | the delay before checking for connection | 1000 | in ms
649
664
  * | CACHE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
@@ -654,8 +669,8 @@ configuration.locationProvider = setupLocationProvider();
654
669
  * | REDIS_RECONNECT_INTERVAL | time to wait before retry | 500 | in milliseconds
655
670
  * | REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache | 10 | in megabytes
656
671
  * | REDIS_REQUEST_MAX_MEMORY_POLICY | eviction policy of the request cache | allkeys-lru |
657
- * | REDIS_SOCKET_KEEPALIVE | keep alive for long running connections | yes |
658
- * | REDIS_ENABLE_OFFLINE_QUEUE | queuing event when not connected | yes |
672
+ * | REDIS_SOCKET_KEEPALIVE | keep long running connections alive for x seconds | 5000 | in seconds
673
+ * | REDIS_DISABLE_OFFLINE_QUEUE | queuing event when not connected | no |
659
674
  */
660
675
  const setConfig = (pack, options) => {
661
676
  process.env.SERVER_VERSION = pack.version;
package/lib/common.js CHANGED
@@ -21,7 +21,6 @@ const DEFAULT_CLOUD_PROVIDER = 'noCloud';
21
21
  const DEFAULT_CUSTOMER_CODE = '';
22
22
 
23
23
  const DEFAULT_CACHE_IP = 'localhost:6379';
24
- const DEFAULT_CACHE_PASSWORD = null;
25
24
  const DEFAULT_CACHE_CONNECTION_TIMEOUT = 30; // in seconds
26
25
  const DEFAULT_CACHE_RECONNECTION_OFFSET = 5; // in seconds
27
26
  const DEFAULT_CACHE_VALIDATION_CHECK = 1000; // in ms
@@ -33,8 +32,8 @@ const DEFAULT_REDIS_RECONNECT_TRIES = 100;
33
32
  const DEFAULT_REDIS_RECONNECT_INTERVAL = 500; // in ms
34
33
  const DEFAULT_REDIS_REQUEST_MAX_MEMORY = '10mb';
35
34
  const DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY = 'allkeys-lru';
36
- const DEFAULT_REDIS_SOCKET_KEEPALIVE = true;
37
- const DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE = true;
35
+ const DEFAULT_REDIS_SOCKET_KEEPALIVE = 5000;
36
+ const DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE = false;
38
37
 
39
38
  const DEFAULT_AWS_REGION = '---noRegion--';
40
39
  const DEFAULT_AWS_LOCAL_PROPERTIES = '169.254.169.254'; // to access properties of the instance on AWS
@@ -118,7 +117,6 @@ module.exports = {
118
117
  DEFAULT_LOCATION_PROVIDER,
119
118
  DEFAULT_CLOUD_PROVIDER,
120
119
  DEFAULT_CACHE_IP,
121
- DEFAULT_CACHE_PASSWORD,
122
120
  DEFAULT_CACHE_CONNECTION_TIMEOUT,
123
121
  DEFAULT_CACHE_RECONNECTION_OFFSET,
124
122
  DEFAULT_CACHE_VALIDATION_CHECK,
@@ -130,7 +128,7 @@ module.exports = {
130
128
  DEFAULT_REDIS_REQUEST_MAX_MEMORY,
131
129
  DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
132
130
  DEFAULT_REDIS_SOCKET_KEEPALIVE,
133
- DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE,
131
+ DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE,
134
132
  DEFAULT_AWS_REGION,
135
133
  DEFAULT_AWS_LOCAL_PROPERTIES,
136
134
  DEFAULT_DYNAMODB_LOCAL_URL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimik/configuration",
3
- "version": "5.0.5",
3
+ "version": "5.0.7",
4
4
  "description": "Common configuration for mimik services",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -30,21 +30,21 @@
30
30
  "url": "https://bitbucket.org/mimiktech/configuration"
31
31
  },
32
32
  "dependencies": {
33
- "@mimik/request-helper": "^1.7.8",
34
- "@mimik/sumologic-winston-logger": "^1.6.15",
33
+ "@mimik/request-helper": "^1.7.9",
34
+ "@mimik/sumologic-winston-logger": "^1.6.19",
35
35
  "@mimik/user-filters": "1.3.6",
36
36
  "ip": "2.0.0",
37
37
  "lodash": "4.17.21",
38
- "uuid": "9.0.0"
38
+ "uuid": "9.0.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@mimik/eslint-plugin-dependencies": "^2.4.5",
42
42
  "@mimik/eslint-plugin-document-env": "^1.0.5",
43
- "eslint": "8.40.0",
43
+ "eslint": "8.50.0",
44
44
  "eslint-config-airbnb": "19.0.4",
45
- "eslint-plugin-import": "2.27.5",
45
+ "eslint-plugin-import": "2.28.1",
46
46
  "eslint-plugin-jsx-a11y": "6.7.1",
47
- "eslint-plugin-react": "7.32.2",
47
+ "eslint-plugin-react": "7.33.2",
48
48
  "eslint-plugin-react-hooks": "4.6.0",
49
49
  "husky": "8.0.3",
50
50
  "jsdoc-to-markdown": "8.0.0"