Restructure (4): HTTP client interface with cluster wide queries#582
Restructure (4): HTTP client interface with cluster wide queries#582roosterfish merged 22 commits intocanonical:v3from
Conversation
d2aa5c2 to
e1d4466
Compare
There was a problem hiding this comment.
Pull request overview
This pull request restructures the microcluster HTTP client interface by introducing new Client and Connector interfaces that provide a cleaner abstraction for cluster-wide HTTP connections. The refactoring moves internal query functions from the public client package to internal/rest/client, making the API boundaries clearer.
Changes:
- Introduces
ClientandConnectorinterfaces inmicrocluster/types/client.gofor standardized cluster communication - Adds new application-level functions (
GetClusterMembers,RemoveClusterMember,Shutdown) toMicroClusterstruct for common operations - Refactors internal client functions to accept
types.Clientinterface instead of concrete types, improving testability and flexibility
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| microcluster/types/client.go | New file defining Client and Connector interfaces and Clients type with query methods |
| microcluster/types/addrport.go | Removes SelectRandom method (moved to state package) |
| microcluster/app.go | Updates to use new types.Client interface and adds new public methods for cluster operations |
| internal/state/state.go | Implements Connector interface methods and adds RandomMember function |
| internal/rest/client/*.go | Refactors all client functions to accept types.Client interface parameter |
| internal/rest/resources/*.go | Updates resource handlers to use new Connect() method and interface types |
| internal/trust/remotes.go | Removes SelectRandom method and updates Cluster to return types.Clients |
| internal/daemon/daemon.go | Updates to use new client interface throughout |
| internal/db/dqlite.go | Updates SendHeartbeat to accept types.Client interface |
| internal/recover/recover.go | Updates to use types.Clients instead of client.Cluster |
| example/cmd/microctl/*.go | Simplifies CLI commands by using new MicroCluster methods |
| example/client/client.go | Updates to use microTypes.Client interface |
| example/api/extended.go | Updates to use new types.IsNotification and interface methods |
| client/cluster.go | Deleted - functionality moved to types.Clients |
| client/client.go | Deleted - functionality moved to types.Client interface |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Client is an actual client to a cluster member whereas Connector is a more general concept allowing to reach out to specific members, the cluster leader or multiple members of a cluster at once. Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
…kage Also switch the concurrent Query implementation to use errgroup instead of waitgroup. Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
…plement Client interface Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
56c12bf to
ddc43cf
Compare
| return c, nil | ||
| } | ||
|
|
||
| func (s *InternalState) Member(url *url.URL, isNotification bool, cert *x509.Certificate) (types.Client, error) { |
| type cmdClusterMembers struct { | ||
| common *CmdControl | ||
| } | ||
|
|
There was a problem hiding this comment.
I believe the other example files (example/api and example/client) contain comment lines explaining the functions. However, these comments are not present for the functions in this file. Was this done intentionally? Or was it overlooked?
There was a problem hiding this comment.
Putting comments on lowercase/unexported funcs is optional.
However the linter doesn't pick this rule up consistently, it failed at least for one occasion in this PR, see #582 (comment).
markylaing
left a comment
There was a problem hiding this comment.
Just a couple of nits.
Overall I think this is a good simplification - exemplified by the example package!
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
This allows easy access for cluster internal connections through the state interface without having to access connection functions from another client package wich should provide a more smooth user experience. Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
…lable through client funcs We should take the same approach for all operations and not require the user to switch between app level funcs and client funcs inside another package. Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
…Connector interface Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
…e others Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
As we have detached the client funcs from the client type, there should be an app level func for both server and certificate update too. Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
ddc43cf to
48681f7
Compare
markylaing
left a comment
There was a problem hiding this comment.
Looks great, thanks :)
This is the fourth PR taken from a single commit in #534.
The final package layout will be different but to allow reviewing the changes in smaller chunks I will split this PR by its commits.
In this PR two new
ClientandConnectorinterfaces are added to address all use cases when it comes to cluster wide HTTP connections.In addition we now have app level funcs for all user facing operations which previously required going to a separate client package.
Furthermore the specific query functions are now moved to
internal/as they should not be exposed directly to the end user.