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

refactor: Make config internal to CLI #2310

Merged
merged 13 commits into from
Feb 16, 2024

Conversation

nasdf
Copy link
Member

@nasdf nasdf commented Feb 13, 2024

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 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

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • 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).
  • 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

@nasdf nasdf added the area/config Related to configuration label Feb 13, 2024
@nasdf nasdf added this to the DefraDB v0.10 milestone Feb 13, 2024
@nasdf nasdf self-assigned this Feb 13, 2024
Copy link

codecov bot commented Feb 13, 2024

Codecov Report

Attention: 86 lines in your changes are missing coverage. Please review.

Comparison is base (765156e) 74.12% compared to head (25c427b) 74.28%.
Report is 1 commits behind head on develop.

❗ Current head 25c427b differs from pull request most recent head 225f02e. Consider uploading reports for the commit 225f02e to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             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     
Flag Coverage Δ
all-tests 74.28% <71.43%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
cli/backup_export.go 89.58% <100.00%> (ø)
cli/backup_import.go 100.00% <100.00%> (ø)
cli/cli.go 100.00% <100.00%> (ø)
cli/collection_create.go 53.57% <100.00%> (ø)
cli/collection_delete.go 44.44% <100.00%> (ø)
cli/collection_describe.go 83.78% <100.00%> (ø)
cli/collection_get.go 70.97% <100.00%> (ø)
cli/collection_update.go 42.67% <100.00%> (ø)
cli/index_create.go 87.76% <100.00%> (ø)
cli/index_drop.go 76.92% <100.00%> (ø)
... and 29 more

... and 12 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aec7a61...225f02e. Read the comment docs.

Copy link
Collaborator

@fredcarle fredcarle left a 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 :)

cli/config.go Outdated Show resolved Hide resolved
cli/utils.go Show resolved Hide resolved
cli/utils.go Outdated Show resolved Hide resolved
cli/config.go Show resolved Hide resolved
@nasdf nasdf marked this pull request as ready for review February 13, 2024 18:06
@nasdf nasdf requested review from a team and fredcarle February 13, 2024 18:06
Copy link
Contributor

@AndrewSisley AndrewSisley left a 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).
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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)

Copy link
Member Author

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`.
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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
Copy link
Contributor

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:

  1. We have our own memory store, and I though that was what datastore.store=memory was
  2. 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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Collaborator

@fredcarle fredcarle left a 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 :)

Copy link
Member

@shahzadlone shahzadlone left a 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

@nasdf nasdf changed the title refactor: Config refactor: Make config internal to CLI Feb 15, 2024
@nasdf nasdf merged commit ae6cebe into sourcenetwork:develop Feb 16, 2024
27 of 28 checks passed
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config Related to configuration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EPIC] Config refactor
4 participants