Skip to content

misc(native): Decouple HttpServer and HttpClient from SystemConfig singleton#27104

Merged
amitkdutta merged 1 commit intoprestodb:masterfrom
amitkdutta:export-D92604681
Feb 9, 2026
Merged

misc(native): Decouple HttpServer and HttpClient from SystemConfig singleton#27104
amitkdutta merged 1 commit intoprestodb:masterfrom
amitkdutta:export-D92604681

Conversation

@amitkdutta
Copy link
Copy Markdown
Contributor

@amitkdutta amitkdutta commented Feb 7, 2026

Remove direct SystemConfig/NodeConfig singleton access from HttpServer.cpp
and HttpClient.cpp in the presto_http library. Instead, inject configuration
via option structs (HttpServerStartupOptions, HttpClientOptions, JwtOptions)
that callers populate from SystemConfig at construction/call sites.

This decouples the HTTP transport layer from Presto's configuration system,
making the HTTP components independently testable and reusable without
requiring a global SystemConfig singleton to be initialized.

Key changes:

  • Add HttpServerStartupOptions struct for HttpServer::start() parameters
  • Add HttpClientOptions struct for HttpClient constructor parameters
  • Add JwtOptions struct for RequestBuilder JWT configuration
  • Move SystemConfig access to caller sites (PrestoServer, PrestoExchangeSource,
    PeriodicServiceInventoryManager, RestRemoteClient)
== NO RELEASE NOTE ==

Summary by Sourcery

Decouple HTTP server/client components from global configuration singletons by injecting configuration via option structs, improving modularity and testability of the HTTP layer.

New Features:

  • Introduce HttpClientOptions to configure HTTP client transport, resource limits, and metrics behavior at construction time.
  • Introduce JwtOptions to configure request JWT signing on a per-client or per-request basis.
  • Introduce HttpServerStartupOptions to configure HTTP server timeouts, HTTP/2 settings, and compression behavior at startup.

Enhancements:

  • Move SystemConfig and NodeConfig access out of HttpClient, HttpServer, and RequestBuilder into higher-level callers such as PrestoServer, PrestoExchangeSource, PeriodicServiceInventoryManager, and RestRemoteClient.
  • Update HTTP tests and helper wrappers to construct HttpServer and HttpClient with the new option-based interfaces.

Tests:

  • Adjust HTTP server and client test utilities and test cases to use the new HttpServerStartupOptions and HttpClientOptions when starting servers and creating clients.

Summary by Sourcery

Decouple HTTP server/client components and JWT handling from global configuration singletons by injecting configuration via dedicated option structs at construction/startup sites.

New Features:

  • Introduce HttpServerStartupOptions to configure HTTP server timeouts, HTTP/2 settings, and compression behavior at startup.
  • Introduce HttpClientOptions to configure HTTP client transport limits and metrics behavior at construction time.
  • Introduce JwtOptions to configure internal JWT signing per client/request in the HTTP request builder.

Enhancements:

  • Move SystemConfig and NodeConfig access for HTTP client, server, and JWT to higher-level callers such as PrestoServer, PrestoExchangeSource, PeriodicServiceInventoryManager, RestRemoteClient, and tests.
  • Adjust HTTP utilities and tests to construct HttpServer, HttpClient, and RequestBuilder using the new option-based interfaces.
  • Simplify internal authentication error handling by collapsing specific JWT verification exceptions into generic unauthorized/error responses.

Tests:

  • Update HTTP client/server and JWT tests and helpers to pass the new options structs when creating clients, servers, and requests.

@amitkdutta amitkdutta requested review from a team as code owners February 7, 2026 08:20
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Feb 7, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Feb 7, 2026

Reviewer's Guide

Decouples HttpServer, HttpClient, and RequestBuilder from direct SystemConfig/NodeConfig singleton access by introducing explicit option structs (HttpServerStartupOptions, HttpClientOptions, JwtOptions) and wiring configuration at higher-level call sites and tests.

Class diagram for decoupled HTTP configuration options

classDiagram

class SystemConfig {
}

class NodeConfig {
}

class HttpServerStartupOptions {
  uint32 idleTimeoutMs
  uint32 http2InitialReceiveWindow
  uint32 http2ReceiveStreamWindowSize
  uint32 http2ReceiveSessionWindowSize
  uint32 http2MaxConcurrentStreams
  bool enableContentCompression
  uint32 contentCompressionLevel
  uint32 contentCompressionMinimumSize
  bool enableZstdCompression
  uint32 zstdContentCompressionLevel
  bool enableGzipCompression
}

