apache / dubbo-go

Go Implementation For Apache Dubbo .
https://dubbo.apache.org/
Apache License 2.0
4.67k stars 910 forks source link

Design and implement new conditional rules V3.1 #2686

Closed YarBor closed 1 month ago

YarBor commented 1 month ago

to support #2684

Doc for New Routing Configuration

Configuration Format

This doc show how to set up condition-router configurations for your services/application.

The configurations are defined in a YAML format and must adhere to specific rules and parameters to ensure proper functioning.

Examples

configVersion: v3.1 # be v3.1 or V3.1 to use this
scope: service      # must be 'service' or 'application'
key: org.apache.dubbo.samples.CommentService # [service name] or [application name]
force: false        # decide hole condition route an empty set, return err Or ignore this rule
runtime: true       # decide is use cache
enabled: true       # decide is the rule enabled 
conditions:         # contains by many conditions, sort by condition.priority

  - priority: 10    # default 0, expect > 0
    from:           # match consumer-side url, match fail jump next condition, match success to match provider-side urls
      match: region=$region & version=v1    # string, use '&' to separate rules
    trafficDisable: false # default false, if set true & from match successfully,
                          # it will ignore ./{'to','force','ratio'} value AND ../../{'force'} value, return empty.
    to:             # match provider-side urls, contains by many destination-subsets
      - match: env=$env & region=shanghai   # if match fail, ignore subset
        weight: 100                         # int, default 100, Max INT_MAX, Min 0
      - match: env=$env & region=beijing
        weight: 200
      - match: env=$env & region=hangzhou
        weight: 300
    force: false    # here [force] decide to jump next or return empty, when get empty peer-set or ratio check false
    ratio: 20       # default 0, Max 100, Min 0 -- e.g. expect $result/$all-peers >= 20% -- fail to jump next(or return empty [decide by key(force)])

# e.g. this condition rule will ban all traffic which sent from version=1
  - priority: 5     
    from:
      match: version=v1
    trafficDisable: true

# e.g. this condition rule will show how to set region priority
  - priority: 20
    from:
      match:
    to:
      - match: region=$region
    ratio: 20

Configuration Structure

Top-Level Structure

Conditions

Each condition block contains the following parameters:

Matching and Filtering Conditions

Supported Parameters

Condition Operators

Value Support

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
2.5% Duplication on New Code

See analysis details on SonarCloud

wcy666103 commented 1 month ago

Is it better to trafficDisable by default to false? Every traffic rule that is written should be meaningful by default, instead of having to be shown to be false, and a false value that works by default gives the impression that it doesn't work, I think it can be set to false to reduce that thinking for the user and omit the line by default