This lab was developed with our partner, Confluent. Your personal information may be shared with Confluent, the lab sponsor, if you have opted-in to receive product updates, announcements, and offers in your Account Profile.
GSP731
Overview
This lab will cover how to create a clickstream data analysis pipeline using ksqlDB. First, you will run multiple Docker containers and create source connectors that generate clickstream data, which you will be able to view in the Confluent Control Center UI. You will then load the data into ksqlDB, and verify that it is being streamed through various tables and streams. Next, you will send the ksqlDB tables to Elasticsearch and Grafana via the ksqlDB REST API. Lastly, you will view the streaming data in the Grafana dashboard.
What you'll learn
In this lab, you will:
Download and run the Confluent tutorial
Create mock clickstream data
Load the streaming data to ksqlDB
Send the ksqlDB tables to Elasticsearch and Grafana
Sessionize the data
View the data in Grafana
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 are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials 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).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.
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 dialog opens for you to select your payment method.
On the left is the Lab Details pane 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 pane.
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 pane.
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.
Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field.
Task 1. Download and run the tutorial
The tutorial is built using Docker Compose. It brings together several Docker images with the required networking and dependencies. The images are quite large and depending on your network connection may take a few minutes to download.
In the Cloud console, on the Navigation menu (), click Compute Engine > VM instances. Your instance should be listed.
In your provided VM instance, click SSH to start your SSH session. Accept the authorization prompts when the new SSH window opens.
In your SSH session, to set the active account as the username provided in the lab details panel, run:
gcloud config set account {{{user_0.username | "STUDENT USER ACCOUNT"}}}
Navigate to the examples/clickstream directory and switch to the Confluent Platform release branch:
cd examples/clickstream
git checkout 5.5.0-post
Use a sed command to change the client version.
sed -i "s/version: '2'/version: '3'/g" docker-compose.yml
Run the below command to update the grafana port.
sed -i "s/3000:3000/4000:3000/g" docker-compose.yml
Get the Jar files for kafka-connect-datagen (source connector) and kafka-connect-elasticsearch (sink connector):
sudo service docker status
Note: Press CTRL+C to terminate the above Query.
sudo service docker start
Add user to the docker group and refresh your current terminal session:
export username=$(whoami)
sudo usermod -aG docker $username
sudo su -l $username
cd examples/clickstream
git checkout 5.5.0-post
docker run -v $PWD/confluent-hub-components:/share/confluent-hub-components confluentinc/ksqldb-server:0.8.0 confluent-hub install --no-prompt confluentinc/kafka-connect-datagen:0.3.2
docker run -v $PWD/confluent-hub-components:/share/confluent-hub-components confluentinc/ksqldb-server:0.8.0 confluent-hub install --no-prompt confluentinc/kafka-connect-elasticsearch:5.4.1
Note: If you are getting permission denied error please try restarting your SSH session and navigate to the examples/clickstream directory and switch to the Confluent Platform release branch.
Increase the virtual memory for elasticsearch sink connector:
sudo sysctl -w vm.max_map_count=262144
Remove Unused Docker Images/Containers:
sudo docker system prune -af
Now, launch the tutorial in Docker:
docker-compose up -d
After a minute or so, run the docker-compose ps status command to ensure that everything has started correctly:
docker-compose ps
Your output should resemble:
Note: Re-run the docker-compose ps command until your ksqldb-server is in Up (healthy) state before moving forward to the next steps.
Click Check my progress to verify the objective.
Clone the Confluent examples repository.
Task 2. Create the Clickstream data
Once you've confirmed all the Docker containers are running, create the source connectors that generate mock data. This lab leverages the embedded Connect worker in ksqlDB.
Launch the ksqlDB CLI:
Note: Make sure your ksqldb-server is Up (healthy) and running before you execute the following command. This may take several minutes to start up.
docker-compose exec ksqldb-cli ksql http://ksqldb-server:8088
Run the script create-connectors.sql that executes the ksqlDB statements to create three source connectors for generating mock data:
After the RUN SCRIPT command completes, exit out of the ksqldb-cli by typing exit in the prompt to go back to your terminal. Now the clickstream generator is running, simulating the stream of clicks. Sample these messages in clickstream:
Click Check my progress to verify the objective.
Create source connectors.
Navigate to the Compute Engine > VM Instances page and copy the External IP of your VM instance. Paste it in a new browser tab and add :9021 along with the IP. Your URL should now look something like: http://34.86.135.207:9021/. Press Enter.
If required, click Continue to site.
Click Cluster 1 > Connect > connect-default.
You should now be able to view the three kafka-connect-datagen source connectors created with the ksqlDB CLI.
Load the statements.sql file that runs the tutorial app. Important: before running this step, you must have already run ksql-datagen utility to create the clickstream data, status codes, and set of users.
RUN SCRIPT '/scripts/statements.sql';
Click Check my progress to verify the objective.
Load streaming data to ksqlDB.
Verify the data
Go back to the Confluent Control Center UI. Navigate to the ksqlDB menu, click on your clickstream application, and then click on Flow.
Go back to the ksqlDB CLI and verify that data is being streamed through various tables and streams. Query one of the streams CLICKSTREAM:
select * from CLICKSTREAM emit changes LIMIT 100;
Task 4. Load the Clickstream data in Grafana
In this section, you'll send the ksqlDB tables to Elasticsearch and Grafana.
Exit the ksqldb-cli by typing exit in the prompt to go back to your terminal.
Set up the required Elasticsearch document mapping template:
In the Confluent Control Center UI, view the running connectors again. The three kafka-connect-datagen source connectors were created with the ksqlDB CLI, and the seven Elasticsearch sink connectors were created with the ksqlDB REST API.
Task 5. Sessionize the data
One of the tables created by the demo, CLICK_USER_SESSIONS, shows a count of user activity for a given user session. All clicks from the user count towards the total user activity for the current session. If a user is inactive for 30 seconds, then any subsequent click activity is counted towards a new session.
The clickstream demo simulates user sessions with a script. The script pauses the DATAGEN_CLICKSTREAM connector every 90 seconds for a 35 second period of inactivity. By stopping the DATAGEN_CLICKSTREAMconnector for some time greater than 30 seconds, you will see distinct user sessions.
You'll probably use a longer inactivity gap for session windows in practice. But the demo uses 30 seconds so you can see the sessions in action in a reasonable amount of time.
Session windows are different because they monitor user behavior and other window implementations consider only time.
To generate the session data execute the following statement from the examples/clickstream directory. The script will issue some statements to the console about where it is in the process.
cd ~/examples/clickstream
./sessionize-data.sh
Task 6. View the data in Grafana
Navigate to the Compute Engine > VM Instances page and copy the External IP of your VM instance. Paste it in a new browser tab and add :4000 along with the IP. Your URL should now look something like: http://34.86.135.207:4000/. Press Enter.
The Grafana login interface should appear. You can login with user ID user and password user.
Once you're in, from the left-side pane, click the tile icon: Dashboards > Manage. Now you can click your Click Stream Analysis Dashboard to enter.
This dashboard demonstrates a series of streaming functionality where the title of each panel describes the type of stream processing required to generate the data. For example, the large chart in the middle is showing web-resource requests on a per-username basis using a Session window - where a session expires after 300 seconds of inactivity. Editing the panel allows you to view the datasource - which is named after the streams and tables captured in the statements.sql file.
To check the Data Sources page in Grafana, click the Configuration gear icon on the left-side pane, and go to Data Sources. Select one of your data sources and scroll to the bottom and click the Save & Test button. This will indicate whether your data source is valid.
Once you've viewed and tested your data sources, you go back to SSH terminal and exit out of the clickstream demo with the CTRL+C command.
Task 7. Test your understanding
Below are multiple choice questions to reinforce your understanding of this lab's concepts. Answer them to the best of your abilities.
Congratulations!
In this lab, you ran multiple Docker containers, created source connectors that generate mock clickstream data and loaded them into ksqlDB. You then sent the ksqlDB tables to Elasticsearch and Grafana, sessionized the data, and viewed the data in Grafana.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated April 29, 2025
Lab Last Tested April 29, 2025
Copyright 2025 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.
Lab membuat project dan resource Google Cloud untuk jangka waktu tertentu
Lab memiliki batas waktu dan tidak memiliki fitur jeda. Jika lab diakhiri, Anda harus memulainya lagi dari awal.
Di kiri atas layar, klik Start lab untuk memulai
Gunakan penjelajahan rahasia
Salin Nama Pengguna dan Sandi yang diberikan untuk lab tersebut
Klik Open console dalam mode pribadi
Login ke Konsol
Login menggunakan kredensial lab Anda. Menggunakan kredensial lain mungkin menyebabkan error atau dikenai biaya.
Setujui persyaratan, dan lewati halaman resource pemulihan
Jangan klik End lab kecuali jika Anda sudah menyelesaikan lab atau ingin mengulanginya, karena tindakan ini akan menghapus pekerjaan Anda dan menghapus project
Konten ini tidak tersedia untuk saat ini
Kami akan memberi tahu Anda melalui email saat konten tersedia
Bagus!
Kami akan menghubungi Anda melalui email saat konten tersedia
Satu lab dalam satu waktu
Konfirmasi untuk mengakhiri semua lab yang ada dan memulai lab ini
Gunakan penjelajahan rahasia untuk menjalankan lab
Gunakan jendela Samaran atau browser pribadi untuk menjalankan lab ini. Langkah ini akan mencegah konflik antara akun pribadi Anda dan akun Siswa yang dapat menyebabkan tagihan ekstra pada akun pribadi Anda.
This lab will cover how to create a clickstream data analysis pipeline using ksqlDB.