Skip to content

Commit 0d02bfe

Browse files
committed
suppport v2 api
1 parent 1db1988 commit 0d02bfe

File tree

5 files changed

+152
-65
lines changed

5 files changed

+152
-65
lines changed

timeouts-retries/README.md

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Timeouts and Retries
22

3+
Envoy allows retries to be configured both in the [route configuration](https://www.envoyproxy.io/docs/envoy/v1.5.0/api-v2/rds.proto#envoy-api-msg-routeaction-retrypolicy) as well as for specific requests via [request headers](https://www.envoyproxy.io/docs/envoy/v1.5.0/configuration/http_filters/router_filter#config-http-filters-router-headers). The demo here shows how to configure request timeouts and retries using the envoy route configuration.
4+
35
## Demo Overview
46

57
![](../assets/demo-timeouts-retries.png)
68

7-
Front-proxy configurations are the same as the ones in [HTTP Routing: Simple Match Routing](../httproute-simple-match). Differences from [HTTP Routing: Simple Match Routing](../httproute-simple-match) are the following 2 additional behaviors:
9+
Front proxy configurations in this demo are the same as the ones in [HTTP Routing: Simple Match Routing](../httproute-simple-match) except the following two additional behaviors:
810
- `Timeouts` (5 seconds) for the request to `service_blue`
911
- `Retries` that Envoy will attempt to do if `service_red` responds with any 5xx response code
1012

11-
For Service Containers, `delay` fault injection and `abort` fault injection are configured in `service_blue` and `service_red` respectively (which are the same configuration as the ones in [Fault Injection Demo](../fault-injection))
13+
For Service Containers in the demo, `delay` fault injection and `abort` fault injection are configured in `service_blue` and `service_red` respectively (which are the same configuration as the ones in [Fault Injection Demo](../fault-injection))
1214

1315
Key definition - `virtual_hosts` in [front-envoy.yaml](front-envoy.yaml)
1416
```yaml
@@ -31,12 +33,15 @@ Key definition - `virtual_hosts` in [front-envoy.yaml](front-envoy.yaml)
3133
route:
3234
cluster: service_red
3335
retry_policy:
34-
retry_on: "5xx"
35-
num_retries: 3
36-
per_try_timeout: 5s
36+
retry_on: "5xx"
37+
num_retries: 3
38+
per_try_timeout: 5s
3739
```
38-
> - `timeout`: (Duration) Specifies the timeout for the route. If not specified, the default is 15s. For more detail, see `timeout` section in [RouteAction](https://www.envoyproxy.io/docs/envoy/v1.5.0/api-v2/rds.proto#routeaction)
39-
> - `retry_policy` indicates the retry policy for all routes in this virtual host. For more detail on retry_policy, see [route.RetryPolicy](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route.proto.html#envoy-api-msg-route-retrypolicy)
40+
> - `timeout`: (Duration) Specifies the timeout for the route. If not specified, the default is 15s. For more detail, see`timeout`section in [RouteAction](https://www.envoyproxy.io/docs/envoy/v1.5.0/api-v2/rds.proto#routeaction)
41+
> - `retry_policy` indicates the retry policy for all routes in this virtual host. For more detail on retry_policy, see [route.RetryPolicy](https://www.envoyproxy.io/docs/envoy/v1.5.0/api-v2/rds.proto#envoy-api-msg-routeaction-retrypolicy)
42+
> - `retry_on`: it's retry condition by which the Envoy can retry on different types of conditions depending on application requirements. For example, network failure, all 5xx response codes, idempotent 4xx response codes, etc.
43+
> - `num_retires`: Maximum number of retries. Envoy will continue to retry any number of times. An exponential backoff algorithm is used between each retry.
44+
4045

4146
## Getting Started
4247
```sh
@@ -50,24 +55,24 @@ cd envoy-proxy-demos/timeouts-retries
5055
### Build and Run containers
5156

5257
```sh
53-
$ docker-compose up --build -d
58+
docker-compose up --build -d
5459
5560
# check all services are up
56-
$ docker-compose ps --service
61+
docker-compose ps --service
5762
5863
front-envoy
5964
service_blue
6065
service_green
6166
service_red
6267
6368
# List containers
64-
$ docker-compose ps
69+
docker-compose ps
6570
6671
Name Command State Ports
6772
-----------------------------------------------------------------------------------------------------------------------------------
68-
timeouts-retries_front-envoy_1 /usr/bin/dumb-init -- /bin ... Up 10000/tcp, 0.0.0.0:8000->80/tcp, 0.0.0.0:8001->8001/tcp
69-
timeouts-retries_service_blue_1 /bin/sh -c /usr/local/bin/ ... Up 10000/tcp, 80/tcp
70-
timeouts-retries_service_green_1 /bin/sh -c /usr/local/bin/ ... Up 10000/tcp, 80/tcp
73+
timeouts-retries_front-envoy_1 /docker-entrypoint.sh /bin ... Up 10000/tcp, 0.0.0.0:8000->8000/tcp, 0.0.0.0:8001->8001/tcp
74+
timeouts-retries_service_blue_1 /bin/sh -c /usr/local/bin/ ... Up 10000/tcp, 80/tcp
75+
timeouts-retries_service_green_1 /bin/sh -c /usr/local/bin/ ... Up 10000/tcp, 80/tcp
7176
timeouts-retries_service_red_1 /bin/sh -c /usr/local/bin/ ... Up 10000/tcp, 80/tcp
7277
```
7378

@@ -76,7 +81,7 @@ timeouts-retries_service_red_1 /bin/sh -c /usr/local/bin/ ... Up 1000
7681
Access serivce_blue and check if 50% of requests to service_blue are timeout error (over 5 seconds timeout error with 504 status code). The following helper command allow you to send requests repeatedly (For example, send 10 requests to http://localhost:8000/service/blue).
7782

7883
```sh
79-
$ ../helpers/send-requests.sh http://localhost:8000/service/blue 10
84+
../helpers/send-requests.sh http://localhost:8000/service/blue 10
8085
8186
Sending GET request: http://localhost:8000/service/blue
8287
504
@@ -93,13 +98,13 @@ Sending GET request: http://localhost:8000/service/blue
9398
Access serivce_blue and check if green background page is displayed. It is expected that nothting special will occur
9499

95100
```sh
96-
$ curl -s http://localhost:8000/service/green
101+
curl -s http://localhost:8000/service/green
97102
```
98103

99104
Access serivce_red and check if most of requests to service_red are ok (200 status code), but seldomly you'll get abort error (503 status code). To explain what happens behind the senene, 50% of requests to `service_red` will be aborted with 503 error code due to the fault injection config in service_red, however the request will be recovered by the front proxy's retry mechanism, which is why most of the requests to service_red tuned out to be ok (200 status code). The following helper command allow you to send requests repeatedly (For example, send 10 requests to http://localhost:8000/service/blue)
100105

101106
```sh
102-
$ ../helpers/send-requests.sh http://localhost:8000/service/red 10
107+
../helpers/send-requests.sh http://localhost:8000/service/red 10
103108
104109
Sending GET request: http://localhost:8000/service/red
105110
200
@@ -108,26 +113,53 @@ Sending GET request: http://localhost:8000/service/red
108113
Sending GET request: http://localhost:8000/service/red
109114
200
110115
Sending GET request: http://localhost:8000/service/red
111-
200
116+
503
112117
Sending GET request: http://localhost:8000/service/red
113118
200
114119
Sending GET request: http://localhost:8000/service/red
115120
200
116121
Sending GET request: http://localhost:8000/service/red
117122
200
118123
Sending GET request: http://localhost:8000/service/red
119-
503
124+
200
120125
Sending GET request: http://localhost:8000/service/red
121126
200
122127
Sending GET request: http://localhost:8000/service/red
123128
200
124129
```
125130

131+
The example run above shows 503 status code one time out of 10 requests, however as explained above this isn't what actually occured. Let's see what it was like with `docker-compose logs`:
132+
133+
```
134+
docker-compose logs -f
135+
136+
service_red_1 | [2020-08-13T22:58:42.619Z] "GET /service/red HTTP/2" 200 - 0 148 1 1 "-" "curl/7.54.0" "c381450e-b8f9-4b06-9b08-adab5bbb5b87" "localhost:8000" "127.0.0.1:8080"
137+
service_red_1 | [2020-08-13T22:58:43.645Z] "GET /service/red HTTP/2" 200 - 0 148 2 1 "-" "curl/7.54.0" "fd67460c-a332-4510-8b78-fc870a8db246" "localhost:8000" "127.0.0.1:8080"
138+
service_red_1 | [2020-08-13T22:58:44.671Z] "GET /service/red HTTP/2" 503 FI 0 18 0 - "-" "curl/7.54.0" "0e89d112-3e53-4c23-8360-83d8debc8b14" "localhost:8000" "-"
139+
service_red_1 | [2020-08-13T22:58:44.688Z] "GET /service/red HTTP/2" 200 - 0 148 2 2 "-" "curl/7.54.0" "0e89d112-3e53-4c23-8360-83d8debc8b14" "localhost:8000" "127.0.0.1:8080"
140+
service_red_1 | [2020-08-13T22:58:45.714Z] "GET /service/red HTTP/2" 503 FI 0 18 0 - "-" "curl/7.54.0" "536e2d42-92fb-4146-833d-8501ed859d04" "localhost:8000" "-"
141+
service_red_1 | [2020-08-13T22:58:45.729Z] "GET /service/red HTTP/2" 503 FI 0 18 0 - "-" "curl/7.54.0" "536e2d42-92fb-4146-833d-8501ed859d04" "localhost:8000" "-"
142+
service_red_1 | [2020-08-13T22:58:45.755Z] "GET /service/red HTTP/2" 503 FI 0 18 0 - "-" "curl/7.54.0" "536e2d42-92fb-4146-833d-8501ed859d04" "localhost:8000" "-"
143+
service_red_1 | [2020-08-13T22:58:45.755Z] "GET /service/red HTTP/2" 503 FI 0 18 0 - "-" "curl/7.54.0" "536e2d42-92fb-4146-833d-8501ed859d04" "localhost:8000" "-"
144+
service_red_1 | [2020-08-13T22:58:45.779Z] "GET /service/red HTTP/2" 200 - 0 148 2 1 "-" "curl/7.54.0" "536e2d42-92fb-4146-833d-8501ed859d04" "localhost:8000" "127.0.0.1:8080"
145+
service_red_1 | [2020-08-13T22:58:46.805Z] "GET /service/red HTTP/2" 200 - 0 148 3 2 "-" "curl/7.54.0" "c84a1945-f342-43a2-bb72-27a3dcc25ab6" "localhost:8000" "127.0.0.1:8080"
146+
service_red_1 | [2020-08-13T22:58:47.826Z] "GET /service/red HTTP/2" 200 - 0 148 2 1 "-" "curl/7.54.0" "7700a887-d419-4f9f-965d-107504007a6c" "localhost:8000" "127.0.0.1:8080"
147+
service_red_1 | [2020-08-13T22:58:48.853Z] "GET /service/red HTTP/2" 200 - 0 148 1 1 "-" "curl/7.54.0" "9f3a2717-83da-495f-8115-159a02854446" "localhost:8000" "127.0.0.1:8080"
148+
service_red_1 | [2020-08-13T22:58:49.881Z] "GET /service/red HTTP/2" 503 FI 0 18 0 - "-" "curl/7.54.0" "664deb97-c446-464c-82c0-ad5f4ed2c8d1" "localhost:8000" "-"
149+
service_red_1 | [2020-08-13T22:58:49.893Z] "GET /service/red HTTP/2" 503 FI 0 18 0 - "-" "curl/7.54.0" "664deb97-c446-464c-82c0-ad5f4ed2c8d1" "localhost:8000" "-"
150+
service_red_1 | [2020-08-13T22:58:49.936Z] "GET /service/red HTTP/2" 200 - 0 148 2 1 "-" "curl/7.54.0" "664deb97-c446-464c-82c0-ad5f4ed2c8d1" "localhost:8000" "127.0.0.1:8080"
151+
service_red_1 | [2020-08-13T22:58:50.965Z] "GET /service/red HTTP/2" 200 - 0 148 1 1 "-" "curl/7.54.0" "f4d7012b-7eb3-44a3-9a16-c8d345049707" "localhost:8000" "127.0.0.1:8080"
152+
...
153+
```
154+
155+
It shows `service_red` was be aborted with 503 error code, and that requests from the front proxy was retried and was recovered if it was within `3` retries, the value of `num_retries`.
156+
157+
126158
## Stop & Cleanup
127159

128160
```sh
129-
$ docker-compose down --remove-orphans --rmi all
161+
docker-compose down --remove-orphans --rmi all
130162
```
131163

132164
---
133-
[Top](../README.md)
165+
[Top](../README.md)

timeouts-retries/docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '3.7'
22
services:
33

44
front-envoy:
@@ -13,12 +13,12 @@ services:
1313
# Create and use a Docker network named “envoymesh” for this container
1414
- envoymesh
1515
expose:
16-
# Expose ports 80 (for general traffic) and 8001 (for the admin server)
17-
- "80"
16+
# Expose ports 8000 (for general traffic) and 8001 (for the admin server)
17+
- "8000"
1818
- "8001"
1919
ports:
20-
# Map the host port 8000 to container port 80, and the host port 8001 to container port 8001
21-
- "8000:80"
20+
# Map the host port 8000 to container port 8000, and the host port 8001 to container port 8001
21+
- "8000:8000"
2222
- "8001:8001"
2323

2424
service_blue:

timeouts-retries/front-envoy.yaml

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ static_resources:
33
- address:
44
socket_address:
55
address: 0.0.0.0
6-
port_value: 80
6+
port_value: 8000
77
filter_chains:
88
- filters:
9-
- name: envoy.http_connection_manager
10-
config:
9+
- name: envoy.filters.network.http_connection_manager
10+
typed_config:
11+
"@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
1112
codec_type: auto
1213
stat_prefix: ingress_http
1314
route_config:
@@ -35,39 +36,63 @@ static_resources:
3536
num_retries: 3
3637
per_try_timeout: 5s
3738
http_filters:
38-
- name: envoy.router
39-
config: {}
39+
- name: envoy.filters.http.router
40+
typed_config: {}
4041
clusters:
4142
- name: service_blue
4243
connect_timeout: 0.25s
4344
type: strict_dns
4445
lb_policy: round_robin
4546
http2_protocol_options: {}
46-
hosts:
47-
- socket_address:
48-
address: service_blue
49-
port_value: 80
47+
load_assignment:
48+
cluster_name: service_blue
49+
endpoints:
50+
- lb_endpoints:
51+
- endpoint:
52+
address:
53+
socket_address:
54+
address: service_blue
55+
port_value: 80
5056
- name: service_green
5157
connect_timeout: 0.25s
5258
type: strict_dns
5359
lb_policy: round_robin
5460
http2_protocol_options: {}
55-
hosts:
56-
- socket_address:
57-
address: service_green
58-
port_value: 80
61+
load_assignment:
62+
cluster_name: service_green
63+
endpoints:
64+
- lb_endpoints:
65+
- endpoint:
66+
address:
67+
socket_address:
68+
address: service_green
69+
port_value: 80
5970
- name: service_red
6071
connect_timeout: 0.25s
6172
type: strict_dns
6273
lb_policy: round_robin
6374
http2_protocol_options: {}
64-
hosts:
65-
- socket_address:
66-
address: service_red
67-
port_value: 80
75+
load_assignment:
76+
cluster_name: service_red
77+
endpoints:
78+
- lb_endpoints:
79+
- endpoint:
80+
address:
81+
socket_address:
82+
address: service_red
83+
port_value: 80
6884
admin:
6985
access_log_path: "/dev/null"
7086
address:
7187
socket_address:
7288
address: 0.0.0.0
7389
port_value: 8001
90+
layered_runtime:
91+
layers:
92+
- name: static_layer_0
93+
static_layer:
94+
envoy:
95+
resource_limits:
96+
listener:
97+
example_listener_name:
98+
connection_limit: 10000

timeouts-retries/service-envoy-fault-injection-abort.yaml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ static_resources:
66
port_value: 80
77
filter_chains:
88
- filters:
9-
- name: envoy.http_connection_manager
10-
config:
9+
- name: envoy.filters.network.http_connection_manager
10+
typed_config:
11+
"@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
1112
codec_type: auto
1213
stat_prefix: ingress_http
14+
access_log:
15+
name: envoy.access_loggers.file
16+
typed_config:
17+
"@type": type.googleapis.com/envoy.config.accesslog.v2.FileAccessLog
18+
path: /dev/stdout
1319
route_config:
1420
name: local_route
1521
virtual_hosts:
@@ -22,27 +28,36 @@ static_resources:
2228
route:
2329
cluster: local_service
2430
http_filters:
25-
- name: envoy.fault
26-
config:
31+
- name: envoy.filters.http.fault
32+
typed_config:
33+
"@type": type.googleapis.com/envoy.config.filter.http.fault.v2.HTTPFault
2734
abort:
2835
http_status: 503
2936
percentage:
3037
numerator: 50
3138
denominator: HUNDRED
32-
- name: envoy.router
33-
config: {}
39+
- name: envoy.filters.http.router
40+
typed_config: {}
3441
clusters:
3542
- name: local_service
3643
connect_timeout: 0.25s
3744
type: strict_dns
3845
lb_policy: round_robin
39-
hosts:
40-
- socket_address:
41-
address: 127.0.0.1
42-
port_value: 8080
46+
load_assignment:
47+
cluster_name: local_service
48+
endpoints:
49+
- lb_endpoints:
50+
- endpoint:
51+
address:
52+
socket_address:
53+
address: 127.0.0.1
54+
port_value: 8080
4355
admin:
44-
access_log_path: "/dev/null"
56+
access_log_path: /dev/stdout
4557
address:
4658
socket_address:
4759
address: 0.0.0.0
4860
port_value: 8081
61+
#runtime:
62+
# symlink_root: /srv/runtime/current
63+
# subdirectory: envoy

0 commit comments

Comments
 (0)