VirtualService

入站流量的规则

VirtualService

VirtualService是用来处理入站流量的规则,也就是说用来描述哪些入站流量适用于该路由规则。

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  • 属性说明
FieldTypeDescriptionRequired
namestring 应以 应用名/Router类型的方式来命名。name属性一经定义Router类型就确定下来了YES
hostsstring[] 一般指应用名NO
dubboDubboRoute[]dubbo 路由规则,顺序执行,符合条件立即返回NO

Router类型如下:

nameDescription
StandardRouter完全使用标准 VirtualService 描述的 Router
待补充待补充

DubboRoute

DubboRouteVirtualService中的属性,用来描述路由策略的边界。

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo: #DubboRoute
  8. - name:
  9. service:
  10. fault:
  11. mirror:
  12. retries:
  13. timeout:
  14. routedetail:
  • 属性说明
FieldTypeDescriptionRequired
namestring规则的名字,方便识别规则用意NO
servicesStringMatch[]规则生效的服务名列表,可使用具体的服务名,也可以使用正则 * 的方式进行匹配;默认不配置,则代表所有的服务都生效
faultdubboFaultInject[]故障注入(未实现)NO
mirrorDestination镜像流量(未实现)NO
retriesDubboRetry[]重试相关(未实现)NO
timeoutDubboTimeout[]超时相关(未实现)NO
routedetailDubboRouteDetail[]具体的流量规则,顺序执行,符合条件立即返回YES

DubboRouteDetail

DubboRouteDetail用来描述详细的路由规则

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail: #DubboRouteDetail
  9. - name:
  10. match:
  11. route:
  12. mirror:
  13. retries:
  14. timeout:
  • 属性说明
FieldTypeDescriptionRequired
namestring规则详情的名字,方便识别规则用意NO
matchDubboMatchRequest[]匹配条件YES
routeDubboRouteDestination[]符合条件的流量的实际目标地址YES
mirrorDestination镜像流量(未实现)NO
retriesDubboRetry[]重试相关(未实现)NO
timeoutDubboTimeout[]超时相关(未实现)NO

DubboMatchRequest

DubboMatchRequest用来描述请求的匹配规则

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - match: #DubboMatchRequest
  10. - name:
  11. method:
  12. sourceLabels:
  13. attachments:
  14. headers:
  15. threshold:
  • 属性说明
FieldTypeDescriptionRequired
namestring匹配规则名称YES
methodDubboMethodMatch方法相关的匹配YES
sourceLabelsmap<string, string>调用端打的相关 lables, 包含应用名、机器分组、机器环境变量信息等; 对于 HSF-JAVA 来说,可以从上报的 URL 拿到对应的 key/valueYES
attachmentsDubboAttachmentMatch请求附带的其他信息,比如 HSF 请求上下文、Eagleeye 上下文等NO
headersmap<string, StringMatch>通用的请求协议字段等,如接口名、方法名、超时等NO
thresholdDoubleMatch调用的 subset 列表的机器,占整个 host 的阀值NO

由于 headers 、attachemes 、method 之间可能存在字段一样重复的情况,TODO 进一步细化

DubboMethodMatch

DubboMethodMatch是用来实现方法的匹配

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - match:
  10. - method: #DubboMethodRequest
  11. - name_match:
  12. argc:
  13. args:
  14. argp:
  15. headers:
  • 属性说明
FieldTypeDescriptionRequired
name_matchStringMatch匹配请求中的调用方法名YES
argcint匹配请求的参数个数NO
argsDubboMethodArg[]为 DubboMethodArg 类型的数组,表示每个参数值需要满足的条件NO
argpStringMatch[]匹配请求的参数类型NO
headersmap<string, StringMatch>预留NO

DubboMethodArg

DubboMethodArg用来实现方法参数的匹配

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - match:
  10. - method:
  11. - args: #DubboMethodArg
  12. - index:
  13. str_value:
  14. type:
  15. num_value:
  16. bool_value:
  17. reserve:
  • 属性说明
FieldTypeDescriptionRequired
indexuint32匹配参数的位置,index字段从1开始(即第$index个参数)YES
typestring匹配参数的类型,以java的 string 类型为例,该字段取值 java.lang.String,该字段默认为 java.lang.StringYES
str_valueListStringMatch匹配参数的值,根据$type进行解析 ListStringMatcher:匹配 java.lang.String)NO
num_valueListDoubleMatch数值类型匹配NO
bool_valueBoolMatchbool 值类型匹配NO
reservereserve复杂类型的匹配,暂时不定义NO

DubboAttachmentMatch

DubboAttachmentMatch用来对任意对象的完全匹配

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - match:
  10. - attachments: #DubboAttachmentMatch
  11. eagleeyecontext:
  12. dubbocontext:
  • 属性说明
