Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge trino query code changes to main #923

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
608 changes: 331 additions & 277 deletions server/src/cli.rs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions server/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const COOKIE_AGE_DAYS: usize = 7;
const SESSION_COOKIE_NAME: &str = "session";
const USER_COOKIE_NAME: &str = "username";

//constants for trino
const TRINO_SCHEMA: &str = "x-trino-schema";
const TRINO_CATALOG: &str = "x-trino-catalog";
const TRINO_USER: &str = "x-trino-user";

// constants for log Source values for known sources and formats
const LOG_SOURCE_KINESIS: &str = "kinesis";

Expand Down
1 change: 1 addition & 0 deletions server/src/handlers/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod otel;
pub(crate) mod query;
pub(crate) mod rbac;
pub(crate) mod role;
pub(crate) mod trino;
pub mod users;
pub const MAX_EVENT_PAYLOAD_SIZE: usize = 10485760;
pub const API_BASE_PATH: &str = "api";
Expand Down
30 changes: 12 additions & 18 deletions server/src/handlers/http/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

use actix_web::web::Json;
use human_size::SpecificSize;
use serde_json::json;

use crate::{
Expand Down Expand Up @@ -79,21 +78,6 @@ pub async fn about() -> Json<serde_json::Value> {
let is_oidc_active = CONFIG.parseable.openid.is_some();
let ui_version = option_env!("UI_VERSION").unwrap_or("development");

let cache_details: String = if CONFIG.cache_dir().is_none() {
"Disabled".to_string()
} else {
let cache_dir: &Option<PathBuf> = CONFIG.cache_dir();
let cache_size: SpecificSize<human_size::Gigibyte> =
SpecificSize::new(CONFIG.cache_size() as f64, human_size::Byte)
.unwrap()
.into();
format!(
"Enabled, Path: {} (Size: {})",
cache_dir.as_ref().unwrap().display(),
cache_size
)
};

let hot_tier_details: String = if CONFIG.hot_tier_dir().is_none() {
"Disabled".to_string()
} else {
Expand All @@ -105,6 +89,16 @@ pub async fn about() -> Json<serde_json::Value> {
};

let ms_clarity_tag = &CONFIG.parseable.ms_clarity_tag;
let mut query_engine = "Parseable".to_string();
if let (Some(_), Some(_), Some(_), Some(_)) = (
CONFIG.parseable.trino_endpoint.as_ref(),
CONFIG.parseable.trino_catalog.as_ref(),
CONFIG.parseable.trino_schema.as_ref(),
CONFIG.parseable.trino_username.as_ref(),
) {
// Trino is enabled
query_engine = "Trino".to_string();
}

Json(json!({
"version": current_version,
Expand All @@ -119,7 +113,6 @@ pub async fn about() -> Json<serde_json::Value> {
"license": "AGPL-3.0-only",
"mode": mode,
"staging": staging,
"cache": cache_details,
"hotTier": hot_tier_details,
"grpcPort": grpc_port,
"store": {
Expand All @@ -128,7 +121,8 @@ pub async fn about() -> Json<serde_json::Value> {
},
"analytics": {
"clarityTag": ms_clarity_tag
}
},
"queryEngine": query_engine

}))
}
1 change: 1 addition & 0 deletions server/src/handlers/http/modal/query_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl QueryServer {
web::scope(&base_path())
// POST "/query" ==> Get results of the SQL query passed in request body
.service(Server::get_query_factory())
.service(Server::get_trino_factory())
.service(Server::get_cache_webscope())
.service(Server::get_liveness_factory())
.service(Server::get_readiness_factory())
Expand Down
8 changes: 8 additions & 0 deletions server/src/handlers/http/modal/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::handlers::http::base_path;
use crate::handlers::http::cache;
use crate::handlers::http::health_check;
use crate::handlers::http::query;
use crate::handlers::http::trino;
use crate::handlers::http::users::dashboards;
use crate::handlers::http::users::filters;
use crate::handlers::http::API_BASE_PATH;
Expand Down Expand Up @@ -169,6 +170,7 @@ impl Server {
web::scope(&base_path())
// POST "/query" ==> Get results of the SQL query passed in request body
.service(Self::get_query_factory())
.service(Self::get_trino_factory())
.service(Self::get_cache_webscope())
.service(Self::get_ingest_factory())
.service(Self::get_liveness_factory())
Expand All @@ -187,6 +189,12 @@ impl Server {
.service(Self::get_generated());
}

// get the trino factory
pub fn get_trino_factory() -> Resource {
web::resource("/trinoquery")
.route(web::post().to(trino::trino_query).authorize(Action::Query))
}

pub fn get_metrics_webscope() -> Scope {
web::scope("/metrics").service(
web::resource("").route(web::get().to(metrics::get).authorize(Action::Metrics)),
Expand Down
6 changes: 6 additions & 0 deletions server/src/handlers/http/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,9 @@ impl actix_web::ResponseError for QueryError {
.body(self.to_string())
}
}

impl From<reqwest::Error> for QueryError {
fn from(value: reqwest::Error) -> Self {
QueryError::Anyhow(anyhow::Error::msg(value.to_string()))
}
}
Loading
Loading