diff --git a/config/config.md b/config/config.md
index 8a31fc0eb2c..773fe30fa3f 100644
--- a/config/config.md
+++ b/config/config.md
@@ -34,6 +34,9 @@
| `http.prom_validation_mode` | String | `strict` | Whether to enable validation for Prometheus remote write requests. Available options: - strict: deny invalid UTF-8 strings (default). - lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD). - unchecked: do not valid strings. |
| `http.experimental_enable_prometheus_native_histogram` | Bool | `false` | Experimental: enable Prometheus remote write v2 native histogram ingestion. |
| `http.experimental_enable_explain_analyze_stream` | Bool | `true` | Experimental: enable POST /v1/sql/analyze/stream for streaming EXPLAIN ANALYZE VERBOSE metrics. |
+| `http.api_server_enable` | Bool | `true` | Whether to start the dedicated public HTTP **API** server. This server serves only the `v1` interfaces plus the dashboard, and shares every other `[http]` option with the main server. It is enabled by default. |
+| `http.api_server_host` | String | `127.0.0.1` | Host of the dedicated HTTP API server. Defaults to `127.0.0.1`. |
+| `http.api_server_port` | Integer | `4006` | Port of the dedicated HTTP API server. Defaults to `4006`. |
| `grpc` | -- | -- | The gRPC server options. |
| `grpc.bind_addr` | String | `127.0.0.1:4001` | The address to bind the gRPC server. |
| `grpc.runtime_size` | Integer | `8` | The number of server worker threads. |
@@ -255,6 +258,9 @@
| `http.prom_validation_mode` | String | `strict` | Whether to enable validation for Prometheus remote write requests. Available options: - strict: deny invalid UTF-8 strings (default). - lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD). - unchecked: do not valid strings. |
| `http.experimental_enable_prometheus_native_histogram` | Bool | `false` | Experimental: enable Prometheus remote write v2 native histogram ingestion. |
| `http.experimental_enable_explain_analyze_stream` | Bool | `true` | Experimental: enable POST /v1/sql/analyze/stream for streaming EXPLAIN ANALYZE VERBOSE metrics. |
+| `http.api_server_enable` | Bool | `true` | Whether to start the dedicated public HTTP **API** server. This server serves only the `v1` interfaces plus the dashboard, and shares every other `[http]` option with the main server. It is enabled by default. |
+| `http.api_server_host` | String | `127.0.0.1` | Host of the dedicated HTTP API server. Defaults to `127.0.0.1`. |
+| `http.api_server_port` | Integer | `4006` | Port of the dedicated HTTP API server. Defaults to `4006`. |
| `grpc` | -- | -- | The gRPC server options. |
| `grpc.bind_addr` | String | `127.0.0.1:4001` | The address to bind the gRPC server. |
| `grpc.server_addr` | String | `127.0.0.1:4001` | The address advertised to the metasrv, and used for connections from outside the host. If left empty or unset, the server will automatically use the IP address of the first network interface on the host, with the same port number as the one specified in `grpc.bind_addr`. |
diff --git a/config/frontend.example.toml b/config/frontend.example.toml
index a0dffcfa97f..27f13f9b7f3 100644
--- a/config/frontend.example.toml
+++ b/config/frontend.example.toml
@@ -70,6 +70,15 @@ experimental_enable_prometheus_native_histogram = false
## Experimental: enable POST /v1/sql/analyze/stream for streaming EXPLAIN ANALYZE VERBOSE metrics.
experimental_enable_explain_analyze_stream = true
+## Whether to start the dedicated public HTTP **API** server. This server serves
+## only the `v1` interfaces plus the dashboard, and shares every other `[http]`
+## option with the main server. It is enabled by default.
+api_server_enable = true
+## Host of the dedicated HTTP API server. Defaults to `127.0.0.1`.
+api_server_host = "127.0.0.1"
+## Port of the dedicated HTTP API server. Defaults to `4006`.
+api_server_port = 4006
+
## The gRPC server options.
[grpc]
## The address to bind the gRPC server.
diff --git a/config/standalone.example.toml b/config/standalone.example.toml
index 3f141c8ad64..d20d582ac05 100644
--- a/config/standalone.example.toml
+++ b/config/standalone.example.toml
@@ -84,6 +84,15 @@ experimental_enable_prometheus_native_histogram = false
## Experimental: enable POST /v1/sql/analyze/stream for streaming EXPLAIN ANALYZE VERBOSE metrics.
experimental_enable_explain_analyze_stream = true
+## Whether to start the dedicated public HTTP **API** server. This server serves
+## only the `v1` interfaces plus the dashboard, and shares every other `[http]`
+## option with the main server. It is enabled by default.
+api_server_enable = true
+## Host of the dedicated HTTP API server. Defaults to `127.0.0.1`.
+api_server_host = "127.0.0.1"
+## Port of the dedicated HTTP API server. Defaults to `4006`.
+api_server_port = 4006
+
## The gRPC server options.
[grpc]
## The address to bind the gRPC server.
diff --git a/src/frontend/src/frontend.rs b/src/frontend/src/frontend.rs
index c7f7e71d34c..a3807ba7986 100644
--- a/src/frontend/src/frontend.rs
+++ b/src/frontend/src/frontend.rs
@@ -198,6 +198,16 @@ mod tests {
let _parsed: FrontendOptions = toml::from_str(&toml_string).unwrap();
}
+ #[test]
+ fn test_http_api_server_defaults_on_when_absent() {
+ // When `[http]` is not present in the config, the dedicated API server must
+ // still be enabled by default on port 4006.
+ let parsed: FrontendOptions = toml::from_str("").unwrap();
+ assert!(parsed.http.api_server_enable);
+ assert_eq!(parsed.http.api_server_port, 4006);
+ assert_eq!(parsed.http.api_server_host, "127.0.0.1");
+ }
+
struct SuspendableHeartbeatServer {
suspend: Arc,
}
diff --git a/src/frontend/src/server.rs b/src/frontend/src/server.rs
index 835be4fd600..54fd822b483 100644
--- a/src/frontend/src/server.rs
+++ b/src/frontend/src/server.rs
@@ -281,18 +281,21 @@ where
opts: &FrontendOptions,
toml: String,
request_memory_limiter: ServerMemoryLimiter,
- ) -> Result {
+ ) -> Result<(HttpServer, Option)> {
let builder = if let Some(builder) = self.http_server_builder.take() {
builder
} else {
self.http_server_builder(opts, request_memory_limiter)
};
- let http_server = builder
+ // The API server is configured entirely under `[http]` (`api_server_enable`,
+ // `api_server_host`, `api_server_port`) and shares every other `[http]`
+ // option with the main server.
+ let (internal, api) = builder
.with_metrics_handler(MetricsHandler)
.with_greptime_config_options(toml)
- .build();
- Ok(http_server)
+ .build_servers();
+ Ok((internal, api))
}
pub fn build(mut self) -> Result {
@@ -333,12 +336,22 @@ where
}
{
- // Always init HTTP server
+ // Always init the internal/full HTTP server (v1 + internal interfaces)
+ // and, when enabled, the dedicated HTTP API server (v1 + dashboard only).
let http_options = &opts.http;
let http_addr = parse_addr(&http_options.addr)?;
- let http_server =
+ let (http_server, http_api_server) =
self.build_http_server(&opts, toml, self.server_memory_limiter.clone())?;
handlers.insert((Box::new(http_server), http_addr));
+
+ if let Some(http_api_server) = http_api_server {
+ let http_api_addr = parse_addr(&format!(
+ "{}:{}",
+ http_options.api_server_host, http_options.api_server_port
+ ))?;
+ info!("HTTP API server is enabled at {}", http_api_addr);
+ handlers.insert((Box::new(http_api_server), http_api_addr));
+ }
}
if opts.mysql.enable {
diff --git a/src/servers/src/http.rs b/src/servers/src/http.rs
index 10ffba39db6..d12b9d28dd6 100644
--- a/src/servers/src/http.rs
+++ b/src/servers/src/http.rs
@@ -123,6 +123,8 @@ pub const HTTP_API_PREFIX: &str = "/v1/";
pub const HTTP_API_PREFIX_WITHOUT_TRAILING_SLASH: &str = "/v1";
/// Default http body limit (64M).
const DEFAULT_BODY_LIMIT: ReadableSize = ReadableSize::mb(64);
+/// Default address port for the public HTTP API server.
+const DEFAULT_HTTP_API_ADDR_PORT: u16 = 4006;
/// Authorization header
pub const AUTHORIZATION_HEADER: &str = "x-greptime-auth";
@@ -138,6 +140,9 @@ pub static PUBLIC_API_PREFIX: [&str; 4] = [
#[derive(Default)]
pub struct HttpServer {
router: StdMutex,
+ /// Accumulated internal-only (non-`v1`) routes such as `/metrics` and `/config`.
+ /// They are mounted on the internal/full HTTP server but not on the API-only server.
+ internal_router: StdMutex,
shutdown_tx: Mutex