From 25e040ffb9154d095edc4d14ef2c83daa8947010 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Wed, 10 Dec 2025 20:52:49 +0100 Subject: [PATCH] Move buffer/httpclient pools to pool package. --- .codecov.yml | 4 ++++ backend_client.go | 8 ++++---- backend_client_test.go | 3 ++- backend_server.go | 3 ++- capabilities.go | 7 ++++--- capabilities_test.go | 3 ++- client.go | 3 ++- buffer_pool.go => pool/buffer_pool.go | 2 +- http_client_pool.go => pool/http_client_pool.go | 6 +++++- .../http_client_pool_stats_prometheus.go | 2 +- http_client_pool_test.go => pool/http_client_pool_test.go | 2 +- 11 files changed, 28 insertions(+), 15 deletions(-) rename buffer_pool.go => pool/buffer_pool.go (98%) rename http_client_pool.go => pool/http_client_pool.go (97%) rename http_client_pool_stats_prometheus.go => pool/http_client_pool_stats_prometheus.go (98%) rename http_client_pool_test.go => pool/http_client_pool_test.go (99%) diff --git a/.codecov.yml b/.codecov.yml index b3f0da5..f59167a 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -50,6 +50,10 @@ component_management: name: nats paths: - nats/** + - component_id: module_pool + name: pool + paths: + - pool/** - component_id: module_proxy name: proxy paths: diff --git a/backend_client.go b/backend_client.go index b521ca6..826e816 100644 --- a/backend_client.go +++ b/backend_client.go @@ -34,10 +34,10 @@ import ( "github.com/dlintw/goconf" "github.com/strukturag/nextcloud-spreed-signaling/log" + "github.com/strukturag/nextcloud-spreed-signaling/pool" ) var ( - ErrNotRedirecting = errors.New("not redirecting to different host") ErrUnsupportedContentType = errors.New("unsupported_content_type") ErrIncompleteResponse = errors.New("incomplete OCS response") @@ -53,9 +53,9 @@ type BackendClient struct { version string backends *BackendConfiguration - pool *HttpClientPool + pool *pool.HttpClientPool capabilities *Capabilities - buffers BufferPool + buffers pool.BufferPool } func NewBackendClient(ctx context.Context, config *goconf.ConfigFile, maxConcurrentRequestsPerHost int, version string, etcdClient *EtcdClient) (*BackendClient, error) { @@ -70,7 +70,7 @@ func NewBackendClient(ctx context.Context, config *goconf.ConfigFile, maxConcurr logger.Println("WARNING: Backend verification is disabled!") } - pool, err := NewHttpClientPool(maxConcurrentRequestsPerHost, skipverify) + pool, err := pool.NewHttpClientPool(maxConcurrentRequestsPerHost, skipverify) if err != nil { return nil, err } diff --git a/backend_client_test.go b/backend_client_test.go index 3f35d5d..3b60930 100644 --- a/backend_client_test.go +++ b/backend_client_test.go @@ -36,6 +36,7 @@ import ( "github.com/stretchr/testify/require" "github.com/strukturag/nextcloud-spreed-signaling/log" + "github.com/strukturag/nextcloud-spreed-signaling/pool" ) func returnOCS(t *testing.T, w http.ResponseWriter, body []byte) { @@ -145,7 +146,7 @@ func TestPostOnRedirectDifferentHost(t *testing.T) { err = client.PerformJSONRequest(ctx, u, request, &response) if err != nil { // The redirect to a different host should have failed. - require.ErrorIs(err, ErrNotRedirecting) + require.ErrorIs(err, pool.ErrNotRedirecting) } else { require.Fail("The redirect should have failed") } diff --git a/backend_server.go b/backend_server.go index a6905c2..a149f8d 100644 --- a/backend_server.go +++ b/backend_server.go @@ -53,6 +53,7 @@ import ( "github.com/strukturag/nextcloud-spreed-signaling/container" "github.com/strukturag/nextcloud-spreed-signaling/internal" "github.com/strukturag/nextcloud-spreed-signaling/log" + "github.com/strukturag/nextcloud-spreed-signaling/pool" ) const ( @@ -83,7 +84,7 @@ type BackendServer struct { statsAllowedIps atomic.Pointer[container.IPList] invalidSecret []byte - buffers BufferPool + buffers pool.BufferPool } func NewBackendServer(ctx context.Context, config *goconf.ConfigFile, hub *Hub, version string) (*BackendServer, error) { diff --git a/capabilities.go b/capabilities.go index c609eb9..784c18e 100644 --- a/capabilities.go +++ b/capabilities.go @@ -35,6 +35,7 @@ import ( "github.com/strukturag/nextcloud-spreed-signaling/api" "github.com/strukturag/nextcloud-spreed-signaling/log" + "github.com/strukturag/nextcloud-spreed-signaling/pool" ) const ( @@ -249,16 +250,16 @@ type Capabilities struct { getNow func() time.Time version string - pool *HttpClientPool + pool *pool.HttpClientPool // +checklocks:mu entries map[string]*capabilitiesEntry // +checklocks:mu nextInvalidate map[string]time.Time - buffers BufferPool + buffers pool.BufferPool } -func NewCapabilities(version string, pool *HttpClientPool) (*Capabilities, error) { +func NewCapabilities(version string, pool *pool.HttpClientPool) (*Capabilities, error) { result := &Capabilities{ getNow: time.Now, diff --git a/capabilities_test.go b/capabilities_test.go index a53d00f..b3980c9 100644 --- a/capabilities_test.go +++ b/capabilities_test.go @@ -43,12 +43,13 @@ import ( "github.com/strukturag/nextcloud-spreed-signaling/api" "github.com/strukturag/nextcloud-spreed-signaling/log" + "github.com/strukturag/nextcloud-spreed-signaling/pool" ) func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*CapabilitiesResponse, http.ResponseWriter) error) (*url.URL, *Capabilities) { require := require.New(t) assert := assert.New(t) - pool, err := NewHttpClientPool(1, false) + pool, err := pool.NewHttpClientPool(1, false) require.NoError(err) capabilities, err := NewCapabilities("0.0", pool) require.NoError(err) diff --git a/client.go b/client.go index 2f8bf94..ebb5888 100644 --- a/client.go +++ b/client.go @@ -39,6 +39,7 @@ import ( "github.com/strukturag/nextcloud-spreed-signaling/internal" "github.com/strukturag/nextcloud-spreed-signaling/log" + "github.com/strukturag/nextcloud-spreed-signaling/pool" ) const ( @@ -85,7 +86,7 @@ func IsValidCountry(country string) bool { var ( InvalidFormat = NewError("invalid_format", "Invalid data format.") - bufferPool BufferPool + bufferPool pool.BufferPool ) type WritableClientMessage interface { diff --git a/buffer_pool.go b/pool/buffer_pool.go similarity index 98% rename from buffer_pool.go rename to pool/buffer_pool.go index 5e13c0b..8164bc5 100644 --- a/buffer_pool.go +++ b/pool/buffer_pool.go @@ -19,7 +19,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package signaling +package pool import ( "bytes" diff --git a/http_client_pool.go b/pool/http_client_pool.go similarity index 97% rename from http_client_pool.go rename to pool/http_client_pool.go index 9b2b2f9..55004be 100644 --- a/http_client_pool.go +++ b/pool/http_client_pool.go @@ -19,7 +19,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package signaling +package pool import ( "context" @@ -32,6 +32,10 @@ import ( "github.com/prometheus/client_golang/prometheus" ) +var ( + ErrNotRedirecting = errors.New("not redirecting to different host") +) + func init() { RegisterHttpClientPoolStats() } diff --git a/http_client_pool_stats_prometheus.go b/pool/http_client_pool_stats_prometheus.go similarity index 98% rename from http_client_pool_stats_prometheus.go rename to pool/http_client_pool_stats_prometheus.go index 13ba363..8d2c3b4 100644 --- a/http_client_pool_stats_prometheus.go +++ b/pool/http_client_pool_stats_prometheus.go @@ -19,7 +19,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package signaling +package pool import ( "github.com/prometheus/client_golang/prometheus" diff --git a/http_client_pool_test.go b/pool/http_client_pool_test.go similarity index 99% rename from http_client_pool_test.go rename to pool/http_client_pool_test.go index dff3866..1433b5f 100644 --- a/http_client_pool_test.go +++ b/pool/http_client_pool_test.go @@ -19,7 +19,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package signaling +package pool import ( "context"