misc(native): Decouple HttpServer and HttpClient from SystemConfig singleton#27104
misc(native): Decouple HttpServer and HttpClient from SystemConfig singleton#27104amitkdutta merged 1 commit intoprestodb:masterfrom
Conversation
Reviewer's GuideDecouples 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 optionsclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The logic to populate
HttpClientOptionsfromSystemConfigis 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
PrestoExchangeSourceis now fairly verbose; you might consider a helper that buildsJwtOptionsfromSystemConfig/NodeConfigso 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
9ca35c4 to
d35a36a
Compare
…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
d35a36a to
635f7f2
Compare
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The construction of
HttpClientOptionsfromSystemConfigis 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
JwtOptionsfromSystemConfig/NodeConfigappears in multiple places (e.g.,PrestoExchangeSource,HttpJwtTest); a shared helper or factory forJwtOptionswould 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
aditi-pandit
left a comment
There was a problem hiding this comment.
@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; |
There was a problem hiding this comment.
Abstract a function for this ?
| sslContext_); | ||
| sslContext_, | ||
| std::move(httpClientOptions)); | ||
| if (systemConfig->internalCommunicationJwtEnabled()) { |
There was a problem hiding this comment.
Abstract a function for this as well.
635f7f2 to
798e0f1
Compare
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
798e0f1 to
837e4ba
Compare
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:
PeriodicServiceInventoryManager, RestRemoteClient)
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:
Enhancements:
Tests:
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:
Enhancements:
Tests: