screwdriver-api 4.1.293 → 4.1.294

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.
@@ -262,6 +262,8 @@ executor:
262
262
  queue:
263
263
  enabled: EXECUTOR_QUEUE_ENABLED
264
264
  options:
265
+ # redis or redisCluster(beta)
266
+ connectionType: QUEUE_REDIS_TYPE
265
267
  # Configuration of the redis instance containing resque
266
268
  redisConnection:
267
269
  host: QUEUE_REDIS_HOST
@@ -270,6 +272,14 @@ executor:
270
272
  password: QUEUE_REDIS_PASSWORD
271
273
  tls: QUEUE_REDIS_TLS_ENABLED
272
274
  database: QUEUE_REDIS_DATABASE
275
+ redisClusterConnection:
276
+ hosts:
277
+ __name: QUEUE_REDIS_CLUSTER_HOSTS
278
+ __format: json
279
+ options:
280
+ password: QUEUE_REDIS_PASSWORD
281
+ tls: QUEUE_REDIS_TLS_ENABLED
282
+ slotsRefreshTimeout: QUEUE_REDIS_CLUSTER_SLOTS_REFRESH_TIMEOUT
273
283
 
274
284
 
275
285
  queueWebhook:
@@ -427,6 +437,8 @@ redisLock:
427
437
  retryJitter: REDLOCK_RETRY_JITTER
428
438
  # the maximum time in milliseconds living of a key that has a timeout
429
439
  ttl: REDLOCK_TTL
440
+ # redis or redisCluster(beta)
441
+ connectionType: REDLOCK_REDIS_TYPE
430
442
  # Configuration of the redis instance
431
443
  redisConnection:
432
444
  host: REDLOCK_REDIS_HOST
@@ -435,6 +447,14 @@ redisLock:
435
447
  password: REDLOCK_REDIS_PASSWORD
436
448
  tls: REDLOCK_REDIS_TLS_ENABLED
437
449
  database: REDLOCK_REDIS_DATABASE
450
+ redisClusterConnection:
451
+ hosts:
452
+ __name: REDLOCK_REDIS_CLUSTER_HOSTS
453
+ __format: json
454
+ options:
455
+ password: REDLOCK_REDIS_PASSWORD
456
+ tls: REDLOCK_REDIS_TLS_ENABLED
457
+ slotsRefreshTimeout: REDLOCK_REDIS_CLUSTER_SLOTS_REFRESH_TIMEOUT
438
458
 
439
459
  # environment release information
440
460
  release:
@@ -181,6 +181,8 @@ executor:
181
181
  queue:
182
182
  enabled: true
183
183
  options:
184
+ # redis or redisCluster(beta)
185
+ connectionType: redis
184
186
  # Configuration of the redis instance containing resque
185
187
  redisConnection:
186
188
  host: "127.0.0.1"
@@ -189,6 +191,12 @@ executor:
189
191
  password: "THIS-IS-A-PASSWORD"
190
192
  tls: false
191
193
  database: 0
194
+ redisClusterConnection:
195
+ hosts: []
196
+ options:
197
+ password: a-secure-password
198
+ tls: false
199
+ slotsRefreshTimeout: 1000
192
200
 
193
201
  queueWebhook:
194
202
  # Enabled events from webhook queue or not
@@ -358,6 +366,8 @@ redisLock:
358
366
  retryJitter: 200
359
367
  # the maximum time in milliseconds living of a key that has a timeout
360
368
  ttl: 20000
369
+ # redis or redisCluster(beta)
370
+ connectionType: redis
361
371
  # Configuration of the redis instance
362
372
  redisConnection:
363
373
  host: "127.0.0.1"
@@ -366,3 +376,9 @@ redisLock:
366
376
  password: "THIS-IS-A-PASSWORD"
367
377
  tls: false
368
378
  database: 0
