Build the image pipeline in pixad's fx graph (closes #313)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The new package internal/providers builds the cache, the fetcher, the processor, the image service, the session manager and the encrypted URL generator from the config. pixad's fx graph provides them with providers.Constructors(), and handlers.New receives them built. The server tests build the same graph, with only the fetcher's dial function replaced. database.New opens the database, so these parts can read it while fx builds them; the cache's stop hook still runs before the database's. Each setting's default is declared in internal/config, and internal/providers works out the default cache_max_bytes. The cache's MaxBytes is the one value for the disk cache limit, and 0 turns the disk cache off. The fetcher and the processor take explicit values. Model: opus-5-5
This commit was merged in pull request #330.
This commit is contained in:
@@ -32,6 +32,7 @@ import (
|
||||
"sneak.berlin/go/pixa/internal/imagerequest"
|
||||
"sneak.berlin/go/pixa/internal/logger"
|
||||
"sneak.berlin/go/pixa/internal/middleware"
|
||||
"sneak.berlin/go/pixa/internal/providers"
|
||||
)
|
||||
|
||||
// upstreamHost is the upstream host of the image URLs below. It is a
|
||||
@@ -138,22 +139,21 @@ func startImageProxy(
|
||||
AllowHTTP: true,
|
||||
// A limit of its own, so the cache does not size itself from the
|
||||
// host's free disk space.
|
||||
CacheMaxBytes: 64 << 20,
|
||||
CacheMaxBytesExplicit: true,
|
||||
UpstreamMaxResponseSize: config.DefaultUpstreamMaxResponseSize,
|
||||
DownstreamTimeout: config.DefaultDownstreamTimeout,
|
||||
CacheMaxBytes: 64 << 20,
|
||||
CacheMaxBytesExplicit: true,
|
||||
UpstreamFetchTimeout: config.DefaultUpstreamFetchTimeout,
|
||||
UpstreamMaxResponseSize: config.DefaultUpstreamMaxResponseSize,
|
||||
UpstreamConnectionsPerHost: config.DefaultUpstreamConnectionsPerHost,
|
||||
UpstreamConnections: config.DefaultUpstreamConnections,
|
||||
MaxConcurrentProcessing: 2,
|
||||
DownstreamTimeout: config.DefaultDownstreamTimeout,
|
||||
}
|
||||
|
||||
fetcherCfg := httpfetcher.DefaultConfig()
|
||||
fetcherCfg.AllowHTTP = true
|
||||
fetcherCfg.DialContext = func(
|
||||
ctx context.Context, network, _ string,
|
||||
) (net.Conn, error) {
|
||||
dialUpstream := func(ctx context.Context, network, _ string) (net.Conn, error) {
|
||||
var dialer net.Dialer
|
||||
|
||||
return dialer.DialContext(ctx, network, upstream.Listener.Addr().String())
|
||||
}
|
||||
fetcher := httpfetcher.New(fetcherCfg)
|
||||
|
||||
var (
|
||||
h *handlers.Handlers
|
||||
@@ -170,9 +170,14 @@ func startImageProxy(
|
||||
healthcheck.New,
|
||||
handlers.New,
|
||||
middleware.New,
|
||||
func() httpfetcher.Fetcher { return fetcher },
|
||||
func() prometheus.Registerer { return prometheus.NewRegistry() },
|
||||
),
|
||||
fx.Provide(providers.Constructors()...),
|
||||
fx.Decorate(func(fetcherConfig *httpfetcher.Config) *httpfetcher.Config {
|
||||
fetcherConfig.DialContext = dialUpstream
|
||||
|
||||
return fetcherConfig
|
||||
}),
|
||||
fx.Populate(&h, &mw, &db),
|
||||
)
|
||||
app.RequireStart()
|
||||
@@ -188,10 +193,10 @@ func startImageProxy(
|
||||
|
||||
// startImageProxyWithBlockedNetworks starts the components pixad's fx app
|
||||
// builds, from a config with a fresh state directory and blockedNetworks as
|
||||
// blocked_networks. Unlike startImageProxy it provides no upstream fetcher, so
|
||||
// the handlers build the one pixad uses, which checks every address it
|
||||
// connects to against the built-in blocked ranges and blocked_networks. It
|
||||
// returns the server with its routes.
|
||||
// blocked_networks. Unlike startImageProxy it keeps pixad's dial function,
|
||||
// which checks every address the fetcher connects to against the built-in
|
||||
// blocked ranges and blocked_networks. It returns the server with its
|
||||
// routes.
|
||||
func startImageProxyWithBlockedNetworks(
|
||||
t *testing.T, blockedNetworks []netip.Prefix,
|
||||
) *Server {
|
||||
@@ -207,8 +212,9 @@ func startImageProxyWithBlockedNetworks(
|
||||
// fails within this time at the latest.
|
||||
UpstreamFetchTimeout: 2 * time.Second,
|
||||
// With no connection slots, the fetch would fail before connecting.
|
||||
UpstreamConnections: config.DefaultUpstreamConnections,
|
||||
DownstreamTimeout: config.DefaultDownstreamTimeout,
|
||||
UpstreamConnectionsPerHost: config.DefaultUpstreamConnectionsPerHost,
|
||||
UpstreamConnections: config.DefaultUpstreamConnections,
|
||||
DownstreamTimeout: config.DefaultDownstreamTimeout,
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -227,6 +233,7 @@ func startImageProxyWithBlockedNetworks(
|
||||
middleware.New,
|
||||
func() prometheus.Registerer { return prometheus.NewRegistry() },
|
||||
),
|
||||
fx.Provide(providers.Constructors()...),
|
||||
fx.Populate(&h, &mw),
|
||||
)
|
||||
app.RequireStart()
|
||||
|
||||
Reference in New Issue
Block a user