Skip to content

bug: traffic-split plugin do not match if the first matcher failed #6288

Description

@tangzhenhuang

Issue description

According to the plugin's documentation: https://apisix.apache.org/docs/apisix/plugins/traffic-split/
I configured two rules:

"traffic-split": {
      "rules": [
        {
          "match": [
            {
              "vars": [
                [
                  "http_x-my-header",
                  "==",
                  "1"
                ]
              ]
            }
          ],
          "weighted_upstreams": [
            {
              "upstream_id": "demo-1",
              "weight": 100
            }
          ]
        },
        {
          "weighted_upstreams": [
            {
              "upstream_id": "demo-2",
              "weight": 50
            },
            {
              "weight": 50
            }
          ]
        }
      ]
    }

When the first rule does not match, the second rule also fails, I looked at the relevant code, the problem should be here:
image

Environment

  • apisix version (cmd: apisix version): 2.12.0

Steps to reproduce

1、create arbitrary routes
2、add traffic-split plugin for it config like above
3、access the relevant route, intentionally not matching the first rule

Actual result

The second rule is ignored

Error log

2022/02/10 19:46:47 [info] 137#137: *898767 [lua] traffic-split.lua:264: phase_func(): match_passed: false, client: 127.0.0.1, server: _, request: "GET /demo/ip HTTP/1.1", host: "test.com"

Expected result

The second rule should be matched

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions