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: create upstream error when pass host is node and nodes without port #2421

Merged
merged 3 commits into from
May 19, 2022
Merged

fix: create upstream error when pass host is node and nodes without port #2421

merged 3 commits into from
May 19, 2022

Conversation

jwrookie
Copy link
Contributor

Signed-off-by: Wei Jiang [email protected]

Please answer these questions before submitting a pull request, or your PR will get closed.

Why submit this pull request?

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches

What changes will this PR take into?
Create upstream should succeed when pass_host is node and nodes without port

Related issues

fix/resolve #2409

Checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@codecov-commenter
Copy link

codecov-commenter commented Apr 11, 2022

Codecov Report

Merging #2421 (f73c75c) into master (6f4200c) will increase coverage by 0.38%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##           master    #2421      +/-   ##
==========================================
+ Coverage   70.04%   70.43%   +0.38%     
==========================================
  Files         189      189              
  Lines        7441     7498      +57     
  Branches      828      845      +17     
==========================================
+ Hits         5212     5281      +69     
+ Misses       1923     1912      -11     
+ Partials      306      305       -1     
Flag Coverage Δ
backend-e2e-test 37.65% <41.66%> (+0.58%) ⬆️
backend-e2e-test-ginkgo 59.99% <41.66%> (+0.41%) ⬆️
backend-unit-test 49.91% <58.33%> (+1.28%) ⬆️
frontend-e2e-test 68.80% <ø> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
api/internal/core/store/validate.go 71.64% <20.00%> (+0.93%) ⬆️
api/internal/core/entity/format.go 87.27% <100.00%> (+19.96%) ⬆️
web/src/components/Plugin/UI/cors.tsx 82.22% <0.00%> (-7.07%) ⬇️
web/src/components/Upstream/service.ts 86.20% <0.00%> (-1.73%) ⬇️
web/src/pages/SSL/List.tsx 85.00% <0.00%> (ø)
web/src/hooks/usePagination.ts 100.00% <0.00%> (ø)
web/src/pages/Service/List.tsx 94.11% <0.00%> (ø)
...omponents/Upstream/components/ServiceDiscovery.tsx 100.00% <0.00%> (ø)
web/src/components/Plugin/PluginPage.tsx 98.82% <0.00%> (+0.08%) ⬆️
api/internal/core/store/storehub.go 73.10% <0.00%> (+0.18%) ⬆️
... and 12 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 6f4200c...f73c75c. Read the comment docs.

@membphis
Copy link
Member

typo in your title

image

@jwrookie jwrookie changed the title fix: cerate upstream error when pass host is node and nodes without port fix: create upstream error when pass host is node and nodes without port Apr 12, 2022
@jwrookie
Copy link
Contributor Author

typo in your title
done, thanks for your checking!

api/internal/core/entity/format.go Outdated Show resolved Hide resolved
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
})
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add test to check the upstream is work ?

Copy link
Member

Choose a reason for hiding this comment

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

need a test case for DP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. it is done now

jwrookie and others added 2 commits April 12, 2022 09:37
Copy link
Member

@nic-chen nic-chen left a comment

Choose a reason for hiding this comment

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

test failed @jwrookie

@jwrookie
Copy link
Contributor Author

test failed @jwrookie

Start the depend error, pls rerun it thanks

image

@starsz starsz requested a review from bzp2010 April 29, 2022 01:18
@jwrookie
Copy link
Contributor Author

jwrookie commented May 5, 2022

@bzp2010 have a check, thanks!

@starsz starsz reopened this May 16, 2022
hp := strings.Split(key, ":")
host := hp[0]
// according to APISIX upstream nodes policy, port is optional
port := "0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it appropriate to use port 0 by default? Should port 80 be used by default? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

type Node struct {
Host string `json:"host,omitempty"`
Port int `json:"port,omitempty"`
Weight int `json:"weight"`
Metadata interface{} `json:"metadata,omitempty"`
Priority int `json:"priority,omitempty"`
}

We cannot give default values to port, the value of 0 is assigned because the zero value is ignored during json.Marshal

Copy link
Contributor

Choose a reason for hiding this comment

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

image

When there is no port in host, port 0 will be used by default, which I think is wrong. For HTTP it should be 80 and for HTTPS it should be 443, so I think it should be set to 80 by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Port is not required, when using https and not configured port it will cause problems, if we do not configure the port there is no such problem

If 80 is given, you need to determine the schema type, when it is https and then change the port default back to 443. I think the first one is more convenient, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

So to put it another way, if the port is 0, the JSON will not contain the port field when it is encoded in JSON? The port is required.

image

image

@bzp2010 bzp2010 merged commit 227b200 into apache:master May 19, 2022
hongbinhsu pushed a commit to fitphp/apix-dashboard that referenced this pull request May 24, 2022
* upstream: (28 commits)
  docs: update some tips in develop.md (apache#2451)
  fix: create upstream error when pass host is node and nodes without port (apache#2421)
  fix: correct data  type of filed Active.checks.active.https_verify_certificate (apache#2422)
  feat: basic support Apache APISIX 2.13.0 (apache#2428)
  feat: add page reload judgment (apache#2370)
  docs: Update RPM install package link (apache#2439)
  docs: Remove hyperlinks from documents (apache#2431)
  chore(deps): bump actions/upload-artifact from 2 to 3 (apache#2423)
  fix: consumer without plugins causes page crashes (apache#2437)
  chore(deps): bump axios from 0.21.1 to 0.21.4 in /web (apache#2420)
  feat: Modify plugin preview page (apache#2359)
  chore(deps): bump moment from 2.29.1 to 2.29.2 in /web (apache#2418)
  chore: use json schema instead hard code (apache#2399)
  refactor: migrate route tests to e2enew (apache#2411)
  chore(deps): bump actions/setup-python from 2.3.2 to 3.1.1 (apache#2414)
  chore: update the year of copyright and fix typo (apache#2417)
  docs: update online playground url (apache#2416)
  chore: update README for online demo (apache#2404)
  refactor: migrate id compatible tests to e2enew (apache#2400)
  docs: fix invalid link (apache#2366)
  ...

# Conflicts:
#	api/internal/route.go
#	web/src/components/Footer/index.tsx
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.

upstream config, cann't select Host header for option 'Keep the same Host from client request'
6 participants