Memuat…
Tidak ditemukan hasil.

Google Cloud Skills Boost

Terapkan keterampilan Anda di Konsol Google Cloud

Getting Started with Datadog on Google Cloud

Dapatkan akses ke 700+ lab dan kursus

Monitor Cloud Run with Datadog

Lab 1 jam universal_currency_alt Tanpa biaya show_chart Pengantar
info Lab ini mungkin menggabungkan alat AI untuk mendukung pembelajaran Anda.
Dapatkan akses ke 700+ lab dan kursus

This lab was developed with our partner, Datadog. Your personal information may be shared with Datadog, the lab sponsor, if you have opted-in to receive product updates, announcements, and offers in your Account Profile.

GSP1147

Overview

Datadog is a monitoring and analytics platform for cloud-based applications, infrastructure, and networks. It provides real-time visibility into application performance, infrastructure health, and user experience.

The Datadog integration for Google Cloud Platform is a powerful way to get data into Datadog with minimal effort. It is agentless and pulls metadata at the Platform level from Google Cloud APIs. In addition, the new Datadog Cloud Run agent delivers official support for traces and custom metrics in managed Cloud Run instances.

In this lab, you'll explore how to connect Datadog to your Google Cloud project, and use it to monitor a Cloud Run app. You'll also explore the new APM/tracing capabilities offered by the new Datadog Cloud Run agent.

Objectives

You will learn how to:

  • Set up the Datadog platform integration
  • Configure log forwarding
  • View tracing information collected by the new Datadog Cloud Run agent
  • Explore Cloud Run metrics in Datadog
  • Explore Cloud Run logs in Datadog

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 Qwiklabs 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.

What you need

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.

Note: If you already have your own personal Google Cloud account or project, do not use it for this lab.

Note: If you are using a Pixelbook, open an Incognito window to run this lab.

How to start your lab and sign in to the Google Cloud Console

  1. 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 a panel populated with the temporary credentials that you must use for this lab.

  2. Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Open the tabs in separate windows, side-by-side.

  3. In the Sign in page, paste the username that you copied from the Connection Details panel. Then copy and paste the password.

    Important: You must use the credentials from the Connection Details panel. Do not use your Qwiklabs credentials. If you have your own Google Cloud account, do not use it for this lab (avoids incurring charges).

  4. 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 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.

In the Cloud Console, in the top right toolbar, click the Activate Cloud Shell button.

Click Continue.

It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

You can list the active account name with this command:

gcloud auth list

(Output)

Credentialed accounts: - <myaccount>@<mydomain>.com (active)

(Example output)

Credentialed accounts: - google1623327_student@qwiklabs.net

You can list the project ID with this command:

gcloud config list project

(Output)

[core] project = <project_ID>

(Example output)

[core] project = qwiklabs-gcp-44776a13dea667a6

Task 1. Set up a Datadog trial account

If you already have a trial account set up, you can use that. It is recommended that you do not use your production Datadog account to avoid cluttering the environment with test and training assets.

  1. Navigate to https://us5.datadoghq.com/signup and enter your name, email, company, and a password.

  2. Next, select your software stack. For this lab, you will be using Google Cloud Platform. Click Next.

  3. Navigate to https://us5.datadoghq.com/organization-settings/api-keys Use the Copy Key button as shown to copy your API Key to your clipboard.

  4. Back in the Cloud Console, navigate back to your Cloud Shell window. Run the following command, replacing <YOUR_DATADOG_API_KEY>with your API key in the appropriate slot:

export DD_API_KEY=<YOUR_DATADOG_API_KEY>
  1. Run the following command to set your Project ID.
export PROJECT_ID={{{ project_0.project_id | Project ID }}} Note: If you close Cloud Shell, you'll lose the environment variable you just added. Keep it somewhere safe temporarily, or just leave the page open with the API key as mentioned above in case you need to add it again.

Task 2. Enable Google Cloud services

With Google Cloud, nothing is enabled by default to protect you from using a costly system by accident. Run the following in Cloud Shell to enable all the APIs needed for this lab:

gcloud services enable \ run.googleapis.com \ cloudbilling.googleapis.com \ compute.googleapis.com \ cloudasset.googleapis.com \ monitoring.googleapis.com

Task 3. Set up the Google Cloud platform-level integration for Datadog

To use Datadog to monitor a project, you need to enable APIs needed for Datadog, create a service account, and connect the service account to Datadog.

Create a service account

Datadog's Google Cloud integration uses a service account to make calls to the Cloud Logging API to collect node-level metrics from your Compute Engine instances.

  1. In Cloud Shell, create a service account for Datadog:
DATADOG_SA_NAME=datadog-service-account gcloud iam service-accounts create $DATADOG_SA_NAME \ --display-name "Datadog Service Account"
  1. Enable the Datadog service account to collect metrics, tags, events, and user labels by granting the following IAM roles:
DATADOG_SA_EMAIL=$DATADOG_SA_NAME@$PROJECT_ID.iam.gserviceaccount.com gcloud projects add-iam-policy-binding $PROJECT_ID \ --member serviceAccount:$DATADOG_SA_EMAIL \ --role roles/cloudasset.viewer gcloud projects add-iam-policy-binding $PROJECT_ID \ --member serviceAccount:$DATADOG_SA_EMAIL \ --role roles/compute.viewer gcloud projects add-iam-policy-binding $PROJECT_ID \ --member serviceAccount:$DATADOG_SA_EMAIL \ --role roles/monitoring.viewer Note: These steps came directly from Datadog's documentation. For more information, visit https://docs.datadoghq.com/integrations/google_cloud_platform/#setup

Add the Datadog principal to your service account

  1. In Datadog, navigate to Integrations, search for Google Cloud Platform and select it.

  2. Click on Add GCP Account. If you have no configured projects, you are automatically redirected to this page.

  3. If you have not generated a Datadog principal for your org, click the Generate Principal button.

  4. Copy your Datadog principal to the clipboard and keep it for the next section.

  5. Back in the Google Cloud console, under the Service Acounts menu, find the service account you created in the first section.

  6. Go to the Permissions tab and click on Grant Access.

  7. Paste your Datadog principal into the New principals text box.

  8. Assign the role of Service Account Token Creator and click Save.

Note: If you previously configured access using a shared Datadog principal, you can revoke the permission for that principal after you complete these steps.

Complete the integration setup in Datadog

  1. In your Google Cloud console, navigate to the Service Account > Details tab for the service account you created. There, you can find the email associated with this Google service account. It resembles <sa-name>@<project-id>.iam.gserviceaccount.com. Copy this email.

  2. Return to the integration configuration tile in Datadog (where you copied your Datadog principal in the previous section).

  3. In the box under Add Service Account Email, paste the email you previously copied.

  4. Click on Verify and Save Account.

Task 4. Configure Cloud Pub/Sub from Google Cloud to Datadog (for log forwarding)

Create a Cloud Pub/Sub

  1. Go to the Cloud Pub/Sub console in Google Cloud .
  2. Create a topic (the button is on the top).
  3. Give that topic the name export-logs-to-datadog (make sure to use this exact name for proper assessment.in this lab) and Save. The default options are fine. Make sure Add a default subscription is checked.

Forward Logs to Datadog

  1. Go back to the Cloud Pub/Sub console in Google Cloud, and select Subscriptions in the left-hand navigation.

  2. Create a subscription ID by selecting Create Subscription. Give it an appropriate name and select the topic you previously created (export-logs-to-datadog).

  3. Change the method to Push. For the endpoint, enter the following (make sure to replace the Datadog API key in this string): https://gcp-intake.logs.us5.datadoghq.com/api/v2/logs?dd-api-key=<DD_API_KEY>&dd-protocol=gcp. Do NOT enable authentication.

    Note: Make sure you replace with your API key from before. You can also create an API key or pick an existing API key in Datadog Organization Settings -> API Keys
  4. Hit Create at the bottom.

🎉 The Cloud Pub/Sub is ready to receive logs from Google Cloud Logging and forward them to Datadog.

Click Check my progress to verify the objective. Create Cloud PubSub Topic and Configure Subscription