FieldTypeDescriptionRequired
eagleeyecontextmap<string, StringMatch>鹰眼上下文NO
dubbocontextmap<string, StringMatch>Dubbo 请求上下文NO

ListStringMatch

ListStringMatch是一组StringMatch集合,任何一个 StringMatch匹配则匹配

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - match:
  10. - method:
  11. - args:
  12. - index: 1
  13. str_value: #ListStringMatch
  14. oneof:
  15. - regex: "*abc*"
  16. - exact: parameter-1
  • 属性说明
FieldTypeDescriptionRequired
oneofStringMatch[]任何一个StringMatch匹配则匹配NO

StringMatch

StringMatch用来描述字符串匹配规则

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - service: #StringMatch
  9. - exact: org.apache.dubbo.demoService:1.0.0
  10. - prefix: org.apache.dubbo.hello
  11. - regex: org.apache.dubbo.*Service:2.0.0
  • 属性说明
FieldTypeDescriptionRequired
exactstring (oneof)完全匹配NO
prefixstring (oneof)前缀匹配NO
regexstring (oneof)正则匹配NO
noemptystring (oneof)非空字符匹配NO
emptystring (oneof)空字符匹配NO

ListDoubleMatch

ListDoubleMatch是一组DoubleMatch集合,任何一个 DoubleMatch匹配则匹配参数

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - match:
  10. - method:
  11. - args:
  12. - index: 1
  13. type: java.lang.Double
  14. num_value: #ListDoubleMatch
  15. oneof:
  16. - range:
  17. start: 1
  18. end: 100
  • 属性说明
FieldTypeDescriptionRequired
oneofDoubleMatch[]任何一个DoubleMatch匹配则匹配NO

DoubleMatch

DoubleMatch用于匹配 int, long, double类型的数值

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - match:
  10. - method:
  11. - args:
  12. - index: 1
  13. type: java.lang.Double
  14. num_value:
  15. oneof: #DoubleMatch[]
  16. - range:
  17. start: 1
  18. end: 100
  19. #假设当前输入的Double类型的参数值为x,
  20. #则下面表达式的意思是:x%mode=exact,
  21. #即当x%10=6才匹配
  22. - exact: 6
  23. mode: 10
  • 属性说明
FieldTypeDescriptionRequired
exactdouble(oneof)数值完全匹配NO
rangeDoubleRangeMatch(oneof)数值范围匹配NO
modedouble取模操作,需要与上面两个语义一起配置使用NO

DoubleRangeMatch

DoubleRangeMatch是对double值的范围进行匹配

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - match:
  10. - method:
  11. - args:
  12. - index: 1
  13. type: java.lang.Double
  14. num_value:
  15. oneof:
  16. - range: #DoubleRangeMatch
  17. start: 1.2
  18. end: 1000.5
  • 属性说明
FieldTypeDescriptionRequired
startdouble数值大于或等于YES
enddouble数值小于YES

BoolMatch

BoolMatch用来对true, false的完全匹配

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - match:
  10. - method:
  11. - args:
  12. - index: 1
  13. type: java.lang.Boolean
  14. bool_value: #BoolMatch
  15. - exact: true
  • 属性说明
FieldTypeDescriptionRequired
exactbool(oneof)true, false ,完全匹配

ObjectMatch(未实现)

ObjectMatch用来对任意对象的完全匹配

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - match:
  10. - method:
  11. - args:
  12. - index: 1
  13. type: java.lang.String
  14. str_value:
  15. oneof:
  16. - regex: "*abc*"
  17. - exact: parameter-1
  • 属性说明
FieldTypeDescriptionRequired
typestring匹配参数的类型,以java的 string 类型为例,该字段取值 java.lang.String,该字段默认为 java.lang.StringYES
str_valueListStringMatch匹配参数的值,根据$type进行解析 ListStringMatcher:匹配 java.lang.String)NO
num_valueListDoubleMatchNO
bool_valueBoolMatchNO

DubboRouteDestination

DubboRouteDestination用来描述流量到目标地址的策略

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - route: #DubboRouteDestination
  10. destination:
  11. weight: 50
  • 属性说明
FieldTypeDescriptionRequired
destinationDubboDestination路由目标 DestinationYES
weightint路由权重NO

DubboDestination

DubboDestination用来描述路由流量的目标地址

  • 使用示例
  1. apiVersion: service.dubbo.apache.org/v1alpha1
  2. kind: VirtualService
  3. metadata:
  4. name: demo/StandardRouter
  5. spec:
  6. hosts:
  7. dubbo:
  8. - routedetail:
  9. - route: #DubboRouteDestination
  10. destination:
  11. host:
  12. subnet:
  13. port:
  14. fallback:
  • 属性说明
FieldTypeDescriptionRequired
hoststring注册中心里面对应的key值,现在是接口名YES
subsetstring地址列表YES
portint端口号YES
fallbackDubboDestinationfallback到的另外一个地址列表NO