Skip to content

Commit

Permalink
refactor: remove built-in apidocs and schemars (#5068)
Browse files Browse the repository at this point in the history
* feat: feature gate apidocs

* refactor: remove built-in apidocs and schemars

* remove redoc html
  • Loading branch information
sunng87 authored Nov 29, 2024
1 parent d931389 commit 3626383
Show file tree
Hide file tree
Showing 24 changed files with 62 additions and 228 deletions.
24 changes: 0 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ rstest = "0.21"
rstest_reuse = "0.7"
rust_decimal = "1.33"
rustc-hash = "2.0"
schemars = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["float_roundtrip"] }
serde_with = "3"
Expand Down
3 changes: 1 addition & 2 deletions src/common/version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ license.workspace = true
workspace = true

[features]
codec = ["dep:serde", "dep:schemars"]
codec = ["dep:serde"]

[dependencies]
const_format = "0.2"
schemars = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
shadow-rs.workspace = true

Expand Down
5 changes: 1 addition & 4 deletions src/common/version/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ impl Display for BuildInfo {
}

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "codec",
derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)
)]
#[cfg_attr(feature = "codec", derive(serde::Serialize, serde::Deserialize))]
pub struct OwnedBuildInfo {
pub branch: String,
pub commit: String,
Expand Down
3 changes: 1 addition & 2 deletions src/servers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition.workspace = true
license.workspace = true

[features]
default = []
dashboard = []
mem-prof = ["dep:common-mem-prof"]
pprof = ["dep:common-pprof"]
Expand All @@ -15,7 +16,6 @@ workspace = true

[dependencies]
ahash = "0.8"
aide = { version = "0.9", features = ["axum"] }
api.workspace = true
arrow.workspace = true
arrow-flight.workspace = true
Expand Down Expand Up @@ -92,7 +92,6 @@ rust-embed = { version = "6.6", features = ["debug-embed"] }
rustls = { version = "0.23", default-features = false, features = ["ring", "logging", "std", "tls12"] }
rustls-pemfile = "2.0"
rustls-pki-types = "1.0"
schemars.workspace = true
serde.workspace = true
serde_json.workspace = true
session.workspace = true
Expand Down
83 changes: 21 additions & 62 deletions src/servers/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ use std::net::SocketAddr;
use std::sync::Mutex as StdMutex;
use std::time::Duration;

use aide::axum::{routing as apirouting, ApiRouter, IntoApiResponse};
use aide::openapi::{Info, OpenApi, Server as OpenAPIServer};
use aide::OperationOutput;
use async_trait::async_trait;
use auth::UserProviderRef;
use axum::error_handling::HandleErrorLayer;
use axum::extract::DefaultBodyLimit;
use axum::response::{Html, IntoResponse, Json, Response};
use axum::{middleware, routing, BoxError, Extension, Router};
use axum::response::{IntoResponse, Json, Response};
use axum::{middleware, routing, BoxError, Router};
use common_base::readable_size::ReadableSize;
use common_base::Plugins;
use common_error::status_code::StatusCode;
Expand All @@ -39,7 +36,6 @@ use datatypes::schema::SchemaRef;
use datatypes::value::transform_value_ref_to_json_value;
use event::{LogState, LogValidatorRef};
use futures::FutureExt;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use snafu::{ensure, ResultExt};
Expand Down Expand Up @@ -148,7 +144,7 @@ impl Default for HttpOptions {
}
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Eq, PartialEq)]
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct ColumnSchema {
name: String,
data_type: String,
Expand All @@ -160,7 +156,7 @@ impl ColumnSchema {
}
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Eq, PartialEq)]
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct OutputSchema {
column_schemas: Vec<ColumnSchema>,
}
Expand Down Expand Up @@ -188,7 +184,7 @@ impl From<SchemaRef> for OutputSchema {
}
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Eq, PartialEq)]
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct HttpRecordsOutput {
schema: OutputSchema,
rows: Vec<Vec<Value>>,
Expand Down Expand Up @@ -264,7 +260,7 @@ impl HttpRecordsOutput {
}
}

#[derive(Serialize, Deserialize, Debug, JsonSchema, Eq, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum GreptimeQueryOutput {
AffectedRows(usize),
Expand Down Expand Up @@ -352,7 +348,7 @@ impl Display for Epoch {
}
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Debug)]
pub enum HttpResponse {
Arrow(ArrowResponse),
Csv(CsvResponse),
Expand Down Expand Up @@ -420,10 +416,6 @@ impl IntoResponse for HttpResponse {
}
}

