Injecting HTTP delay faults

The bookinfo application that's been built by Istio's community of developers has hardcoded timeouts at 10 seconds for calls to the ratings service from reviews:v2:

...
private JsonObject getRatings(String productId, HttpHeaders requestHeaders) {
ClientBuilder cb = ClientBuilder.newBuilder();
Integer timeout = star_color.equals("black") ? 10000 : 2500;
...

Let's inject a delay of 7 seconds for the end user, jason, for the ratings service:

  1. Enter the following command:
# Script : 08-inject-http-delay-fault.yaml

kind: VirtualService
metadata:
name: ratings
spec:
hosts:
- ratings
http:
- match:
- headers:
end-user:
exact: jason
fault:
delay:
percentage:
value: 100.0
fixedDelay: 7s
route:
- destination:
host: ratings
subset: v1
- route:
- destination:
host: ratings
subset: v1
  1. Now, modify the ratings virtual service to inject a delay for 7 seconds, but only for jason:
$ kubectl -n istio-lab apply -f 08-inject-http-delay-fault.yaml
virtualservice.networking.istio.io/ratings configured
  1. From a browser, click Sign In and log in as jason.
  2. As soon as you click Sign in, you will notice that the page takes a while to load. This is due to the 7-second delay we introduced for jason.
  3. Now, you will see the message Error fetching product reviews!
  4. Click the three vertical bars on the top right-hand side of the Chrome address bar, click More Tools | Developer Tools, open the Network tab, and refresh  productpage again.
  1. You will notice that productpage timed out for 6 seconds: 

  1. Close the developer tools of the Chrome browser.

Even though we had a timeout of 7 seconds injected between the reviews and ratings services, a timeout of 6 seconds (two attempts, each timing out at three seconds, as per the following code) occurred between the productpage and reviews services:

...
for _ in range(2):
try:
url = reviews['name'] + "/" + reviews['endpoint'] + "/" + str(product_id)
res = requests.get(url, headers=headers, timeout=3.0)
except BaseException:
res = None
if res and res.status_code == 200:
return 200, res.json()
...

This is due to the hardcoded timeout limit between the productpage and reviews services. This helps us to find out the effects of the timeout injection that led to the discovery of the unrelated timeout. 

This demonstrates that without instrumenting anything in the original code of the application, testing the application can be done by injecting latency into the application. This is advanced testing that's done without having to wait for actual latency to occur, which can have unforeseen effects on the application. Istio's fault injection helps us to test the application without impacting other users while the application is in production. Remember that the latency rule was only injected for jason.

Note that injecting an http delay can also simulate the network latency for assigned services to test the overall application's behavior. Now, let's inject abort faults. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.105.239