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

Spring Cloud Alibaba Traffic Governance Scheme Design | Spring Cloud Alibaba流量治理方案设计 #2700

Open
HHoflittlefish777 opened this issue Aug 8, 2022 · 10 comments
Labels
kind/discussion Mark as discussion issues/pr
Milestone

Comments

@HHoflittlefish777
Copy link
Contributor

HHoflittlefish777 commented Aug 8, 2022

Background

Spring Cloud Alibaba microservice governance capabilities are relatively weak, we currently intends to dock Istio to complete the traffic governance function, and need to abstract Spring Cloud Alibaba's own governance data rules to facilitate docking.

Scheme Design

Desgin Idea

The initially intended module is called spring-cloud-starter-alibaba-governance, which contains two main modules: resource-transform and gainance-core:

resource-transform
 -istio-resource-transform
  opensergo-resource-transform
  
governance-core
 -label-routing
  service-authentication

CRD Design

hosts:
  user-Service:
    name:java-user-service #The caller service name
    version:v2
  target-service:
    name:java-target-service #The service name that is invoked matches the following routing rule
-match:
  rule:
    -type: header 
     condition: exact 
     key: 'region'   
     value: beijing  
   - type: url-path 
     condition: prefix 
     value: /test  
   - type: url-parameter 
     condition: eaxct
     key: uid
     value: 1
  route:
     version: v2
     weight: 10
-match:  
  rule:
   - type: header 
     condition: eaxct
     key: 'cookie'  
     value: shanghai  
   - type: header 
     condition: regex
     key: 'uid'   
     value: /^\+?[1-9][0-9]*$/  
  route:
     version: v2
     weight: 10
default-routeversion: v1

Design Describe

Each service in the microservice system has its own traffic rules, and considering that each service only needs to save its own service rules, a user-sevice is provided to identify the service corresponding to the service governance rules, and taget-service represents the service name of the call. For traffic matching, the match rule is also an array that allows multiple routes to exist. Each route provides a rule array to match, and a rule array may contain multiple tpye, each with different rules. Finally, if none of the above rules match, it matches to the default path.
All the supported types are shown in the following table (more types will be supported later):

