0z5a opened a new pull request, #1091:
URL: https://github.com/apache/dubbo-go-pixiu/pull/1091
**What this PR does**:
In `dgp.filter.http.traffic`, a cluster that sets `canary-weight` but no
`canary-by-header` catches every request that does not carry a
`canary-by-header` header, so the configured weights are ignored.
With two rules on `/user`, `user-v1` at `canary-weight: 80` and `user-v2` at
`canary-weight: 20`, every request goes to `user-v1`. Swapping the weights to
20/80 still sends every request to `user-v1`. A single rule `user-canary` at
`canary-weight: 20` takes all of the traffic instead of about 20%, and the
route's own cluster gets none.
I loaded these configs through `FilterManager.Apply`, ran 2000 requests per
config through `PrepareFilterChain`/`OnDecode` and counted `ctx.Route.Cluster`.
On `develop` (923b6a6c): 80/20 gives `user-v1: 2000`, 20/80 gives `user-v1:
2000`, and the single 20% rule gives `user-canary: 2000`. With this change (one
run; the weight is drawn per request): 80/20 gives `user-v1: 1583, user-v2:
417`, 20/80 gives `user-v1: 429, user-v2: 1571`, and the single rule gives
`user: 1601, user-canary: 399`. A config that sets `canary-by-header` on every
cluster splits about 80/20 both before and after.
The cause is in `Filter.trafficHeader`. A rule without `canary-by-header`
keeps `header == ""`, and `spiltHeader` compares
`req.Header.Get("canary-by-header")` with it. `Get` returns "" when the header
is missing, so the first header-less rule wins the header pass and the weight
pass never runs. Before #501 this match was guarded by `if c.header != ""`; the
guard was dropped when the header and weight checks were split into two loops.
This change puts the guard back: a rule without `canary-by-header` is only
chosen by weight. Rules that set `canary-by-header` behave as before.
**Which issue(s) this PR fixes**:
None filed.
**Special notes for your reviewer**:
The traffic filter had no unit tests, so this adds `traffic_test.go`. The
tests pin the random weight so they are deterministic, and cover weight-only
80/20, a single 20% rule, and a weight-only rule next to a header rule. On
`develop` three assertions fail, for example `expected: "user-v2"` and `actual:
"user-v1"`; with the fix all pass.
A rule that sets neither `canary-by-header` nor `canary-weight` used to
catch every request without the header, so it could look like a default
cluster. After this change it never matches, which is how it behaved before
#501, and the route's own `cluster` stays the fallback. It was not a reliable
default before either: a request with an unknown `canary-by-header` value
already skipped it.
The sample in dubbo-go-pixiu-samples (`dubbogo/simple/traffic`) sets
`canary-by-header` on every cluster, so it never reaches this path and is not
affected.
I ran the new tests, `go test -race -gcflags=-l ./pkg/filter/traffic/...
./pkg/common/extension/filter/...`, `gofmt -s -l`, `go tool imports-formatter`
(no diff) and `go vet ./pkg/filter/traffic/` on macOS arm64. I did not run
golangci-lint or the samples integration suite.
**Does this PR introduce a user-facing change?**:
```release-note
The traffic filter now applies canary-weight to clusters that do not set
canary-by-header. Before, the first such cluster received every request without
a canary-by-header header.
```
This change was drafted with Claude Code (claude-opus-5-5); the test results
above are from the runs described.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]