Skip to content

Commit

Permalink
{cmd,pkg}/linksharing: add support for satellite connection pool
Browse files Browse the repository at this point in the history
It's possible to have a separate connection pool for satellites and
other connections.

Change-Id: Id52848eb1188ac5f680be90c70d952b56be546c2
  • Loading branch information
egonelbre authored and Storj Robot committed Jun 8, 2023
1 parent 138abc0 commit 7fddae2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
9 changes: 9 additions & 0 deletions cmd/linksharing/config.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ public-url: ""
# redirect to HTTPS
redirect-https: true

# RPC connection pool capacity (satellite connections)
# satellite-connectionpool.capacity: 200

# RPC connection pool idle expiration (satellite connections)
# satellite-connectionpool.idle-expiration: 10m0s

# RPC connection pool limit per key (satellite connections)
# satellite-connectionpool.key-capacity: 0

# time to delay server shutdown while returning 503s on the health endpoint
shutdown-delay: 45s

Expand Down
45 changes: 28 additions & 17 deletions cmd/linksharing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ type LinkSharing struct {
UseClientIPHeaders bool `user:"true" help:"use the headers sent by the client to identify its IP. When true the list of IPs set by --client-trusted-ips-list, when not empty, is used" default:"true"`
StandardRendersContent bool `user:"true" help:"enable standard (non-hosting) requests to render content and not only download it" default:"false"`
StandardViewsHTML bool `user:"true" help:"serve HTML as text/html instead of text/plain for standard (non-hosting) requests" default:"false"`
ConnectionPool connectionPoolConfig
CertMagic certMagic
ShutdownDelay time.Duration `user:"true" help:"time to delay server shutdown while returning 503s on the health endpoint" devDefault:"1s" releaseDefault:"45s"`
StartupCheck startupCheck

SatelliteConnectionpool satelliteConnectionPoolConfig // Note: using `Connectionpool` with lowercase to make flag consistent with gateway-mt
ConnectionPool connectionPoolConfig

CertMagic certMagic
ShutdownDelay time.Duration `user:"true" help:"time to delay server shutdown while returning 503s on the health endpoint" devDefault:"1s" releaseDefault:"45s"`
StartupCheck startupCheck
}

// connectionPoolConfig is a config struct for configuring RPC connection pool options.
Expand All @@ -63,6 +66,13 @@ type connectionPoolConfig struct {
IdleExpiration time.Duration `user:"true" help:"RPC connection pool idle expiration" default:"2m0s"`
}

// satelliteConnectionPoolConfig is a config struct for configuring RPC connection pool of Satellite connections.
type satelliteConnectionPoolConfig struct {
Capacity int `help:"RPC connection pool capacity (satellite connections)" default:"200"`
KeyCapacity int `help:"RPC connection pool limit per key (satellite connections)" default:"0"`
IdleExpiration time.Duration `help:"RPC connection pool idle expiration (satellite connections)" default:"10m0s"`
}

// certMagic is a config struct for configuring CertMagic options.
type certMagic struct {
Enabled bool `user:"true" help:"use CertMagic to handle TLS certificates" default:"false"`
Expand Down Expand Up @@ -158,19 +168,20 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) {
StartupCheckConfig: httpserver.StartupCheckConfig(runCfg.StartupCheck),
},
Handler: sharing.Config{
URLBases: publicURLs,
Templates: runCfg.Templates,
StaticSourcesPath: runCfg.StaticSourcesPath,
RedirectHTTPS: runCfg.RedirectHTTPS,
LandingRedirectTarget: runCfg.LandingRedirectTarget,
TXTRecordTTL: runCfg.TXTRecordTTL,
AuthServiceConfig: runCfg.AuthService,
DNSServer: runCfg.DNSServer,
ConnectionPool: sharing.ConnectionPoolConfig(runCfg.ConnectionPool),
ClientTrustedIPsList: runCfg.ClientTrustedIPSList,
UseClientIPHeaders: runCfg.UseClientIPHeaders,
StandardViewsHTML: runCfg.StandardViewsHTML,
StandardRendersContent: runCfg.StandardRendersContent,
URLBases: publicURLs,
Templates: runCfg.Templates,
StaticSourcesPath: runCfg.StaticSourcesPath,
RedirectHTTPS: runCfg.RedirectHTTPS,
LandingRedirectTarget: runCfg.LandingRedirectTarget,
TXTRecordTTL: runCfg.TXTRecordTTL,
AuthServiceConfig: runCfg.AuthService,
DNSServer: runCfg.DNSServer,
SatelliteConnectionPool: sharing.ConnectionPoolConfig(runCfg.SatelliteConnectionpool),
ConnectionPool: sharing.ConnectionPoolConfig(runCfg.ConnectionPool),
ClientTrustedIPsList: runCfg.ClientTrustedIPSList,
UseClientIPHeaders: runCfg.UseClientIPHeaders,
StandardViewsHTML: runCfg.StandardViewsHTML,
StandardRendersContent: runCfg.StandardRendersContent,
Uplink: &uplink.Config{
UserAgent: "linksharing",
DialTimeout: runCfg.DialTimeout,
Expand Down
16 changes: 16 additions & 0 deletions pkg/linksharing/sharing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ type Config struct {
// uplink Config settings
Uplink *uplink.Config

// SatelliteConnectionPool is configuration for satellite RPC connection pool options.
SatelliteConnectionPool ConnectionPoolConfig

// ConnectionPool is configuration for RPC connection pool options.
ConnectionPool ConnectionPoolConfig

Expand Down Expand Up @@ -181,6 +184,19 @@ func NewHandler(log *zap.Logger, mapper *objectmap.IPDB, txtRecords *TXTRecords,
return nil, err
}

if config.SatelliteConnectionPool != (ConnectionPoolConfig{}) {
err = transport.SetSatelliteConnectionPool(context.TODO(), uplinkConfig,
rpcpool.New(rpcpool.Options{
Name: "satellite",
Capacity: config.SatelliteConnectionPool.Capacity,
KeyCapacity: config.SatelliteConnectionPool.KeyCapacity,
IdleExpiration: config.SatelliteConnectionPool.IdleExpiration,
}))
if err != nil {
return nil, err
}
}

var trustedClientIPs trustedip.List
if config.UseClientIPHeaders {
if len(config.ClientTrustedIPsList) > 0 {
Expand Down

0 comments on commit 7fddae2

Please sign in to comment.