@ti-engine/core 1.1.2 → 1.1.3
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/CHANGELOG.md +7 -0
- package/README.md +131 -7
- package/bin/start-instance.js +2 -1
- package/components/service-instance.js +2 -1
- package/package.json +1 -1
- package/utils/config.js +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# ti-engine changelog
|
|
2
2
|
|
|
3
|
+
## Version 1.1.3
|
|
4
|
+
|
|
5
|
+
* feat(config)!: removed ENV variable `TI_OPERATION_MODE` as it was duplicating the practical purpose of `NODE_ENV`
|
|
6
|
+
* feat(config)!: setting `OPERATION_MODE` is now initialized by the `NODE_ENV` ENV variable (if provided)
|
|
7
|
+
* feat(service instance): show application operation mode in log at successful startup
|
|
8
|
+
* docs: add more sections and information in `README.md`
|
|
9
|
+
|
|
3
10
|
## Version 1.1.2
|
|
4
11
|
|
|
5
12
|
* feat(localization): add new functionality for localization based on labels and system language. It is currently utilized by the `exceptions` module for localizing the exception descriptions. The new `localization` module can also be accessed externally in the implementing application's files via standard import
|
package/README.md
CHANGED
|
@@ -21,18 +21,21 @@ This is what you gain by using **ti-engine** in your project:
|
|
|
21
21
|
|
|
22
22
|
These are just some benefits **ti-engine** offers. Get to know it better to find out more ways in which it can help you improve productivity.
|
|
23
23
|
|
|
24
|
-
## Overview
|
|
25
|
-
|
|
26
|
-
Being a messaging system, the **ti-engine** relies on a message broker for the actual exchange of messages between microservice instances. The default implementation of the framework uses [Redis](https://redis.io/) cache, however, you could create your own implementation using something like [Rabbit MQ](https://www.rabbitmq.com/). See the [Advanced topics](#advanced-topics) section of this documentation for guides on how to do this.
|
|
27
|
-
|
|
28
24
|
## Prerequisites & installation
|
|
29
25
|
|
|
26
|
+
Being a messaging system, the **ti-engine** relies on a message broker for the actual exchange of messages between microservice instances. The default implementation of the framework uses [Redis](https://redis.io/) cache, however, you could create your own implementation using something like [Rabbit MQ](https://www.rabbitmq.com/). See the [Advanced topics](#advanced-topics) section of this documentation for guides on how to do this. For now let's focus on the default setup.
|
|
27
|
+
|
|
30
28
|
In order to run the basic ti-engine framework you will need a couple of things:
|
|
31
29
|
|
|
32
30
|
* A local [node.js installation](https://nodejs.org/en/download/) with a minimum version of **14.17.0**
|
|
33
31
|
* A local or remote [Redis cache installation](https://redis.io/download) with a minimum version of **5.0.14**
|
|
34
32
|
|
|
35
|
-
If you are working under Windows 10+ OS and you need to install Redis, take a look at this [guide](https://redis.com/blog/redis-on-windows-10/). You could also use [Redis Cloud](https://app.redislabs.com/) for development purposes as it offers free basic account.
|
|
33
|
+
If you are working under Windows 10+ OS and you need to install Redis, take a look at this [guide](https://redis.com/blog/redis-on-windows-10/). You could also use [Redis Cloud](https://app.redislabs.com/) for development purposes as it offers free basic account. You can configure your connection to remote Redis server using the following ENV variables:
|
|
34
|
+
|
|
35
|
+
* `TI_MEMORY_CACHE_AUTH_KEY` can be used to provide the Redis password if there is any at all.
|
|
36
|
+
* `TI_MEMORY_CACHE_REDIS_DB` can be used to specify the Redis DB you want to use. Make sure to set the correct number as for example Redis Cloud only uses DB `0`.
|
|
37
|
+
* `TI_MEMORY_CACHE_REDIS_HOST` can be used to provide the remote host. This can be an IP or URL depending on your setup.
|
|
38
|
+
* `TI_MEMORY_CACHE_REDIS_PORT` can be used to provide the remote port. By default, Redis uses `6379` however many implementations might use a custom port that needs to be specified in the connection settings.
|
|
36
39
|
|
|
37
40
|
To get the framework itself, use the command `npm install @ti-engine/core`. And to include it directly in your package.json dependencies execute `npm install @ti-engine/core --save-prod`.
|
|
38
41
|
|
|
@@ -330,11 +333,132 @@ Now without exiting this node process let's start the original tester microservi
|
|
|
330
333
|
|
|
331
334
|
This means the service call processing was successful and result was returned to `my-service`. Because we made the receiving of the result blocking and part of the initialization sequence, the new microservice did not report successful startup until it received that response from `ti-tester-service`.
|
|
332
335
|
|
|
333
|
-
And with this we are
|
|
336
|
+
And with this step we are done. The new microservice is now operational. You can continue to tweak and play with it in order to understand better how it all works. For more details on the **ti-engine** inner working please see the following sections.
|
|
334
337
|
|
|
335
338
|
## Using the framework
|
|
336
339
|
|
|
337
|
-
|
|
340
|
+
### Framework settings
|
|
341
|
+
|
|
342
|
+
Here you can find all settings used by **ti-engine** together with information on what they do. They are defined inside the `config` module and the full list can be accessed through the public `setting` enum. To get the current value of a setting, you can use the public method `getSetting` from the same module. Some settings can be overridden by providing ENV variables as specified below at node application start up.
|
|
343
|
+
|
|
344
|
+
AUDITING_LOG_CONSOLE_ENABLED
|
|
345
|
+
: JSON path `auditing.logConsoleEnabled`, type `boolean`, default `true`
|
|
346
|
+
: ENV variable `TI_AUDITING_LOG_CONSOLE_ENABLED`
|
|
347
|
+
: This setting controls whether the `auditing` module will send the log entries to the OS console or not. In some cases, like Cloud environments, you might want to disable this, especially if the OS console is not made available. This functions independently of other logging outputs like for example GCloud error reporting.
|
|
348
|
+
|
|
349
|
+
AUDITING_LOG_DETAILS
|
|
350
|
+
: JSON path `auditing.logDetails`, type `boolean`, default `true`
|
|
351
|
+
: ENV variable `TI_AUDITING_LOG_DETAILS`
|
|
352
|
+
: This setting controls whether the `auditing` module will include the log entry details (located in the `data` property) in the final log output. You might want to disable this if you want a leaner log output or the log entry details are not something you plan to use for analysis later.
|
|
353
|
+
|
|
354
|
+
AUDITING_LOG_MIN_LEVEL
|
|
355
|
+
: JSON path `auditing.logMinLevel`, type `number`, default `0`
|
|
356
|
+
: ENV variable `TI_AUDITING_LOG_MIN_LEVEL`
|
|
357
|
+
: This setting controls the minimum log severity level that the framework will log in the log output. You can and should set this to `200` (INFO) for production environments in order to filter out the DEBUG and the low-level DEFAULT entries.
|
|
358
|
+
|
|
359
|
+
AUDITING_LOG_USES_JSON
|
|
360
|
+
: JSON path `auditing.logUsesJSON`, type `boolean`, default `false`
|
|
361
|
+
: ENV variable `TI_AUDITING_LOG_USES_JSON`
|
|
362
|
+
: This setting controls whether the log entries would be sent to output formatted as JSONs or not. By default, the framework outputs log entries as prettified text. In some cases however you might want to have the entire entry as a JSON for further processing (for example if you're sending all logs to Elasticsearch).
|
|
363
|
+
|
|
364
|
+
GCLOUD_API_KEY (Alpha)
|
|
365
|
+
: JSON path `gcloudIntegration.apiKey`
|
|
366
|
+
: This setting holds the API key for the GCloud integration module.
|
|
367
|
+
|
|
368
|
+
GCLOUD_PROJECT_ID (Alpha)
|
|
369
|
+
: JSON path `gcloudIntegration.projectID`
|
|
370
|
+
: This setting holds the project ID for the GCloud integration module.
|
|
371
|
+
|
|
372
|
+
LOCALIZATION_LABELS_PATH
|
|
373
|
+
: JSON path `localization.labelsPath`, type `string`, default `../core/bin/localization/labels.json`
|
|
374
|
+
: ENV variable `TI_LOCALIZATION_LABELS_PATH`
|
|
375
|
+
: This setting holds the file system path to the `.json` file containing the localization information. By default, the framework provides such a file with english texts that can be customized further. Alternatively, you can provide your own file from a different location, but it still has to follow the rules of the `localization` module.
|
|
376
|
+
|
|
377
|
+
LOCALIZATION_LANGUAGE
|
|
378
|
+
: JSON path `localization.language`, type `string`, default `en`
|
|
379
|
+
: ENV variable `TI_LOCALIZATION_LANGUAGE`
|
|
380
|
+
: This setting specifies the default framework language. It will be used when translating labels into a localized text.
|
|
381
|
+
|
|
382
|
+
MEMORY_CACHE_AUTH_KEY
|
|
383
|
+
: JSON path `memoryCache.authKey`, type `string`, default `undefined`
|
|
384
|
+
: ENV variable `TI_MEMORY_CACHE_AUTH_KEY`
|
|
385
|
+
: This setting holds the Redis password for accessing the Redis server if such password is required.
|
|
386
|
+
|
|
387
|
+
MEMORY_CACHE_REDIS_DB
|
|
388
|
+
: JSON path `memoryCache.redisDB`, type `number`, default `0`
|
|
389
|
+
: ENV variable `TI_MEMORY_CACHE_REDIS_DB`
|
|
390
|
+
: This setting specifies the Redis DB to be used for all operations. When setting this make sure that the Redis server actually supports multiple DBs (for example Redis Cloud has only one DB with ID `0`).
|
|
391
|
+
|
|
392
|
+
MEMORY_CACHE_REDIS_HOST
|
|
393
|
+
: JSON path `memoryCache.redisHost`, type `string`, default `127.0.0.1`
|
|
394
|
+
: ENV variable `TI_MEMORY_CACHE_REDIS_HOST`
|
|
395
|
+
: This setting holds the Redis server hostname. It can be an IP or URL depending on your configuration.
|
|
396
|
+
|
|
397
|
+
MEMORY_CACHE_REDIS_PORT
|
|
398
|
+
: JSON path `memoryCache.redisPort`, type `number`, default `6379`
|
|
399
|
+
: ENV variable `TI_MEMORY_CACHE_REDIS_PORT`
|
|
400
|
+
: This setting holds the Redis server port.
|
|
401
|
+
|
|
402
|
+
MEMORY_CACHE_USER
|
|
403
|
+
: JSON path `memoryCache.user`, type `string`, default `default`
|
|
404
|
+
: ENV variable `TI_MEMORY_CACHE_USER`
|
|
405
|
+
: This setting holds the Redis username for accessing the Redis server if this is supported by the Redis version (it will be ignored otherwise).
|
|
406
|
+
|
|
407
|
+
MESSAGE_EXCHANGE_QUEUE_PREFIX (Advanced)
|
|
408
|
+
: JSON path `messageExchange.messageQueuePrefix`, type `string`, default `ti:messages:`
|
|
409
|
+
: This setting holds the Redis key prefix for the queues that will hold the messages of the message exchange. This is not something you should modify unless you are making a customized implementation of the tier 1 architectural layer.
|
|
410
|
+
|
|
411
|
+
MESSAGE_EXCHANGE_MESSAGE_STORE (Advanced)
|
|
412
|
+
: JSON path `messageExchange.messageStore`, type `string`, default `ti:messages:store`
|
|
413
|
+
: This setting holds the Redis key name of the hash table that will hold the message payloads of the message exchange. This is not something you should modify unless you are making a customized implementation of the tier 1 architectural layer.
|
|
414
|
+
|
|
415
|
+
MESSAGE_EXCHANGE_SECURITY_HASH_ENABLED (Advanced)
|
|
416
|
+
: JSON path `messageExchange.securityHashEnabled`, type `boolean`, default `true`
|
|
417
|
+
: ENV variable `TI_MESSAGE_EXCHANGE_SECURITY_HASH_ENABLED`
|
|
418
|
+
: This setting controls whether the message exchange will use a control hash mechanism to ensure there is no tampering with the messages in between service calls. In most cases you would want to keep this enabled since it ensures the integrity of your data. If you are concerned about performance (hashing with `blake2` is very fast, but it still eats some milliseconds) you might want to try and disable this to see if it makes any notable difference.
|
|
419
|
+
|
|
420
|
+
MESSAGE_EXCHANGE_SECURITY_HASH_KEY (Advanced)
|
|
421
|
+
: JSON path `messageExchange.securityHashKey`, type `string`, default `random uuid`
|
|
422
|
+
: ENV variable `TI_MESSAGE_EXCHANGE_SECURITY_HASH_KEY`
|
|
423
|
+
: This setting holds the encryption key used by the message exchange control hash mechanism. By default, this has a random uuid value that can be used for development purposes only. For production environments you absolutely must provide your own encryption key via the ENV variable. Depending on your configuration and infrastructure it might come from a secure storage, HSM, key vault, etc.
|
|
424
|
+
|
|
425
|
+
MESSAGE_EXCHANGE_TRACE_EXPIRATION_TIME
|
|
426
|
+
: JSON path `messageExchange.traceExpirationTime`, type `number`, default `3600`
|
|
427
|
+
: This setting specifies the expiration time in seconds of the Redis key that will hold the message trace entries. Set this to `0` to disable expiration altogether.
|
|
428
|
+
|
|
429
|
+
MESSAGE_EXCHANGE_TRACE_LOG_ENABLED
|
|
430
|
+
: JSON path `messageExchange.traceLogEnabled`, type `boolean`, default `false`
|
|
431
|
+
: ENV variable `TI_MESSAGE_EXCHANGE_TRACE_LOG_ENABLED`
|
|
432
|
+
: This setting controls whether the `auditing` module should output all trace messages as normal log entries or not. Normally, you don't want that since it will clutter the standard log quite a lot. All traces go their own storage and can be reviewed and processed separately from the log entries. In some cases, however, as in debugging, enabling this can help you identify hard to track problem.
|
|
433
|
+
|
|
434
|
+
MESSAGE_EXCHANGE_TRACE_REPOSITORY (Advanced)
|
|
435
|
+
: JSON path `messageExchange.traceRepository`, type `string`, default `ti:messages:trace`
|
|
436
|
+
: This setting holds the Redis key name for the message trace cache storage. This is not something you should modify unless you are making a customized implementation of the tier 1 architectural layer.
|
|
437
|
+
|
|
438
|
+
SERVICE_EXECUTION_TIMEOUT
|
|
439
|
+
: JSON path `serviceConfig.executionTimeout`, type `number`, default `180000`
|
|
440
|
+
: This setting specifies the timeout in milliseconds of the service call executions at tier 2 of the architecture. Any service call that hasn't received response within this time will interrupt the wait and raise an `E_COM_SERVICE_EXEC_TIMEOUT` exception. Please keep in mind that reaching the timeout does not mean the remote service did not process the request. You might want to tweak this setting if you have many time-consuming operations in business services, or you plan to integrate with slow APIs.
|
|
441
|
+
|
|
442
|
+
SERVICE_HEALTH_CHECK_ADDRESS (Advanced)
|
|
443
|
+
: JSON path `serviceConfig.healthCheckAddress`, type `string`, default `ti:services:registry:health:`
|
|
444
|
+
: This setting specifies the address of the health check report endpoint for the microservice. In the default implementation this is a prefix for a Redis key that gets updated once at every `SERVICE_HEALTH_CHECK_INTERVAL`. If you override the `reportHealthy` method of the microservice, this setting can contain a URL or another type of destination that can be used by your custom implementation.
|
|
445
|
+
|
|
446
|
+
SERVICE_HEALTH_CHECK_INTERVAL (Advanced)
|
|
447
|
+
: JSON path `serviceConfig.healthCheckInterval`, type `CRON string`, default `*/1 * * * * *`
|
|
448
|
+
: This setting specifies the health check report interval at which the endpoint in `SERVICE_HEALTH_CHECK_ADDRESS` is notified.
|
|
449
|
+
|
|
450
|
+
SERVICE_HEALTH_CHECK_TIMEOUT (Advanced)
|
|
451
|
+
: JSON path `serviceConfig.healthCheckTimeout`, type `number`, default `3`
|
|
452
|
+
: This setting specifies the timeout in seconds after which a microservice is no longer considered healthy. In the default implementation this represents an expiration parameter to the Redis key defined in `SERVICE_HEALTH_CHECK_ADDRESS`. Essentially, if the microservice does not update the Redis key within this time interval, it will expire and the monitoring application will lose the healthy status of the microservice. If you override the `reportHealthy` method of the microservice, this setting can be used for your custom implementation as needed.
|
|
453
|
+
|
|
454
|
+
SERVICE_REGISTRY_ADDRESS (Advanced)
|
|
455
|
+
: JSON path `serviceConfig.serviceRegistryAddress`, type `string`, default `ti:services:registry:catalog:`
|
|
456
|
+
: This setting holds the prefix of the Redis key name used as business service registry. If the microservice is a `ServiceProvider`, on start up it will register its business service portfolio in that Redis set. Also, on each service call that same registry will be searched for the existence of the called business service. This is not something you should modify unless you are making a customized implementation of the tier 1 architectural layer.
|
|
457
|
+
|
|
458
|
+
OPERATION_MODE
|
|
459
|
+
: JSON path `operationMode`, type `string`, default `production`
|
|
460
|
+
: ENV variable `NODE_ENV`
|
|
461
|
+
: This setting holds the current operation mode of the node application. It will inherit the value from the `NODE_ENV` variable if it exists, otherwise will use its default.
|
|
338
462
|
|
|
339
463
|
## Advanced topics
|
|
340
464
|
|
package/bin/start-instance.js
CHANGED
|
@@ -75,13 +75,14 @@ process.on( "uncaughtException", ( error ) => {
|
|
|
75
75
|
try {
|
|
76
76
|
logger.log( `Starting new instance of type '${ process.env.TI_INSTANCE_NAME }' with instance ID '${ process.env.TI_INSTANCE_ID }'.`, logger.logSeverity.NOTICE );
|
|
77
77
|
|
|
78
|
-
/** @type ServiceInstance */
|
|
79
78
|
const serviceConstructor = require( path.join( process.cwd(), process.env.TI_INSTANCE_CLASS ) );
|
|
80
79
|
const serviceConfigPath = process.env.TI_INSTANCE_CONFIG;
|
|
80
|
+
/** @type ServiceConfiguration */
|
|
81
81
|
let serviceConfig = {};
|
|
82
82
|
if ( serviceConfigPath ) {
|
|
83
83
|
serviceConfig = require( path.join( process.cwd(), process.env.TI_INSTANCE_CONFIG ) );
|
|
84
84
|
}
|
|
85
|
+
/** @type ServiceInstance */
|
|
85
86
|
const mainInstance = new serviceConstructor( process.env.TI_INSTANCE_NAME, serviceConfig );
|
|
86
87
|
|
|
87
88
|
/** @override */
|
|
@@ -225,7 +225,8 @@ class ServiceInstance {
|
|
|
225
225
|
} );
|
|
226
226
|
|
|
227
227
|
logger.log( `Instance '${ ServiceInstance.instanceID }' started successfully.`, logger.logSeverity.NOTICE, {
|
|
228
|
-
nodeVersion: process.version
|
|
228
|
+
nodeVersion: process.version,
|
|
229
|
+
operationMode: config.getSetting( config.setting.OPERATION_MODE )
|
|
229
230
|
} );
|
|
230
231
|
|
|
231
232
|
resolve();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ti-engine/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.",
|
|
5
5
|
"author": "Boris Kostadinov <kostadinov.boris@gmail.com>",
|
|
6
6
|
"license": "ISC",
|
package/utils/config.js
CHANGED
|
@@ -34,7 +34,6 @@ const tools = require( "#tools" );
|
|
|
34
34
|
* @property {EnvironmentVariable} env.TI_MESSAGE_EXCHANGE_SECURITY_HASH_ENABLED
|
|
35
35
|
* @property {EnvironmentVariable} env.TI_MESSAGE_EXCHANGE_SECURITY_HASH_KEY
|
|
36
36
|
* @property {EnvironmentVariable} env.TI_MESSAGE_EXCHANGE_TRACE_LOG_ENABLED
|
|
37
|
-
* @property {EnvironmentVariable} env.TI_OPERATION_MODE
|
|
38
37
|
*/
|
|
39
38
|
|
|
40
39
|
/**
|
|
@@ -174,7 +173,7 @@ if ( process.env.TI_GCLOUD_ENABLED === true && settings.gcloudIntegration ) {
|
|
|
174
173
|
settings.gcloudIntegration.projectID = ( process.env.TI_GCLOUD_PROJECT_ID !== undefined ) ? process.env.TI_GCLOUD_PROJECT_ID : settings.gcloudIntegration.projectID;
|
|
175
174
|
}
|
|
176
175
|
|
|
177
|
-
settings.operationMode = process.env.
|
|
176
|
+
settings.operationMode = process.env.NODE_ENV || settings.operationMode;
|
|
178
177
|
|
|
179
178
|
// prevent further modifications to the settings object:
|
|
180
179
|
Object.freeze( settings );
|