feat: add docs

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-08-10 00:17:12 +02:00
parent a5196b005e
commit cf321d110e
Signed by: kjuulh
GPG Key ID: D85D7535F18F35FA
4 changed files with 563 additions and 496 deletions

965
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1 +1,24 @@
# nodata
Nodata is a simple binary that consists of two parts:
1. Data ingest
2. Data storage
3. Data aggregation
4. Data API / egress
## Data ingest
Nodata presents a simple protobuf grpc api for ingesting either single events or batch
## Data storage
Nodata stores data locally in a parquet partitioned scheme
## Data aggregation
Nodata accepts wasm routines for running aggregations over data to be processed
## Data Egress
Nodata exposes aggregations as apis, or events to be sent as grpc streamed apis to a service.

View File

@ -13,6 +13,13 @@ dotenv.workspace = true
axum.workspace = true
serde = { version = "1.0.197", features = ["derive"] }
sqlx = { version = "0.7.3", features = ["runtime-tokio", "tls-rustls", "postgres", "uuid", "time"] }
sqlx = { version = "0.7.3", features = [
"runtime-tokio",
"tls-rustls",
"postgres",
"uuid",
"time",
] }
uuid = { version = "1.7.0", features = ["v4"] }
tower-http = { version = "0.5.2", features = ["cors", "trace"] }
mad = { git = "https://github.com/kjuulh/mad", branch = "main" }

View File

@ -3,9 +3,10 @@ use std::{net::SocketAddr, ops::Deref, sync::Arc};
use anyhow::Context;
use axum::extract::MatchedPath;
use axum::http::Request;
use axum::Router;
use axum::routing::get;
use axum::Router;
use clap::{Parser, Subcommand};
use mad::{Mad, MadError};
use sqlx::{Pool, Postgres};
use tower_http::trace::TraceLayer;
@ -36,32 +37,42 @@ async fn main() -> anyhow::Result<()> {
let state = SharedState(Arc::new(State::new().await?));
let app = Router::new()
.route("/", get(root))
.with_state(state.clone())
.layer(
TraceLayer::new_for_http().make_span_with(|request: &Request<_>| {
// Log the matched route's path (with placeholders not filled in).
// Use request.uri() or OriginalUri if you want the real path.
let matched_path = request
.extensions()
.get::<MatchedPath>()
.map(MatchedPath::as_str);
let state = state.clone();
Mad::builder()
.add_fn(move |_cancel| {
let state = state.clone();
async move {
let app = Router::new()
.route("/", get(root))
.with_state(state.clone())
.layer(TraceLayer::new_for_http().make_span_with(
|request: &Request<_>| {
let matched_path = request
.extensions()
.get::<MatchedPath>()
.map(MatchedPath::as_str);
tracing::info_span!(
"http_request",
method = ?request.method(),
matched_path,
some_other_field = tracing::field::Empty,
)
}), // ...
);
tracing::info_span!(
"http_request",
method = ?request.method(),
matched_path,
some_other_field = tracing::field::Empty,
)
},
));
tracing::info!("listening on {}", host);
let listener = tokio::net::TcpListener::bind(host).await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
tracing::info!("listening on {}", host);
let listener = tokio::net::TcpListener::bind(host).await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.context("axum server stopped")
.map_err(MadError::Inner)?;
Ok(())
}
})
.run()
.await?;
}
Ok(())
@ -103,4 +114,3 @@ impl State {
Ok(Self { db })
}
}