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

rust插件支持发送外部请求 #1376

Closed
titrxw opened this issue Oct 10, 2024 · 17 comments
Closed

rust插件支持发送外部请求 #1376

titrxw opened this issue Oct 10, 2024 · 17 comments
Assignees
Labels

Comments

@titrxw
Copy link

titrxw commented Oct 10, 2024

Why do you need it?

Is your feature request related to a problem? Please describe in details
如题

How could it be?

A clear and concise description of what you want to happen. You can explain more about input of the feature, and output of it.

Other related information

Add any other context or screenshots about the feature request here.

@johnlanni
Copy link
Collaborator

这块已经有一个初步的实现,不过sdk还在优化中 cc @007gzs

@007gzs
Copy link
Collaborator

007gzs commented Oct 10, 2024

外部请求是指http_call么?

@titrxw
Copy link
Author

titrxw commented Oct 10, 2024

@007gzs 是的, 还有就是http_call这个没法同步返回响应结果(body,status)? 只能走回调?

@jizhuozhi
Copy link
Collaborator

jizhuozhi commented Oct 10, 2024

受限于envoy的IO模型,wasm是没办法写同步风格的外部调用的(GO也不行)。

之前想过能不能通过JS Promise风格的API来简化外部调用,刚好昨天实现了一个原型, #1377 ,可以看下能不能满足需求http-dispatch-example

@titrxw
Copy link
Author

titrxw commented Oct 11, 2024

看着可以, 我试试看

@titrxw
Copy link
Author

titrxw commented Oct 11, 2024

self.http_dispatcher.dispatch(
"httpbin",
vec![
(":method", "GET"),
(":path", "/bytes/1"),
(":authority", "httpbin.org"),
],
None,
vec![],
Duration::from_secs(1)
)

panicked at /Users/rxwyun/Develop/rust/higress/plugins/wasm-rust/src/dispatcher.rs │ │
│ :36:87: │ │
│ called Result::unwrap() on an Err value: BadArgument

BadArgument一般是什么原因?

@jizhuozhi
Copy link
Collaborator

这里httpbin是需要envoy有注册过这个cluster,如果没有配置话这里是没办法正确分配的

@007gzs
Copy link
Collaborator

007gzs commented Oct 11, 2024

@titrxw
Copy link
Author

titrxw commented Oct 12, 2024

经过网关的原始请求的数据包大小超过30K后, 插件里面如果设置cache_response_body为true, 会直接影响原始请求响应的下发。 这个是什么原因?

@007gzs
Copy link
Collaborator

007gzs commented Oct 12, 2024

经过网关的原始请求的数据包大小超过30K后, 插件里面如果设置cache_response_body为true, 会直接影响原始请求响应的下发。 这个是什么原因?

@johnlanni 网关缓存大小有限制么

@hanxiantao
Copy link
Collaborator

经过网关的原始请求的数据包大小超过30K后, 插件里面如果设置cache_response_body为true, 会直接影响原始请求响应的下发。 这个是什么原因?

应该是这个配置 downstream.connectionBufferLimits。可以看下这个文档全局配置说明

@titrxw
Copy link
Author

titrxw commented Oct 12, 2024

我修改下试试

@titrxw
Copy link
Author

titrxw commented Oct 14, 2024

可以了,感谢

@jizhuozhi
Copy link
Collaborator

可以了,感谢

可以了解下最终形态么,我们也看下怎么优化HTTP调用这块

@cuisongliu
Copy link

cuisongliu commented Oct 20, 2024

受限于envoy的IO模型,wasm是没办法写同步风格的外部调用的(GO也不行)。

之前想过能不能通过JS Promise风格的API来简化外部调用,刚好昨天实现了一个原型, #1377 ,可以看下能不能满足需求http-dispatch-example

我记得这个是因为envoy的wasm必须实现ABI协议才行 之前做过尝试应该是不大行的 不知道higress能否脱离这个。 https://github.com/proxy-wasm/spec

@johnlanni
Copy link
Collaborator

@cuisongliu 也是遵循这个ABI协议的,你是说基于wasi么,这个在envoy里不太现实。envoy本身有个eventloop,如果用wasi的异步IO,还需要在wasm里再起一个eventloop,两个eventloop之间目前无法联动。

@007gzs
Copy link
Collaborator

007gzs commented Oct 22, 2024

最新版支持回调模式了,可以看下

let self_rc = match self.weak.upgrade() {
Some(rc) => rc.clone(),
None => {
self.log.error("self_weak upgrade error");
return DataAction::Continue;
}
};
let http_call_res = self.http_call(
&cluster,
&Method::POST,
"http://httpbin.org/post",
MultiMap::new(),
Some("test_body".as_bytes()),
Box::new(move |status_code, headers, body| {
if let Some(this) = self_rc.borrow().downcast_ref::<DemoWasm>() {
this.log.info(&format!(
"test_callback status_code:{}, headers: {:?}, body: {}",
status_code,
headers,
format_body(body)
));
this.resume_http_request();
} else {
self_rc.borrow().resume_http_request();
}
}),
Duration::from_secs(5),
);
match http_call_res {
Ok(_) => DataAction::StopIterationAndBuffer,
Err(e) => {
self.log.info(&format!("http_call fail {:?}", e));
DataAction::Continue
}
}

@johnlanni johnlanni added this to Higress Nov 5, 2024
@johnlanni johnlanni moved this to Done in Higress Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

6 participants