You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+68-5Lines changed: 68 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,35 +1,76 @@
1
1
# NR Object Storage Rotate
2
2
3
-
A Sidecar container for rotating, compressing and backing up log files to Object Storage.
3
+
A sidecar container for rotating, compressing and backing up log files to object storage.
4
4
5
5
## Architecture
6
6
7
7
The container is a Typescipt Node.js application that uses a SQLite database to track the files as they are stepped through each stage. The stages run independantely on a configurable cron schedule.
8
8
9
-
COnfigurable environment variables will be shown like `ENV_VAR` below.
9
+
Configurable environment variables will be shown like `ENV_VAR` below.
10
10
11
11
### Stage 0 - Log file generated
12
12
13
13
The application logs to disk. Files to be rotated must end with `LOGROTATE_SUFFIX`.
14
14
15
15
### Stage 1 - Rotate log file
16
16
17
-
The environment variable `CRON_ROTATE` is used to schedule the rotation of the files. Matching files are rotated by renaming the files to append a timestamp.
17
+
The environment variable `CRON_ROTATE` is used to schedule the rotation of the files. The `LOGROTATE_DIRECTORY` is examined for files with the `LOGROTATE_SUFFIX` (default: log).
18
18
19
19
If any files are rotated then, optionally, `LOGROTATE_POSTROTATE_COMMAND` is called. It can be necessary to signal the application that the rotation occurred so it can open a new file.
20
20
21
+
Rotated files are appended with the file's change date and the current UTC timestamp. See: https://nodejs.org/api/fs.html#stat-time-values
22
+
21
23
### Stage 2 - Compress log file
22
24
23
-
The environment variable `CRON_COMPRESS` is used to schedule the compression of the rotated files.
25
+
The environment variable `CRON_COMPRESS` is used to schedule the compression of the rotated files. The each file is compressed into a 'tgz' archive.
26
+
27
+
This stage can run frequently with little cost.
24
28
25
29
### Stage 3 - Backup log file
26
30
27
-
The environment variable `CRON_BACKUP` is used to schedule the back of the compressed files to Object Storage. To identify the source, a prefix can be configured by setting `OBJECT_STORAGE_FILENAME_PREFIX`. Any arbitrary metadata can be set by setting `OBJECT_STORAGE_METADATA` to be a key/value JSON string.
31
+
The environment variable `CRON_BACKUP` is used to schedule the backup of the compressed files to object storage.
32
+
33
+
If you have massive files or slow connectivity, increase the cron settings period. Otherwise, this stage can run frequently with little cost.
34
+
35
+
Any arbitrary metadata can be set by setting `OBJECT_STORAGE_METADATA` to be a key/value JSON string.
36
+
37
+
If you are sending similarly named files from multiple sources (OpenShift/Kubernetes nodes), then it is recommended that you set `OBJECT_STORAGE_FILENAME_PREFIX` to identify the source and avoid collisions.
38
+
39
+
If you set `OBJECT_STORAGE_ENABLED` to anything but the default of 'true' then the backup to object storage is skipped.
40
+
41
+
#### Required Configuration
42
+
43
+
The following are the environment variables that need to be set for the tool to use object storage.
44
+
45
+
*`OBJECT_STORAGE_END_POINT`
46
+
*`OBJECT_STORAGE_ACCESS_KEY`
47
+
*`OBJECT_STORAGE_BUCKET`
48
+
*`OBJECT_STORAGE_SECRET_KEY`
28
49
29
50
### Stage 4 - Janitor
30
51
31
52
The environment variable `CRON_JANITOR` is used to schedule the janitor which removes files after they have been backed up. The number of log files to retain can be configured by setting `JANITOR_COPIES`.
32
53
54
+
This stage can run frequently with little cost.
55
+
56
+
## SQLite Database
57
+
58
+
The SQLite database can be viewed by running a command like:
59
+
60
+
`sqlite3 ./logs/cron.db 'select * from logs'`
61
+
62
+
### Missing Files
63
+
64
+
Prior to each stage, the database and the file system are compared. Any file missing from the file system will be logged and deleted from the database.
65
+
66
+
### Moving the Log Directory
67
+
68
+
If you are moving the location of the files, you will need to update the path column of the logs table in the SQLite database. As well, you should take care not to trigger the missing files process.
69
+
70
+
## Object Storage Lifecycle Policies
71
+
72
+
This tool does not manage the lifecycle policies for the bucket the data is uploaded to. Please refer to the documentation for the object storage service you are using to setup a bucket lifecycle.
73
+
33
74
## Rotation Setups
34
75
35
76
The default rotates files once every day. If you change the cron to run hourly, then it will rotate hourly. The minimum file size environment variable can be set to skip rotating files until they grow larger enough. The age maximum can ensure files don't remain on the server indefinitely.
@@ -42,6 +83,28 @@ The minimum file size (in bytes) before the file is rotated. Empty files are alw
42
83
43
84
The maximum age (in milliseconds) of a file before it is rotated (even if the minimum file size is not met). Values less than 1 are ignored. Default: 0
44
85
86
+
### Integration with NR Broker
87
+
88
+
The backup stage can read credentials from NR Vault and report the backed up files to NR Broker if the NR Broker environment variables (`BROKER_*`) are set.
89
+
90
+
The required environment variables to set are:
91
+
92
+
*`BROKER_JWT`
93
+
*`BROKER_PROJECT`
94
+
*`BROKER_SERVICE`
95
+
*`BROKER_ENVIRONMENT`
96
+
97
+
This will set it up to read secrets from the standard key/value credential location in NR Vault for the service. The `VAULT_CRED_PATH_SUFFIX` variable can be set to include a path from the service's root.
98
+
99
+
The key/value document read from NR Vault will do nothing by default. The `VAULT_CRED_KEYS_*` variables replace the equivalent `OBJECT_STORAGE_*` with the value of the key read from Vault.
0 commit comments