Type condition Example
header exact regex -type: header condition: exact key: 'region' value: beijing - type: header condition: regex key: 'uid' value: /^+?[1-9][0-9]*$/
url-path exact prefix regex - type: url-path condition: exact value: /test - type: url-path condition: prefix value: /test - type: url-path condition: regex value: ^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=_|!:,.;]*[-a-zA-Z0-9+&@#/%=_|]
url-parameter exact regex -type: url-parameter condition: exact key: 'region' value: beijing - type: header condition: regex key: 'uid' value: /^+?[1-9][0-9]*$/

背景

Spring Cloud Alibaba微服务治理能力比较弱,目前打算对接istio完成流量治理功能,需要抽象出Spring Cloud Alibaba自己的治理数据规则方便对接。

方案设计

设计思路

初步打算模块名称为spring-cloud-starter-alibaba-governance,其中包含两个主要模块:resource-transform和governance-core:

resource-transform
 -istio-resource-transform
  opensergo-resource-transform
  
governance-core
 -label-routing
  service-authentication

目前打算对接Istio,后续SCA可能还会对接其他控制面进行流量治理,考虑到可拓展性,将数据层抽象出来放在label-routing中,后续对接openSergo等控制面时直接将opensergo数据结构转化成该数据结构即可。无需进行其他修改。

设计方案

hosts:
  user-Service:
    name:java-user-service #调用方服务名
    version:v2
  target-service:
    name:java-target-service #被调用的服务名,匹配下面的路由规则
-match:
  rule:
    -type: header # 请求头匹配
     condition: exact # 精确匹配
     key: 'region'   # 参数名
     value: beijing  # 参数值
   - type: url-path # url路径匹配
     condition: prefix #前缀匹配
     value: /test  
   - type: url-parameter # url参数匹配
     condition: eaxct
     key: uid
     value: 1
  route:
     version: v2
     weight: 10
-match:  
  rule:
   - type: header 
     condition: eaxct
     key: 'cookie'  
     value: shanghai  
   - type: header 
     condition: regex
     key: 'uid'   
     value: /^\+?[1-9][0-9]*$/  
  route:
     version: v2
     weight: 10
default-routeversion: v1

方案说明

微服务体系中的每一个服务都有自己的流量规则,同时,考虑到每一个服务只需保存自己的服务规则,提供了user-sevice来对服务治理规则对应的服务进行标识,taget-service表示调用的服务名称。对于流量匹配,匹配规则(match)也是一个数组,允许多个路径(route)存在。每一个路径(route)都提供了一个rule数组来匹配,一个rule数组中可能包含多个tpye,每一个type的规则都不同。最后,如果上述规则都无法匹配,则匹配到默认的路径中。
支持的所有类型如下表所示(后续会支持更多的的类型):

类型 条件 示例
header exact 精确匹配regex 正则表达式 -type: header condition: exact key: 'region' value: beijing - type: header condition: regex key: 'uid' value: /^+?[1-9][0-9]*$/
url-path exact 精确匹配prefix 前缀regex 正则表达式 - type: url-path condition: exact value: /test - type: url-path condition: prefix value: /test - type: url-path condition: regex value: ^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=_|!:,.;]*[-a-zA-Z0-9+&@#/%=_|]
url-parameter exact 精确匹配regex 正则表达式 -type: header condition: exact key: 'region' value: beijing - type: header condition: regex key: 'uid' value: /^+?[1-9][0-9]*$/
@HHoflittlefish777
Copy link
Contributor Author

If there are any suggestions or governance options that the community wants to implement, they can be discussed here
如果有任何建议或者希望社区实现的治理方案可以在这里讨论

@steverao steverao added the kind/discussion Mark as discussion issues/pr label Aug 9, 2022
@steverao steverao changed the title Traffic Governance CRD Scheme Design 流量治理CRD方案设计 Spring Cloud Alibaba Traffic Governance Scheme Design | Spring Cloud Alibaba流量治理方案设计 Aug 9, 2022
@steverao
Copy link
Collaborator

steverao commented Aug 9, 2022

方案说明里面格式有些乱,最好保持格式的简洁和清晰!

@icodening
Copy link

是否有考虑将dubbo路由也纳入,用同样的配置模型来配置不同协议的路由,可以降低用户的学习成本

@steverao
Copy link
Collaborator

是否有考虑将dubbo路由也纳入,用同样的配置模型来配置不同协议的路由,可以降低用户的学习成本

能再详细说明一下你的意思吗?不是特别理解你说的纳入dubbo路由。

@HHoflittlefish777
Copy link
Contributor Author

是否有考虑将dubbo路由也纳入,用同样的配置模型来配置不同协议的路由,可以降低用户的学习成本

未来spring cloud alibaba 会对接opensergo控制面,dubbo也在opensergo的蓝图中,可以无缝转化。实际上,这不是spring cloud Alibaba定义的规则,他是将控制面的规则转化为该数据结构,无需学习。

@icodening
Copy link

是否有考虑将dubbo路由也纳入,用同样的配置模型来配置不同协议的路由,可以降低用户的学习成本

能再详细说明一下你的意思吗?不是特别理解你说的纳入dubbo路由。

就是疑惑是否会把dubbo路由治理也规划进来。不过HHoflittlefish777同学已经解答了我的疑惑了 🙏

@cevencheng
Copy link
Contributor

我看到route里面有 version,是已经包含了灰度的能力在规划里面吗 ? @HHoflittlefish777 @steverao

@HHoflittlefish777
Copy link
Contributor Author

我看到route里面有 version,是已经包含了灰度的能力在规划里面吗 ? @HHoflittlefish777 @steverao

是的

@HHoflittlefish777
Copy link
Contributor Author

我看到route里面有 version,是已经包含了灰度的能力在规划里面吗 ? @HHoflittlefish777 @steverao

后续我们会提供详细的文档,包括使用场景方面

@cevencheng
Copy link
Contributor

我看到route里面有 version,是已经包含了灰度的能力在规划里面吗 ? @HHoflittlefish777 @steverao

后续我们会提供详细的文档,包括使用场景方面

非常不错的一个特性,很期待。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/discussion Mark as discussion issues/pr
Projects
None yet
Development

No branches or pull requests

4 participants