impl OperationOutput for HttpResponse {
type Inner = Response;
}

impl From<ArrowResponse> for HttpResponse {
fn from(value: ArrowResponse) -> Self {
HttpResponse::Arrow(value)
Expand Down Expand Up @@ -466,14 +458,6 @@ impl From<JsonResponse> for HttpResponse {
}
}

async fn serve_api(Extension(api): Extension<OpenApi>) -> impl IntoApiResponse {
Json(api)
}

async fn serve_docs() -> Html<String> {
Html(include_str!("http/redoc.html").to_owned())
}

#[derive(Clone)]
pub struct ApiState {
pub sql_handler: ServerSqlQueryHandlerRef,
Expand All @@ -490,45 +474,28 @@ pub struct HttpServerBuilder {
options: HttpOptions,
plugins: Plugins,
user_provider: Option<UserProviderRef>,
api: OpenApi,
router: Router,
}

impl HttpServerBuilder {
pub fn new(options: HttpOptions) -> Self {
let api = OpenApi {
info: Info {
title: "GreptimeDB HTTP API".to_string(),
description: Some("HTTP APIs to interact with GreptimeDB".to_string()),
version: HTTP_API_VERSION.to_string(),
..Info::default()
},
servers: vec![OpenAPIServer {
url: format!("/{HTTP_API_VERSION}"),
..OpenAPIServer::default()
}],
..OpenApi::default()
};
Self {
options,
plugins: Plugins::default(),
user_provider: None,
api,
router: Router::new(),
}
}

pub fn with_sql_handler(
mut self,
self,
sql_handler: ServerSqlQueryHandlerRef,
script_handler: Option<ScriptHandlerRef>,
) -> Self {
let sql_router = HttpServer::route_sql(ApiState {
sql_handler,
script_handler,
})
.finish_api(&mut self.api)
.layer(Extension(self.api.clone()));
});

Self {
router: self
Expand Down Expand Up @@ -635,11 +602,10 @@ impl HttpServerBuilder {
Self { plugins, ..self }
}

pub fn with_greptime_config_options(mut self, opts: String) -> Self {
pub fn with_greptime_config_options(self, opts: String) -> Self {
let config_router = HttpServer::route_config(GreptimeOptionsConfigState {
greptime_config_options: opts,
})
.finish_api(&mut self.api);
});

Self {
router: self.router.nest("", config_router),
Expand Down Expand Up @@ -791,22 +757,15 @@ impl HttpServer {
.with_state(log_state)
}

fn route_sql<S>(api_state: ApiState) -> ApiRouter<S> {
ApiRouter::new()
.api_route(
"/sql",
apirouting::get_with(handler::sql, handler::sql_docs)
.post_with(handler::sql, handler::sql_docs),
)
.api_route(
fn route_sql<S>(api_state: ApiState) -> Router<S> {
Router::new()
.route("/sql", routing::get(handler::sql).post(handler::sql))
.route(
"/promql",
apirouting::get_with(handler::promql, handler::sql_docs)
.post_with(handler::promql, handler::sql_docs),
routing::get(handler::promql).post(handler::promql),
)
.api_route("/scripts", apirouting::post(script::scripts))
.api_route("/run-script", apirouting::post(script::run_script))
.route("/private/api.json", apirouting::get(serve_api))
.route("/private/docs", apirouting::get(serve_docs))
.route("/scripts", routing::post(script::scripts))
.route("/run-script", routing::post(script::run_script))
.with_state(api_state)
}

Expand Down Expand Up @@ -902,9 +861,9 @@ impl HttpServer {
.with_state(otlp_handler)
}

fn route_config<S>(state: GreptimeOptionsConfigState) -> ApiRouter<S> {
ApiRouter::new()
.route("/config", apirouting::get(handler::config))
fn route_config<S>(state: GreptimeOptionsConfigState) -> Router<S> {
Router::new()
.route("/config", routing::get(handler::config))
.with_state(state)
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/servers/src/http/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use pipeline::error::PipelineTransformSnafu;
use pipeline::util::to_pipeline_version;
use pipeline::PipelineVersion;
use prost::Message;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::{Deserializer, Map, Value};
use session::context::{Channel, QueryContext, QueryContextRef};
Expand Down Expand Up @@ -89,7 +88,7 @@ lazy_static! {
];
}

#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct LogIngesterQueryParams {
pub table: Option<String>,
pub db: Option<String>,
Expand Down
Loading

0 comments on commit 3626383

Please sign in to comment.