Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Create and use config.js script merging defaults and custom configuration - Closes #3171 #3373

Merged
merged 30 commits into from
Apr 24, 2019

Conversation

nazarhussain
Copy link
Contributor

What was the problem?

The config compilation logic for all modules and component was distributed in different places.

How did I fix it?

Created a configurator object which compiles and reuse that logic.

How to test it?

Run all tests

Review checklist

@nazarhussain
Copy link
Contributor Author

You can get following output with the new structure, which is way more detailed compared to previous implementation.

➜  lisk-sdk git:(3171-config-generator) ✗ node lisk/src/index.js usage
Your can customize the configuration runtime with following env variables and command 
line options:

--log,-l        LISK_FILE_LOG_LEVEL       components.logger.fileLogLevel
                LISK_REDIS_HOST           components.logger.logFileName
                LISK_CONSOLE_LOG_LEVEL    components.logger.consoleLogLevel
                LISK_CACHE_ENABLED        components.cache.enabled
--redis,-r      LISK_REDIS_HOST           components.cache.host
                LISK_REDIS_PORT           components.cache.port
                LISK_REDIS_DB_NAME        components.cache.db
                LISK_REDIS_DB_PASSWORD    components.cache.password
                LISK_DB_HOST              components.storage.host
                LISK_DB_PORT              components.storage.port
--database,-d   LISK_DB_NAME              components.storage.database
                LISK_DB_USER              components.storage.user
                LISK_DB_PASSWORD          components.storage.password
                LISK_FORGING_DELEGATES    modules.chain.forging.delegates
--snapshot,-s                             modules.chain.loading.snapshotRound
--port,-p       LISK_WS_PORT              modules.chain.network.wsPort
--address,-a    LISK_ADDRESS              modules.chain.network.address
--peers,-x      LISK_PEERS                modules.chain.network.list
--http-port,-h  LISK_HTTP_PORT            modules.http_api.httpPort
--address,-a    LISK_ADDRESS              modules.http_api.address
                LISK_API_PUBLIC           modules.http_api.access.public
                LISK_API_WHITELIST        modules.http_api.access.whiteList
                LISK_FORGING_WHITELIST    modules.http_api.forging.access.whiteList
--network,-n    LISK_NETWORK              NETWORK
--config,-c     LISK_CONFIG_FILE          CUSTOM_CONFIG_FILE

For rest of configuration, please modify those directly to your custom config file.

@nazarhussain nazarhussain force-pushed the 3171-config-generator branch 2 times, most recently from 07c3418 to 1b27382 Compare April 17, 2019 12:58
@nazarhussain
Copy link
Contributor Author

@fchavant @ManuGowda You can run the command to see all the usage of this file.

node lisk/scripts/generate_config.js usage

And run with proper parameters to get the config as console output. Then pipe it to jq or stream to file with > to do any thing...

Copy link
Contributor

@fchavant fchavant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After creating a build I am not able to run generate_config.js usage:

francois@ams1-lisk-build-003:~/tmp/lisk-1.6.0-rc.4-Linux-x86_64$ node ./scripts/generate_config.js usage
/home/francois/tmp/lisk-1.6.0-rc.4-Linux-x86_64/src/helpers/config.js:32
configurator.registerSchema(appSchema);
             ^

TypeError: Cannot read property 'registerSchema' of undefined
    at Object.<anonymous> (/home/francois/tmp/lisk-1.6.0-rc.4-Linux-x86_64/src/helpers/config.js:32:14)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/home/francois/tmp/lisk-1.6.0-rc.4-Linux-x86_64/scripts/generate_config.js:22:16)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)

Copy link
Contributor

@fchavant fchavant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package.json and package-lock.json in lisk/ are not in sync.

@nazarhussain
Copy link
Contributor Author

@fchavant That change is not introduced by this PR.

@fchavant
Copy link
Contributor

@nazarhussain that may be but I cannot create a build and so cannot test config.js

Copy link
Collaborator

@shuse2 shuse2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general looks good, some minor comments

@@ -0,0 +1,148 @@
const _ = require('lodash');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this folder to
controller/configurator/configurator.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am convinced its a utility not a main namespace. As we planned to rename helpers to util then it will look more appropriate.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utility but it's one of the main functionality for controller, and it has specific logic init, so i think it's worth to put it as first citizen.
Also, i want to get rid of helpers or utils in general =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me its not a main functionality of the controller, rather add on to simplify configuration management for end user. These functions still exists and must required, call these helpers or util. In any large project you always have such collection of functions. And util is a known convention in NodeJS community so not a bad thing to have.

And wether we treat these as first citizen or not that depends how much we test coverage we have for them.

framework/src/index.js Show resolved Hide resolved
);
Object.keys(this.metaInfo).forEach(key => {
message.push(
`${(this.metaInfo[key].arg || '').padEnd(15)} ${(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why padEnd this? and next one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To show an aligned output on the console in help command. See the output in start of the PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe comment or use of constants?

Copy link
Contributor

@ManuGowda ManuGowda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I am just waiting for the build to get consistently green.

shuse2
shuse2 previously approved these changes Apr 23, 2019
Copy link
Contributor

@fchavant fchavant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't test inside of a binary build but looks good.

@shuse2 shuse2 merged commit 7c9d9e9 into development Apr 24, 2019
@shuse2 shuse2 deleted the 3171-config-generator branch April 24, 2019 07:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create and use config.js script merging defaults and custom configuration
4 participants