Skip to content

Commit

Permalink
drop common-api
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Feb 21, 2024
1 parent c2ccd24 commit bf1368b
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 80 deletions.
6 changes: 0 additions & 6 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ members = [
"src/catalog",
"src/client",
"src/cmd",
"src/common/api",
"src/common/base",
"src/common/catalog",
"src/common/config",
Expand Down Expand Up @@ -153,7 +152,6 @@ auth = { path = "src/auth" }
catalog = { path = "src/catalog" }
client = { path = "src/client" }
cmd = { path = "src/cmd" }
common-api = { path = "src/common/api" }
common-base = { path = "src/common/base" }
common-catalog = { path = "src/common/catalog" }
common-config = { path = "src/common/config" }
Expand Down
8 changes: 0 additions & 8 deletions src/common/api/Cargo.toml

This file was deleted.

7 changes: 0 additions & 7 deletions src/common/api/README.md

This file was deleted.

38 changes: 0 additions & 38 deletions src/common/api/src/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/common/error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ edition.workspace = true
license.workspace = true

[dependencies]
common-api.workspace = true
snafu.workspace = true
strum.workspace = true
6 changes: 5 additions & 1 deletion src/common/error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ pub mod format;
pub mod mock;
pub mod status_code;

pub use common_api::http_headers::{GREPTIME_DB_HEADER_ERROR_CODE, GREPTIME_DB_HEADER_ERROR_MSG};
pub use snafu;

// HACK - these headers are here for shared in gRPC services. For common HTTP headers,
// please define in `src/servers/src/http/header.rs`.
pub const GREPTIME_DB_HEADER_ERROR_CODE: &str = "x-greptime-err-code";
pub const GREPTIME_DB_HEADER_ERROR_MSG: &str = "x-greptime-err-msg";
1 change: 0 additions & 1 deletion src/servers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ base64.workspace = true
bytes.workspace = true
catalog.workspace = true
chrono.workspace = true
common-api.workspace = true
common-base.workspace = true
common-catalog.workspace = true
common-error.workspace = true
Expand Down
16 changes: 9 additions & 7 deletions src/servers/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,11 @@ pub enum Error {
},

#[snafu(display(
"Column: {}, {} incompatible, expected: {}, actual: {}",
column_name,
datatype,
expected,
actual
"Column: {}, {} incompatible, expected: {}, actual: {}",
column_name,
datatype,
expected,
actual
))]
IncompatibleSchema {
column_name: String,
Expand Down Expand Up @@ -438,7 +438,7 @@ pub enum Error {
MissingQueryContext { location: Location },

#[snafu(display(
"Invalid parameter, physical_table is not expected when metric engine is disabled"
"Invalid parameter, physical_table is not expected when metric engine is disabled"
))]
UnexpectedPhysicalTable { location: Location },
}
Expand Down Expand Up @@ -596,9 +596,11 @@ macro_rules! define_into_tonic_status {
($Error: ty) => {
impl From<$Error> for tonic::Status {
fn from(err: $Error) -> Self {
use common_error::{GREPTIME_DB_HEADER_ERROR_CODE, GREPTIME_DB_HEADER_ERROR_MSG};
use tonic::codegen::http::{HeaderMap, HeaderValue};
use tonic::metadata::MetadataMap;
use $crate::http::header::constants::{
GREPTIME_DB_HEADER_ERROR_CODE, GREPTIME_DB_HEADER_ERROR_MSG,
};

let mut headers = HeaderMap::<HeaderValue>::with_capacity(2);

Expand Down
2 changes: 1 addition & 1 deletion src/servers/src/http/error_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use axum::http::HeaderValue;
use axum::response::{IntoResponse, Response};
use axum::Json;
use common_api::http_headers::{GREPTIME_DB_HEADER_ERROR_CODE, GREPTIME_DB_HEADER_ERROR_MSG};
use common_error::ext::ErrorExt;
use common_error::status_code::StatusCode;
use common_telemetry::logging::{debug, error};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::http::header::constants::{GREPTIME_DB_HEADER_ERROR_CODE, GREPTIME_DB_HEADER_ERROR_MSG};
use crate::http::header::{GREPTIME_DB_HEADER_EXECUTION_TIME, GREPTIME_DB_HEADER_FORMAT};
use crate::http::ResponseFormat;

Expand Down
41 changes: 33 additions & 8 deletions src/servers/src/http/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,45 @@

use headers::{Header, HeaderName, HeaderValue};

pub mod constants {
// New HTTP headers would better distinguish use cases among:
// * GreptimeDB
// * GreptimeCloud
// * ...
//
// And thus trying to use:
// * x-greptime-db-xxx
// * x-greptime-cloud-xxx
//
// ... accordingly
//
// Most of the headers are for GreptimeDB and thus using `x-greptime-db-` as prefix.
// Only use `x-greptime-cloud` when it's intentionally used by GreptimeCloud.

// LEGACY HEADERS - KEEP IT UNMODIFIED
pub const GREPTIME_DB_HEADER_FORMAT: &str = "x-greptime-format";
pub const GREPTIME_DB_HEADER_EXECUTION_TIME: &str = "x-greptime-execution-time";
pub const GREPTIME_DB_HEADER_METRICS: &str = "x-greptime-metrics";
pub const GREPTIME_DB_HEADER_NAME: &str = "x-greptime-db-name";
pub const GREPTIME_TIMEZONE_HEADER_NAME: &str = "x-greptime-timezone";
pub const GREPTIME_DB_HEADER_ERROR_CODE: &str = common_error::GREPTIME_DB_HEADER_ERROR_CODE;
pub const GREPTIME_DB_HEADER_ERROR_MSG: &str = common_error::GREPTIME_DB_HEADER_ERROR_MSG;
}

pub static GREPTIME_DB_HEADER_FORMAT: HeaderName =
HeaderName::from_static(common_api::http_headers::GREPTIME_DB_HEADER_FORMAT);
HeaderName::from_static(constants::GREPTIME_DB_HEADER_FORMAT);
pub static GREPTIME_DB_HEADER_EXECUTION_TIME: HeaderName =
HeaderName::from_static(common_api::http_headers::GREPTIME_DB_HEADER_EXECUTION_TIME);
HeaderName::from_static(constants::GREPTIME_DB_HEADER_EXECUTION_TIME);
pub static GREPTIME_DB_HEADER_METRICS: HeaderName =
HeaderName::from_static(common_api::http_headers::GREPTIME_DB_HEADER_METRICS);
HeaderName::from_static(constants::GREPTIME_DB_HEADER_METRICS);

/// Header key of `db-name`. Example format of the header value is `greptime-public`.
pub static GREPTIME_DB_HEADER_NAME: HeaderName =
HeaderName::from_static(common_api::http_headers::GREPTIME_DB_HEADER_NAME);
HeaderName::from_static(constants::GREPTIME_DB_HEADER_NAME);

/// Header key of query specific timezone. Example format of the header value is `Asia/Shanghai` or `+08:00`.
pub static GREPTIME_TIMEZONE_HEADER_NAME: HeaderName =
HeaderName::from_static(common_api::http_headers::GREPTIME_TIMEZONE_HEADER_NAME);
HeaderName::from_static(constants::GREPTIME_TIMEZONE_HEADER_NAME);

pub struct GreptimeDbName(Option<String>);

Expand All @@ -37,9 +62,9 @@ impl Header for GreptimeDbName {
}

fn decode<'i, I>(values: &mut I) -> Result<Self, headers::Error>
where
Self: Sized,
I: Iterator<Item = &'i HeaderValue>,
where
Self: Sized,
I: Iterator<Item=&'i HeaderValue>,
{
if let Some(value) = values.next() {
let str_value = value.to_str().map_err(|_| headers::Error::invalid())?;
Expand Down

0 comments on commit bf1368b

Please sign in to comment.