Skip to content

Commit b4d314c

Browse files
denyshlddenis.gladikovA3a3e1
authored
Add support for reading a file from a remote URL in Read CSV attachment action (#84)
* Add support for reading a file from a remote URL in Read CSV attachment action * Update Sailor version to 2.6.24 Co-authored-by: denis.gladikov <denis.gladikov@elastic.io> Co-authored-by: Pavel Voropaiev <pavel.voropaiev@elastic.io>
1 parent 255e096 commit b4d314c

File tree

6 files changed

+4368
-70
lines changed

6 files changed

+4368
-70
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
## 2.1.7 (March 12, 2021)
2+
3+
* Add support for reading a file from a remote URL in Read CSV attachment action
4+
* Update Sailor version to 2.6.24
5+
16
## 2.1.6 (January 4, 2021)
7+
28
* Fix bug with Write From Array and multiple messages
39
* Bump node version to 14
410
* Bump dependencies

README.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ attachment. It can also write a CSV file from the incoming events.
1515
## Environment variables
1616
Name|Mandatory|Description|Values|
1717
|----|---------|-----------|------|
18-
|EIO_REQUIRED_RAM_MB| false | Value of allocated memory to component | Recommended: 512 |
19-
|REQUEST_TIMEOUT| false | HTTP request timeout in milliseconds | Default value: 10000 |
20-
|REQUEST_RETRY_DELAY| false | Delay between retry attempts in milliseconds | Default value: 7000 |
21-
|REQUEST_MAX_RETRY| false | Number of HTTP request retry attempts | Default value: 7 |
22-
|REQUEST_MAX_CONTENT_LENGTH| false | Max size of http request in bytes | Default value: 10485760 |
23-
|TIMEOUT_BETWEEN_EVENTS| false | Number of milliseconds write action wait before creating separate attachments | Default value: 10000 |
24-
|LOG_LEVEL| false | Level of logger verbosity | trace, debug, info, warning, error Default: info |
18+
|EIO_REQUIRED_RAM_MB| false | Value of allocated memory to component | Recommended: `512`/`1024` |
19+
|REQUEST_TIMEOUT| false | HTTP request timeout in milliseconds | Default value: `10000` |
20+
|REQUEST_RETRY_DELAY| false | Delay between retry attempts in milliseconds | Default value: `7000` |
21+
|REQUEST_MAX_RETRY| false | Number of HTTP request retry attempts | Default value: `7` |
22+
|REQUEST_MAX_CONTENT_LENGTH| false | Max size of http request in bytes | Default value: `10485760` |
23+
|TIMEOUT_BETWEEN_EVENTS| false | Number of milliseconds write action wait before creating separate attachments | Default value: `10000` |
24+
2525

2626
## Credentials
2727

@@ -36,8 +36,6 @@ This trigger will fetch the CSV file from a given URL. The address must be acces
3636
to the component. The fetched CSV file will be placed in the attachment part of the
3737
outgoing message.
3838

39-
![image](https://user-images.githubusercontent.com/40201204/60707311-190dae00-9f14-11e9-81a8-d48d9dcd1d03.png)
40-
4139
* `CSV URL` - the full URL to the file for retrieving data.
4240
* `Emit all messages` - this checkbox configures output behavior of the component. If the option is checked - the component emits an array of messages, otherwise - the component emits a message per row.
4341
* `CSV Header` - this is a required field. Input the names of headers separated with a comma.
@@ -49,17 +47,17 @@ outgoing message.
4947

5048
### Read CSV attachment
5149

52-
This action will read the CSV attachment of the incoming message and output
53-
a `JSON` object. To configure this action the following fields can be used:
50+
This action will read the CSV attachment of the incoming message or from the specified URL and output a JSON object.
51+
To configure this action the following fields can be used:
52+
5453

54+
* `CSV URL` - the full URL to the file for retrieving data. Leave the field blank and action will read CSV attachment of the incoming message (if any). Error will be thrown if URL of the CSV is missing and no CSV file in incoming message found
5555
* `Emit all messages` - this checkbox configures output behavior of the component. If the option is checked - the component emits an array of messages, otherwise - the component emits a message per row.
5656
* `CSV Header` - this is a required field. Input the names of headers separated with a comma.
5757
* `Separators` - Specify the separator type. Usually it is a comma (`,`) but values like Semicolon (`;`), Space (` `), Tab (`\t`) and Hash (`#`) are also supported.
5858
* `Skip rows` - if you know that the incoming CSV file has certain number of headers you can indicate to skip them. The supported values are `None`, `First row`, `First two`, `First three` and `First four`.
5959
* `Data columns` - here the values will be added dynamically based on the values in the `CSV Header` field. Here each data column will be listed with the name, Data Type and the Format to enable further configuration.
6060

61-
![image](https://user-images.githubusercontent.com/40201204/60706373-fda1a380-9f11-11e9-8b5a-2acd2df33a87.png)
62-
6361
### Write CSV attachment
6462

6563
* `Include Header` - this select configures output behavior of the component. If option is `Yes` or no value chosen than header of csv file will be written to attachment, this is default behavior. If value `No` selected than csv header will be omitted from attachment.
@@ -93,8 +91,6 @@ When columns are added in the UI, you will be presented with an opportunity to
9391
provide a JSONata expression per column. If you require number formatting that
9492
is specific to a locale, the JSONata expression should handle that concern.
9593

96-
![screenshot from 2017-10-17 09-28-04](https://user-images.githubusercontent.com/5710732/31651871-926b4530-b31d-11e7-936f-bcf3ff05f8e2.png)
97-
9894
The output of the CSV Write component will be a message with an attachment. In
9995
order to access this attachment, the component following the CSV Write must be
10096
able to handle file attachments.
@@ -194,7 +190,7 @@ able to handle file attachments.
194190
#### General
195191

196192
1. You may get `Component run out of memory and terminated.` error during run-time, that means that component needs more memory, please add
197-
`EIO_REQUIRED_RAM_MB` environment variable with an appropriate value (e.g. value `512` means that 512 MB will be allocated) for the component in this case.
193+
`EIO_REQUIRED_RAM_MB` environment variable with an appropriate value (e.g. value `1024` means that 1024 MB will be allocated) for the component in this case.
198194
2. You may get `Error: write after end` error, as a current workaround try increase value of environment variable: `TIMEOUT_BETWEEN_EVENTS`.
199195
3. Maximal possible size for an attachment is 10 MB.
200-
4. Attachments mechanism does not work with [Local Agent Installation](https://support.elastic.io/support/solutions/articles/14000076461-announcing-the-local-agent-)
196+
4. Attachments mechanism does not work with [Local Agent Installation](https://docs.elastic.io/getting-started/local-agent.html)

component.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
"link": "/components/csv/actions#read-csv-attachment"
3939
},
4040
"fields": {
41+
"url": {
42+
"label": "CSV URL",
43+
"required": false,
44+
"placeholder": "http://my-url.com/foo.csv",
45+
"note": "We will fetch this URL and parse it as CSV file, leave the field blank if you expect CSV attachment from previous step",
46+
"viewClass": "TextFieldWithNoteView"
47+
},
4148
"emitAll": {
4249
"label": "Emit all messages",
4350
"viewClass": "CheckBoxView"

lib/triggers/read.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ async function ProcessRead(msg, cfg) {
6868
that.logger.trace('Attachment found');
6969
csvURL = msg.attachments[key].url;
7070
} else {
71-
that.logger.error('URL of the CSV is missing');
72-
that.emit('error', 'URL of the CSV is missing');
73-
return that.emit('end');
71+
72+
that.logger.error('URL of the CSV is missing and no CSV file in incoming attachment found');
73+
that.emit('error', 'URL of the CSV is missing and no CSV file in incoming attachment found');
74+
that.emit('end');
75+
return;
7476
}
7577
}
7678
const parser = csv.parse({

0 commit comments

Comments
 (0)