mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-29 01:04:15 -04:00 
			
		
		
		
	adding sequential policy to forward plugin (#1704)
* adding sequential policy to forward plugin * making sequential an alias to first in proxy plugin
This commit is contained in:
		
				
					committed by
					
						 Miek Gieben
						Miek Gieben
					
				
			
			
				
	
			
			
			
						parent
						
							26d1432ae6
						
					
				
				
					commit
					19a1ef48f2
				
			| @@ -56,7 +56,7 @@ forward FROM TO\.\.\. { | |||||||
|     max_fails INTEGER |     max_fails INTEGER | ||||||
|     tls CERT KEY CA |     tls CERT KEY CA | ||||||
|     tls_servername NAME |     tls_servername NAME | ||||||
|     policy random|round_robin |     policy random|round_robin|sequential | ||||||
|     health_check DURATION |     health_check DURATION | ||||||
| } | } | ||||||
| . | . | ||||||
|   | |||||||
| @@ -47,7 +47,7 @@ forward FROM TO... { | |||||||
|     max_fails INTEGER |     max_fails INTEGER | ||||||
|     tls CERT KEY CA |     tls CERT KEY CA | ||||||
|     tls_servername NAME |     tls_servername NAME | ||||||
|     policy random|round_robin |     policy random|round_robin|sequential | ||||||
|     health_check DURATION |     health_check DURATION | ||||||
| } | } | ||||||
| ~~~ | ~~~ | ||||||
|   | |||||||
| @@ -193,6 +193,7 @@ type policy int | |||||||
| const ( | const ( | ||||||
| 	randomPolicy policy = iota | 	randomPolicy policy = iota | ||||||
| 	roundRobinPolicy | 	roundRobinPolicy | ||||||
|  | 	sequentialPolicy | ||||||
| ) | ) | ||||||
|  |  | ||||||
| const defaultTimeout = 5 * time.Second | const defaultTimeout = 5 * time.Second | ||||||
|   | |||||||
| @@ -53,3 +53,13 @@ func (r *roundRobin) List(p []*Proxy) []*Proxy { | |||||||
|  |  | ||||||
| 	return robin | 	return robin | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // sequential is a policy that selects hosts based on sequential ordering. | ||||||
|  | type sequential struct {} | ||||||
|  |  | ||||||
|  | func (r *sequential) String() string { return "sequential" } | ||||||
|  |  | ||||||
|  | func (r *sequential) List(p []*Proxy) []*Proxy { | ||||||
|  | 	return p | ||||||
|  | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -225,6 +225,8 @@ func parseBlock(c *caddy.Controller, f *Forward) error { | |||||||
| 			f.p = &random{} | 			f.p = &random{} | ||||||
| 		case "round_robin": | 		case "round_robin": | ||||||
| 			f.p = &roundRobin{} | 			f.p = &roundRobin{} | ||||||
|  | 		case "sequential": | ||||||
|  | 			f.p = &sequential{} | ||||||
| 		default: | 		default: | ||||||
| 			return c.Errf("unknown policy '%s'", x) | 			return c.Errf("unknown policy '%s'", x) | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ func TestSetupPolicy(t *testing.T) { | |||||||
| 		// positive | 		// positive | ||||||
| 		{"forward . 127.0.0.1 {\npolicy random\n}\n", false, "random", ""}, | 		{"forward . 127.0.0.1 {\npolicy random\n}\n", false, "random", ""}, | ||||||
| 		{"forward . 127.0.0.1 {\npolicy round_robin\n}\n", false, "round_robin", ""}, | 		{"forward . 127.0.0.1 {\npolicy round_robin\n}\n", false, "round_robin", ""}, | ||||||
|  | 		{"forward . 127.0.0.1 {\npolicy sequential\n}\n", false, "sequential", ""}, | ||||||
| 		// negative | 		// negative | ||||||
| 		{"forward . 127.0.0.1 {\npolicy random2\n}\n", true, "random", "unknown policy"}, | 		{"forward . 127.0.0.1 {\npolicy random2\n}\n", true, "random", "unknown policy"}, | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -29,6 +29,9 @@ func init() { | |||||||
| 	RegisterPolicy("least_conn", func() Policy { return &LeastConn{} }) | 	RegisterPolicy("least_conn", func() Policy { return &LeastConn{} }) | ||||||
| 	RegisterPolicy("round_robin", func() Policy { return &RoundRobin{} }) | 	RegisterPolicy("round_robin", func() Policy { return &RoundRobin{} }) | ||||||
| 	RegisterPolicy("first", func() Policy { return &First{} }) | 	RegisterPolicy("first", func() Policy { return &First{} }) | ||||||
|  |         // 'sequential' is an alias to 'first' to maintain consistency with the forward plugin | ||||||
|  |         // should probably remove 'first' in a future release | ||||||
|  | 	RegisterPolicy("sequential", func() Policy { return &First{} }) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Random is a policy that selects up hosts from a pool at random. | // Random is a policy that selects up hosts from a pool at random. | ||||||
|   | |||||||
| @@ -25,7 +25,7 @@ However, advanced features including load balancing can be utilized with an expa | |||||||
|  |  | ||||||
| ~~~ | ~~~ | ||||||
| proxy FROM TO... { | proxy FROM TO... { | ||||||
|     policy random|least_conn|round_robin|first |     policy random|least_conn|round_robin|sequential | ||||||
|     fail_timeout DURATION |     fail_timeout DURATION | ||||||
|     max_fails INTEGER |     max_fails INTEGER | ||||||
|     health_check PATH:PORT [DURATION] |     health_check PATH:PORT [DURATION] | ||||||
| @@ -39,7 +39,7 @@ proxy FROM TO... { | |||||||
| * **TO** is the destination endpoint to proxy to. At least one is required, but multiple may be | * **TO** is the destination endpoint to proxy to. At least one is required, but multiple may be | ||||||
|   specified. **TO** may be an IP:Port pair, or may reference a file in resolv.conf format |   specified. **TO** may be an IP:Port pair, or may reference a file in resolv.conf format | ||||||
| * `policy` is the load balancing policy to use; applies only with multiple backends. May be one of | * `policy` is the load balancing policy to use; applies only with multiple backends. May be one of | ||||||
|   random, least_conn, round_robin or first. Default is random. |   random, least_conn, round_robin or sequential. Default is random.  | ||||||
| * `fail_timeout` specifies how long to consider a backend as down after it has failed. While it is | * `fail_timeout` specifies how long to consider a backend as down after it has failed. While it is | ||||||
|   down, requests will not be routed to that backend. A backend is "down" if CoreDNS fails to |   down, requests will not be routed to that backend. A backend is "down" if CoreDNS fails to | ||||||
|   communicate with it. The default value is 2 seconds ("2s"). |   communicate with it. The default value is 2 seconds ("2s"). | ||||||
| @@ -64,7 +64,8 @@ There are four load-balancing policies available: | |||||||
| * `random` (default) - Randomly select a backend | * `random` (default) - Randomly select a backend | ||||||
| * `least_conn` - Select the backend with the fewest active connections | * `least_conn` - Select the backend with the fewest active connections | ||||||
| * `round_robin` - Select the backend in round-robin fashion | * `round_robin` - Select the backend in round-robin fashion | ||||||
| * `first` - Select the first available backend looking by order of declaration from left to right | * `sequential` - Select the first available backend looking by order of declaration from left to right | ||||||
|  | * `first` - Deprecated.  Use sequential instead | ||||||
|  |  | ||||||
|  |  | ||||||
| All polices implement randomly spraying packets to backend hosts when *no healthy* hosts are | All polices implement randomly spraying packets to backend hosts when *no healthy* hosts are | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user