Skip to content

Commit

Permalink
utoipa init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
parmesant committed Aug 14, 2024
1 parent 0df41a7 commit 52ca04f
Show file tree
Hide file tree
Showing 18 changed files with 807 additions and 14 deletions.
81 changes: 81 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ arrow-flight = { version = "52.1.0", features = [ "tls" ] }
tonic = {version = "0.11.0", features = ["tls", "transport", "gzip", "zstd"] }
tonic-web = "0.11.0"
tower-http = { version = "0.4.4", features = ["cors"] }
utoipa = {version = "4.2.3", features = ["actix_extras","chrono","openapi_extensions","preserve_order"]}
utoipa-swagger-ui = {version = "7.1.0", features = ["actix-web"]}

### actix dependencies
actix-web-httpauth = "0.8"
Expand Down
3 changes: 2 additions & 1 deletion server/src/alerts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use datafusion::arrow::datatypes::Schema;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::fmt;
use utoipa::ToSchema;

pub mod parser;
pub mod rule;
Expand All @@ -39,7 +40,7 @@ use crate::{storage, utils};
pub use self::rule::Rule;
use self::target::Target;

#[derive(Default, Debug, serde::Serialize, serde::Deserialize)]
#[derive(Default, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct Alerts {
pub version: AlertVerison,
Expand Down
12 changes: 12 additions & 0 deletions server/src/handlers/http/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ use std::path::PathBuf;
/// "path": store_endpoint
/// }
/// }
#[utoipa::path(
get,
tag = "about",
context_path = "/api/v1",
path = "/about",
responses(
(status = 200, body = Value)
),
security(
("basic_auth" = [])
)
)]
pub async fn about() -> Json<serde_json::Value> {
let meta = StorageMetadata::global();

Expand Down
7 changes: 4 additions & 3 deletions server/src/handlers/http/cluster/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ use itertools::Itertools;
use reqwest::Response;
use serde::{Deserialize, Serialize};
use url::Url;
use utoipa::ToSchema;

#[derive(Debug, Default, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize, ToSchema)]
pub struct QueriedStats {
pub stream: String,
pub time: DateTime<Utc>,
Expand Down Expand Up @@ -81,7 +82,7 @@ impl ClusterInfo {
}
}

#[derive(Debug, Default, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize, ToSchema)]
pub struct IngestionStats {
pub count: u64,
pub size: String,
Expand Down Expand Up @@ -114,7 +115,7 @@ impl IngestionStats {
}
}

#[derive(Debug, Default, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize, ToSchema)]
pub struct StorageStats {
pub size: String,
pub format: String,
Expand Down
22 changes: 22 additions & 0 deletions server/src/handlers/http/health_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,32 @@ use actix_web::HttpResponse;

use crate::option::CONFIG;

#[utoipa::path(
get,
tag = "health check",
context_path = "/api/v1",
path = "/liveness",
responses(
(status = 200, description = "The server is live.")
)
)]
pub async fn liveness() -> HttpResponse {
HttpResponse::new(StatusCode::OK)
}

#[utoipa::path(
get,
tag = "health check",
context_path = "/api/v1",
path = "/readiness",
responses(
(status = 200, description = "The object store is live."),
(status = 503, description = "Service Unavailable.")
),
security(
("basic_auth" = [])
)
)]
pub async fn readiness() -> HttpResponse {
if CONFIG.storage().get_object_store().check().await.is_ok() {
return HttpResponse::new(StatusCode::OK);
Expand Down
21 changes: 21 additions & 0 deletions server/src/handlers/http/ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ async fn flatten_and_push_logs(
// Handler for POST /api/v1/logstream/{logstream}
// only ingests events into the specified logstream
// fails if the logstream does not exist
#[utoipa::path(
post,
tag = "logstream",
context_path = "/api/v1",
path = "/logstream/{logstream}",
params(
("logstream" = String, Path, description = "Name of stream")
),
request_body(
content = Vec<Object>, description = "Log events"
),
responses(
(status = 200, description = "Ingested event", body = Vec<String>),
(status = 400, description = "Error", body = HttpResponse),
(status = 500, description = "Failure", body = HttpResponse),
(status = 404, description = "Stream not found", body = HttpResponse),
),
security(
("basic_auth" = [])
)
)]
pub async fn post_event(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostError> {
let stream_name: String = req.match_info().get("logstream").unwrap().parse().unwrap();
let internal_stream_names = STREAM_INFO.list_internal_streams();
Expand Down
Loading

0 comments on commit 52ca04f

Please sign in to comment.