Analyze BigQuery Usage with Log Analytics
GSP1250
Overview
While BigQuery offers built-in observability capabilities like the INFORMATION_SCHEMA
views, detailed logging remains crucial for in-depth usage analysis, auditing, and troubleshooting potential issues. Enabling Log Analytics lets you query and analyze your log data using familiar SQL queries, then view or chart the query results.
BigQuery is Google Cloud's fully managed enterprise data warehouse that helps you manage and analyze your data with built-in features like machine learning, geospatial analysis, and business intelligence.
In this lab you will enable Log Analytics on Logs Storage buckets, then view the BigQuery logs inside Cloud Logging, and use SQL to analyze the logs using Log Analytics.
Objectives
In this lab you will learn how to:
- Use Cloud Logging effectively to get insight about BigQuery usage
- Effectively build and run SQL queries using Log Analytics
- View and chart the results
Setup and Requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
- Click Activate Cloud Shell at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Configure log buckets
Upgrade log bucket
You will configure Cloud Logging to upgrade all the existing log buckets with Log Analytics enabled.
To upgrade existing buckets to use Log Analytics:
- From the navigation menu, select Logging, and then select Logs Storage:
- Select the bucket _Required.
- When the Log Analytics available column displays Upgrade, you can upgrade the log bucket to use Log Analytics. Click Upgrade.
- Click Confirm.
- Repeat the same steps for the log bucket _Default.
Task 2. Perform BigQuery Activities
Complete the following tasks to generate some BigQuery logs. In the tasks, the BigQuery command line tool bq is used.
- Use the
bq mk
command to create new datasets named bq_logs and bq_logs_test in your project:
- Use the
bq ls
command to list the datasets:
- Use the
bq rm
command to delete the a dataset (select y when prompted):
- Create a new table:
You should see a success message that a new empty table named test_table has been created for your dataset.
Now you'll run some queries to generate logs.
- Run the following query in Cloud Shell:
- Copy the following command into Cloud Shell and click RUN:
(This query uses weather data from the National Oceanic and Atmospheric Administration (NOAA))
Task 3. Perform log analysis
One common task when analyzing BigQuery usage is to search specific operations for your datasets. For each query you run, remember to replace [Your Project Id]
with the project id provisioned for this lab.
- In the left navigation, under Logging, click Log Analytics to access the feature. You should see something like the following:
If your query field is empty or you forget which table you want to use, you can click the Query button to get the sample query back.
- To find operations such as created or deleted, run the following query:
- You should see the output like the following. You can also limit your search with more specifics such as
method_name = 'datasetservice.delete'.
results for datasetservice query
4. To find the operations for BigQuery tables, change the query condition for table services. Run this query to find operations on tables that are created or deleted:
You should see the output like the following:
- To view completed BigQuery queries, search the
data_access
log based on thejobCompletedEvent
. For example, run the following SQL query:
After the SQL query completes, you should see the output like the following:
Since the query strings are included in the SQL query, the results might be large. Scroll through the results and look for the completed BigQuery queries.
Task 4. Create a chart
Instead of using a table to see the results, Log Analytics supports creating charts for visualization.
- Click the Chart button in the result view,
- Select Pie chart as the chart type and query as the column.
- You should see the chart similar to the following.
Congratulations
You now have hands-on experience utilizing Cloud Logging and Log Analytics to build queries, chart results, and gain insights into BigQuery utilization.
Next steps / Learn more
- Log Analytics documentation.
- Learn more about visualizing your Log Analytics results with the charts documentation.
[[/fragments/TrainingCertificationOverview]]
Manual Last Updated June 7, 2024
Lab Last Tested April 23, 2024
Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.