-
Notifications
You must be signed in to change notification settings - Fork 173
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
Update the api for wasm functions; 设计 FaaS 编程 API #611
Comments
I understand it like defining an adaptation layer to decouple business logic from wasm implementation (proxy-wasm). What might be done is:
Maybe like spring-cloud-function, make faas functions written once and can run on different faas clouds:
中文我理解像是定义一个适配层接口,解耦业务逻辑与wasm实现(如proxy-wasm)。要做的可能是:
可能就像 spring-cloud-function 做的一样,使faas函数一次编写,可以运行在不同的faas云上:
|
Yes! I also prefer to keep using |
hello,我继续尝试下跟进这个问题 |
@leemos-xx Ok. Thanks! |
我上周比较忙没有跟进,这两天尝试理解了一下,有些疑问,麻烦有时间了帮忙解答下: 我大致看了下
最终会触发SDK中的方法:
用户在处理HTTP请求时,需要同时实现三个接口,这也就是上面讨论时提到的使用 我参看了一下阿里云、腾讯云以及谷歌云中“云函数”相关的文档,其中用户在开发函数时需要关注的主要概念包括:
可以看到云厂商的“云函数”在对HTTP Handler的定义上比wasm sdk更简单,更符合用户的开发习惯。但由于我前期没有参与Faas相关的讨论,所以我担心我的理解有偏差,主要疑问在于:
|
收到, @zhenjunMa 马老师有空帮忙看看哈 |
@leemos-xx
|
FaaS API考虑函数逻辑相对简单,目前先提供 1.
|
字段 | 说明 |
---|---|
requestId | 本次请求的唯一id,当出现问题时方便排查。 |
logger | 日志对象,用于格式化输出日志,提供不同的日志级别。 |
2. handleHttpRequest
当接收到HTTP请求时,触发该方法,用户在该方法中实现具体的业务逻辑。示例如下:
func handleHttpRequest(context fc.Context, req fc.HttpRequestEntity, resp fc.HttpResponseEntity) {
context.GetDefaultLogger().Debugf("receive header[Content-Type]: %s", req.getHeader(fc.ContentType));
context.GetDefaultLogger().Debugf("receive body: %s", req.getBody());
resp.setHeader(fc.ContentType, "text/plain");
resp.setBody([]byte("<h1>Hello, world!</h1>"));
}
2.1 request
HTTP请求结构体。
字段 | 类型 | 说明 |
---|---|---|
method | string | HTTP请求方法,如GET、POST、PUT、DELETE等。 |
path | string | HTTP请求路径。 |
headers | fc.HttpHeaders | 存放HTTP请求的请求头的键值对。 |
body | fc.HttpBody | HTTP请求体。 |
2.2 response
HTTP响应结构体。
字段 | 类型 | 说明 |
---|---|---|
statusCode | int | HTTP响应状态码。 |
headers | fc.HttpHeaders | 存放HTTP请求的请求头的键值对。 |
body | fc.HttpBody | HTTP请求体。 |
3. destroy
在函数被销毁时调用一次,可以供用户完成一些资源回收的操作。示例如下:
func destroy(context fc.Context) {
context.GetDefaultLogger().Info("destroy...")
}
@kevinten10 @zhenjunMa @rayowang 帮忙review 下? |
如果是GET请求,请求参数会放在path里面吗 |
我想在
此外,对强类型的语言,是不是也可以考虑增加一些对原始参数进行类型转换的方法,方便用户使用,如:
|
@leemos-xx
不过这种方案最大的问题是函数的入参类型怎么定义,比如名字上可以把你的 这里我只是做一个讨论,你可以参考一下阿里云,aws有没有这方面的设计,如果没有的话我们先只支持 http 协议访问函数也是可以的,你可以着手改一个目前的 FaaS Demo 试试 |
从长远来看,如果两种都支持呢。 从使用方的角度,如果要写一些通用逻辑,可能倾向于使用 假如,如果假如未来要两种都支持。 是不是一开始往 如果一开始往 |
那比如现在阶段把函数实现跟触发器分开,比如函数实现 总体来说我还是倾向于小步快跑,不用一次性搞的太复杂,一点点来好一点。 另外今天跟 @Mossaka 聊了一下,他推荐了一个 https://github.com/bytecodealliance/wit-bindgen 我们在Demo改造上可以参考一下这个项目看能不能用上,可以减少我们写转换层的工作量 我这周末也研究一下 |
/good-first-issue cancel |
This issue has been automatically marked as stale because it has not had recent activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue or help wanted) or other activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue or help wanted. Thank you for your contributions. |
1. Background
At present, the API that Layotto interacts with wasm functions is a set of specifications defined by proxy-wasm. The official description of the project is shown in the following figure:
The project itself designed for network proxies, such as envoy, and the goal is to support extending the functionality of envoy through wasm.
If a function developed based on this API wants to receive an http request, it needs to implement the following three interfaces:
This obviously does not meet the "simple" principle.
2. What we need to do
Maybe we can redefine a set of ABIs suitable for functions. The development form can refer to proxy-wasm. For example, create a new repository function-wasm to save the definition, and then use function-wasm-xx to save the specific implementation.
For the definition of function interfaces, please refer to:
It is not easy to define a set of APIs suitable for functions, but we do not need to be perfect at one time. What is more important is to start simple and follow the basic principle of "making functions simple enough for users".
中文
一、背景
目前 Layotto 跟 wasm 函数交互的 API 是使用 proxy-wasm 定义的一套规范,该项目的官方描述如下图所示:
它本身是面向网络代理设计的,目标是支持通过 wasm 扩展 envoy 的功能。
基于这套 API 开发的函数,如果想要接收一个 http request, 它需要实现如下三个接口:
这显然不符合“简单”的原则。
二、需要做什么
或许我们可以重新定义一套适用于函数的 ABI,开发形式可以参考 proxy-wasm, 比如新建一个仓库 function-wasm 来保存定义,然后通过 function-wasm-xx 来保存具体实现。
具体接口的定义可以参考:
想要定义一套适用于函数的 API 本身并不容易,但我们不需要大而全,更重要的是从简单开始,遵守函数场景下的基本原则"让用户开发函数足够简单"。
The text was updated successfully, but these errors were encountered: