Men-deploy OpenTelemetry Collector Buatan Google di Google Kubernetes Engine

Dokumen ini menjelaskan cara menjalankan Google-Built OpenTelemetry Collector di Google Kubernetes Engine untuk mengumpulkan log, metrik, dan rekaman aktivitas OTLP dari aplikasi yang diinstrumentasi, lalu mengekspor data tersebut ke Google Cloud.

Sebelum memulai

Untuk menjalankan Google-Built OpenTelemetry Collector, Anda memerlukan resource berikut:

  1. Login keakun Anda. Google Cloud Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Telemetry, Cloud Logging, Cloud Monitoring, and Cloud Trace APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Telemetry, Cloud Logging, Cloud Monitoring, and Cloud Trace APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  8. Cluster Kubernetes. Jika Anda tidak memiliki cluster Kubernetes, ikuti petunjuk di Panduan memulai GKE.

  9. Alat command line berikut:

    • gcloud
    • kubectl

    Alat gcloud dan kubectl adalah bagian dari Google Cloud CLI. Untuk mengetahui informasi tentang cara menginstalnya, lihat Mengelola komponen Google Cloud CLI. Untuk melihat komponen gcloud CLI yang telah Anda instal, jalankan perintah berikut:

            gcloud components list
            

Mengonfigurasi izin untuk Collector

Jika Anda telah menonaktifkan workload identity GKE, Anda dapat melewati bagian ini.

Untuk memastikan bahwa akun layanan kubernetes OpenTelemetry Collector memiliki izin yang diperlukan untuk mengekspor telemetri, minta administrator Anda untuk memberikan peran IAM berikut ke akun layanan kubernetes OpenTelemetry Collector di project Anda:

Untuk mengetahui informasi selengkapnya tentang pemberian peran, lihat Mengelola akses ke project, folder, dan organisasi.

Administrator Anda mungkin juga dapat memberikan izin yang diperlukan kepada akun layanan kubernetes OpenTelemetry Collector melalui peran kustom atau peran yang telah ditetapkan.

Untuk mengonfigurasi izin, gunakan perintah berikut add-iam-policy-binding:

gcloud projects add-iam-policy-binding projects/PROJECT_ID \
    --role=roles/logging.logWriter \
    --member=principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/opentelemetry/sa/opentelemetry-collector
gcloud projects add-iam-policy-binding projects/PROJECT_ID \
    --role=roles/monitoring.metricWriter \
    --member=principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/opentelemetry/sa/opentelemetry-collector
gcloud projects add-iam-policy-binding projects/PROJECT_ID \
    --role=roles/cloudtrace.agent \
    --member=principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/opentelemetry/sa/opentelemetry-collector

Sebelum menjalankan perintah, ganti variabel berikut:

  • PROJECT_ID: ID project.
  • PROJECT_NUMBER: Nomor Google Cloud project.

Men-deploy Collector

Pipeline Collector dapat di-deploy langsung dari contoh yang telah diverifikasi yang disediakan oleh repo Self-Managed OTLP Kubernetes Ingestion. Anda dapat men-deploy langsung dari GitHub dengan perintah berikut setelah mengganti PROJECT_ID dengan ID Google Cloud project Anda:

export GOOGLE_CLOUD_PROJECT=PROJECT_ID
export PROJECT_NUMBER=PROJECT_NUMBER
kubectl kustomize https://github.com/GoogleCloudPlatform/otlp-k8s-ingest.git/k8s/base | envsubst | kubectl apply -f -

Sebelum menjalankan perintah, ganti variabel berikut:

  • PROJECT_ID: ID project.
  • PROJECT_NUMBER: ID numerik project.

Mengonfigurasi Collector

Kami menyediakan konfigurasi OpenTelemetry Collector untuk Anda gunakan dengan Collector buatan Google. Konfigurasi ini dirancang untuk mengirimkan metrik, log, dan rekaman aktivitas OTLP dalam volume tinggi dengan metadata GKE dan Kubernetes yang konsisten. Konfigurasi ini juga dirancang untuk mencegah masalah penyerapan umum. Anda dapat menambahkan konfigurasi, tetapi sebaiknya jangan menghapus elemen.

