VirtualService

入站流量的规则

此文档已经不再维护。您当前查看的是快照版本。如果想要查看最新版本的文档,请参阅最新版本

VirtualService

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

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

DubboRoute

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

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

DubboRouteDetail

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

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

DubboMatchRequest

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

  • 使用示例
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/StandardRouter
spec:
  hosts:
  dubbo:
  - routedetail:
    - match: #DubboMatchRequest
      - name:
        method:
        sourceLabels:
        attachments:
        headers:
        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是用来实现方法的匹配

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

DubboMethodArg

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

  • 使用示例
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/StandardRouter
spec:
  hosts:
  dubbo:
  - routedetail:
    - match:
      - method:
        - args: #DubboMethodArg
          - index:
            str_value:
            type:
            num_value:
            bool_value:
            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用来对任意对象的完全匹配

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

ListStringMatch

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

  • 使用示例
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/StandardRouter
spec:
  hosts:
  dubbo:
  - routedetail:
    - match:
      - method:
        - args:
          - index: 1
            str_value:  #ListStringMatch
              oneof:
              - regex: "*abc*"
              - exact: parameter-1
  • 属性说明
FieldTypeDescriptionRequired
oneofStringMatch[]任何一个StringMatch匹配则匹配NO

StringMatch

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

  • 使用示例
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/StandardRouter
spec:
  hosts:
  dubbo:
  - service: #StringMatch
    - exact: org.apache.dubbo.demoService:1.0.0
    - prefix: org.apache.dubbo.hello
    - 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匹配则匹配参数

  • 使用示例
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/StandardRouter
spec:
  hosts:
  dubbo:
  - routedetail:
    - match:
      - method:
        - args:
          - index: 1
            type: java.lang.Double
            num_value: #ListDoubleMatch
              oneof:
              - range:
                  start: 1
                  end: 100
                  
  • 属性说明
FieldTypeDescriptionRequired
oneofDoubleMatch[]任何一个DoubleMatch匹配则匹配NO

DoubleMatch

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

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

DoubleRangeMatch

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

  • 使用示例
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/StandardRouter
spec:
  hosts:
  dubbo:
  - routedetail:
    - match:
      - method:
        - args:
          - index: 1
            type: java.lang.Double
            num_value:
              oneof:
              - range: #DoubleRangeMatch
                  start: 1.2
                  end: 1000.5
                  
  • 属性说明
FieldTypeDescriptionRequired
startdouble数值大于或等于YES
enddouble数值小于YES

BoolMatch

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

  • 使用示例
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/StandardRouter
spec:
  hosts:
  dubbo:
  - routedetail:
    - match:
      - method:
        - args: 
          - index: 1
            type: java.lang.Boolean
            bool_value: #BoolMatch
              - exact: true
  • 属性说明
FieldTypeDescriptionRequired
exactbool(oneof)true, false ,完全匹配

ObjectMatch(未实现)

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

  • 使用示例
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/StandardRouter
spec:
  hosts:
  dubbo:
  - routedetail:
    - match:
      - method:
        - args: 
          - index: 1
            type: java.lang.String
            str_value:
              oneof:
              - regex: "*abc*"
              - 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用来描述流量到目标地址的策略

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

DubboDestination

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

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

最后修改 May 10, 2023: Fix blog & java sdk (#2590) (262c1c9724)