class HttpServer {
  +start(startupOptions HttpServerStartupOptions, filters vector~unique_ptr~RequestHandlerFactory~~, onSuccess function, onError function) void
}

class HttpClientOptions {
  bool http2Enabled
  uint32 http2MaxStreamsPerConnection
  uint32 http2InitialStreamWindow
  uint32 http2StreamWindow
  uint32 http2SessionWindow
  uint64 maxAllocateBytes
  bool connectionReuseCounterEnabled
}

class HttpClient {
  -EventBase* eventBase_
  -HttpClientConnectionPool* connPool_
  -SocketAddress address_
  -milliseconds transactionTimeout_
  -milliseconds connectTimeout_
  -HttpClientOptions options_
  -shared_ptr~MemoryPool~ pool_
  -SSLContextPtr sslContext_
  -function~void(int)~ reportOnBodyStatsFunc_
  +HttpClient(eventBase EventBase*, connPool HttpClientConnectionPool*, ioThreadPool Executor*, address SocketAddress, transactionTimeout milliseconds, connectTimeout milliseconds, pool shared_ptr~MemoryPool~, sslContext SSLContextPtr, options HttpClientOptions, reportOnBodyStatsFunc function~void(int)~)
  +connectionReuseCounterEnabled() bool
  +sendRequest(responseHandler shared_ptr~ResponseHandler~) void
}

class JwtOptions {
  bool jwtEnabled
  string sharedSecret
  int32 jwtExpirationSeconds
  string nodeId
}

class RequestBuilder {
  -JwtOptions jwtOptions_
  -HTTPMessage headers_
  +RequestBuilder()
  +jwtOptions(options JwtOptions) RequestBuilder&
  +method(method HTTPMethod) RequestBuilder&
  +url(url string) RequestBuilder&
  +send(client HttpClient*) SemiFuture~unique_ptr~HttpResponse~~
  -addJwtIfConfigured() void
}

class PrestoExchangeSource {
  -shared_ptr~HttpClient~ httpClient_
  -JwtOptions jwtOptions_
}

class PeriodicServiceInventoryManager {
  -shared_ptr~HttpClient~ client_
}

class RestRemoteClient {
  -shared_ptr~HttpClient~ httpClient_
}

SystemConfig ..> HttpServerStartupOptions
SystemConfig ..> HttpClientOptions
SystemConfig ..> JwtOptions
NodeConfig ..> JwtOptions

HttpServer o--> HttpServerStartupOptions
HttpClient o--> HttpClientOptions
RequestBuilder o--> JwtOptions

PrestoExchangeSource *--> HttpClient
PrestoExchangeSource o--> JwtOptions
PeriodicServiceInventoryManager *--> HttpClient
RestRemoteClient *--> HttpClient

SystemConfig ..> PrestoExchangeSource
SystemConfig ..> PeriodicServiceInventoryManager
SystemConfig ..> RestRemoteClient
SystemConfig ..> HttpServer
NodeConfig ..> PrestoExchangeSource
Loading

File-Level Changes

Change Details Files
Inject HttpServer configuration via HttpServerStartupOptions instead of reading SystemConfig inside HttpServer::start.
  • Add HttpServerStartupOptions struct carrying idle timeout, HTTP/2 flow-control, and compression-related options with sensible defaults.
  • Change HttpServer::start signature to take an HttpServerStartupOptions parameter (with default value) and use it to populate proxygen::HTTPServerOptions instead of querying SystemConfig.
  • Update PrestoServer, HttpServerWrapper, and Http test wrappers to construct and pass HttpServerStartupOptions when starting the server.
presto_cpp/main/http/HttpServer.h
presto_cpp/main/http/HttpServer.cpp
presto_cpp/main/PrestoServer.cpp
presto_cpp/main/http/tests/HttpTestBase.h
presto_cpp/main/tests/HttpServerWrapper.cpp
Inject HttpClient transport and metrics configuration via HttpClientOptions instead of reading SystemConfig inside HttpClient.
  • Introduce HttpClientOptions struct capturing HTTP/2 enablement, stream limits, flow-control windows, max response allocation size, and connection reuse metric flag.
  • Extend HttpClient constructor to accept an HttpClientOptions parameter (with defaults) and store it instead of multiple per-field configuration members and SystemConfig lookups.
  • Use HttpClientOptions fields when constructing proxygen::SessionPool and ResponseHandler, and expose a connectionReuseCounterEnabled() accessor for ResponseHandler.
  • Update all HttpClient call sites (exchange source, service inventory manager, REST remote client, tests, and helpers) to build HttpClientOptions from SystemConfig where appropriate and pass it into HttpClient.
presto_cpp/main/http/HttpClient.h
presto_cpp/main/http/HttpClient.cpp
presto_cpp/main/PrestoExchangeSource.cpp
presto_cpp/main/PeriodicServiceInventoryManager.cpp
presto_cpp/main/functions/remote/client/RestRemoteClient.cpp
presto_cpp/main/http/tests/HttpTestBase.h
presto_cpp/main/http/tests/HttpTest.cpp
Inject JWT signing configuration into RequestBuilder via JwtOptions instead of querying SystemConfig/NodeConfig singletons.
  • Define JwtOptions struct holding enable flag, shared secret, token expiration seconds, and node ID.
  • Extend RequestBuilder with a jwtOptions() setter that stores JwtOptions and uses it in addJwtIfConfigured() under PRESTO_ENABLE_JWT.
  • Replace SystemConfig/NodeConfig access in addJwtIfConfigured() with JwtOptions values to compute the secret hash, subject, and expiration.
  • Update PrestoExchangeSource and HTTP tests to construct JwtOptions from SystemConfig/NodeConfig and pass it to RequestBuilder for all relevant requests.
presto_cpp/main/http/HttpClient.h
presto_cpp/main/http/HttpClient.cpp
presto_cpp/main/PrestoExchangeSource.h
presto_cpp/main/PrestoExchangeSource.cpp
presto_cpp/main/http/tests/HttpTestBase.h
presto_cpp/main/http/tests/HttpJwtTest.cpp
Minor ancillary cleanups and behavioral clarifications around error handling and tests.
  • Stop logging exception objects in InternalAuthenticationFilter JWT verification failures by removing unused exception variables from catch blocks.
  • Adjust various JWT and HTTP tests to account for new helper signatures and remove unnecessary std::move on local variables.
  • Include Configs.h where needed now that configuration is pulled at higher-level components (e.g., PeriodicServiceInventoryManager, RestRemoteClient).
presto_cpp/main/http/filters/InternalAuthenticationFilter.cpp
presto_cpp/main/http/tests/HttpJwtTest.cpp
presto_cpp/main/PeriodicServiceInventoryManager.cpp
presto_cpp/main/functions/remote/client/RestRemoteClient.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The logic to populate HttpClientOptions from SystemConfig is duplicated in multiple call sites (PrestoExchangeSource, PeriodicServiceInventoryManager, RestRemoteClient); consider extracting a small helper/factory to build these options to avoid future divergence and make updates easier.
  • Similarly, the JWT configuration wiring in PrestoExchangeSource is now fairly verbose; you might consider a helper that builds JwtOptions from SystemConfig/NodeConfig so that any future JWT settings changes are centralized.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The logic to populate `HttpClientOptions` from `SystemConfig` is duplicated in multiple call sites (`PrestoExchangeSource`, `PeriodicServiceInventoryManager`, `RestRemoteClient`); consider extracting a small helper/factory to build these options to avoid future divergence and make updates easier.
- Similarly, the JWT configuration wiring in `PrestoExchangeSource` is now fairly verbose; you might consider a helper that builds `JwtOptions` from `SystemConfig`/`NodeConfig` so that any future JWT settings changes are centralized.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@amitkdutta amitkdutta changed the title [presto] Decouple HttpServer and HttpClient from SystemConfig singleton misc(native): Decouple HttpServer and HttpClient from SystemConfig singleton Feb 7, 2026
@amitkdutta amitkdutta force-pushed the export-D92604681 branch 3 times, most recently from 9ca35c4 to d35a36a Compare February 7, 2026 15:43
amitkdutta added a commit to amitkdutta/presto that referenced this pull request Feb 7, 2026
…on (prestodb#27104)

Summary:

Remove direct SystemConfig/NodeConfig singleton access from HttpServer.cpp
and HttpClient.cpp in the presto_http library. Instead, inject configuration
via option structs (HttpServerStartupOptions, HttpClientOptions, JwtOptions)
that callers populate from SystemConfig at construction/call sites.

This decouples the HTTP transport layer from Presto's configuration system,
making the HTTP components independently testable and reusable without
requiring a global SystemConfig singleton to be initialized.

Key changes:
- Add HttpServerStartupOptions struct for HttpServer::start() parameters
- Add HttpClientOptions struct for HttpClient constructor parameters
- Add JwtOptions struct for RequestBuilder JWT configuration
- Move SystemConfig access to caller sites (PrestoServer, PrestoExchangeSource,
  PeriodicServiceInventoryManager, RestRemoteClient)
- Move presto_common from exported_deps to deps in http/BUCK
- Add json target to presto_http exported_deps (needed by HttpServer.h)
- Add presto_common to presto_server_lib exported_deps (needed by
  PrestoExchangeSource.h)

Differential Revision: D92604681
@amitkdutta amitkdutta marked this pull request as ready for review February 7, 2026 18:39
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The construction of HttpClientOptions from SystemConfig is duplicated in multiple callers (PrestoExchangeSource, PeriodicServiceInventoryManager, RestRemoteClient); consider factoring this into a small helper to ensure consistent configuration and simplify future changes to client options.
  • Similarly, the logic to populate JwtOptions from SystemConfig/NodeConfig appears in multiple places (e.g., PrestoExchangeSource, HttpJwtTest); a shared helper or factory for JwtOptions would reduce repetition and the risk of inconsistent JWT setup across call sites.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The construction of `HttpClientOptions` from `SystemConfig` is duplicated in multiple callers (`PrestoExchangeSource`, `PeriodicServiceInventoryManager`, `RestRemoteClient`); consider factoring this into a small helper to ensure consistent configuration and simplify future changes to client options.
- Similarly, the logic to populate `JwtOptions` from `SystemConfig`/`NodeConfig` appears in multiple places (e.g., `PrestoExchangeSource`, `HttpJwtTest`); a shared helper or factory for `JwtOptions` would reduce repetition and the risk of inconsistent JWT setup across call sites.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

@amitkdutta : Would be good to add functions in SystemConfig class (or a new SystemConfigUtils class) to populate jwtOptions, HttpClientOptions from it. Then it will be easier for us to use those functions in all places that need to set the options.

Rest the idea and code is fine.

setTaskUriCb(httpsPort.has_value(), address.address.getPort());
break;
}
http::HttpServerStartupOptions startupOptions;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Abstract a function for this ?

sslContext_);
sslContext_,
std::move(httpClientOptions));
if (systemConfig->internalCommunicationJwtEnabled()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Abstract a function for this as well.

Summary:
Remove direct SystemConfig/NodeConfig singleton access from HttpServer.cpp
and HttpClient.cpp in the presto_http library. Instead, inject configuration
via option structs (HttpServerStartupOptions, HttpClientOptions, JwtOptions)
that callers populate from SystemConfig at construction/call sites.

This decouples the HTTP transport layer from Presto's configuration system,
making the HTTP components independently testable and reusable without
requiring a global SystemConfig singleton to be initialized.

Key changes:
- Extract HttpServerStartupOptions, HttpClientOptions, and JwtOptions structs
  into their own headers with separate lightweight Buck targets to break
  the circular dependency between presto_common and presto_http
- Add httpServerStartupOptions(), httpClientOptions(), and jwtOptions()
  methods to SystemConfig that construct and return fully populated option
  structs from config
- Simplify callsites in PrestoServer.cpp, PrestoExchangeSource.cpp,
  PeriodicServiceInventoryManager.cpp, RestRemoteClient.cpp, and
  HttpJwtTest.cpp to single method calls
- Move SystemConfig access to caller sites (PrestoServer, PrestoExchangeSource,
  PeriodicServiceInventoryManager, RestRemoteClient)
- Move presto_common from exported_deps to deps in http/BUCK
- Add json target to presto_http exported_deps (needed by HttpServer.h)
- Add presto_common to presto_server_lib exported_deps (needed by
  PrestoExchangeSource.h)

Differential Revision: D92604681
Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

Thanks @amitkdutta

@amitkdutta amitkdutta merged commit def6ddf into prestodb:master Feb 9, 2026
83 of 84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants