1. Home
  2. Training Library
  3. Google Cloud Platform
  4. Courses
  5. Managing Your Google Cloud Infrastructure

Error Reporting and Debugging

The course is part of these learning paths

Google Cloud Platform for System Administrators
course-steps 3 certification 1 quiz-steps 3

Contents

keyboard_tab
Introduction
Stackdriver
2
3
Logging8m 48s
5
Tracing2m 59s
Testing
6
Testing2m 49s
Storage Management
Conclusion
play-arrow
Start course
Overview
DifficultyIntermediate
Duration56m
Students1027

Description

Once you have implemented your application infrastructure on Google Cloud Platform, you will need to maintain it. Although you can set up Google Cloud to automate many operations tasks, you will still need to monitor, test, manage, and troubleshoot it over time to make sure your systems are running properly.

This course will walk you through these maintenance tasks and give you hands-on demonstrations of how to perform them. You can follow along with your own GCP account to try these examples yourself.

Learning Objectives

  • Use Stackdriver to monitor, log, report on errors, trace, and debug
  • Ensure your infrastructure can handle higher loads, failures, and cyber-attacks by performing load, resilience, and penetration tests
  • Manage your data using lifecycle management and migration from outside sources
  • Troubleshoot SSH errors, instance startup failures, and network traffic dropping

 

Transcript

So far we've been looking at alerts and log messages from system software. Now it's time to look at how to get error information from your applications. That's where the Stackdriver error reporting service comes in. To show you how this works I'm going to install Google's Hello, World application in App Engine and then get it to generate an error.

If you're going to follow along on your own system then first make sure you have these three packages installed on your work station, the Google Cloud SDK, Git and the Python SDK for App Engine.

First, get a copy of the Hello, World application with this Git clone command. Then go into the directory where the app is.

Now use the local development server to make sure the app works. If you go to localhost:8080 in your browser you should see a Hello, World message. Okay, it's working so let's stop the development server and upload the application to App Engine. You can stop the development server with a control C.

If you haven't already set your project ID using the GCloud command, then do it now. Use gcloud config set project, and then the project ID. Be sure to use your own project ID in the command. If you're not sure what it is then go to the Home page. Your project info will be in the upper left corner.

Now use the GCloud app deploy command to upload it to App Engine. If you're doing this yourself then it may look slightly different because I've already deployed this app before. If this is your first time deploying to App Engine, then it will likely ask you to choose a region. Okay, it's done deploying.

There a couple of ways to test it. You could copy this appspot.com URL and put it in your browser or you could do a GCloud app browse, which is pretty handy. Either way you should see Hello, World again.

Now, in order to see an error in Stackdriver error reporting we need to generate an error. Let's edit the main.py file and mess something up. Suppose you tried to import webapp instead of webapp2. That should cause an error.

Now run GCloud app deploy again. When it's done bring the app up in your browser again. This time it gives you a big error message which is actually what we want for once.

Let's see if Stackdriver picked it up. You can see that it's showing the error in the Google Cloud dashboard. Let's click on Go to Error Reporting to see what it shows. If you click on the error you'll see more details, including the stack trace. You can even click on the line where the error occurred and it will take you into your source code in the debugger.

The debugger is a great tool that you can use whether an error occurred or not. Let's put a more subtle bug in the code and see how we can use the debugger to figure out what's wrong.

Suppose that instead of saying Hello, World we want to check the operating system running our app and if it's Linux, then we'll print Linux rocks.

First, we have to fix the bug that we introduced previously so we'll change webapp back to webapp2. We also have to add another import line because we're going to access the function from the OS library. I'll skip ahead after adding the rest of the new code. I just replaced the Hello, World line with three new lines.

Now we'll upload it to App Engine again. Okay, now refresh the web page. And Hello, World disappears but it doesn't say Linux rocks. That might be because the underlying operating system isn't Linux but let's go back to the debugger and see if that's the reason.

You'll notice that this is still the old version of the main.py file. Even if you refresh the browser, it will still show this old version. To get to the new version you have to click on this dropdown menu and select it. The latest version should be at the top. That's better.

Bring up the main.py file. You'll see some text on the right-hand side that says to click a line number to take a snapshot of the variables and call stack. It also points out that taking a snapshot does not stop the running application, which is good to know.

Click in the left-hand gutter on the line just after the OS name variable is set. Now that the snapshot point is set we can refresh the web page and trigger the snapshot. If we go back to the debugger tab you'll see that it's showing the variables and call stack on the right-hand side. We'll click on OS name to see what it's set to and it says it's set to Linux, but wait, it's actually an array or a tuple in Python lingo. So, we need to refer to the first element to the tuple.

We'll just make a quick change to that line in the source code.

Save the file and deploy the new version. Now refresh the web page and it works.

Let's go back to the main error reporting page and I'll show you a couple of other things. First, if you're sitting on this page watching for errors in real time, then you should click the Auto Reload button, which will refresh the page every five seconds. If you don't want to hang around here and just want to get an email when an error occurs, then click the Turn On Notifications button.

Alright, that's it for this lesson.

About the Author

Students14152
Courses41
Learning paths22

Guy launched his first training website in 1995 and he's been helping people learn IT technologies ever since. He has been a sysadmin, instructor, sales engineer, IT manager, and entrepreneur. In his most recent venture, he founded and led a cloud-based training infrastructure company that provided virtual labs for some of the largest software vendors in the world. Guy’s passion is making complex technology easy to understand. His activities outside of work have included riding an elephant and skydiving (although not at the same time).