VirtualService

2022-03-29 16:09 更新

入站流量的規(guī)則

VirtualService

VirtualService是用來處理入站流量的規(guī)則,也就是說用來描述哪些入站流量適用于該路由規(guī)則。

  • 使用示例
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/StandardRouter
spec:
  hosts:
  dubbo:
  • 屬性說明
FieldTypeDescriptionRequired
namestring 應(yīng)以 應(yīng)用名/Router類型的方式來命名。name屬性一經(jīng)定義Router類型就確定下來了YES
hostsstring[] 一般指應(yīng)用名NO
dubboDubboRoute[]dubbo 路由規(guī)則,順序執(zhí)行,符合條件立即返回NO
  • Router類型如下:
nameDescription
StandardRouter完全使用標(biāo)準(zhǔn) VirtualService 描述的 Router
待補(bǔ)充待補(bǔ)充

DubboRoute

DubboRoute是VirtualService中的屬性,用來描述路由策略的邊界。

  • 使用示例
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規(guī)則的名字,方便識(shí)別規(guī)則用意NO
servicesStringMatch[]規(guī)則生效的服務(wù)名列表,可使用具體的服務(wù)名,也可以使用正則 * 的方式進(jìn)行匹配;默認(rèn)不配置,則代表所有的服務(wù)都生效
faultdubboFaultInject[]故障注入(未實(shí)現(xiàn))NO
mirrorDestination鏡像流量(未實(shí)現(xiàn))NO
retriesDubboRetry[]重試相關(guān)(未實(shí)現(xiàn))NO
timeoutDubboTimeout[]超時(shí)相關(guān)(未實(shí)現(xiàn))NO
routedetailDubboRouteDetail[]具體的流量規(guī)則,順序執(zhí)行,符合條件立即返回YES

DubboRouteDetail

DubboRouteDetail用來描述詳細(xì)的路由規(guī)則

  • 使用示例
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規(guī)則詳情的名字,方便識(shí)別規(guī)則用意NO
matchDubboMatchRequest[]匹配條件YES
routeDubboRouteDestination[]符合條件的流量的實(shí)際目標(biāo)地址YES
mirrorDestination鏡像流量(未實(shí)現(xiàn))NO
retriesDubboRetry[]重試相關(guān)(未實(shí)現(xiàn))NO
timeoutDubboTimeout[]超時(shí)相關(guān)(未實(shí)現(xiàn))NO

DubboMatchRequest

DubboMatchRequest用來描述請(qǐng)求的匹配規(guī)則

  • 使用示例
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匹配規(guī)則名稱YES
methodDubboMethodMatch方法相關(guān)的匹配YES
sourceLabelsmap<string, string>調(diào)用端打的相關(guān) lables, 包含應(yīng)用名、機(jī)器分組、機(jī)器環(huán)境變量信息等; 對(duì)于 HSF-JAVA 來說,可以從上報(bào)的 URL 拿到對(duì)應(yīng)的 key/valueYES
attachmentsDubboAttachmentMatch請(qǐng)求附帶的其他信息,比如 HSF 請(qǐng)求上下文、Eagleeye 上下文等NO
headersmap<string, StringMatch>通用的請(qǐng)求協(xié)議字段等,如接口名、方法名、超時(shí)等NO
thresholdDoubleMatch調(diào)用的 subset 列表的機(jī)器,占整個(gè) host 的閥值NO

由于 headers 、attachemes 、method 之間可能存在字段一樣重復(fù)的情況,TODO 進(jìn)一步細(xì)化

DubboMethodMatch

DubboMethodMatch是用來實(shí)現(xiàn)方法的匹配

  • 使用示例
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匹配請(qǐng)求中的調(diào)用方法名YES
argcint匹配請(qǐng)求的參數(shù)個(gè)數(shù)NO
argsDubboMethodArg[]為 DubboMethodArg 類型的數(shù)組,表示每個(gè)參數(shù)值需要滿足的條件NO
argpStringMatch[]匹配請(qǐng)求的參數(shù)類型NO
headersmap<string, StringMatch>預(yù)留NO

DubboMethodArg

DubboMethodArg用來實(shí)現(xiàn)方法參數(shù)的匹配

  • 使用示例
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匹配參數(shù)的位置,index字段從1開始(即第$index個(gè)參數(shù))YES
typestring匹配參數(shù)的類型,以java的 string 類型為例,該字段取值 java.lang.String,該字段默認(rèn)為 java.lang.StringYES
str_valueListStringMatch匹配參數(shù)的值,根據(jù)$type進(jìn)行解析 ListStringMatcher:匹配 java.lang.String)NO
num_valueListDoubleMatch數(shù)值類型匹配NO
bool_valueBoolMatchbool 值類型匹配NO
reservereserve復(fù)雜類型的匹配,暫時(shí)不定義NO

DubboAttachmentMatch

DubboAttachmentMatch用來對(duì)任意對(duì)象的完全匹配

  • 使用示例
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 請(qǐng)求上下文NO

ListStringMatch

ListStringMatch是一組StringMatch集合,任何一個(gè) 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[]任何一個(gè)StringMatch匹配則匹配NO

StringMatch

StringMatch用來描述字符串匹配規(guī)則

  • 使用示例
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集合,任何一個(gè) DoubleMatch匹配則匹配參數(shù)

  • 使用示例
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[]任何一個(gè)DoubleMatch匹配則匹配NO

DoubleMatch

DoubleMatch用于匹配 int, long, double類型的數(shù)值

  • 使用示例
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
              #假設(shè)當(dāng)前輸入的Double類型的參數(shù)值為x,
              #則下面表達(dá)式的意思是:x%mode=exact, 
              #即當(dāng)x%10=6才匹配
              - exact: 6
                mode: 10
                  
  • 屬性說明
FieldTypeDescriptionRequired
exactdouble(oneof)數(shù)值完全匹配NO
rangeDoubleRangeMatch(oneof)數(shù)值范圍匹配NO
modedouble取模操作,需要與上面兩個(gè)語義一起配置使用NO

DoubleRangeMatch

DoubleRangeMatch是對(duì)double值的范圍進(jìn)行匹配

  • 使用示例
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數(shù)值大于或等于YES
enddouble數(shù)值小于YES

BoolMatch

BoolMatch用來對(duì)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(未實(shí)現(xiàn))

ObjectMatch用來對(duì)任意對(duì)象的完全匹配

  • 使用示例
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匹配參數(shù)的類型,以java的 string 類型為例,該字段取值 java.lang.String,該字段默認(rèn)為 java.lang.StringYES
str_valueListStringMatch匹配參數(shù)的值,根據(jù)$type進(jìn)行解析 ListStringMatcher:匹配 java.lang.String)NO
num_valueListDoubleMatchNO
bool_valueBoolMatchNO

DubboRouteDestination

DubboRouteDestination用來描述流量到目標(biāo)地址的策略

  • 使用示例
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/StandardRouter
spec:
  hosts:
  dubbo:
  - routedetail:
    - route: #DubboRouteDestination
        destination:
        weight: 50
  • 屬性說明
FieldTypeDescriptionRequired
destinationDubboDestination路由目標(biāo) DestinationYES
weightint路由權(quán)重NO

DubboDestination

DubboDestination用來描述路由流量的目標(biāo)地址

  • 使用示例
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注冊(cè)中心里面對(duì)應(yīng)的key值,現(xiàn)在是接口名YES
subsetstring地址列表YES
portint端口號(hào)YES
fallbackDubboDestinationfallback到的另外一個(gè)地址列表NO


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)