Introducing an app "error"

In this case, we are going to make the Submit button fail to work.

We need to modify the application code for that.

To properly do this, you need to create a new image with the wrong code, upload it to your Docker repository and use that image for serving the application.

We will use the kubectl exec command that lets you run the commands on a pod. With the -it option, it attaches an interactive terminal to the pod and gives us a shell that we can run our commands on. The following command launches a Bash Terminal on the pod:

kubectl exec -it <frontend-pod-name> bash

Once you are in the container shell, run the following:

apt update
apt install -y vim

The preceding code installs the vim editor so that we can edit the file to introduce error.

You can run another instance of the cloud shell by clicking the button shown. This will allow debugging while editing the application code:

In shell #1, open the guestbook.php file:

vim guestbook.php

Add the following line after the #18 line:

    $host = 'localhost';

The file will look similar to the following:

 18   if ($_GET['cmd'] == 'set') {
19 $host = 'localhost';
20 $client = new PredisClient([

We are introducing an error where reading messages would work, but not writing them. We do this by asking the frontend to connect to the Redis master at the non-existent local host server. The writes should fail.

Open up your guestbook and note the entries there:

Now add a new entry and click on Submit:

This shows that the app is not production ready. If we did not know any better, we would have thought the entry was written safely. So what is going on?

Without going too much into the application design, the way the app works is as follows:
  • It grabs all the entries on startup and stores them in its cache
  • Any time a new entry is added, the object is added to its cache independent of whether the server acknowledges that it was written.

If you have network debugging tools turned on your browser, you can catch the response from the server.

To verify that it has not been written to the database, hit the Refresh button in your browser; you will see only the initial entries and the new entry has disappeared:

As an app developer or operator, you probably get a ticket like this: After the new deployment, new entries are not persisted. Fix it.

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

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