Skip to content

Commit

Permalink
Merge branch 'master' into add-admin-package
Browse files Browse the repository at this point in the history
  • Loading branch information
RWDai committed Nov 2, 2023
2 parents 1c59091 + 0f03a1b commit 90442b0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
urlencoding = { version = "2" }

# Tardis
tardis = { version = "0.1.0-rc.2" }
tardis = { version = "0.1.0-rc.3" }
# tardis = { path = "../tardis/tardis" }
# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "25baf2a" }

Expand Down
4 changes: 2 additions & 2 deletions kernel/res/spacegate-httproute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ spec:
default: 5000
description: TimeoutMs specifies the timeout for backend by milliseconds
format: int32
maximum: 1000000
maximum: 10000000
minimum: 1
type: integer
required:
Expand Down Expand Up @@ -1640,7 +1640,7 @@ spec:
default: 5000
description: TimeoutMs specifies the timeout for rules by milliseconds
format: int32
maximum: 1000000
maximum: 10000000
minimum: 1
type: integer
type: object
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/functions/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub async fn request(
let url = format!("{}://{}{}{}", scheme, host, port, ctx.request.get_uri().path_and_query().map(|p| p.as_str()).unwrap_or(""));
let timeout_ms = if let Some(timeout_ms) = backend.timeout_ms { Some(timeout_ms) } else { rule_timeout_ms };
ctx = do_request(client, &url, timeout_ms, ctx).await?;
ctx.set_chose_backend(backend);
ctx.set_chose_backend_inst(backend);
}
Ok(ctx)
}
Expand Down
7 changes: 6 additions & 1 deletion kernel/src/functions/http_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ pub async fn process(gateway_name: Arc<String>, req_scheme: &str, (remote_addr,
&gateway_inst.filters,
matched_rule_inst,
matched_match_inst,
backend,
)
.await?;

Expand Down Expand Up @@ -701,8 +702,9 @@ async fn process_req_filters_http(
global_filters: &[(String, BoxSgPluginFilter)],
matched_rule_inst: Option<&SgHttpRouteRuleInst>,
matched_match_inst: Option<&SgHttpRouteMatchInst>,
matched_backend_inst: Option<&SgBackendInst>,
) -> TardisResult<SgRoutePluginContext> {
let ctx = SgRoutePluginContext::new_http(
let mut ctx = SgRoutePluginContext::new_http(
request.method().clone(),
request.uri().clone(),
request.version(),
Expand All @@ -712,6 +714,9 @@ async fn process_req_filters_http(
gateway_name,
matched_rule_inst.map(|m| ChosenHttpRouteRuleInst::clone_from(m, matched_match_inst)),
);
if let Some(back_inst) = matched_backend_inst {
ctx.set_chose_backend_inst(back_inst);
}
process_req_filters(ctx, backend_filters, rule_filters, route_filters, global_filters).await
}

Expand Down
3 changes: 3 additions & 0 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ pub mod helpers;
pub mod instance;
pub mod plugins;

#[inline]
pub async fn startup_k8s(namespace: Option<String>) -> TardisResult<()> {
startup(true, namespace, None).await
}

#[inline]
pub async fn startup_native(conf_uri: String, check_interval_sec: u64) -> TardisResult<()> {
startup(false, Some(conf_uri), Some(check_interval_sec)).await
}

#[inline]
pub async fn startup_simplify(conf_path: String, check_interval_sec: u64) -> TardisResult<()> {
startup(false, Some(conf_path), Some(check_interval_sec)).await
}
Expand Down
18 changes: 15 additions & 3 deletions kernel/src/plugins/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,20 @@ impl SgRoutePluginContext {
self.action = action;
}

pub fn set_chose_backend(&mut self, chose_backend: &SgBackendInst) {
self.chosen_backend = Some(AvailableBackendInst::clone_from(chose_backend));
pub fn set_chose_backend_inst(&mut self, chose_backend: &SgBackendInst) {
self.set_chose_backend(AvailableBackendInst::clone_from(chose_backend));
}

pub fn set_chose_backend(&mut self, chose_backend: AvailableBackendInst) {
self.chosen_backend = Some(chose_backend);
}

pub fn get_chose_backend(&self) -> Option<AvailableBackendInst> {
self.chosen_backend.clone()
}

pub fn get_chose_backend_name(&self) -> Option<String> {
self.chosen_backend.clone().map(|b| b.name_or_host)
self.get_chose_backend().map(|b| b.name_or_host)
}

pub fn get_available_backend(&self) -> Vec<&AvailableBackendInst> {
Expand Down Expand Up @@ -643,6 +651,10 @@ impl SgRoutePluginContext {
self.ident_info = Some(cert_info);
}

pub fn get_remote_addr(&self) -> SocketAddr {
self.request.remote_addr
}

#[cfg(feature = "cache")]
pub async fn cache(&self) -> TardisResult<std::sync::Arc<tardis::cache::cache_client::TardisCacheClient>> {
crate::functions::cache_client::get(&self.gateway_name).await
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/plugins/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ macro_rules! def_filter {
fn get_code(&self) -> &'static str {
CODE
}
fn inst(&self, spec: serde_json::Value) -> TardisResult<$crate::plugins::filters::BoxSgPluginFilter> {
fn inst(&self, spec: serde_json::Value) -> tardis::basic::result::TardisResult<$crate::plugins::filters::BoxSgPluginFilter> {
let filter = tardis::TardisFuns::json.json_to_obj::<$filter_type>(spec)?;
Ok(filter.boxed())
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/plugins/filters/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ mod tests {
Some(ChosenHttpRouteRuleInst::clone_from(&SgHttpRouteRuleInst { ..Default::default() }, None)),
);

ctx.set_chose_backend(&mock_backend);
ctx.set_chose_backend_inst(&mock_backend);

let ctx = ctx.resp_from_error(TardisError::bad_request("mock resp error", ""));
let (is_ok, ctx) = stats.resp_filter("id1", ctx).await.unwrap();
Expand Down

0 comments on commit 90442b0

Please sign in to comment.