Task 5. Clone the repo

  1. In Cloud Shell, run the following commands to clone the repo and build the container.

First, Clone the repo with a sample app:

git clone https://github.com/Scott-Mabe/crpb.git

Next, set the repository name variable:

export REPO_NAME="datadog-repo"

Create a Google Cloud Artifact Registry repository:

gcloud artifacts repositories create $REPO_NAME --repository-format docker --location {{{ project_0.default_region | "Lab project's default region." }}}

After that, build the Docker image:

docker build -t {{{ project_0.default_region | "Lab project's default region." }}}-docker.pkg.dev/{{{ project_0.project_id | "Lab project's ID." }}}/$REPO_NAME/cloud-run-demo-go:v1 crpb/go

Nearly done! Now push the Docker image to Google Cloud Artifact Registry:

docker push {{{ project_0.default_region | "Lab project's default region." }}}-docker.pkg.dev/{{{ project_0.project_id | "Lab project's ID." }}}/$REPO_NAME/cloud-run-demo-go:v1

Finally, deploy to Google Cloud Run:

gcloud run deploy cloud-run-demo-go \ --project=$PROJECT_ID \ --platform=managed \ --region={{{ project_0.default_region | DEFAULT_REGION }}} \ --image={{{ project_0.default_region | "Lab project's default region." }}}-docker.pkg.dev/{{{ project_0.project_id | "Lab project's ID." }}}/$REPO_NAME/cloud-run-demo-go:v1 \ --port=80 \ --set-env-vars=DD_API_KEY=$DD_API_KEY \ --set-env-vars=DD_SITE=us5.datadoghq.com \ --allow-unauthenticated \ --memory=512Mi \ --cpu=1 \ --no-use-http2

If you get a message that says Allow unauthenticated invocations to [cloud-run-demo-go] (y/N)?, it probably means you typed something wrong or the command wasn't copied properly. Ctrl-C and try again.

When this completes, you should see the URL for your running app:

It's very important that you now click the URL and visit the page to generate some traces! Refresh the page a few times for good measure.

Now make logs flow for Cloud Run:

  1. Go to the Google Cloud Logging page and filter by Cloud Run Revision logs.

  2. Click Create Sink (in the "More Actions" menu)and name the sink datadog-cloudrun (use this name exactly for proper assessment)

  3. Choose “Cloud Pub/Sub” as the destination and select the Pub/Sub that was created for that purpose.

    Note: For future reference, the pub/sub can be located in a different project.
  4. In step 3, make sure the inclusion filter is resource.type="cloud_run_revision"

  5. Click Create Sink and wait for the confirmation message to show up.

🎉 Nice work! The Cloud Run app should now be running and sending metrics to Datadog.

Click Check my progress to verify the objective. Deploy App and Create Sink for Cloud Run Service

Task 6. Observe tracing in Datadog

Head over to your Datadog console. If you go to APM > Traces, you should see some traces from your Cloud Run app!

You can click on a trace to see more details:

Not seeing your traces? Hit your app endpoint a view times (just refresh the Hello World page). You can also try changing the time period located at the top right of the Datadog UI

Task 7. Explore Metrics in Datadog

Head over to your Datadog console. If you go to Infrastructure > Serverless, you should see all of available metrics about your Cloud Run app!

Task 8. Investigate Logs in Datadog

You should also be able to head over to Logs in the Datadog console, select a log, and get more context.

Congratulations!

In this lab, you got hands-on experience using Datadog's new Google Cloud Run integration and Datadog's Google Cloud Platform-level integration which makes monitoring your workloads easy!

Next Steps / Learn More

Be sure to check out the following labs for more practice with Datadog:

Google Cloud training and certification

...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 May 8, 2024

Lab Last Tested May 8, 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.

Sebelumnya Berikutnya

Sebelum memulai

  1. Lab membuat project dan resource Google Cloud untuk jangka waktu tertentu
  2. Lab memiliki batas waktu dan tidak memiliki fitur jeda. Jika lab diakhiri, Anda harus memulainya lagi dari awal.
  3. Di kiri atas layar, klik Start lab untuk memulai

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.
Pratinjau