Skip to content

Commit ef3ac16

Browse files
committed
utoipa init commit
1 parent e04653f commit ef3ac16

18 files changed

+807
-14
lines changed

Cargo.lock

+81
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ arrow-flight = { version = "52.1.0", features = [ "tls" ] }
2222
tonic = {version = "0.11.0", features = ["tls", "transport", "gzip", "zstd"] }
2323
tonic-web = "0.11.0"
2424
tower-http = { version = "0.4.4", features = ["cors"] }
25+
utoipa = {version = "4.2.3", features = ["actix_extras","chrono","openapi_extensions","preserve_order"]}
26+
utoipa-swagger-ui = {version = "7.1.0", features = ["actix-web"]}
2527

2628
### actix dependencies
2729
actix-web-httpauth = "0.8"

server/src/alerts/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use datafusion::arrow::datatypes::Schema;
2525
use regex::Regex;
2626
use serde::{Deserialize, Serialize};
2727
use std::fmt;
28+
use utoipa::ToSchema;
2829

2930
pub mod parser;
3031
pub mod rule;
@@ -39,7 +40,7 @@ use crate::{storage, utils};
3940
pub use self::rule::Rule;
4041
use self::target::Target;
4142

42-
#[derive(Default, Debug, serde::Serialize, serde::Deserialize)]
43+
#[derive(Default, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
4344
#[serde(rename_all = "camelCase")]
4445
pub struct Alerts {
4546
pub version: AlertVerison,

server/src/handlers/http/about.rs

+12
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ use std::path::PathBuf;
4848
/// "path": store_endpoint
4949
/// }
5050
/// }
51+
#[utoipa::path(
52+
get,
53+
tag = "about",
54+
context_path = "/api/v1",
55+
path = "/about",
56+
responses(
57+
(status = 200, body = Value)
58+
),
59+
security(
60+
("basic_auth" = [])
61+
)
62+
)]
5163
pub async fn about() -> Json<serde_json::Value> {
5264
let meta = StorageMetadata::global();
5365

server/src/handlers/http/cluster/utils.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ use itertools::Itertools;
2626
use reqwest::Response;
2727
use serde::{Deserialize, Serialize};
2828
use url::Url;
29+
use utoipa::ToSchema;
2930

30-
#[derive(Debug, Default, Serialize, Deserialize)]
31+
#[derive(Debug, Default, Serialize, Deserialize, ToSchema)]
3132
pub struct QueriedStats {
3233
pub stream: String,
3334
pub time: DateTime<Utc>,
@@ -81,7 +82,7 @@ impl ClusterInfo {
8182
}
8283
}
8384

84-
#[derive(Debug, Default, Serialize, Deserialize)]
85+
#[derive(Debug, Default, Serialize, Deserialize, ToSchema)]
8586
pub struct IngestionStats {
8687
pub count: u64,
8788
pub size: String,
@@ -114,7 +115,7 @@ impl IngestionStats {
114115
}
115116
}
116117

117-
#[derive(Debug, Default, Serialize, Deserialize)]
118+
#[derive(Debug, Default, Serialize, Deserialize, ToSchema)]
118119
pub struct StorageStats {
119120
pub size: String,
120121
pub format: String,

server/src/handlers/http/health_check.rs

+22
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,32 @@ use actix_web::HttpResponse;
2121

2222
use crate::option::CONFIG;
2323

24+
#[utoipa::path(
25+
get,
26+
tag = "health check",
27+
context_path = "/api/v1",
28+
path = "/liveness",
29+
responses(
30+
(status = 200, description = "The server is live.")
31+
)
32+
)]
2433
pub async fn liveness() -> HttpResponse {
2534
HttpResponse::new(StatusCode::OK)
2635
}
2736

37+
#[utoipa::path(
38+
get,
39+
tag = "health check",
40+
context_path = "/api/v1",
41+
path = "/readiness",
42+
responses(
43+
(status = 200, description = "The object store is live."),
44+
(status = 503, description = "Service Unavailable.")
45+
),
46+
security(
47+
("basic_auth" = [])
48+
)
49+
)]
2850
pub async fn readiness() -> HttpResponse {
2951
if CONFIG.storage().get_object_store().check().await.is_ok() {
3052
return HttpResponse::new(StatusCode::OK);

server/src/handlers/http/ingest.rs

+21
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,27 @@ async fn flatten_and_push_logs(
174174
// Handler for POST /api/v1/logstream/{logstream}
175175
// only ingests events into the specified logstream
176176
// fails if the logstream does not exist
177+
#[utoipa::path(
178+
post,
179+
tag = "logstream",
180+
context_path = "/api/v1",
181+
path = "/logstream/{logstream}",
182+
params(
183+
("logstream" = String, Path, description = "Name of stream")
184+
),
185+
request_body(
186+
content = Vec<Object>, description = "Log events"
187+
),
188+
responses(
189+
(status = 200, description = "Ingested event", body = Vec<String>),
190+
(status = 400, description = "Error", body = HttpResponse),
191+
(status = 500, description = "Failure", body = HttpResponse),
192+
(status = 404, description = "Stream not found", body = HttpResponse),
193+
),
194+
security(
195+
("basic_auth" = [])
196+
)
197+
)]
177198
pub async fn post_event(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostError> {
178199
let stream_name: String = req.match_info().get("logstream").unwrap().parse().unwrap();
179200
if stream_name.eq(INTERNAL_STREAM_NAME) {

0 commit comments

Comments
 (0)