screwdriver-queue-service 2.0.19 → 2.0.23
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/config/default.yaml
CHANGED
package/config/kafka.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const config = require('config');
|
|
4
|
+
const kafkaConfig = config.get('kafka');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* get config
|
|
8
|
+
* @returns Object containing kafka config values
|
|
9
|
+
*/
|
|
10
|
+
function get() {
|
|
11
|
+
return {
|
|
12
|
+
kafkaEnabled: kafkaConfig.enabled === 'true',
|
|
13
|
+
useShortRegionName: kafkaConfig.shortRegion === 'true'
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
get
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screwdriver-queue-service",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.23",
|
|
4
4
|
"description": "Screwdriver Queue Service API",
|
|
5
5
|
"main": "app.js",
|
|
6
6
|
"directories": {
|
|
@@ -11,28 +11,28 @@
|
|
|
11
11
|
"@hapi/good": "^9.0.1",
|
|
12
12
|
"@hapi/good-console": "^9.0.1",
|
|
13
13
|
"@hapi/good-squeeze": "^6.0.0",
|
|
14
|
-
"@hapi/hapi": "^20.1
|
|
14
|
+
"@hapi/hapi": "^20.2.1",
|
|
15
15
|
"@hapi/hoek": "^9.1.1",
|
|
16
|
-
"amqp-connection-manager": "^3.
|
|
16
|
+
"amqp-connection-manager": "^3.8.1",
|
|
17
17
|
"amqplib": "^0.8.0",
|
|
18
18
|
"blipp": "^4.0.2",
|
|
19
19
|
"circuit-fuses": "^4.0.5",
|
|
20
20
|
"config": "^1.31.0",
|
|
21
|
-
"cron-parser": "^2.
|
|
21
|
+
"cron-parser": "^4.2.1",
|
|
22
22
|
"hapi-auth-jwt2": "^10.2.0",
|
|
23
23
|
"ioredis": "^3.2.2",
|
|
24
|
-
"joi": "^17.
|
|
24
|
+
"joi": "^17.5.0",
|
|
25
25
|
"js-yaml": "^3.14.1",
|
|
26
26
|
"jsonwebtoken": "^8.5.1",
|
|
27
27
|
"laabr": "^6.1.3",
|
|
28
28
|
"node-resque": "^5.5.3",
|
|
29
29
|
"npm-auto-version": "^1.0.0",
|
|
30
30
|
"redlock": "^4.2.0",
|
|
31
|
-
"screwdriver-aws-producer-service": "^1.
|
|
32
|
-
"screwdriver-data-schema": "^21.
|
|
31
|
+
"screwdriver-aws-producer-service": "^1.3.0",
|
|
32
|
+
"screwdriver-data-schema": "^21.17.0",
|
|
33
33
|
"screwdriver-executor-docker": "^5.0.2",
|
|
34
34
|
"screwdriver-executor-jenkins": "^5.0.1",
|
|
35
|
-
"screwdriver-executor-k8s": "^14.
|
|
35
|
+
"screwdriver-executor-k8s": "^14.16.0",
|
|
36
36
|
"screwdriver-executor-k8s-vm": "^4.3.2",
|
|
37
37
|
"screwdriver-executor-router": "^2.1.2",
|
|
38
38
|
"screwdriver-logger": "^1.0.2",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"mockery": "^2.1.0",
|
|
54
54
|
"nyc": "^15.1.0",
|
|
55
55
|
"sinon": "^9.2.4",
|
|
56
|
-
"snyk": "^1.
|
|
56
|
+
"snyk": "^1.814.0",
|
|
57
57
|
"util": "^0.12.2"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
@@ -74,12 +74,11 @@ const timeOutOfWindow = (cronExp, timeToCheck) => {
|
|
|
74
74
|
const utcDayOfWeek = timeToCheck.getUTCDay();
|
|
75
75
|
const utcMonth = timeToCheck.getUTCMonth() + 1;
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const monthField = cronObj._fields.month;
|
|
77
|
+
const minuteField = cronObj.fields.minute;
|
|
78
|
+
const hourField = cronObj.fields.hour;
|
|
79
|
+
const dayOfMonthField = cronObj.fields.dayOfMonth;
|
|
80
|
+
const dayOfWeekField = cronObj.fields.dayOfWeek;
|
|
81
|
+
const monthField = cronObj.fields.month;
|
|
83
82
|
|
|
84
83
|
const includesMinute = minuteField.includes(utcMinutes);
|
|
85
84
|
const includesHour = hourField.includes(utcHours);
|
|
@@ -15,11 +15,12 @@ const blockedByConfig = config.get('plugins').blockedBy;
|
|
|
15
15
|
const { connectionDetails, queuePrefix, runningJobsPrefix, waitingJobsPrefix } = require('../../../config/redis');
|
|
16
16
|
const rabbitmqConf = require('../../../config/rabbitmq');
|
|
17
17
|
const { amqpURI, exchange, connectOptions } = rabbitmqConf.getConfig();
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const kafkaConfig = require('../../../config/kafka');
|
|
19
|
+
const { kafkaEnabled, useShortRegionName } = kafkaConfig.get();
|
|
20
20
|
const RETRY_LIMIT = 3;
|
|
21
21
|
// This is in milliseconds, reference: https://github.com/actionhero/node-resque/blob/2ffdf0/lib/plugins/Retry.js#L12
|
|
22
22
|
const RETRY_DELAY = 5 * 1000;
|
|
23
|
+
const DEFAULT_BUILD_TIMEOUT = 90;
|
|
23
24
|
const redis = new Redis(connectionDetails.port, connectionDetails.host, connectionDetails.options);
|
|
24
25
|
|
|
25
26
|
const ecosystem = config.get('ecosystem');
|
|
@@ -57,6 +58,17 @@ const blockedByOptions = {
|
|
|
57
58
|
|
|
58
59
|
collapse: blockedByConfig.collapse
|
|
59
60
|
};
|
|
61
|
+
// AWS region map
|
|
62
|
+
const AWS_REGION_MAP = {
|
|
63
|
+
north: 'n',
|
|
64
|
+
west: 'w',
|
|
65
|
+
northeast: 'nw',
|
|
66
|
+
east: 'e',
|
|
67
|
+
south: 's',
|
|
68
|
+
central: 'c',
|
|
69
|
+
southeast: 'se'
|
|
70
|
+
};
|
|
71
|
+
|
|
60
72
|
let rabbitmqConn;
|
|
61
73
|
|
|
62
74
|
/**
|
|
@@ -125,15 +137,62 @@ async function pushToRabbitMq(message, queue, messageId) {
|
|
|
125
137
|
* Push message to Kafka topic
|
|
126
138
|
* @param {Object} message Job and build config metadata
|
|
127
139
|
* @param {String} topic Topic name
|
|
140
|
+
* @param {String} messageId The message id
|
|
128
141
|
*/
|
|
129
|
-
async function pushToKafka(message, topic) {
|
|
130
|
-
const
|
|
142
|
+
async function pushToKafka(message, topic, messageId) {
|
|
143
|
+
const producer = await AWSProducer.connect();
|
|
131
144
|
|
|
132
|
-
if (
|
|
133
|
-
await AWSProducer.sendMessage(message, topic);
|
|
145
|
+
if (producer) {
|
|
146
|
+
await AWSProducer.sendMessage(producer, message, topic, messageId);
|
|
134
147
|
}
|
|
135
148
|
}
|
|
136
149
|
|
|
150
|
+
/**
|
|
151
|
+
*
|
|
152
|
+
* @param {*String} accountId The AWS accountId
|
|
153
|
+
* @param {*String} region The region name
|
|
154
|
+
* @returns String topicName
|
|
155
|
+
*/
|
|
156
|
+
function getTopicName(accountId, region) {
|
|
157
|
+
const items = region.split('-');
|
|
158
|
+
|
|
159
|
+
if (items.length < 3 || !useShortRegionName) {
|
|
160
|
+
return `builds-${accountId}-${region}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const shortRegion = ''.concat(items[0], AWS_REGION_MAP[items[1]], items[2]);
|
|
164
|
+
|
|
165
|
+
return `builds-${accountId}-${shortRegion}`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* @param {String} job type of job start|stop`
|
|
171
|
+
* @param {*} buildConfig
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
function getKafkaMessageRequest(job, buildConfig) {
|
|
175
|
+
const { accountId, region, executor: executorType } = buildConfig.provider;
|
|
176
|
+
|
|
177
|
+
const topic = getTopicName(accountId, region);
|
|
178
|
+
const messageId = `${job}-${buildConfig.buildId}`;
|
|
179
|
+
|
|
180
|
+
const timeout = parseInt(hoek.reach(buildConfig, 'annotations>screwdriver.cd/timeout', { separator: '>' }), 10);
|
|
181
|
+
const buildTimeout = Number.isNaN(timeout) ? DEFAULT_BUILD_TIMEOUT : timeout;
|
|
182
|
+
|
|
183
|
+
const message = {
|
|
184
|
+
job,
|
|
185
|
+
executorType,
|
|
186
|
+
buildConfig: {
|
|
187
|
+
...buildConfig,
|
|
188
|
+
buildTimeout,
|
|
189
|
+
uiUri: ecosystem.ui,
|
|
190
|
+
storeUri: ecosystem.store
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
return { message, topic, messageId };
|
|
195
|
+
}
|
|
137
196
|
/**
|
|
138
197
|
* Schedule a job based on mode
|
|
139
198
|
* @method schedule
|
|
@@ -146,18 +205,17 @@ async function schedule(job, buildConfig) {
|
|
|
146
205
|
|
|
147
206
|
delete buildConfig.buildClusterName;
|
|
148
207
|
|
|
208
|
+
if (kafkaEnabled && buildConfig.provider) {
|
|
209
|
+
const { message, topic, messageId } = getKafkaMessageRequest(job, buildConfig);
|
|
210
|
+
|
|
211
|
+
return pushToKafka(message, topic, messageId);
|
|
212
|
+
}
|
|
213
|
+
|
|
149
214
|
const msg = {
|
|
150
215
|
job,
|
|
151
216
|
buildConfig
|
|
152
217
|
};
|
|
153
218
|
|
|
154
|
-
if (kafkaEnabled && buildConfig.provider) {
|
|
155
|
-
const { accountId, region } = buildConfig.provider;
|
|
156
|
-
const topic = `builds-${accountId}-${region}`;
|
|
157
|
-
|
|
158
|
-
return pushToKafka(msg, topic);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
219
|
if (rabbitmqConf.getConfig().schedulerMode) {
|
|
162
220
|
try {
|
|
163
221
|
return await pushToRabbitMq(msg, buildCluster, buildConfig.buildId);
|