379
+ redisClusterConnection:
380
+ hosts: []
381
+ options:
382
+ password: "THIS-IS-A-PASSWORD"
383
+ tls: false
384
+ slotsRefreshTimeout: 1000
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "4.1.293",
3
+ "version": "4.1.294",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -88,7 +88,7 @@
88
88
  "hapi-auth-jwt2": "^10.2.0",
89
89
  "hapi-rate-limit": "^5.0.1",
90
90
  "hapi-swagger": "^14.5.5",
91
- "ioredis": "^4.28.0",
91
+ "ioredis": "^5.2.3",
92
92
  "joi": "^17.4.2",
93
93
  "js-yaml": "^3.14.1",
94
94
  "jsonwebtoken": "^8.5.1",
package/plugins/lock.js CHANGED
@@ -25,32 +25,44 @@ class Lock {
25
25
  * Constructor
26
26
  */
27
27
  constructor() {
28
- if (parseBool(config.get('redisLock.enabled'))) {
29
- const redisLockConfig = config.get('redisLock.options');
30
- const connectionDetails = {
31
- host: redisLockConfig.redisConnection.host,
32
- options: {
33
- password:
34
- redisLockConfig.redisConnection.options && redisLockConfig.redisConnection.options.password,
35
- tls: redisLockConfig.redisConnection.options
36
- ? parseBool(redisLockConfig.redisConnection.options.tls)
37
- : false
38
- },
39
- port: redisLockConfig.redisConnection.port
40
- };
28
+ if (!parseBool(config.get('redisLock.enabled'))) {
29
+ return;
30
+ }
41
31
 
42
- try {
43
- this.redis = new Redis(connectionDetails.port, connectionDetails.host, connectionDetails.options);
44
- this.redlock = new Redlock([this.redis], {
45
- driftFactor: parseFloat(redisLockConfig.driftFactor),
46
- retryCount: parseInt(redisLockConfig.retryCount, 10),
47
- retryDelay: parseFloat(redisLockConfig.retryDelay),
48
- retryJitter: parseFloat(redisLockConfig.retryJitter)
32
+ const redisLockConfig = config.get('redisLock.options');
33
+ const connectionType = redisLockConfig.connectionType;
34
+
35
+ if (!connectionType || (connectionType !== 'redis' && connectionType !== 'redisCluster')) {
36
+ throw new Error(
37
+ `'connectionType ${connectionType}' is not supported, use 'redis' or 'redisCluster' for the queue.connectionType setting`
38
+ );
39
+ }
40
+
41
+ const redisConfig = redisLockConfig[`${connectionType}Connection`];
42
+ const redisOptions = {
43
+ password: redisConfig.options && redisConfig.options.password,
44
+ tls: redisConfig.options ? parseBool(redisConfig.options.tls) : false
45
+ };
46
+
47
+ try {
48
+ if (connectionType === 'redisCluster') {
49
+ this.redis = new Redis.Cluster(redisConfig.hosts, {
50
+ redisOptions,
51
+ slotsRefreshTimeout: parseInt(redisConfig.slotsRefreshTimeout, 10),
52
+ clusterRetryStrategy: () => 100
49
53
  });
50
- this.ttl = parseFloat(redisLockConfig.ttl);
51
- } catch (err) {
52
- logger.error('Failed to initialize redlock', err);
54
+ } else {
55
+ this.redis = new Redis(redisConfig.port, redisConfig.host, redisOptions);
53
56
  }
57
+ this.redlock = new Redlock([this.redis], {
58
+ driftFactor: parseFloat(redisLockConfig.driftFactor),
59
+ retryCount: parseInt(redisLockConfig.retryCount, 10),
60
+ retryDelay: parseFloat(redisLockConfig.retryDelay),
61
+ retryJitter: parseFloat(redisLockConfig.retryJitter)
62
+ });
63
+ this.ttl = parseFloat(redisLockConfig.ttl);
64
+ } catch (err) {
65
+ logger.error('Failed to initialize redlock', err);
54
66
  }
55
67
  }
56
68