-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: support SRV record #3686
Merged
Merged
feat: support SRV record #3686
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
--> | ||
|
||
* [service discovery via DNS](#service-discovery-via-dns) | ||
* [SRV record](#src-record) | ||
|
||
## service discovery via DNS | ||
|
||
|
@@ -62,7 +63,6 @@ and `test.consul.service` be resolved as `1.1.1.1` and `1.1.1.2`, this result wi | |
Note that all the IPs from `test.consul.service` share the same weight. | ||
|
||
If a service has both A and AAAA records, A record is preferred. | ||
Currently we support A / AAAA records, SRV has not been supported yet. | ||
|
||
If you want to specify the port for the upstream server, you can add it to the `service_name`: | ||
|
||
|
@@ -74,3 +74,60 @@ If you want to specify the port for the upstream server, you can add it to the ` | |
"type": "roundrobin" | ||
} | ||
``` | ||
|
||
Another way to do it is via the SRV record, see below. | ||
|
||
### SRV record | ||
|
||
By using SRV record you can specify the port and the weight of a service. | ||
|
||
Assumed you have the SRV record like this: | ||
|
||
``` | ||
; under the section of blah.service | ||
A 300 IN A 1.1.1.1 | ||
B 300 IN A 1.1.1.2 | ||
B 300 IN A 1.1.1.3 | ||
srv 86400 IN SRV 10 60 1980 A | ||
srv 86400 IN SRV 10 20 1981 B | ||
``` | ||
|
||
Upstream configuration like: | ||
|
||
```json | ||
{ | ||
"id": 1, | ||
"discovery_type": "dns", | ||
"service_name": "srv.blah.service", | ||
"type": "roundrobin" | ||
} | ||
``` | ||
|
||
is the same as: | ||
|
||
```json | ||
{ | ||
"id": 1, | ||
"type": "roundrobin", | ||
"nodes": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @membphis |
||
{"host": "1.1.1.1", "port": 1980, "weight": 60}, | ||
{"host": "1.1.1.2", "port": 1981, "weight": 10}, | ||
{"host": "1.1.1.3", "port": 1981, "weight": 10} | ||
} | ||
} | ||
``` | ||
|
||
Note that two records of domain B split the weight evenly. | ||
|
||
As for 0 weight SRV record, the [RFC 2782](https://www.ietf.org/rfc/rfc2782.txt) says: | ||
|
||
> Domain administrators SHOULD use Weight 0 when there isn't any server | ||
selection to do, to make the RR easier to read for humans (less | ||
noisy). In the presence of records containing weights greater | ||
than 0, records with weight 0 should have a very small chance of | ||
being selected. | ||
|
||
We treat weight 0 record has a weight of 1 so the node "have a very small chance of | ||
being selected", which is also the common way to treat this type of record. | ||
|
||
TODO: support priority. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the explantation to treat zero weight record to
1
https://github.com/apache/apisix/blob/3af2175629f727d0374b7f77dbdc3a510cf44d81/docs/en/latest/dns.md#srv-record, can also add here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added: https://github.com/apache/apisix/pull/3686/files#diff-eeebb3321eff56ec1f7b883a6a08b29bbc6359cdd06407eca329772b9a619676R122