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

Add support for Dapr API #361

Closed
Tracked by #539
seeflood opened this issue Dec 13, 2021 · 15 comments · Fixed by #377
Closed
Tracked by #539

Add support for Dapr API #361

seeflood opened this issue Dec 13, 2021 · 15 comments · Fixed by #377
Assignees
Labels
kind/enhancement New feature or request stale

Comments

@seeflood
Copy link
Member

seeflood commented Dec 13, 2021

TLDR

本提案想让开源Layotto 既支持 Layotto API,又支持Dapr API。类似于“Minio 既支持Minio API,又支持AWS S3 API”

想解决的问题

  1. 目前,我们尽量保证Layotto API 里各个字段定义的和Dapr一样,但用户真正关心的是两者sdk能否复用。虽然我们努力保证proto字段一致,但只要不能复用sdk就没解决用户的问题,还给自己增加维护成本。
    比如:
    image
    因此,我们想让Layotto直接支持Dapr的grpc API (一模一样,包括 package名),对于用户来说,他可以用Dapr sdk在两者之间自由切换,不用担心被厂商绑定。

  2. 另一方面,还需要有一定扩展性。我们在生产落地的过程中发现目前的Dapr API没法完全满足需求,难免要对API做一些扩展。扩展的API已经加到了现在的 Layotto API里,提案提给了 Dapr 社区、但还在等社区慢慢接受,比如config API,比如Lock API

方案

Layotto API on Dapr API

image

  1. Layotto 会启动一个grpc服务器,前阵子刚加了个API插件功能,我们可以通过 API插件的形式注册一个Dapr API 插件;
  2. 另一方面,保留Layotto API。Layotto接收到Layotto API请求后,翻译成Dapr API,然后按Dapr API处理。
    这样的好处有:
  • 复用代码
  • Layotto API 可以按生产需求进行扩展,比如支持Lock API,configuration API等;做了扩展后可以提给Dapr 社区,再慢慢讨论,即使最终讨论的结果和原始方案不一样,也只是影响最终做出来的Dapr API,不会影响已经用上Layotto API的用户。

用户价值

对于用户来说:
如果用户担心厂商绑定,可以只用Dapr API,可以用同一套Dapr sdk在Dapr 和Layotto 之间迁移,减少用户疑虑;
如果用户相信我们的落地经验、愿意用Layotto API,那他们可以用Layotto API,代价是没法用同一个sdk在两个sidecar之间迁移

Q&A

想给Dapr API加字段怎么加

想加个字段(field)

比如想给layotto api加个abc字段,可以通过metadata或者grpc头把这个字段传给dapr API
dapr API的实现再把这个字段透传给组件,组件解析这个字段

不只加字段,还要加一些逻辑、机制(mechanism)

比如layotto api加个abc字段,如果abc==true,那么runtime走一段特殊逻辑
这种情况要修改Dapr API的实现,加一段if else

想加新API怎么加

加在layotto API上,新API不需要复用Dapr API;等Dapr接收提案后再修改实现,layotto API不变

@seeflood
Copy link
Member Author

seeflood commented Dec 14, 2021

Stable Version:

Alpha version:
- [ ] Configuration
- [ ] QueryStateAlpha1

@zach030
Copy link
Contributor

zach030 commented Dec 23, 2021

I am willing to take this issue

@seeflood
Copy link
Member Author

@zach030 Cool ! Which API would u want to implement?

@zach030
Copy link
Contributor

zach030 commented Dec 23, 2021

@zach030 Cool ! Which API would u want to implement?

I wanna try State API.
I also want to know the difference with the implementation in dapr, compared with the definition in dapr api, is it necessary to be the same?
image

@seeflood
Copy link
Member Author

seeflood commented Dec 23, 2021

@zach030 OK
We just keep the proto definition and corrosponding .pb.go files same with dapr's.
As for the implementation , it's ok to be different. You can check InvokeService and InvokeBinding in dapr_api.go. These code was in layotto's api.go. I just moved it here and then....we support Dapr's InvokeService API ! Yeah !
image

@zach030
Copy link
Contributor

zach030 commented Dec 23, 2021

@zach030 OK We just keep the proto definition and corrosponding .pb.go files same with dapr's. As for the implementation , it's ok to be different. You can check InvokeService and InvokeBinding in dapr_api.go. These code was in layotto's api.go. I just moved it here and then....we support Dapr's InvokeService API ! Yeah ! image

Thx, I got it!

@seeflood seeflood added good first issue Good for newcomers help wanted Extra attention is needed labels Dec 23, 2021
@zach030
Copy link
Contributor

zach030 commented Dec 25, 2021

@seeflood I was working on it these days, It's easy to implement the logic but I still have some confusions.

  1. I need to write lots of code to transfer struct which defined in dapr runtime to layotto runtime . Any better solutions to improve it cause they were defined with the same proto file?
    	key, err := runtime_state.GetModifiedStateKey(s.Key, request.StoreName, d.appId)
    	if err != nil {
    		return &emptypb.Empty{}, err
    	}
    	s1 := &runtimev1pb.StateItem{
    		Key:      s.Key,
    		Value:    s.Value,
    		Etag:     &runtimev1pb.Etag{Value: s.Etag.Value},
    		Metadata: s.Metadata,
    		Options: &runtimev1pb.StateOptions{
    			Concurrency: runtimev1pb.StateOptions_StateConcurrency(s.Options.Concurrency),
    			Consistency: runtimev1pb.StateOptions_StateConsistency(s.Options.Consistency),
    		},
    	}
    	reqs = append(reqs, *converter.StateItem2SetRequest(s1, key))
    
  2. I have to overwrite some method in layotto's api like func getStateStore(name string) (state.Store, error) because the receiver is daprGrpcAPI now. Go not supprt Generics now, So it's a little annoying.

@seeflood
Copy link
Member Author

seeflood commented Dec 27, 2021

@seeflood I was working on it these days, It's easy to implement the logic but I still have some confusions.

  1. I need to write lots of code to transfer struct which defined in dapr runtime to layotto runtime . Any better solutions to improve it cause they were defined with the same proto file?

Yes,this is a problem. I'm working on a PR #375 to extract reusable code.
For example, we can refactor function func StateConcurrencyToString(c runtimev1pb.StateOptions_StateConcurrency) string to func StateConcurrencyToString(c int32) string

Wait a minute ,let me think about it

  1. I have to overwrite some method in layotto's api like func getStateStore(name string) (state.Store, error) because the receiver is daprGrpcAPI now. Go not supprt Generics now, So it's a little annoying.

Sorry I don't understand 😢 Could u give an example or submit a WIP pull request that we can have discussion on?

@seeflood
Copy link
Member Author

seeflood commented Dec 27, 2021

@zach030 The converter code is inevitable (and annoying) :(
But I don't understand these GetModifiedStateKey logic you refered to :
image
I added the Dapr SaveState API as an example in #375
image

@zach030
Copy link
Contributor

zach030 commented Dec 27, 2021

@zach030 The converter code is inevitable (and annoying) :( But I don't understand these GetModifiedStateKey logic you refered to : image I added the Dapr SaveState API as an example in #375 image

感谢!我之前的理解有点偏差🥲,这里结构转换的代码和重复的代码比较多,所以对自己写的代码有点困惑。
另外,在#375 中给出的示例中我看到,在原来(a *api) SaveState方法中调用了daprGrpcAPI的SaveState实现,我也需要修改default_api/api.go 中与state相关的其他几个方法吗?

@seeflood
Copy link
Member Author

另外,在#375 中给出的示例中我看到,在原来(a *api) SaveState方法中调用了daprGrpcAPI的SaveState实现,我也需要修改default_api/api.go 中与state相关的其他几个方法吗?

对的,大致的方案就是把原来 default_api/api.go 里的代码挪到 dapr/dapr_api.go ,然后 default_api/api.go 改成调用 dapr/dapr_api.go,相当于把layotto协议翻译成dapr协议

@seeflood
Copy link
Member Author

seeflood commented Mar 4, 2022

Dapr pubsub API will be assigned to @LXPWing
You can take #377 and #362 as examples

@Xunzhuo
Copy link
Member

Xunzhuo commented Mar 6, 2023

/good-first-issue cancel
/help-wanted cancel

@github-actions github-actions bot removed good first issue Good for newcomers help wanted Extra attention is needed labels Mar 6, 2023
@github-actions
Copy link

github-actions bot commented Apr 7, 2023

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.

@github-actions github-actions bot added the stale label Apr 7, 2023
@github-actions
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants