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

fix(be): Modify the upstream to use the new JSON patch package #1395

Conversation

Jaycean
Copy link
Member

@Jaycean Jaycean commented Jan 29, 2021

Please answer these questions before submitting a pull request


Bugfix

  • Description
    I find that the jsonpatch(github.com/api7/go-jsonpatch) used by upstream and service when calling the patch method is still the old package,updated to github.com/evanphx/json-patch/v5

  • How to fix?
    Modify the upstream to use the new JSON patch package

@imjoey
Copy link
Member

imjoey commented Jan 29, 2021

@Jaycean In order to be a semantic pull request, please change the title to fix: Modify the upstream to use the new JSON patch package . Thanks.

@codecov-io
Copy link

codecov-io commented Jan 29, 2021

Codecov Report

Merging #1395 (1583435) into master (bff19b5) will increase coverage by 22.24%.
The diff coverage is 78.57%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1395       +/-   ##
===========================================
+ Coverage   44.72%   66.97%   +22.24%     
===========================================
  Files          35       44        +9     
  Lines        2522     2937      +415     
===========================================
+ Hits         1128     1967      +839     
+ Misses       1233      729      -504     
- Partials      161      241       +80     
Impacted Files Coverage Δ
api/internal/handler/upstream/upstream.go 83.05% <78.57%> (+62.88%) ⬆️
api/cmd/manager/main.go 0.00% <0.00%> (ø)
api/internal/conf/conf.go 67.85% <0.00%> (ø)
api/internal/core/storage/etcd.go 48.48% <0.00%> (ø)
api/internal/route.go 84.84% <0.00%> (ø)
api/internal/core/storage/storage_mock.go 0.00% <0.00%> (ø)
...l/handler/route_online_debug/route_online_debug.go 73.80% <0.00%> (ø)
api/internal/handler/healthz/healthz.go 66.66% <0.00%> (ø)
api/internal/log/log.go 60.00% <0.00%> (ø)
api/cmd/managerapi.go 60.29% <0.00%> (ø)
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bff19b5...1583435. Read the comment docs.

@Jaycean Jaycean changed the title Modify the upstream to use the new JSON patch package fix: Modify the upstream to use the new JSON patch package Jan 29, 2021
@Jaycean Jaycean changed the title fix: Modify the upstream to use the new JSON patch package fix(be): Modify the upstream to use the new JSON patch package Jan 29, 2021
Copy link
Member

@imjoey imjoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jaycean Since #1396 has been merged already, the Upstream is the only resource that's using github.com/api7/go-jsonpatch. So within this PR, we would better completely remove the dependency of github.com/api7/go-jsonpatch.

Please rebase the master branch with the latest code and run go mod tidy for that. Thanks.

@Jaycean Jaycean force-pushed the Modify_the_upstream_to_use_the_new_json-patch_package branch from 657431f to bfdea43 Compare January 30, 2021 02:48
@Jaycean
Copy link
Member Author

Jaycean commented Jan 30, 2021

@Jaycean Since #1396 has been merged already, the Upstream is the only resource that's using github.com/api7/go-jsonpatch. So within this PR, we would better completely remove the dependency of github.com/api7/go-jsonpatch.

Please rebase the master branch with the latest code and run go mod tidy for that. Thanks.

Thanks for the reminder.done.

@imjoey
Copy link
Member

imjoey commented Jan 30, 2021

@nic-chen Backend E2E Test seems broken since this morning, prompted with the following error. Could you please have a check? Thanks.

--- FAIL: TestBalancer_roundrobin_with_weight (0.66s)
    printer.go:54: PUT http://127.0.0.1:9000/apisix/admin/upstreams/1
    --- PASS: TestBalancer_roundrobin_with_weight/create_upstream_(roundrobin_with_same_weight) (0.06s)
    printer.go:54: PUT http://127.0.0.1:9000/apisix/admin/routes/1
    --- PASS: TestBalancer_roundrobin_with_weight/create_route_using_the_upstream_just_created (0.31s)
    base.go:150: 
        	Error Trace:	base.go:150
        	            				balancer_test.go:77
        	Error:      	Expected nil, but got: &url.Error{Op:"Get", URL:"http://127.0.0.1:9081/server_port", Err:(*net.OpError)(0xc0001b61e0)}
        	Test:       	TestBalancer_roundrobin_with_weight
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x8c8eed]

}
input := c.Input().(*PatchInput)
reqBody := input.Body
ID := input.ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use variables started with letter in small case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Thks

if err := patch.Apply(&stored); err != nil {
var upstream entity.Upstream
err = json.Unmarshal(res, &upstream)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be merged into:

if err := json.Unmarshal(res, &upstream); err != nil {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Thks

if err := patch.Apply(&stored); err != nil {
var upstream entity.Upstream
err = json.Unmarshal(res, &upstream)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be merged into:

if err := json.Unmarshal(res, &upstream); err != nil {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Thks

@@ -314,3 +314,4 @@ func (h *Handler) listUpstreamNames(c droplet.Context) (interface{}, error) {

return output, nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep an empty line here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my problem. Maybe I forgot to delete it when using vim. Done. Thks

@nic-chen
Copy link
Member

@nic-chen Backend E2E Test seems broken since this morning, prompted with the following error. Could you please have a check? Thanks.

--- FAIL: TestBalancer_roundrobin_with_weight (0.66s)
    printer.go:54: PUT http://127.0.0.1:9000/apisix/admin/upstreams/1
    --- PASS: TestBalancer_roundrobin_with_weight/create_upstream_(roundrobin_with_same_weight) (0.06s)
    printer.go:54: PUT http://127.0.0.1:9000/apisix/admin/routes/1
    --- PASS: TestBalancer_roundrobin_with_weight/create_route_using_the_upstream_just_created (0.31s)
    base.go:150: 
        	Error Trace:	base.go:150
        	            				balancer_test.go:77
        	Error:      	Expected nil, but got: &url.Error{Op:"Get", URL:"http://127.0.0.1:9081/server_port", Err:(*net.OpError)(0xc0001b61e0)}
        	Test:       	TestBalancer_roundrobin_with_weight
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x8c8eed]

@imjoey @Jaycean hi, have you found the reason of the failure of ci?

@Jaycean
Copy link
Member Author

Jaycean commented Jan 30, 2021

@nic-chen Backend E2E Test seems broken since this morning, prompted with the following error. Could you please have a check? Thanks.

--- FAIL: TestBalancer_roundrobin_with_weight (0.66s)
    printer.go:54: PUT http://127.0.0.1:9000/apisix/admin/upstreams/1
    --- PASS: TestBalancer_roundrobin_with_weight/create_upstream_(roundrobin_with_same_weight) (0.06s)
    printer.go:54: PUT http://127.0.0.1:9000/apisix/admin/routes/1
    --- PASS: TestBalancer_roundrobin_with_weight/create_route_using_the_upstream_just_created (0.31s)
    base.go:150: 
        	Error Trace:	base.go:150
        	            				balancer_test.go:77
        	Error:      	Expected nil, but got: &url.Error{Op:"Get", URL:"http://127.0.0.1:9081/server_port", Err:(*net.OpError)(0xc0001b61e0)}
        	Test:       	TestBalancer_roundrobin_with_weight
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x8c8eed]

@imjoey @Jaycean hi, have you found the reason of the failure of ci?
At present, we can only locate there

func BatchTestServerPort(t *testing.T, times int) map[string]int {
	url := APISIXSingleWorkerHost + "/server_port"
	req, err := http.NewRequest(http.MethodGet, url, nil)
	assert.Nil(t, err)

APISIXSingleWorkerHost = "http://127.0.0.1:9081"

This requesthttp://127.0.0.1:9081/server_port
A new route is created, which is exposed by apimix. It looks like a network problem here, but it can't be reproduced locally. No further problem is found.

@imjoey
Copy link
Member

imjoey commented Jan 30, 2021

@imjoey @Jaycean hi, have you found the reason of the failure of ci?

@nic-chen sorry, not get the solution yet. 😢

@nic-chen
Copy link
Member

@Jaycean @imjoey
It seems to be affected by the last merged commit of APISIX

@Jaycean
Copy link
Member Author

Jaycean commented Jan 31, 2021

@Jaycean @imjoey
It seems to be affected by the last merged commit of APISIX

Yes, just now I pulled the latest code of apisix, and the error has been reproduced locally.

@nic-chen
Copy link
Member

nic-chen commented Feb 1, 2021

@Jaycean CI passed

@imjoey
Copy link
Member

imjoey commented Feb 1, 2021

@Jaycean CI passed

@nic-chen great thanks.

Copy link
Member

@imjoey imjoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Thanks @Jaycean .

@Jaycean
Copy link
Member Author

Jaycean commented Feb 1, 2021

@Jaycean CI passed

Great Thks.

@liuxiran liuxiran merged commit 94d952f into apache:master Feb 1, 2021
@Jaycean Jaycean deleted the Modify_the_upstream_to_use_the_new_json-patch_package branch February 3, 2021 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants