-
Notifications
You must be signed in to change notification settings - Fork 53
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: CLI client interface #1839
refactor: CLI client interface #1839
Conversation
…t test wrapper to http package. fix tests with missing result fields
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'm only part way through my review, but I thought I'd submit the comments I have so far. Overall it looks really good, and it is a fantastic amount of code you've been able to remove, whilst gaining features :)
cli/backup_export.go
Outdated
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
store := cmd.Context().Value(storeContextKey).(client.Store) |
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: You do cmd.Context().Value(storeContextKey).(client.Store)
quite a lot, it might be worth hiding the const and the cast behind a func (perhaps located next to the func that sets it).
"github.com/sourcenetwork/defradb/config" | ||
) | ||
|
||
func MakeBlocksGetCommand(cfg *config.Config) *cobra.Command { |
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: It might be handy for reviewers (and yourself) to list the commands that have been totally removed without replacement, such as this one. It would make it easier to spot and then talk about them.
I am pretty happy losing functionality in this PR, but medium-long term we may want some of them back via the client interfaces.
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 added a list of the new, renamed, and removed commands to the description.
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 Keenan!
cli/p2p_replicator_getall.go
Outdated
"github.com/sourcenetwork/defradb/client" | ||
) | ||
|
||
func MakeP2PReplicatorGetallCommand() *cobra.Command { |
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.
nitpick: The a
in all
should really be capitalised.
cli/p2p_replicator_getall.go
Outdated
@@ -0,0 +1,36 @@ | |||
// Copyright 2022 Democratized Data Foundation |
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 hate that we have to do this, and am personally happy with being a bit sloppy here, but I know that others are not - this (and any others) should be 2023
.
cli/p2p_collection_getall.go
Outdated
) | ||
|
||
func MakeP2PCollectionGetallCommand(cfg *config.Config) *cobra.Command { | ||
func MakeP2PCollectionGetallCommand() *cobra.Command { |
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.
nitpick: The a in all should really be capitalised.
cli/document_create.go
Outdated
var collection string | ||
var file string | ||
var cmd = &cobra.Command{ | ||
Use: "create --collection <collection> <document>", |
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: <collection>
is ambiguous here and it is not clear (outside of Long) whether this means collection ID, collection name, or a collection json blob. Suggest changing to <collectionName>
, if this behaviour is kept (read other comments RE structure first maybe).
cli/document_create.go
Outdated
Long: `Create a new document. | ||
|
||
Example: create document | ||
defradb client document create --collection User '{ "name": "Bob" }' |
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: Here the cli now differs in structure to the client
API. Here document is a sibling to collection, despite internally using collection commands.
I think it would reduce the cognitive load on the user if all clients followed the same structure, and I thought this was one of the goals of this block of work.
You are also limiting the user to the default schema version here, if you fix the structure you should get more complex collection selection for free. This also is breaking from the client API.
It might be worth creating a discord thread to discuss this, will leave that up to you though.
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 reorganized this so it better matches the client API.
cli/document_create.go
Outdated
return err | ||
} | ||
return col.Create(cmd.Context(), doc) | ||
case []any: |
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 is quite a lot of code not covered by tests, and the PR description says your only testing was via the make test
command, is the PR description incorrect, or have you manually tested these blocks?
suggestion: Write some tests :)
The same question/suggestion applies to quite a few commands in this 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.
I think adding more integration tests would be the best option. I will put together a list of areas that are missing coverage.
cli/document_create.go
Outdated
} | ||
return col.CreateMany(cmd.Context(), docs) | ||
default: | ||
return fmt.Errorf("invalid document") |
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: This, and any other error string should be in an errors.go file. Happy to expand on why I think so if you need (I cant remember how much you know about this 'standard' :)).
cli/wrapper.go
Outdated
|
||
var _ client.DB = (*Wrapper)(nil) | ||
|
||
type Wrapper struct { |
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: Why is this production code?
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'd like to move this and the http wrapper to the integration tests package. I think there was something blocking me from doing that, but I will give it another look.
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 Keenan - please give me a shout here once you've pushed changes/decided against moving and I'll review them fully.
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.
Update: I was able to move them to a new tests/clients
package.
cli/document_keys.go
Outdated
if docKey.Err != nil { | ||
results.Error = docKey.Err.Error() | ||
} | ||
writeJSON(cmd, results) //nolint:errcheck |
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: Please document why this is okay
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 decided to return the error here instead.
Short: "Delete a replicator. It will stop synchronizing", | ||
Long: `Delete a replicator. It will stop synchronizing.`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { |
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: This entire command appears to be untested, please test it.
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'd like for this to be covered in an integration test so we can get coverage on other implementations as well. I'll follow up shortly with a fix.
func MakeP2PReplicatorSetCommand() *cobra.Command { | ||
var collections []string | ||
var cmd = &cobra.Command{ | ||
Use: "set [-c, --collection] <peer>", |
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: [-c, --collection]
appears to be inconsistent with the rest of the CLI, I think it should be consistent.
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.
Are you referring to the naming or that it's a slice type?
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 forgot that this was a slice type, but I was referring to the existence of the shorthand. However the way you have moved the document stuff into collection has removed the inconsistency (as there is no longer a --collection
flag there).
This comment is now no longer relevant :)
"github.com/sourcenetwork/defradb/errors" | ||
) | ||
|
||
func MakePeerIDCommand(cfg *config.Config) *cobra.Command { |
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: Is this now provided by p2p_info?
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.
Yes, as a follow up I will be adding the multiaddresses as a return value there as well.
cli/schema_migration_down.go
Outdated
var schemaVersionID string | ||
var cmd = &cobra.Command{ | ||
Use: "down --version <version> <src>", | ||
Short: "Reverse a migration on the specified schema version.", |
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: Please explain to the user what <src>
is :)
suggestion: on
is somewhat ambiguous here I think, from
(or to
, I cant remember which way round) might be better.
Same goes for the up command.
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 tried to describe it in more detail. I believe it is the list of documents to apply / reverse the migration to / from.
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 Keenan - looks good
Use: "collection [--name <name> --schema <schemaID> --version <versionID>]", | ||
Short: "Interact with a collection.", | ||
Long: `Create, read, update, and delete documents within a collection.`, | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) { |
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.
Sweet :) I was hoping you'd be able to find a way to do it like this when I was commenting earlier - forces consistency and we get all the features :)
cli/collection_create.go
Outdated
`, | ||
Args: cobra.RangeArgs(0, 1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
col, ok := cmd.Context().Value(colContextKey).(client.Collection) |
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: Similar to store
, I'd suggest refactoring out cmd.Context().Value(colContextKey).(client.Collection)
into a private func, located next to where it is set (collection.go).
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, and looking forward to having it in :) Would suggest a quick manual sanity check of a couple of CLI commands before merge, just in case :)
Good job Keenan :)
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! Just posted one small nitpick.
We can coordinate merging this as would need to turn off the required checks right before merge.
## Relevant issue(s) ## Description This PR is split into two to make reviewing easier: sourcenetwork#1839 This PR adds an HTTP client and server implementation that implements the `client.DB` interface and runs through the existing integration test suite. ## 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) Closes sourcenetwork#1472 Closes sourcenetwork#1507 Closes sourcenetwork#1860 ## Description This is a follow up to sourcenetwork#1776 This PR adds a CLI implementation that implements the client.DB interface and runs through the existing integration test suite. - [x] Merge existing server config code - [x] Refactor CLI to use new HTTP client - [x] Remove `net/api` package - [x] Remove `api/http` package - [x] Lens tests are timing out in CI: fixed sourcenetwork#1862 - [x] Code coverage is incorrectly reporting: fixed sourcenetwork#1861 - [x] Flaky test causing failures: fixed sourcenetwork#1912 Renamed Commands: - `peerid` to `client peer info` - `client p2pcollection` to `client p2p collection` - `client replicator` to `client p2p replicator` - `client schema list` to `client collection describe` Removed Commands: - `block get` - `ping` - `rpc` Added Commands: - `client collection create` - `client collection delete` - `client collection get` - `client collection keys` - `client collection update` - `client tx create` - `client tx discard` - `client tx commit` - `client schema migration up` - `client schema migration down` - `client schema migration reload` **Notes for reviewers**: - `.github` changes are merged from sourcenetwork#1871 - `Makefile` most of these changes are also from sourcenetwork#1871 - `docs/cli` ignore these changes, it will be updated next release - sorry for all of the merge commits, I am working on learning rebase flow ## 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)
Closes #1472
Closes #1507
Closes #1860
Description
This is a follow up to #1776
This PR adds a CLI implementation that implements the client.DB interface and runs through the existing integration test suite.
net/api
packageapi/http
packageRenamed Commands:
peerid
toclient peer info
client p2pcollection
toclient p2p collection
client replicator
toclient p2p replicator
client schema list
toclient collection describe
Removed Commands:
block get
ping
rpc
Added Commands:
client collection create
client collection delete
client collection get
client collection keys
client collection update
client tx create
client tx discard
client tx commit
client schema migration up
client schema migration down
client schema migration reload
Notes for reviewers:
.github
changes are merged from ci: Parallelize change detector #1871Makefile
most of these changes are also from ci: Parallelize change detector #1871docs/cli
ignore these changes, it will be updated next releaseTasks
How has this been tested?
make test
Specify the platform(s) on which this was tested: