Skip to content

Restructure (4): HTTP client interface with cluster wide queries#582

Merged
roosterfish merged 22 commits intocanonical:v3from
roosterfish:restructure_client_package
Jan 15, 2026
Merged

Restructure (4): HTTP client interface with cluster wide queries#582
roosterfish merged 22 commits intocanonical:v3from
roosterfish:restructure_client_package

Conversation

@roosterfish
Copy link
Contributor

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 Client and Connector interfaces 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.

@roosterfish roosterfish changed the title Restructure (3): HTTP client interface with cluster wide queries Restructure (4): HTTP client interface with cluster wide queries Jan 12, 2026
@roosterfish roosterfish marked this pull request as draft January 12, 2026 13:58
@roosterfish roosterfish force-pushed the restructure_client_package branch from d2aa5c2 to e1d4466 Compare January 12, 2026 14:01
@roosterfish roosterfish marked this pull request as ready for review January 12, 2026 14:30
@roosterfish roosterfish requested a review from Copilot January 12, 2026 14:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 Client and Connector interfaces in microcluster/types/client.go for standardized cluster communication
  • Adds new application-level functions (GetClusterMembers, RemoveClusterMember, Shutdown) to MicroCluster struct for common operations
  • Refactors internal client functions to accept types.Client interface 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>
@roosterfish roosterfish force-pushed the restructure_client_package branch from 56c12bf to ddc43cf Compare January 12, 2026 15:25
return c, nil
}

func (s *InternalState) Member(url *url.URL, isNotification bool, cert *x509.Certificate) (types.Client, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

type cmdClusterMembers struct {
common *CmdControl
}

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor

@markylaing markylaing left a comment

Choose a reason for hiding this comment

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

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>
@roosterfish roosterfish force-pushed the restructure_client_package branch from ddc43cf to 48681f7 Compare January 15, 2026 13:30
Copy link
Contributor

@markylaing markylaing left a comment

Choose a reason for hiding this comment

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

Looks great, thanks :)

@roosterfish roosterfish merged commit a822744 into canonical:v3 Jan 15, 2026
5 checks passed
@roosterfish roosterfish deleted the restructure_client_package branch January 15, 2026 16:07
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