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 trace OTLP dari aplikasi yang diinstrumentasi, lalu mengekspor data tersebut ke Google Cloud.

Sebelum memulai

Menjalankan OpenTelemetry Collector Buatan Google memerlukan resource berikut:

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  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 (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 Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. 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 (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 Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. 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
            
  10. Mengonfigurasi izin untuk Pengumpul

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

    Untuk memastikan akun layanan kubernetes OpenTelemetry Collector memiliki izin yang diperlukan untuk mengekspor telemetri, minta administrator Anda untuk memberikan peran IAM berikut kepada 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 khusus atau peran bawaan lainnya.

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

    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: Google Cloud Nomor project.

    Men-deploy Pengumpul

    Pipeline Pengumpul dapat di-deploy langsung dari contoh yang telah diperiksa yang disediakan oleh repo Penyerapan OTLP Kubernetes yang Dikelola Sendiri. Anda dapat men-deploy langsung dari GitHub dengan perintah berikut setelah mengganti PROJECT_ID dengan ID project Google Cloud 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 Pengumpul

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

    Bagian ini menjelaskan konfigurasi yang diberikan, komponen utama seperti eksportir, pemroses, penerima, dan komponen lain yang tersedia.

    Konfigurasi Pengumpul yang disediakan

    Anda dapat menemukan konfigurasi Pengumpul untuk lingkungan Kubernetes di repositori otlp-k8s-ingest:

    # 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: ${env:MY_POD_IP}:14317
    

    Pengekspor

    Konfigurasi Pengumpul mencakup eksportir berikut:

    • pengekspor googlecloud, untuk log dan rekaman aktivitas. Exporter ini dikonfigurasi dengan nama log default.

    • googlemanagedprometheus pengekspor, untuk metrik. Exporter ini tidak memerlukan konfigurasi apa pun, tetapi ada opsi konfigurasi. Untuk mengetahui informasi tentang opsi konfigurasi untuk eksportir googlemanagedprometheus, lihat Mulai menggunakan OpenTelemetry Collector dalam dokumentasi Google Cloud Managed Service for Prometheus.

    Prosesor

    Konfigurasi Pengumpul mencakup pemroses 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 saja yang lebih dulu).

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

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

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

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

    Penerima

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

    Komponen yang tersedia

    Pengumpul OpenTelemetry Buatan Google berisi komponen yang dibutuhkan sebagian besar pengguna untuk mengaktifkan pengalaman yang kaya dalam Google Cloud Observability. Untuk mengetahui daftar lengkap komponen yang tersedia, lihat Komponen di repositori opentelemetry-operations-collector.

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

    Membuat telemetri

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

    Jika sudah memiliki aplikasi yang diinstrumentasikan dengan SDK OpenTelemetry, Anda dapat mengarahkan aplikasi ke endpoint Pengumpul.

    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 dihasilkan oleh aplikasi mulai mengalir melalui Collector ke konsol Google Cloud untuk setiap sinyal.

    Melihat telemetri

    Pengumpul OpenTelemetry Buatan Google mengirimkan metrik, log, dan trace dari aplikasi yang diinstrumentasi ke Google Cloud Observability. Kolektor juga mengirimkan metrik pengamatan mandiri. Bagian berikut menjelaskan cara melihat telemetri ini.

    Melihat metrik

    Pengumpul OpenTelemetry Buatan Google mengumpulkan metrik Prometheus yang dapat Anda lihat menggunakan Metrics Explorer. Metrik yang dikumpulkan bergantung pada instrumentasi aplikasi, meskipun Pengumpul yang dibuat Google juga menulis beberapa metriknya sendiri.

    Untuk melihat metrik yang dikumpulkan oleh OpenTelemetry Collector Buatan Google, lakukan langkah-langkah berikut:
    1. Di konsol Google Cloud , 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 konsol Google Cloud , pilih project Google Cloud Anda. Untuk konfigurasi App Hub, pilih project host App Hub atau project pengelolaan folder yang mendukung aplikasi.
    3. Pada elemen Metrik, luaskan menu Pilih metrik, 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 Kategori metrik aktif dan Metrik aktif. Metrik yang dikumpulkan oleh OpenTelemetry Collector Buatan Google memiliki prefiks prometheus.googleapis.com.
      3. Klik Terapkan.
    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, sehingga diagram menampilkan rasio. 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 informasi selengkapnya tentang cara mengonfigurasi diagram, lihat Memilih metrik saat menggunakan Metrics Explorer.

    Melihat trace Anda

    Untuk melihat data rekaman aktivitas, lakukan hal berikut:

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

      Buka Trace explorer

      Anda juga dapat menemukan halaman ini dengan menggunakan kotak penelusuran.

    2. Di toolbar konsol Google Cloud , pilih project Google Cloud Anda. Untuk konfigurasi App Hub, pilih project host App Hub atau project pengelolaan folder yang mendukung aplikasi.
    3. Di bagian tabel halaman, pilih baris.
    4. Pada diagram Gantt di panel Detail rekaman aktivitas, pilih rentang.

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

    5. Untuk melihat log yang terkait dengan rekaman aktivitas ini, pilih tab Log & Peristiwa.

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

    Untuk mengetahui informasi selengkapnya tentang cara menggunakan penjelajah Cloud Trace, 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 konsol Google Cloud , 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 Pengumpul

    Pengumpul OpenTelemetry Buatan Google secara otomatis menyediakan metrik kemampuan observasi mandiri untuk membantu Anda memantau performanya dan memastikan pipeline penyerapan OTLP terus beroperasi.

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

    Untuk menginstal dasbor, lakukan tindakan berikut:

    1. Di konsol Google Cloud , buka halaman  Dashboards:

      Buka Dasbor

      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 Tambahkan dasbor ke daftar Anda, 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.