apache / apache/apisix-go-plugin-runner

bug: limit-req plugin does not work

Open
#76 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
198
Forks
68
PR merge metrics
No merged PRs in 30d

Description

### Issue description

```go
"conf":[
{
"name":"limit-req",
"value":"{\"rate\":5,\"burst\":1}"
}
]
```

and add two requests

```go
table.Entry("Test if limit-req plugin work.", tools.HttpTestCase{
Object: tools.GetA6Expect(),
Method: http.MethodGet,
Path: "/test/go/runner/limitreq",
ExpectStatus: http.StatusOK,
}),
table.Entry("Test if limit-req plugin work.", tools.HttpTestCase{
Object: tools.GetA6Expect(),
Method: http.MethodGet,
Path: "/test/go/runner/limitreq",
ExpectStatus: http.StatusOK,
}),

```

It does not work. Then I got:

```shell
Error:
expected status equal to:
"200 OK"

but got:
"503 Service Unavailable"
```
I tail the APISIX's log, find that "limit req rate exceeded".
And I try to solve this problem. I found that the code of `limit-req` in `/apisix-go-plugin-runner/cmd/go-runner/plugins` does not work.

Can someone help me?

### Environment

* APISIX Go Plugin Runner's version: version latest-d3fe333-go1.18( result after run `APISIX_LISTEN_ADDRESS=unix:/tmp/runner.sock ./go-runner version`
* APISIX version: run `docker-compose -f ci/docker-compose.yml up -d`
* Go version: 1.18
* OS (cmd: `uname -a`): Darwin Johns-MacBook-Pro.local 21.4.0 Darwin Kernel Version 21.4.0: Mon Feb 21 20:35:58 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T6000 arm64

### Minimal test code / Steps to reproduce the issue

1. `git clone git@github.com:Chever-John/apisix-go-plugin-runner.git`
2. `cd apisix-go-plugin-runner`
3. `make build`
4. `APISIX_LISTEN_ADDRESS=unix:/tmp/runner.sock APISIX_CONF_EXPIRE_TIME=3600 ./go-runner run &`
5. `docker-compose -f ci/docker-compose.yml up -d`
6. `go install github.com/onsi/ginkgo/ginkgo@v1.16.5`
7. `cd /tests/e2e`
8. You can modify the conf `tests/e2e/plugins/plugins_limit_req_test.go`
9. `ginkgo -r`

### What's the actual result? (including assertion message & call stack if applicable)

I guess the file `cmd/go-runner/plugins/limit_req.go`

### What's the expected result?
if conf is
```shell
"conf":[{"name":"limit-req","value":"{\"rate\":0,\"burst\":1}"}]
```
then
```shell
table.Entry("Test if limit-req plugin work.", tools.HttpTestCase{
Object: tools.GetA6Expect(),
Method: http.MethodGet,
Path: "/test/go/runner/limitreq",
ExpectStatus: http.StatusOK,
}),
table.Entry("Test if limit-req plugin work.", tools.HttpTestCase{
Object: tools.GetA6Expect(),
Method: http.MethodGet,
Path: "/test/go/runner/limitreq",
ExpectStatus: http.StatusServiceUnavailable,
}),
```

will work.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with cmd/go-runner/plugins/limit_req.go and the reproducer in tests/e2e/plugins/plugins_limit_req_test.go. Build the runner, start the Docker Compose environment, and run the limit-req end-to-end test with the two requests described in the issue. Done means the configured rate and burst produce the expected 200 and 503 responses without the reported mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.