elasticio-sailor-nodejs 3.0.0-sailor-proxy-dev9 → 3.0.0-sailor-proxy-dev11
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/{.eslintrc → .eslintrc.json} +1 -0
- package/lib/encryptor.js +1 -0
- package/lib/proxy-client.js +77 -73
- package/lib/sailor.js +47 -47
- package/package.json +1 -1
- package/postpublish.js +3 -0
package/lib/encryptor.js
CHANGED
package/lib/proxy-client.js
CHANGED
|
@@ -16,10 +16,10 @@ const {
|
|
|
16
16
|
NGHTTP2_NO_ERROR
|
|
17
17
|
} = http2.constants;
|
|
18
18
|
|
|
19
|
+
const MESSAGE_METADATA_QUERY_PARAM = 'message-metadata';
|
|
19
20
|
const HEADER_ROUTING_KEY = 'x-eio-routing-key';
|
|
20
21
|
const AMQP_HEADER_META_PREFIX = 'x-eio-meta-';
|
|
21
22
|
const OBJECT_ID_HEADER = 'x-ipaas-object-storage-id';
|
|
22
|
-
const PROXY_FORWARD_HEADER_PREFIX = 'x-sailor-proxy-forward-';
|
|
23
23
|
const MESSAGE_PROCESSING_STATUS = {
|
|
24
24
|
SUCCESS: 'success',
|
|
25
25
|
ERROR: 'error'
|
|
@@ -315,9 +315,7 @@ class ProxyClient {
|
|
|
315
315
|
return body;
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
logger.info('Object id header found, message is lightweight.', { objectId });
|
|
319
|
-
|
|
320
|
-
logger.info('Going to fetch message body.', { objectId });
|
|
318
|
+
logger.info('Object id header found, message is lightweight. Going to fetch message body.', { objectId });
|
|
321
319
|
|
|
322
320
|
await this._proxyRequestWithRetries('Fetch message body', () => new Promise((resolve, reject) => {
|
|
323
321
|
const getObjectStream = this.clientSession.request({
|
|
@@ -456,10 +454,10 @@ class ProxyClient {
|
|
|
456
454
|
});
|
|
457
455
|
});
|
|
458
456
|
|
|
459
|
-
const
|
|
460
|
-
const message = this._decodeMessage(body,
|
|
461
|
-
log.debug({
|
|
462
|
-
await messageHandler(
|
|
457
|
+
const messageMetadata = this._extractMessageMetadata(headers);
|
|
458
|
+
const message = this._decodeMessage(body, messageMetadata);
|
|
459
|
+
log.debug({ messageMetadata, message }, 'Processing received message');
|
|
460
|
+
await messageHandler(messageMetadata, message);
|
|
463
461
|
}));
|
|
464
462
|
} catch (err) {
|
|
465
463
|
if (this.closed) {
|
|
@@ -497,7 +495,7 @@ class ProxyClient {
|
|
|
497
495
|
this.listeningForMessages = false;
|
|
498
496
|
}
|
|
499
497
|
|
|
500
|
-
_prepareData(data,
|
|
498
|
+
_prepareData(data, metadata, type) {
|
|
501
499
|
let protocolVersion;
|
|
502
500
|
if (type === 'data') {
|
|
503
501
|
protocolVersion = this.settings.PROTOCOL_VERSION;
|
|
@@ -508,10 +506,16 @@ class ProxyClient {
|
|
|
508
506
|
if (protocolVersion) {
|
|
509
507
|
preparedData = this.encryptMessageContent(data, protocolVersion);
|
|
510
508
|
}
|
|
511
|
-
const
|
|
509
|
+
const preparedMetadata = {
|
|
510
|
+
...metadata,
|
|
511
|
+
messageId: metadata.messageId || uuid.v4()
|
|
512
|
+
};
|
|
512
513
|
return {
|
|
513
514
|
preparedData,
|
|
514
|
-
|
|
515
|
+
preparedMetadata: _.omitBy(
|
|
516
|
+
preparedMetadata,
|
|
517
|
+
(value, key) => key.toLowerCase().startsWith(AMQP_HEADER_META_PREFIX)
|
|
518
|
+
)
|
|
515
519
|
};
|
|
516
520
|
}
|
|
517
521
|
|
|
@@ -519,19 +523,22 @@ class ProxyClient {
|
|
|
519
523
|
incomingMessageId,
|
|
520
524
|
type,
|
|
521
525
|
data,
|
|
522
|
-
|
|
526
|
+
metadata
|
|
523
527
|
}) {
|
|
524
528
|
await this._ensureConnection();
|
|
525
529
|
|
|
526
530
|
const throttledSend = this.throttles[type];
|
|
527
531
|
if (throttledSend) {
|
|
528
|
-
log.debug({ incomingMessageId, type,
|
|
532
|
+
log.debug({ incomingMessageId, type, metadata }, 'Applying rate limiting for message send');
|
|
529
533
|
await throttledSend();
|
|
530
534
|
}
|
|
531
535
|
|
|
532
|
-
|
|
536
|
+
const messageHeaders = _.mapKeys(data.headers || {}, (value, key) => key.toLowerCase());
|
|
537
|
+
const customRoutingKey = messageHeaders[HEADER_ROUTING_KEY];
|
|
538
|
+
|
|
539
|
+
log.debug({ incomingMessageId, type, metadata, customRoutingKey }, 'Sending message to proxy');
|
|
533
540
|
log.trace({ data }, 'Message data to send to proxy');
|
|
534
|
-
const {
|
|
541
|
+
const { preparedMetadata, preparedData } = this._prepareData(data, metadata, type);
|
|
535
542
|
if (preparedData.length > this.settings.OUTGOING_MESSAGE_SIZE_LIMIT) {
|
|
536
543
|
const error = new Error(`Outgoing message size ${preparedData.length}` +
|
|
537
544
|
` exceeds limit of ${this.settings.OUTGOING_MESSAGE_SIZE_LIMIT}.`);
|
|
@@ -539,21 +546,18 @@ class ProxyClient {
|
|
|
539
546
|
throw error;
|
|
540
547
|
}
|
|
541
548
|
|
|
542
|
-
const messageHeaders = _.mapKeys(data.headers || {}, (value, key) => key.toLowerCase());
|
|
543
|
-
const customRoutingKey = messageHeaders[HEADER_ROUTING_KEY];
|
|
544
549
|
const queryParams = new URLSearchParams({
|
|
545
550
|
incomingMessageId,
|
|
546
551
|
stepId: this.settings.STEP_ID,
|
|
547
552
|
type,
|
|
548
553
|
...(customRoutingKey ? { customRoutingKey } : {})
|
|
549
554
|
}).toString();
|
|
550
|
-
|
|
551
555
|
await this._proxyRequestWithRetries('Send message', () => new Promise((resolve, reject) => {
|
|
552
556
|
const postMessageStream = this.clientSession.request({
|
|
553
|
-
...proxyHeaders,
|
|
554
557
|
[HTTP2_HEADER_PATH]: `/message?${queryParams}`,
|
|
555
558
|
[HTTP2_HEADER_METHOD]: 'POST',
|
|
556
|
-
[HTTP2_HEADER_AUTHORIZATION]: this.authHeader
|
|
559
|
+
[HTTP2_HEADER_AUTHORIZATION]: this.authHeader,
|
|
560
|
+
[MESSAGE_METADATA_QUERY_PARAM]: JSON.stringify(preparedMetadata)
|
|
557
561
|
});
|
|
558
562
|
postMessageStream.write(preparedData);
|
|
559
563
|
postMessageStream.end();
|
|
@@ -579,33 +583,35 @@ class ProxyClient {
|
|
|
579
583
|
}));
|
|
580
584
|
}
|
|
581
585
|
|
|
582
|
-
_decodeMessage(originalMessage,
|
|
586
|
+
_decodeMessage(originalMessage, metadata) {
|
|
583
587
|
log.trace('Message received');
|
|
584
588
|
let message;
|
|
585
589
|
if (this.settings.INPUT_FORMAT === 'error') {
|
|
586
|
-
message = this._decodeErrorMessage(originalMessage
|
|
590
|
+
message = this._decodeErrorMessage(originalMessage);
|
|
587
591
|
} else {
|
|
588
|
-
message = this._decodeDefaultMessage(originalMessage,
|
|
592
|
+
message = this._decodeDefaultMessage(originalMessage, metadata);
|
|
589
593
|
}
|
|
590
594
|
message.headers = message.headers || {};
|
|
591
|
-
if (
|
|
592
|
-
message.headers.reply_to =
|
|
595
|
+
if (metadata.reply_to) {
|
|
596
|
+
message.headers.reply_to = metadata.reply_to;
|
|
593
597
|
}
|
|
594
598
|
return message;
|
|
595
599
|
}
|
|
596
600
|
|
|
597
|
-
_decodeDefaultMessage(originalMessage,
|
|
598
|
-
|
|
601
|
+
_decodeDefaultMessage(originalMessage, metadata) {
|
|
602
|
+
log.debug({ metadata }, 'Decoding default message format');
|
|
603
|
+
const protocolVersion = Number(metadata.protocolVersion || 1);
|
|
604
|
+
log.debug({ protocolVersion }, 'Decoding message with protocol version');
|
|
599
605
|
return this._encryptor.decryptMessageContent(
|
|
600
606
|
originalMessage,
|
|
601
607
|
protocolVersion < 2 ? 'base64' : undefined
|
|
602
608
|
);
|
|
603
609
|
}
|
|
604
610
|
|
|
605
|
-
_decodeErrorMessage(originalMessage
|
|
611
|
+
_decodeErrorMessage(originalMessage) {
|
|
606
612
|
const errorBody = JSON.parse(originalMessage.toString());
|
|
607
613
|
// NOTICE both error and errorInput are transferred as base64 encoded.
|
|
608
|
-
// this does not depend on protocolVersion
|
|
614
|
+
// this does not depend on protocolVersion of message (see _decodeDefaultMessage)
|
|
609
615
|
// this should be fixed in future, but it's OK at this moment
|
|
610
616
|
if (errorBody.error) {
|
|
611
617
|
errorBody.error = this._encryptor.decryptMessageContent(Buffer.from(errorBody.error), 'base64');
|
|
@@ -613,19 +619,16 @@ class ProxyClient {
|
|
|
613
619
|
if (errorBody.errorInput) {
|
|
614
620
|
errorBody.errorInput = this._encryptor.decryptMessageContent(errorBody.errorInput, 'base64');
|
|
615
621
|
}
|
|
616
|
-
return
|
|
617
|
-
body: errorBody,
|
|
618
|
-
headers
|
|
619
|
-
};
|
|
622
|
+
return errorBody;
|
|
620
623
|
}
|
|
621
624
|
|
|
622
|
-
async finishProcessing(
|
|
625
|
+
async finishProcessing(metadata, status) {
|
|
623
626
|
await this._ensureConnection();
|
|
624
627
|
|
|
625
628
|
if (Object.values(MESSAGE_PROCESSING_STATUS).indexOf(status) === -1) {
|
|
626
629
|
throw new Error(`Invalid message processing status: ${status}`);
|
|
627
630
|
}
|
|
628
|
-
const incomingMessageId =
|
|
631
|
+
const incomingMessageId = metadata.messageId;
|
|
629
632
|
log.debug({ incomingMessageId, status }, 'Finishing processing of message');
|
|
630
633
|
const queryParams = new URLSearchParams({
|
|
631
634
|
incomingMessageId,
|
|
@@ -661,6 +664,7 @@ class ProxyClient {
|
|
|
661
664
|
}
|
|
662
665
|
|
|
663
666
|
encryptMessageContent(body, protocolVersion = 1) {
|
|
667
|
+
log.debug({ protocolVersion }, 'Encrypting message content with protocol version');
|
|
664
668
|
return this._encryptor.encryptMessageContent(
|
|
665
669
|
body,
|
|
666
670
|
protocolVersion < 2
|
|
@@ -669,7 +673,7 @@ class ProxyClient {
|
|
|
669
673
|
);
|
|
670
674
|
}
|
|
671
675
|
|
|
672
|
-
async sendError(err,
|
|
676
|
+
async sendError(err, outgoingMetadata, originalMessage, metadata) {
|
|
673
677
|
await this._ensureConnection();
|
|
674
678
|
|
|
675
679
|
const encryptedError = this._encryptor.encryptMessageContent({
|
|
@@ -682,94 +686,94 @@ class ProxyClient {
|
|
|
682
686
|
error: encryptedError
|
|
683
687
|
};
|
|
684
688
|
if (originalMessage) {
|
|
685
|
-
const protocolVersion = Number(
|
|
689
|
+
const protocolVersion = Number(metadata.protocolVersion || 1);
|
|
686
690
|
if (protocolVersion >= 2) {
|
|
687
691
|
payload.errorInput = this._encryptor.encryptMessageContent(
|
|
688
692
|
originalMessage,
|
|
689
693
|
'base64'
|
|
690
694
|
).toString();
|
|
691
695
|
} else {
|
|
696
|
+
// TODO: encrypt errorInput
|
|
692
697
|
payload.errorInput = originalMessage;
|
|
693
698
|
}
|
|
694
699
|
}
|
|
695
700
|
const errorPayload = JSON.stringify(payload);
|
|
696
701
|
|
|
697
702
|
const result = await this.sendMessage({
|
|
698
|
-
incomingMessageId:
|
|
703
|
+
incomingMessageId: metadata ? metadata.messageId : undefined,
|
|
699
704
|
type: 'error',
|
|
700
705
|
data: errorPayload,
|
|
701
|
-
|
|
706
|
+
metadata: outgoingMetadata
|
|
702
707
|
});
|
|
703
708
|
|
|
704
709
|
return result;
|
|
705
710
|
}
|
|
706
711
|
|
|
707
|
-
async sendRebound(reboundError,
|
|
712
|
+
async sendRebound(reboundError, metadata, outgoingMetadata) {
|
|
708
713
|
await this._ensureConnection();
|
|
709
714
|
|
|
710
|
-
|
|
711
|
-
|
|
715
|
+
outgoingMetadata.end = new Date().getTime();
|
|
716
|
+
outgoingMetadata.reboundReason = reboundError.message;
|
|
712
717
|
return this.sendMessage({
|
|
713
718
|
type: 'rebound',
|
|
714
|
-
|
|
715
|
-
incomingMessageId:
|
|
719
|
+
metadata: outgoingMetadata,
|
|
720
|
+
incomingMessageId: metadata ? metadata.messageId : undefined,
|
|
716
721
|
data: reboundError
|
|
717
722
|
});
|
|
718
723
|
}
|
|
719
724
|
|
|
720
|
-
async sendSnapshot(data,
|
|
725
|
+
async sendSnapshot(data, metadata) {
|
|
721
726
|
await this._ensureConnection();
|
|
722
727
|
|
|
723
728
|
const payload = JSON.stringify(data);
|
|
724
|
-
const properties = this._createProxyHeaders(headers);
|
|
725
729
|
return this.sendMessage({
|
|
726
730
|
type: 'snapshot',
|
|
727
731
|
data: payload,
|
|
728
|
-
|
|
732
|
+
metadata
|
|
729
733
|
});
|
|
730
734
|
}
|
|
731
735
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
736
|
+
_extractMessageMetadata(headers) {
|
|
737
|
+
log.trace({ headers }, 'Extracting message metadata');
|
|
738
|
+
const messageMetadataQuery = headers[MESSAGE_METADATA_QUERY_PARAM];
|
|
739
|
+
if (!messageMetadataQuery) {
|
|
740
|
+
log.error({ headers }, 'Missing metadata in message stream response');
|
|
741
|
+
throw new Error('Missing metadata in message stream response');
|
|
742
|
+
}
|
|
739
743
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
}, {});
|
|
744
|
+
let parsedMessageMetadata;
|
|
745
|
+
try {
|
|
746
|
+
parsedMessageMetadata = JSON.parse(messageMetadataQuery);
|
|
747
|
+
} catch (e) {
|
|
748
|
+
log.error({ messageMetadataQuery }, 'Failed to parse metadata JSON');
|
|
749
|
+
throw new Error('Failed to parse metadata JSON');
|
|
750
|
+
}
|
|
751
|
+
log.debug({ parsedMessageMetadata }, 'Parsed metadata from query parameter');
|
|
749
752
|
|
|
750
|
-
|
|
753
|
+
// Get meta headers
|
|
754
|
+
const metaHeaderNames = Object.keys(parsedMessageMetadata)
|
|
751
755
|
.filter(key => key.toLowerCase().startsWith(AMQP_HEADER_META_PREFIX));
|
|
752
756
|
|
|
753
|
-
const metaHeaders = _.pick(
|
|
757
|
+
const metaHeaders = _.pick(parsedMessageMetadata, metaHeaderNames);
|
|
754
758
|
const metaHeadersLowerCased = _.mapKeys(metaHeaders, (value, key) => key.toLowerCase());
|
|
755
759
|
|
|
756
760
|
const result = {
|
|
757
|
-
stepId:
|
|
761
|
+
stepId: parsedMessageMetadata.stepId,
|
|
758
762
|
...metaHeadersLowerCased,
|
|
759
|
-
threadId:
|
|
760
|
-
messageId:
|
|
761
|
-
parentMessageId:
|
|
762
|
-
protocolVersion:
|
|
763
|
+
threadId: parsedMessageMetadata.threadId || metaHeaders['x-eio-meta-trace-id'],
|
|
764
|
+
messageId: parsedMessageMetadata.messageId,
|
|
765
|
+
parentMessageId: parsedMessageMetadata.parentMessageId,
|
|
766
|
+
protocolVersion: parsedMessageMetadata.protocolVersion
|
|
763
767
|
};
|
|
764
768
|
if (!result.threadId) {
|
|
765
769
|
const threadId = uuid.v4();
|
|
766
770
|
log.debug({ threadId }, 'Initiate new thread as it is not started ATM');
|
|
767
771
|
result.threadId = threadId;
|
|
768
772
|
}
|
|
769
|
-
if (
|
|
770
|
-
result.
|
|
773
|
+
if (parsedMessageMetadata.reply_to) {
|
|
774
|
+
result.reply_to = parsedMessageMetadata.reply_to;
|
|
771
775
|
}
|
|
772
|
-
log.debug({ result }, 'Extracted
|
|
776
|
+
log.debug({ result }, 'Extracted message metadata');
|
|
773
777
|
return result;
|
|
774
778
|
}
|
|
775
779
|
}
|
package/lib/sailor.js
CHANGED
|
@@ -15,7 +15,7 @@ function convertSettingsToSnakeCase(settings) {
|
|
|
15
15
|
return _.mapKeys(settings, (value, key) => _.snakeCase(key));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function getAdditionalMetadataFromSettings(settings) {
|
|
19
19
|
return convertSettingsToSnakeCase(settings.additionalVars);
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -83,7 +83,7 @@ class Sailor {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
reportError(err) {
|
|
86
|
-
const
|
|
86
|
+
const metadata = Object.assign({}, getAdditionalMetadataFromSettings(this.settings), {
|
|
87
87
|
execId: this.settings.EXEC_ID,
|
|
88
88
|
taskId: this.settings.FLOW_ID,
|
|
89
89
|
workspaceId: this.settings.WORKSPACE_ID,
|
|
@@ -93,7 +93,7 @@ class Sailor {
|
|
|
93
93
|
compId: this.settings.COMP_ID,
|
|
94
94
|
function: this.settings.FUNCTION
|
|
95
95
|
});
|
|
96
|
-
return this.proxyClient.sendError(err,
|
|
96
|
+
return this.proxyClient.sendError(err, metadata);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
startup() {
|
|
@@ -166,9 +166,9 @@ class Sailor {
|
|
|
166
166
|
return this.proxyClient.listenForMessages(handler);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
async processMessageAndMaybeShutdownCallback(
|
|
169
|
+
async processMessageAndMaybeShutdownCallback(metadata, body) {
|
|
170
170
|
try {
|
|
171
|
-
await this.processMessage(
|
|
171
|
+
await this.processMessage(metadata, body);
|
|
172
172
|
} catch (e) {
|
|
173
173
|
log.error(e, 'Something very bad happened during message processing');
|
|
174
174
|
} finally {
|
|
@@ -207,8 +207,8 @@ class Sailor {
|
|
|
207
207
|
return new Promise(resolve => this.shutdownCallback = resolve);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
async runExec(module, payload,
|
|
211
|
-
log.debug({
|
|
210
|
+
async runExec(module, payload, metadata, outgoingMetadata, stepData, timeStart, logger) {
|
|
211
|
+
log.debug({ metadata }, 'runExec started');
|
|
212
212
|
const origPassthrough = _.cloneDeep(payload.passthrough) || {};
|
|
213
213
|
const settings = this.settings;
|
|
214
214
|
const cfg = _.cloneDeep(stepData.config) || {};
|
|
@@ -220,7 +220,7 @@ class Sailor {
|
|
|
220
220
|
let endWasEmitted;
|
|
221
221
|
|
|
222
222
|
const taskExec = new TaskExec({
|
|
223
|
-
loggerOptions: _.pick(
|
|
223
|
+
loggerOptions: _.pick(metadata, ['threadId', 'messageId', 'parentMessageId']),
|
|
224
224
|
variables: stepData.variables,
|
|
225
225
|
services: {
|
|
226
226
|
apiClient: this.apiClient,
|
|
@@ -241,19 +241,19 @@ class Sailor {
|
|
|
241
241
|
taskExec.process(module, payload, cfg, snapshot);
|
|
242
242
|
|
|
243
243
|
async function onData(data) {
|
|
244
|
-
const
|
|
245
|
-
|
|
244
|
+
const metadataToSend = _.clone(outgoingMetadata);
|
|
245
|
+
metadataToSend.messageId = data.id || metadataToSend.messageId;
|
|
246
246
|
logger.trace({
|
|
247
247
|
messagesCount: that.messagesCount,
|
|
248
248
|
messageProcessingTime: Date.now() - timeStart
|
|
249
249
|
}, 'processMessage emit data');
|
|
250
250
|
|
|
251
|
-
|
|
251
|
+
metadataToSend.end = new Date().getTime();
|
|
252
252
|
|
|
253
253
|
if (stepData.is_passthrough === true) {
|
|
254
254
|
data.passthrough = { ...origPassthrough };
|
|
255
255
|
if (settings.NO_SELF_PASSTRHOUGH) {
|
|
256
|
-
const { stepId } =
|
|
256
|
+
const { stepId } = metadata;
|
|
257
257
|
if (stepId) {
|
|
258
258
|
data.passthrough = Object.assign({}, origPassthrough, {
|
|
259
259
|
[stepId]: Object.assign({}, _.omit(payload, 'passthrough'))
|
|
@@ -357,9 +357,9 @@ class Sailor {
|
|
|
357
357
|
|
|
358
358
|
try {
|
|
359
359
|
await that.proxyClient.sendMessage({
|
|
360
|
-
incomingMessageId:
|
|
360
|
+
incomingMessageId: metadata.messageId,
|
|
361
361
|
data,
|
|
362
|
-
|
|
362
|
+
metadata: metadataToSend,
|
|
363
363
|
type: 'data'
|
|
364
364
|
});
|
|
365
365
|
log.trace('Outgoing message sent');
|
|
@@ -369,21 +369,21 @@ class Sailor {
|
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
async function onHttpReply(reply) {
|
|
372
|
-
const
|
|
372
|
+
const metadataToSend = _.clone(outgoingMetadata);
|
|
373
373
|
logger.trace({
|
|
374
374
|
messageProcessingTime: Date.now() - timeStart
|
|
375
375
|
}, 'processMessage emit HttpReply');
|
|
376
376
|
|
|
377
377
|
return that.proxyClient.sendMessage({
|
|
378
|
-
incomingMessageId:
|
|
378
|
+
incomingMessageId: metadata.messageId,
|
|
379
379
|
data: reply,
|
|
380
|
-
|
|
380
|
+
metadata: metadataToSend,
|
|
381
381
|
type: 'http-reply'
|
|
382
382
|
});
|
|
383
383
|
}
|
|
384
384
|
|
|
385
385
|
async function onError(err) {
|
|
386
|
-
const
|
|
386
|
+
const metadataToSend = _.clone(outgoingMetadata);
|
|
387
387
|
err = formatError(err);
|
|
388
388
|
taskExec.errorCount++;
|
|
389
389
|
logger.trace({
|
|
@@ -391,38 +391,38 @@ class Sailor {
|
|
|
391
391
|
messagesCount: that.messagesCount,
|
|
392
392
|
messageProcessingTime: Date.now() - timeStart
|
|
393
393
|
}, 'processMessage emit error');
|
|
394
|
-
|
|
395
|
-
return that.proxyClient.sendError(err,
|
|
394
|
+
metadataToSend.end = new Date().getTime();
|
|
395
|
+
return that.proxyClient.sendError(err, metadataToSend, payload, metadata);
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
async function onRebound(err) {
|
|
399
|
-
const
|
|
399
|
+
const metadataToSend = _.clone(outgoingMetadata);
|
|
400
400
|
err = formatError(err);
|
|
401
401
|
logger.trace({
|
|
402
402
|
err,
|
|
403
403
|
messagesCount: that.messagesCount,
|
|
404
404
|
messageProcessingTime: Date.now() - timeStart
|
|
405
405
|
}, 'processMessage emit rebound');
|
|
406
|
-
return that.proxyClient.sendRebound(err,
|
|
406
|
+
return that.proxyClient.sendRebound(err, metadata, metadataToSend);
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
async function onSnapshot(data) {
|
|
410
|
-
const
|
|
411
|
-
|
|
410
|
+
const metadataToSend = _.clone(outgoingMetadata);
|
|
411
|
+
metadataToSend.snapshotEvent = 'snapshot';
|
|
412
412
|
that.snapshot = data; // replacing `local` snapshot
|
|
413
|
-
return that.proxyClient.sendSnapshot(data,
|
|
413
|
+
return that.proxyClient.sendSnapshot(data, metadataToSend);
|
|
414
414
|
}
|
|
415
415
|
|
|
416
416
|
async function onUpdateSnapshot(data) {
|
|
417
|
-
const
|
|
418
|
-
|
|
417
|
+
const metadataToSend = _.clone(outgoingMetadata);
|
|
418
|
+
metadataToSend.snapshotEvent = 'updateSnapshot';
|
|
419
419
|
|
|
420
420
|
if (_.isPlainObject(data)) {
|
|
421
421
|
if (data.$set) {
|
|
422
422
|
return log.warn('ERROR: $set is not supported any more in `updateSnapshot` event');
|
|
423
423
|
}
|
|
424
424
|
_.extend(that.snapshot, data); // updating `local` snapshot
|
|
425
|
-
return that.proxyClient.sendSnapshot(data,
|
|
425
|
+
return that.proxyClient.sendSnapshot(data, metadataToSend);
|
|
426
426
|
} else {
|
|
427
427
|
log.error('You should pass an object to the `updateSnapshot` event');
|
|
428
428
|
}
|
|
@@ -435,9 +435,9 @@ class Sailor {
|
|
|
435
435
|
|
|
436
436
|
try {
|
|
437
437
|
await that.apiClient.accounts.update(cfg._account, { keys: keys });
|
|
438
|
-
logger.debug({ messageId:
|
|
438
|
+
logger.debug({ messageId: metadata.messageId }, 'Successfully updated keys');
|
|
439
439
|
} catch (error) {
|
|
440
|
-
logger.debug({ messageId:
|
|
440
|
+
logger.debug({ messageId: metadata.messageId }, 'Failed to update keys');
|
|
441
441
|
await onError(error);
|
|
442
442
|
}
|
|
443
443
|
}
|
|
@@ -455,7 +455,7 @@ class Sailor {
|
|
|
455
455
|
endWasEmitted = true;
|
|
456
456
|
|
|
457
457
|
await that.proxyClient.finishProcessing(
|
|
458
|
-
|
|
458
|
+
metadata,
|
|
459
459
|
taskExec.errorCount > 0
|
|
460
460
|
? MESSAGE_PROCESSING_STATUS.ERROR
|
|
461
461
|
: MESSAGE_PROCESSING_STATUS.SUCCESS
|
|
@@ -487,7 +487,7 @@ class Sailor {
|
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
489
|
|
|
490
|
-
async processMessage(
|
|
490
|
+
async processMessage(metadata, payload) {
|
|
491
491
|
// eslint-disable-next-line consistent-this
|
|
492
492
|
const self = this;
|
|
493
493
|
const settings = this.settings;
|
|
@@ -497,9 +497,9 @@ class Sailor {
|
|
|
497
497
|
const timeStart = Date.now();
|
|
498
498
|
|
|
499
499
|
const logger = log.child({
|
|
500
|
-
threadId:
|
|
501
|
-
messageId:
|
|
502
|
-
parentMessageId:
|
|
500
|
+
threadId: metadata.threadId || 'unknown',
|
|
501
|
+
messageId: metadata.messageId || 'unknown',
|
|
502
|
+
parentMessageId: metadata.parentMessageId || 'unknown'
|
|
503
503
|
});
|
|
504
504
|
|
|
505
505
|
logger.trace({ messagesCount: this.messagesCount }, 'processMessage received');
|
|
@@ -508,11 +508,11 @@ class Sailor {
|
|
|
508
508
|
|
|
509
509
|
log.debug('Trigger or action: %s', settings.FUNCTION);
|
|
510
510
|
const outgoingMessageId = uuid.v4();
|
|
511
|
-
const
|
|
512
|
-
...
|
|
513
|
-
...
|
|
514
|
-
parentMessageId:
|
|
515
|
-
threadId:
|
|
511
|
+
const outgoingMetadata = {
|
|
512
|
+
...metadata,
|
|
513
|
+
...getAdditionalMetadataFromSettings(settings),
|
|
514
|
+
parentMessageId: metadata.messageId,
|
|
515
|
+
threadId: metadata.threadId,
|
|
516
516
|
messageId: outgoingMessageId,
|
|
517
517
|
execId: settings.EXEC_ID,
|
|
518
518
|
taskId: settings.FLOW_ID,
|
|
@@ -529,9 +529,9 @@ class Sailor {
|
|
|
529
529
|
module = await this.componentReader.loadTriggerOrAction(settings.FUNCTION);
|
|
530
530
|
} catch (e) {
|
|
531
531
|
log.error(e);
|
|
532
|
-
|
|
533
|
-
self.proxyClient.sendError(e,
|
|
534
|
-
self.proxyClient.finishProcessing(
|
|
532
|
+
outgoingMetadata.end = new Date().getTime();
|
|
533
|
+
self.proxyClient.sendError(e, outgoingMetadata, payload, metadata);
|
|
534
|
+
self.proxyClient.finishProcessing(metadata, MESSAGE_PROCESSING_STATUS.ERROR);
|
|
535
535
|
return;
|
|
536
536
|
}
|
|
537
537
|
|
|
@@ -558,14 +558,14 @@ class Sailor {
|
|
|
558
558
|
]);
|
|
559
559
|
} catch (e) {
|
|
560
560
|
logger.error(e);
|
|
561
|
-
|
|
562
|
-
self.proxyClient.sendError(e,
|
|
563
|
-
self.proxyClient.finishProcessing(
|
|
561
|
+
outgoingMetadata.end = new Date().getTime();
|
|
562
|
+
self.proxyClient.sendError(e, outgoingMetadata, payload, metadata);
|
|
563
|
+
self.proxyClient.finishProcessing(metadata, MESSAGE_PROCESSING_STATUS.ERROR);
|
|
564
564
|
return;
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
567
|
|
|
568
|
-
await this.runExec(module, payload,
|
|
568
|
+
await this.runExec(module, payload, metadata, outgoingMetadata, stepData, timeStart, logger);
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
571
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elasticio-sailor-nodejs",
|
|
3
3
|
"description": "The official elastic.io library for bootstrapping and executing for Node.js connectors",
|
|
4
|
-
"version": "3.0.0-sailor-proxy-
|
|
4
|
+
"version": "3.0.0-sailor-proxy-dev11",
|
|
5
5
|
"main": "run.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
package/postpublish.js
CHANGED
|
@@ -7,6 +7,9 @@ var version = require('./package.json').version;
|
|
|
7
7
|
if (!version) {
|
|
8
8
|
console.error('Can not determine current version');
|
|
9
9
|
process.exit(0);
|
|
10
|
+
} else if (version.indexOf('dev') > -1) {
|
|
11
|
+
console.info('Current version is a development version, skipping tag creation');
|
|
12
|
+
process.exit(0);
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
var tag = 'v' + version;
|