Bagian ini menjelaskan konfigurasi yang disediakan, komponen utama seperti pengekspor, prosesor, penerima, dan komponen lain yang tersedia.

Konfigurasi Collector yang disediakan

Anda dapat menemukan konfigurasi Collector untuk lingkungan Kubernetes di repo otlp-k8s-ingestrepository:

# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

exporters:
  googlecloud:
    log:
      default_log_name: opentelemetry-collector
    user_agent: Google-Cloud-OTLP manifests:0.5.0 OpenTelemetry Collector Built By Google/0.131.0 (linux/amd64)
  googlemanagedprometheus:
    user_agent: Google-Cloud-OTLP manifests:0.5.0 OpenTelemetry Collector Built By Google/0.131.0 (linux/amd64)
  # The otlphttp exporter is used to send traces to Google Cloud Trace using OTLP http/proto
  # The otlp exporter could also be used to send them using OTLP grpc
  otlphttp:
    encoding: proto
    endpoint: https://telemetry.googleapis.com
    # Use the googleclientauth extension to authenticate with Google credentials
    auth:
      authenticator: googleclientauth


extensions:
  health_check:
    endpoint: ${env:MY_POD_IP}:13133
  googleclientauth:


processors:
  filter/self-metrics:
    metrics:
      include:
        match_type: strict
        metric_names:
        - otelcol_process_uptime
        - otelcol_process_memory_rss
        - otelcol_grpc_io_client_completed_rpcs
        - otelcol_googlecloudmonitoring_point_count
  batch:
    send_batch_max_size: 200
    send_batch_size: 200
    timeout: 5s

  k8sattributes:
    extract:
      metadata:
      - k8s.namespace.name
      - k8s.deployment.name
      - k8s.statefulset.name
      - k8s.daemonset.name
      - k8s.cronjob.name
      - k8s.job.name
      - k8s.replicaset.name
      - k8s.node.name
      - k8s.pod.name
      - k8s.pod.uid
      - k8s.pod.start_time
    passthrough: false
    pod_association:
    - sources:
      - from: resource_attribute
        name: k8s.pod.ip
    - sources:
      - from: resource_attribute
        name: k8s.pod.uid
    - sources:
      - from: connection

  memory_limiter:
    check_interval: 1s
    limit_percentage: 65
    spike_limit_percentage: 20

  metricstransform/self-metrics:
    transforms:
    - action: update
      include: otelcol_process_uptime
      operations:
      - action: add_label
        new_label: version
        new_value: Google-Cloud-OTLP manifests:0.5.0 OpenTelemetry Collector Built By Google/0.131.0 (linux/amd64)

  resourcedetection:
    detectors: [gcp]
    timeout: 10s

  transform/collision:
    metric_statements:
    - context: datapoint
      statements:
      - set(attributes["exported_location"], attributes["location"])
      - delete_key(attributes, "location")
      - set(attributes["exported_cluster"], attributes["cluster"])
      - delete_key(attributes, "cluster")
      - set(attributes["exported_namespace"], attributes["namespace"])
      - delete_key(attributes, "namespace")
      - set(attributes["exported_job"], attributes["job"])
      - delete_key(attributes, "job")
      - set(attributes["exported_instance"], attributes["instance"])
      - delete_key(attributes, "instance")
      - set(attributes["exported_project_id"], attributes["project_id"])
      - delete_key(attributes, "project_id")

  # The relative ordering of statements between ReplicaSet & Deployment and Job & CronJob are important.
  # The ordering of these controllers is decided based on the k8s controller documentation available at
  # https://kubernetes.io/docs/concepts/workloads/controllers.
  # The relative ordering of the other controllers in this list is inconsequential since they directly
  # create pods.
  transform/aco-gke:
    metric_statements:
    - context: datapoint
      statements:
      - set(attributes["top_level_controller_type"], "ReplicaSet") where resource.attributes["k8s.replicaset.name"] != nil
      - set(attributes["top_level_controller_name"], resource.attributes["k8s.replicaset.name"]) where resource.attributes["k8s.replicaset.name"] != nil
      - set(attributes["top_level_controller_type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil
      - set(attributes["top_level_controller_name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil
      - set(attributes["top_level_controller_type"], "DaemonSet") where resource.attributes["k8s.daemonset.name"] != nil
      - set(attributes["top_level_controller_name"], resource.attributes["k8s.daemonset.name"]) where resource.attributes["k8s.daemonset.name"] != nil
      - set(attributes["top_level_controller_type"], "StatefulSet") where resource.attributes["k8s.statefulset.name"] != nil
      - set(attributes["top_level_controller_name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.statefulset.name"] != nil
      - set(attributes["top_level_controller_type"], "Job") where resource.attributes["k8s.job.name"] != nil
      - set(attributes["top_level_controller_name"], resource.attributes["k8s.job.name"]) where resource.attributes["k8s.job.name"] != nil
      - set(attributes["top_level_controller_type"], "CronJob") where resource.attributes["k8s.cronjob.name"] != nil
      - set(attributes["top_level_controller_name"], resource.attributes["k8s.cronjob.name"]) where resource.attributes["k8s.cronjob.name"] != nil

  # When sending telemetry to the GCP OTLP endpoint, the gcp.project_id resource attribute is required to be set to your project ID.
  resource/gcp_project_id:
    attributes:
    - key: gcp.project_id
      # MAKE SURE YOU REPLACE THIS WITH YOUR PROJECT ID
      value: ${GOOGLE_CLOUD_PROJECT}
      action: insert
  # The metricstarttime processor is important to include if you are using the prometheus receiver to ensure the start time is set properly.
  # It is a no-op otherwise.
  metricstarttime:
    strategy: subtract_initial_point

receivers:
  # This collector is configured to accept OTLP metrics, logs, and traces, and is designed to receive OTLP from workloads running in the cluster.
  otlp:
    protocols:
      grpc:
        endpoint: ${env:MY_POD_IP}:4317
      http:
        cors:
          allowed_origins:
          - http://*
          - https://*
        endpoint: ${env:MY_POD_IP}:4318
  otlp/self-metrics:
    protocols:
      grpc:
        endpoint: ${env:MY_POD_IP}:14317

service:
  extensions:
  - health_check
  - googleclientauth
  pipelines:
    logs:
      exporters:
      - googlecloud
      processors:
      - k8sattributes
      - resourcedetection
      - memory_limiter
      - batch
      receivers:
      - otlp
    metrics/otlp:
      exporters:
      - googlemanagedprometheus
      processors:
      - k8sattributes
      - memory_limiter
      - metricstarttime
      - resourcedetection
      - transform/collision
      - transform/aco-gke
      - batch
      receivers:
      - otlp
    metrics/self-metrics:
      exporters:
      - googlemanagedprometheus
      processors:
      - filter/self-metrics
      - metricstransform/self-metrics
      - k8sattributes
      - memory_limiter
      - resourcedetection
      - batch
      receivers:
      - otlp/self-metrics
    traces:
      exporters:
      - otlphttp
      processors:
      - k8sattributes
      - memory_limiter
      - resource/gcp_project_id
      - resourcedetection
      - batch
      receivers:
      - otlp
  telemetry:
    logs:
      encoding: json
    metrics:
      readers:
      - periodic:
          exporter:
            otlp:
              protocol: grpc
              endpoint: http://${env:MY_POD_IP}:14317
              insecure: true

Pengekspor

Konfigurasi Collector menggunakan hal berikut:

Prosesor

Konfigurasi Collector mencakup prosesor berikut:

  • batch: Dikonfigurasi untuk mengelompokkan permintaan telemetri pada Google Cloud jumlah maksimum entri per permintaan, atau pada Google Cloud interval minimum setiap 5 detik (mana pun yang lebih dulu).

  • memory_limiter: Membatasi penggunaan memori Collector untuk mencegah error kehabisan memori dengan menghapus titik data saat batas terlampaui.

  • resourcedetection: Mendeteksi Google Cloud label resource secara otomatis seperti project_id dan cluster_name.

  • k8sattributes: Memetakan atribut resource Kubernetes ke label telemetri secara otomatis.

  • transform: Mengganti nama label metrik yang bertentangan dengan label pada Google Cloud resource yang dipantau.

Penerima

Konfigurasi Collector hanya mencakup penerima otlp. Untuk mengetahui informasi tentang cara menginstrumentasi aplikasi Anda untuk mengirim rekaman aktivitas OTLP dan metrik ke endpoint OTLP Collector, lihat Memilih pendekatan instrumentasi.

Komponen yang tersedia

Google-Built OpenTelemetry Collector berisi komponen yang diperlukan sebagian besar pengguna untuk mengaktifkan pengalaman yang kaya dalam Google Cloud Observability. Untuk daftar lengkap komponen yang tersedia, lihat Komponen di repo opentelemetry-operations-collector.

Untuk meminta perubahan atau penambahan pada komponen yang tersedia, buka permintaan fitur. di repo opentelemetry-operations-collector.

Membuat telemetri

Bagian ini menjelaskan cara men-deploy aplikasi contoh dan mengarahkan aplikasi tersebut ke endpoint OTLP Collector, serta melihat telemetri di Google Cloud. Aplikasi contoh adalah generator kecil yang mengekspor rekaman aktivitas, log, dan metrik ke Collector.

Jika sudah memiliki aplikasi yang diinstrumentasi dengan OpenTelemetry SDK, Anda dapat mengarahkan aplikasi ke endpoint Collector.

Untuk men-deploy aplikasi contoh, jalankan perintah berikut:

kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/otlp-k8s-ingest/main/sample/app.yaml

Untuk mengarahkan aplikasi yang ada yang menggunakan OpenTelemetry SDK ke endpoint Collector, tetapkan variabel lingkungan OTEL_EXPORTER_OTLP_ENDPOINT ke http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317.

Setelah beberapa menit, telemetri yang dibuat oleh aplikasi akan mulai mengalir melalui Collector ke Google Cloud konsol untuk setiap sinyal.

Melihat telemetri

Google-Built OpenTelemetry Collector mengirim metrik, log, dan rekaman aktivitas dari aplikasi yang diinstrumentasi ke Google Cloud Observability. Collector juga mengirim metrik observabilitas mandiri. Bagian berikut menjelaskan cara melihat telemetri ini.

Melihat metrik Anda

Google-Built OpenTelemetry Collector mengumpulkan metrik Prometheus yang dapat Anda lihat menggunakan Metrics Explorer. Metrik yang dikumpulkan bergantung pada instrumentasi aplikasi, meskipun Collector buatan Google juga menulis beberapa metrik mandiri.

Untuk melihat metrik yang dikumpulkan oleh Google-Built OpenTelemetry Collector, lakukan hal berikut:
  1. Di Google Cloud konsol, buka halaman  Metrics explorer:

    Buka Metrics explorer

    Jika Anda menggunakan kotak penelusuran untuk menemukan halaman ini, pilih hasil yang subjudulnya adalah Monitoring.

  2. Di toolbar Google Cloud konsol, pilih Google Cloud project Anda. Untuk Pusat Aplikasi konfigurasi, pilih project host Pusat Aplikasi atau project pengelolaan folder khusus aplikasi.
  3. Pada elemen Metric, luaskan menu Select a metric, masukkan Prometheus Target di panel filter, lalu gunakan submenu untuk memilih jenis dan metrik resource tertentu:
    1. Di menu Active resources, pilih Prometheus Target.
    2. Untuk memilih metrik, gunakan menu Active metric categories dan Active metrics. Metrik yang dikumpulkan oleh Google-Built OpenTelemetry Collector memiliki awalan prometheus.googleapis.com.
    3. Klik Apply.
  4. Untuk menambahkan filter, yang menghapus deret waktu dari hasil kueri, gunakan elemen Filter.

  5. Konfigurasi cara data dilihat.

    Jika pengukuran untuk metrik bersifat kumulatif, Metrics Explorer akan otomatis menormalisasi data yang diukur berdasarkan periode perataan, yang akan menghasilkan diagram yang menampilkan tarif. Untuk mengetahui informasi selengkapnya, lihat Jenis, tipe, dan konversi.

    Saat nilai bilangan bulat atau ganda diukur, seperti dengan metrik counter, Metrics Explorer akan otomatis menjumlahkan semua deret waktu. Untuk mengubah perilaku ini, tetapkan menu pertama entri Aggregation ke None.

    Untuk mengetahui informasi selengkapnya tentang cara mengonfigurasi diagram, lihat Memilih metrik saat menggunakan Metrics Explorer.

Melihat rekaman aktivitas Anda

Untuk melihat data rekaman aktivitas, lakukan hal berikut:

  1. Di Google Cloud konsol, buka halaman Trace explorer:

    Buka Trace explorer

    Anda juga dapat menemukan halaman ini menggunakan kotak penelusuran.

  2. Di toolbar konsol Google Cloud , pilih Google Cloud project Anda. Untuk konfigurasi Pusat Aplikasi, pilih project host Pusat Aplikasi atau project pengelolaan.
  3. Di bagian tabel halaman, pilih baris.
  4. Di diagram Gantt pada panel Trace details , pilih rentang.

    Panel akan terbuka dan menampilkan informasi tentang permintaan yang dilacak. Detail ini mencakup metode, kode status, jumlah byte, dan agen pengguna pemanggil.

  5. Untuk melihat log yang terkait dengan rekaman aktivitas ini, pilih tab Logs &Events.

    Tab ini menampilkan log individual. Untuk melihat detail entri log, luaskan entri log. Anda juga dapat mengklik View Logs dan melihat log menggunakan Logs Explorer.

Untuk mengetahui informasi selengkapnya tentang cara menggunakan Trace Explorer, lihat Menemukan dan menjelajahi rekaman aktivitas.

Melihat log

Dari Logs Explorer, Anda dapat memeriksa log, dan Anda juga dapat melihat rekaman aktivitas terkait, jika ada.

  1. Di Google Cloud konsol, buka halaman Logs Explorer:

    Buka Logs Explorer

    Jika Anda menggunakan kotak penelusuran untuk menemukan halaman ini, pilih hasil yang subjudulnya adalah Logging.

  2. Temukan entri log dari aplikasi yang diinstrumentasi. Untuk melihat detailnya, luaskan entri log.

  3. Klik Traces pada entri log dengan pesan rekaman aktivitas, lalu pilih View trace details.

    Panel Trace details akan terbuka dan menampilkan rekaman aktivitas yang dipilih.

Untuk mengetahui informasi selengkapnya tentang cara menggunakan Logs Explorer, lihat Melihat log menggunakan Logs Explorer.

Mengamati dan men-debug Collector

Google-Built OpenTelemetry Collector otomatis menyediakan metrik observabilitas mandiri untuk membantu Anda memantau performanya dan memastikan waktu aktif berkelanjutan dari pipeline penyerapan OTLP.

Untuk memantau Collector, instal dasbor contoh untuk Collector. Dasbor ini menawarkan insight sekilas tentang beberapa metrik dari Collector, termasuk waktu aktif, penggunaan memori, dan panggilan API ke Google Cloud Observability.

Untuk menginstal dasbor, lakukan hal berikut:

  1. Di Google Cloud konsol, buka halaman  Dashboards:

    Buka Dashboards

    Jika Anda menggunakan kotak penelusuran untuk menemukan halaman ini, pilih hasil yang subjudulnya adalah Monitoring.

  2. Klik Dashboard Templates.
  3. Telusuri dasbor OpenTelemetry Collector.
  4. Opsional: Untuk melihat pratinjau dasbor, pilih dasbor.
  5. Klik Add dashboard to your list dan lalu selesaikan dialog.

    Dialog ini memungkinkan Anda memilih nama dasbor, dan menambahkan label ke dasbor.

Untuk mengetahui informasi selengkapnya tentang cara menginstal dasbor, lihat Menginstal template dasbor.