-
Notifications
You must be signed in to change notification settings - Fork 51
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
refactor: Make config internal to CLI #2310
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #2310 +/- ##
===========================================
+ Coverage 74.12% 74.28% +0.17%
===========================================
Files 259 255 -4
Lines 25796 25223 -573
===========================================
- Hits 19119 18736 -383
+ Misses 5341 5194 -147
+ Partials 1336 1293 -43
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 12 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments while it's in draft :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, very happy with the amount of deleted code :)
I have a couple of small comments that I would like resolving before merge, and a small concern around the below:
--logger cli flag has been temporarily removed (will be replaced in upcoming log library)
But if you and everyone else is comfy with that, I'm happy enough.
@@ -73,6 +73,8 @@ In this document, we use the default configuration, which has the following beha | |||
|
|||
The GraphQL endpoint can be used with a GraphQL client (e.g., Altair) to conveniently perform requests (`query`, `mutation`) and obtain schema introspection. | |||
|
|||
Read more about the configuration [here](./docs/config.md). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: This is nice, and keeps both .md
focused.
cli/config.go
Outdated
return err | ||
} | ||
err := cfg.SafeWriteConfig() | ||
if _, ok := err.(viper.ConfigFileAlreadyExistsError); ok { //nolint:errorlint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: Can you please document the reasons for the nolint
stuff with code-comments please (in all locations).
return nil, err | ||
} | ||
|
||
// make paths relative to the rootdir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Thank you for comments like this, it helps a lot when the code itself is non-obvious.
cli/config.go
Outdated
|
||
var format logging.EncoderFormat | ||
switch value := cfg.GetString("format"); value { | ||
case "json": //nolint:goconst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: It is annoying that the linter flags this, but I think that using a const (even though that is also bad here) is slightly less bad that a nolint
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved all of them to const
for now. They should be removed when the new logging package is ready.
id, err := strconv.ParseUint(args[0], 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
tx, err := http.NewTransaction(cfg.API.Address, id) | ||
tx, err := http.NewTransaction(cfg.GetString("api.address"), id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: This feels like it should be a shared const somewhere, not hardcoded here - do you have reasons for declaring it here like this?
(same for the other locations where this is done)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to avoid having const keys or a pre-defined config struct so that the config can be modified more easily. The places that access the api.address
specifically should have good test coverage since they use random port assignments in the tests.
docs/config.md
Outdated
|
||
## `datastore.maxtxnretries` | ||
|
||
Maximum number of times to retry a failed transaction. Defaults to `5`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: I don't think this line fully explains this option, from my memory this is for P2P only txn commit attempts, but that is not clear here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated it with a bit more text from the db documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers, new text looks good.
Store can be badger or memory. Defaults to `badger`. | ||
|
||
- badger: fast pure Go key-value store optimized for SSDs (https://github.com/dgraph-io/badger) | ||
- memory: in-memory version of badger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: memory
here confuses me a little bit:
- We have our own memory store, and I though that was what
datastore.store=memory
was - Badger memory is driven by the badger memory boolean option, if I am incorrect with (1), then why are we duplicating the option
suggestion: Unless I'm really confused/incorrect here, and given that we do document some badger config options in this file, I think it might be worth documenting the badger memory config prop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the same thing and had originally changed datastore.store
to datastore.badger.inMemory
, but @jsimnz had a preference to keep it datastore.store
.
We could swap it to the memory datastore, but I'd prefer to do that in a new PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah fair enough.
We could swap it to the memory datastore, but I'd prefer to do that in a new PR.
I agree that if we want to make that change it should be done in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for applying the changes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, do suggest making the commit/PR Title abit more detailed rather than just Config
after the commit labal
## Relevant issue(s) Resolves sourcenetwork#2257 ## Description This PR refactors the config into a simpler implementation that exists within the `cli` package. Notable changes: - ~~`datastore.store` config key has been replaced with `datastore.badger.inMemory`~~ - ~~`--store` cli flag has been replaced with `--in-memory`~~ - `log.overrides` config map has been added. (contains same keys as `log` but for individual loggers) - `--logger` cli flag has been temporarily removed (will be replaced in upcoming log library) - `init` command has been removed. (can be replaced with `rm -rf ~/.defradb` or similar) ## Tasks - [x] I made sure the code is well commented, particularly hard-to-understand areas. - [x] I made sure the repository-held documentation is changed accordingly. - [x] I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in [tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)). - [x] I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ... ## How has this been tested? `make test` Specify the platform(s) on which this was tested: - MacOS
Relevant issue(s)
Resolves #2257
Description
This PR refactors the config into a simpler implementation that exists within the
cli
package.Notable changes:
datastore.store
config key has been replaced withdatastore.badger.inMemory
--store
cli flag has been replaced with--in-memory
log.overrides
config map has been added. (contains same keys aslog
but for individual loggers)--logger
cli flag has been temporarily removed (will be replaced in upcoming log library)init
command has been removed. (can be replaced withrm -rf ~/.defradb
or similar)Tasks
How has this been tested?
make test
Specify the platform(s) on which this was tested: