
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Clone the Confluent examples repository
/ 35
Create source connectors
/ 35
Load streaming data to ksqlDB
/ 30
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.
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.
In this lab, you will:
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:
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:
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.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
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:
Now, clone the Confluent examples repository:
Navigate to the examples/clickstream
directory and switch to the Confluent Platform release branch:
Use a sed
command to change the client version.
Run the below command to update the grafana port.
Get the Jar files for kafka-connect-datagen
(source connector) and kafka-connect-elasticsearch
(sink connector):
CTRL+C
to terminate the above Query.Add user to the docker group and refresh your current terminal session:
examples/clickstream
directory and switch to the Confluent Platform release branch.Increase the virtual memory for elasticsearch
sink connector:
Remove Unused Docker Images/Containers:
Now, launch the tutorial in Docker:
After a minute or so, run the docker-compose ps
status command to ensure that everything has started correctly:
Your output should resemble:
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.
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:
Run the script create-connectors.sql that executes the ksqlDB statements to create three source connectors for generating mock data:
The output will be similar to this:
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:
The second data generator running is for the HTTP status codes. Sample these messages in clickstream_codes
to view the HTTP status codes:
Your output should resemble something like the following:
The third data generator is for the user information. Samples these messages in clickstream_users
to view the user information:
Your output should resemble:
Click Check my progress to verify the objective.
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.
Back in your SSH session, launch 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.
Click Check my progress to verify the objective.
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
:
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:
Run this command to send the ksqlDB tables to Elasticsearch and Grafana:
Now, you can load the dashboard into Grafana:
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
.
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_CLICKSTREAM
connector 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.
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.
Below are multiple choice questions to reinforce your understanding of this lab's concepts. Answer them to the best of your abilities.
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.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one