Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: route name should be unique, but now it can be duplicate #2479

Closed
liuxiran opened this issue Oct 20, 2020 · 13 comments
Closed

bug: route name should be unique, but now it can be duplicate #2479

liuxiran opened this issue Oct 20, 2020 · 13 comments
Assignees
Labels
checking check first if this issue occurred discuss stale

Comments

@liuxiran
Copy link
Contributor

Issue description

refer to #1655
route name should be unique, actually I can create two routes with the same name.

Environment

  • apisix version (cmd: apisix version): latest master
  • OS: fedora32

Minimal test code / Steps to reproduce the issue

  1. create route, id: 1000, name:test1
[****** compose]$ curl http://127.0.0.1:9080/apisix/admin/routes/1000 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '{"name":"test1","uri":"/index.html","hosts":["foo.com","*.bar.com"],"remote_addrs":["127.0.0.0/8"],"methods":["PUT","GET"],"upstream":{"type":"roundrobin","nodes":{"39.97.63.215:80":1}}}'
HTTP/1.1 201 Created
Server: openresty
Date: Tue, 20 Oct 2020 10:51:27 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600

{"header":{"raft_term":"5","cluster_id":"14841639068965178418","member_id":"10276657743932975437","revision":"97"},"node":{"key":"\/apisix\/routes\/1000","value":{"priority":0,"methods":["PUT","GET"],"uri":"\/index.html","remote_addrs":["127.0.0.0\/8"],"hosts":["foo.com","*.bar.com"],"name":"test1","id":"1000","upstream":{"pass_host":"pass","hash_on":"vars","nodes":{"39.97.63.215:80":1},"type":"roundrobin"}}},"action":"set"}


  1. create route, id: 1001, name test1
[***** compose]$ curl http://127.0.0.1:9080/apisix/admin/routes/1001 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '{"name":"test1","uri":"/index.html","hosts":["foo.com","*.bar.com"],"remote_addrs":["127.0.0.0/8"],"methods":["PUT","GET"],"upstream":{"type":"roundrobin","nodes":{"39.97.63.215:80":1}}}'
HTTP/1.1 201 Created
Server: openresty
Date: Tue, 20 Oct 2020 10:51:43 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600

{"header":{"raft_term":"5","cluster_id":"14841639068965178418","member_id":"10276657743932975437","revision":"98"},"node":{"key":"\/apisix\/routes\/1001","value":{"priority":0,"methods":["PUT","GET"],"uri":"\/index.html","remote_addrs":["127.0.0.0\/8"],"hosts":["foo.com","*.bar.com"],"name":"test1","id":"1001","upstream":{"pass_host":"pass","hash_on":"vars","nodes":{"39.97.63.215:80":1},"type":"roundrobin"}}},"action":"set"}
  1. both of the two routes above can be created successfully

What's the expected result?

In practical application, you will use name to distinguish route, so duplicate names would make users confused.

@liuxiran liuxiran changed the title bug: route name should be unique, but new it can be duplicate bug: route name should be unique, but now it can be duplicate Oct 20, 2020
@liuxiran
Copy link
Contributor Author

I feel that it is a bug that affects the user experience, it would be better to solve before2.0, how about your options @membphis @nic-chen @moonming @juzhiyuan

@moonming
Copy link
Member

you can take the name as id, for example:
http://127.0.0.1:9080/apisix/admin/routes/test1

@juzhiyuan juzhiyuan added checking check first if this issue occurred discuss labels Oct 20, 2020
@liuxiran
Copy link
Contributor Author

you can take the name as id, for example:
http://127.0.0.1:9080/apisix/admin/routes/test1

test result:

  1. create a route id: user1,name:test1
[**** compose]$ curl http://127.0.0.1:9080/apisix/admin/routes/user1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '{"name":"test1","uri":"/index.html","hosts":["foo.com","*.bar.com"],"remote_addrs":["127.0.0.0/8"],"methods":["PUT","GET"],"upstream":{"type":"roundrobin","nodes":{"39.97.63.215:80":1}}}'
HTTP/1.1 201 Created
Server: openresty
Date: Tue, 20 Oct 2020 12:01:43 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600

{"node":{"key":"\/apisix\/routes\/1000","value":{"priority":0,"methods":["PUT","GET"],"uri":"\/index.html","remote_addrs":["127.0.0.0\/8"],"hosts":["foo.com","*.bar.com"],"name":"test1","id":"1000","upstream":{"pass_host":"pass","hash_on":"vars","nodes":{"39.97.63.215:80":1},"type":"roundrobin"}}},"header":{"raft_term":"5","cluster_id":"14841639068965178418","member_id":"10276657743932975437","revision":"102"},"action":"set"}
  1. create route id: user1, name test2
[**** compose]$ curl http://127.0.0.1:9080/apisix/admin/routes/user1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '{"name":"test2","uri":"/index.html","hosts":["foo.com","*.bar.com"],"remote_addrs":["127.0.0.0/8"],"methods":["PUT","GET"],"upstream":{"type":"roundrobin","nodes":{"39.97.63.215:80":1}}}'
HTTP/1.1 200 OK
Server: openresty
Date: Tue, 20 Oct 2020 12:11:10 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600

{"node":{"key":"\/apisix\/routes\/user1","value":{"priority":0,"methods":["PUT","GET"],"uri":"\/index.html","remote_addrs":["127.0.0.0\/8"],"hosts":["foo.com","*.bar.com"],"name":"test2","id":"user1","upstream":{"pass_host":"pass","hash_on":"vars","nodes":{"39.97.63.215:80":1},"type":"roundrobin"}}},"header":{"raft_term":"5","cluster_id":"14841639068965178418","member_id":"10276657743932975437","revision":"105"},"action":"set"}
[**** compose]$ curl http://127.0.0.1:9080/apisix/admin/routes/user1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
{"node":{"value":{"priority":0,"methods":["PUT","GET"],"uri":"\/index.html","remote_addrs":["127.0.0.0\/8"],"hosts":["foo.com","*.bar.com"],"name":"test2","upstream":{"type":"roundrobin","nodes":{"39.97.63.215:80":1},"hash_on":"vars","pass_host":"pass"},"id":"user1"},"modifiedIndex":105,"key":"\/apisix\/routes\/user1","createdIndex":103},"count":"1","action":"get","header":{"raft_term":"5","cluster_id":"14841639068965178418","member_id":"10276657743932975437","revision":"105"}}

Actually two duplicate id route create successfully, and the second one‘s data coverd the former
so there should be a unique key whether it's id or name

@moonming
Copy link
Member

moonming commented Oct 20, 2020 via email

@liuxiran
Copy link
Contributor Author

you used the PUT method, so it will update the exist one. you can try the POST method. Thanks, Ming Wen Twitter:

I also tried POST method, the result:

[****** compose]$ curl http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X POST -i -d '{"name":"just-test","uri":"/index.html","hosts":["foo.com","*.bar.com"],"remote_addrs":["127.0.0.0/8"],"methods":["PUT","GET"],"upstream":{"type":"roundrobin","nodes":{"39.97.63.215:80":1}}}'
HTTP/1.1 201 Created
Server: openresty
Date: Tue, 20 Oct 2020 12:24:14 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600

{"header":{"raft_term":"5","cluster_id":"14841639068965178418","member_id":"10276657743932975437","revision":"107"},"node":{"key":"\/apisix\/routes\/00000000000000000106","value":{"priority":0,"methods":["PUT","GET"],"uri":"\/index.html","remote_addrs":["127.0.0.0\/8"],"hosts":["foo.com","*.bar.com"],"name":"just-test","upstream":{"pass_host":"pass","hash_on":"vars","nodes":{"39.97.63.215:80":1},"type":"roundrobin"}}},"action":"create"}

the Key point is that the response data did not contain id value, so the route created by post cannot be updated,Or there are other ways to update this data ,which are not mentioned in the documentation :)

@moonming
Copy link
Member

@membphis please take a look

@imjoey
Copy link
Member

imjoey commented Oct 21, 2020

the Key point is that the response data did not contain id value, so the route created by post cannot be updated,Or there are other ways to update this data ,which are not mentioned in the documentation :)

Hi @liuxiran , actually there is a field {"node":{"key":"\/apisix\/routes\/00000000000000000106"} within response in your example, and the 00000000000000000106 is indeed the id of route. When we are using POST method to create a route, the id is automatically set to the latest version of the etcd by APISIX, which is a global counter incremented every time the data in etcd modified.

you used the PUT method, so it will update the exist one. you can try the POST method. Thanks, Ming Wen Twitter:

@moonming @membphis @juzhiyuan @liuxiran , I guess the real problem is that we can NOT specify a custom (unique) id within a POST request, which would lead to {"error_msg":"wrong route id, do not need it"}. So using name as id for the uniqueness seems not worked. Looking forward to your feedback, thank you guys.

@liuxiran
Copy link
Contributor Author

Hi @liuxiran , actually there is a field {"node":{"key":"\/apisix\/routes\/00000000000000000106"} within response in your example, and the 00000000000000000106 is indeed the id of route. When we are using POST method to create a route, the id is automatically set to the latest version of the etcd by APISIX, which is a global counter incremented every time the data in etcd modified.

Thanks for your explanation, for this point, it would be better to return the same data format under different circumstances.

@liuxiran
Copy link
Contributor Author

liuxiran commented Aug 31, 2021

I tried to create routes with the same name byPOST method:

image

image

from the above screenshots, we can see that the current Admin-API( run apisix with master branch) still allow to create the route with same name, so any updates on this issue? @membphis @spacewander thanks a lot

@spacewander
Copy link
Member

Why not use the name as id?

@spacewander
Copy link
Member

Better not add a unique restriction on the name field, which will introduce a break change. Since the name field is widely used, such break change is unacceptable.

@github-actions
Copy link

This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Aug 16, 2022
@github-actions
Copy link

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checking check first if this issue occurred discuss stale
Projects
None yet
Development

No branches or pull requests

6 participants