Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configuration service for LogLevel and chain ws address #312

Merged
merged 16 commits into from
Jan 27, 2021

Conversation

LeonFLK
Copy link
Contributor

@LeonFLK LeonFLK commented Dec 3, 2020

fixes KILTProtocol/ticket#774

This merges and replaces ConfigLog.ts.
We do not want to connect implicitly to the default ws address, instead set it directly or via Kilt.config to set the address of our desired node. This address can be changed any time.
LogLevel can still be set by ENV.
This non-strongly typed approach uses generic set and get to manipulate and access configOpts configuration object.
No specific key suggestion anymore since configOpts is union type with generic keyed object.
Throws error on unset generic property key when accessing or on retrieval of unset address.

Checklist:

  • I have verified that the code works
  • I have verified that the code is easy to understand
    • If not, I have left a well-balanced amount of inline comments
  • I have left the code in a better state
  • I have documented the changes (where applicable)

@LeonFLK LeonFLK requested a review from rflechtner December 3, 2020 03:00
@LeonFLK LeonFLK force-pushed the lw-774-config-service branch from 553688e to f60553f Compare December 3, 2020 16:26
@tjwelde
Copy link
Contributor

tjwelde commented Dec 3, 2020

I think from the API it would be best, if I could call Kilt.config({...}).

@LeonFLK LeonFLK force-pushed the lw-774-config-service branch from f60553f to 6244da6 Compare December 3, 2020 16:44
@LeonFLK LeonFLK requested a review from tjwelde December 3, 2020 21:37
Copy link
Contributor

@rflechtner rflechtner left a comment

Choose a reason for hiding this comment

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

I'd prefer a config service that does not rely on a fixed set of fields to be able to extend easily in the future. What would you say, @tjwelde ?
I also remember we talked about config via environment variables, what's your opinion on this now?

@LeonFLK LeonFLK force-pushed the lw-774-config-service branch from 94edfe2 to 65ece3d Compare December 9, 2020 13:47
@LeonFLK
Copy link
Contributor Author

LeonFLK commented Dec 9, 2020

Now works much more under the hood.
Use Kilt.config() to pass partial configOpts (address and logLevel).
If no host address is set, getting the address will result in thrown error.
getCached and similar all use configuration.host get for retrieval of set address.

@LeonFLK LeonFLK requested a review from rflechtner December 9, 2020 13:55
Copy link
Contributor

@rflechtner rflechtner left a comment

Choose a reason for hiding this comment

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

As I had mentioned when we talked about it, I am not a fan of hard-coding specific configuration options into the config service. I predict this will be a nightmare for maintaining our codebase later. Also it doesn't work well with the project to split the SDK into smaller sub-packages. Are we sure we want to go down that road ?

To make for some more constructive feedback, I had imagined something like this:

let configuration: configOpts = {'logLevel': DEFAULT_DEBUG_LEVEL}

export function get<K extends keyof configOpts>(configOpt: K): configOpts[K] {
  if (typeof configuration[configOpt] === 'undefined') 
  throw new Error(`GENERIC NOT CONFIGURED ERROR FOR ${configOpt}`)
    return configuration[configOpt]
}

export function set(opts: Partial<configOpts>): void {
  if(typeof opts['logLevel'] !== 'undefined') {
    opts.logLevel = modifyLogLevel(opts.logLevel)
  }
  configuration = {...configuration, ...opts}
}

which could be exported as ConfigService or Kilt.config and would allow users to set options with (for example) Kilt.config.set({defaultNodeAddress: 'value'}) and get values with Kilt.config.get('defaultNodeAddress').

@LeonFLK LeonFLK force-pushed the lw-774-config-service branch from 65ece3d to af1382d Compare January 7, 2021 13:26
@tjwelde tjwelde changed the title Basic configuration service for LogLevel and chain ws address feat: configuration service for LogLevel and chain ws address Jan 13, 2021
Copy link
Contributor

@tjwelde tjwelde left a comment

Choose a reason for hiding this comment

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

Just two nitpicks, otherwise I think it looks pretty good.
What do you think @rflechtner

@rflechtner
Copy link
Contributor

Just two nitpicks, otherwise I think it looks pretty good.
What do you think @rflechtner

Looks good & works for me!

@rflechtner
Copy link
Contributor

rflechtner commented Jan 27, 2021 via email

@LeonFLK
Copy link
Contributor Author

LeonFLK commented Jan 27, 2021

I mean one can always ctrl+click to get to the definition, and that specific file is quite small, so not much scrolling going on.

Just think if we were to clarify each import like that and hold it to the same standard it's going to be messy.

What do you think, make an exception for this file clarifying the import, or skip?

Edit: import { get as ConfigService.get } does not work, would you want to import the whole ConfigService and then use the different functions like you said?

@LeonFLK LeonFLK force-pushed the lw-774-config-service branch from 99c34b8 to f6a6bd5 Compare January 27, 2021 15:10
@rflechtner
Copy link
Contributor

yeah importing the ConfigService as a whole would we the solution. But it's not a must, leave it if you don't think it adds much

Copy link
Contributor

@tjwelde tjwelde left a comment

Choose a reason for hiding this comment

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

Uff, finally, right? ;)
LGTM 🎉

@LeonFLK LeonFLK merged commit a1b224b into develop Jan 27, 2021
@LeonFLK LeonFLK deleted the lw-774-config-service branch January 27, 2021 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants