Men-deploy OpenTelemetry Collector di Google Kubernetes Engine

Dokumen ini menunjukkan cara menjalankan OpenTelemetry Collector di GKE cluster untuk mengumpulkan log, metrik, dan trace OTLP dari aplikasi berinstrumen dan mengekspor data tersebut ke Google Cloud.

Sebelum memulai

Menjalankan OpenTelemetry Collector di GKE memerlukan hal-hal berikut referensi:

  • Project Google Cloud dengan Cloud Monitoring API, Cloud Trace API, dan Cloud Logging API diaktifkan.

    • Jika Anda tidak memiliki project Google Cloud, lakukan hal berikut:

      1. Di konsol Google Cloud, buka New Project:

        Membuat Project Baru

      2. Di kolom Project Name, masukkan nama project Anda lalu klik Create.

      3. Buka Penagihan:

        Buka Penagihan

      4. Pilih project yang baru saja Anda buat jika belum yang dipilih di bagian atas halaman.

      5. Anda akan diminta untuk memilih profil pembayaran yang sudah ada atau membuat yang baru.

      Monitoring API, Trace API, dan Logging API diaktifkan secara default untuk project baru.

    • Jika Anda sudah memiliki project Google Cloud, pastikan bahwa Monitoring API, Trace API, dan Logging API diaktifkan:

      1. Buka API & layanan:

        Buka API & layanan

      2. Pilih project Anda.

      3. Klik  Enable APIs and services.

      4. Telusuri setiap API berdasarkan nama.

      5. Di hasil penelusuran, klik API yang telah diberi nama. Monitoring API muncul sebagai "Stackdriver Monitoring API".

      6. Jika "API diaktifkan" tidak ditampilkan, lalu klik tombol Enable.

  • Cluster Kubernetes. Jika Anda tidak memiliki cluster Kubernetes, lalu ikuti petunjuk di Panduan Memulai GKE.

  • Alat command line berikut:

    • gcloud
    • kubectl

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

    gcloud components list
    

Men-deploy Kolektor

Pipeline Collector dapat di-deploy langsung dari GitHub dengan perintah setelah mengganti PROJECT_ID dengan ID project Google Cloud Anda:

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

Amati dan debug Collector

OpenTelemetry Collector memberikan metrik kemampuan observasi mandiri yang siap pakai untuk membantu Anda memantau performanya dan memastikan waktu beroperasi OTLP yang berkelanjutan pipeline penyerapan.

Untuk memantau Collector, instal dasbor contoh untuk Collector. Ini menawarkan wawasan sekilas ke dalam beberapa metrik dari Kolektor, termasuk waktu beroperasi, 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 bilah pencarian untuk menemukan halaman ini, kemudian pilih hasil yang sub judulnya Pemantauan.

  2. Pilih tab Sample Library.
  3. Pilih kategori OpenTelemetry Collector.
  4. Pilih "OpenTelemtry Collector" dasbor.
  5. Klik  Impor.

Untuk informasi selengkapnya tentang proses penginstalan, lihat Contoh penginstalan dasbor.

Mengonfigurasi Kolektor

Pipeline penyerapan OTLP yang dikelola sendiri mencakup Konfigurasi OpenTelemetry Collector yang dirancang untuk mengirimkan volume tinggi metrik, log, dan trace OTLP dengan metadata GKE dan Kubernetes yang konsisten terlampir. Hal ini juga dirancang untuk mencegah masalah umum penyerapan.

Namun, Anda mungkin memiliki kebutuhan unik yang memerlukan penyesuaian konfigurasi. Bagian ini menjelaskan default yang dikirimkan bersama pipeline dan cara Anda dapat menyesuaikan {i>default<i} tersebut sesuai kebutuhan Anda.

Konfigurasi Kolektor default terletak di GitHub sebagai config/collector.yaml:

# 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.1.0 otel/opentelemetry-collector-contrib:0.99.0
  googlemanagedprometheus:
    user_agent: Google-Cloud-OTLP manifests:0.1.0 otel/opentelemetry-collector-contrib:0.99.0

extensions:
  health_check:
    endpoint: ${env:MY_POD_IP}:13133
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.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.1.0 otel/opentelemetry-collector-contrib:0.99.0

  # We need to add the pod IP as a resource label so the k8s attributes processor can find it.
  resource/self-metrics:
    attributes:
    - action: insert
      key: k8s.pod.ip
      value: ${env:MY_POD_IP}

  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")

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: ${env:MY_POD_IP}:4317
      http:
        cors:
          allowed_origins:
          - http://*
          - https://*
        endpoint: ${env:MY_POD_IP}:4318
  prometheus/self-metrics:
    config:
      scrape_configs:
      - job_name: otel-self-metrics
        scrape_interval: 1m
        static_configs:
        - targets:
          - ${env:MY_POD_IP}:8888

service:
  extensions:
  - health_check
  pipelines:
    logs:
      exporters:
      - googlecloud
      processors:
      - k8sattributes
      - resourcedetection
      - memory_limiter
      - batch
      receivers:
      - otlp
    metrics/otlp:
      exporters:
      - googlemanagedprometheus
      processors:
      - k8sattributes
      - memory_limiter
      - resourcedetection
      - transform/collision
      - batch
      receivers:
      - otlp
    metrics/self-metrics:
      exporters:
      - googlemanagedprometheus
      processors:
      - filter/self-metrics
      - metricstransform/self-metrics
      - resource/self-metrics
      - k8sattributes
      - memory_limiter
      - resourcedetection
      - batch
      receivers:
      - prometheus/self-metrics
    traces:
      exporters:
      - googlecloud
      processors:
      - k8sattributes
      - memory_limiter
      - resourcedetection
      - batch
      receivers:
      - otlp
  telemetry:
    metrics:
      address: ${env:MY_POD_IP}:8888

Pengekspor

Pengekspor default mencakup googlecloud pengekspor (untuk log dan trace) dan googlemanagedprometheus pengekspor (untuk metrik).

Pengekspor googlecloud dikonfigurasi dengan nama log default. Tujuan Pengekspor googlemanagedprometheus tidak memerlukan konfigurasi default apa pun; lihat Memulai OpenTelemetry Kolektor dalam dokumentasi Google Cloud Managed Service for Prometheus untuk informasi lebih lanjut tentang mengonfigurasi pengekspor ini.

Prosesor

Konfigurasi default mencakup prosesor berikut:

  • batch: Dikonfigurasi ke permintaan telemetri batch pada jumlah maksimum Google Cloud entri per permintaan, atau pada interval minimum Google Cloud setiap 5 detik (mana saja yang lebih dulu).
  • k8sattributes: Secara otomatis memetakan atribut resource Kubernetes ke label telemetri.
  • memory_limiter: Membatasi penggunaan memori Collector pada tingkat yang wajar untuk mencegah kehabisan memori error dengan menurunkan titik data di luar level ini.
  • resourcedetection: Secara otomatis mendeteksi label resource Google Cloud, seperti nama cluster dan project ID Anda.
  • transform: Mengganti nama label metrik yang akan bertabrakan dengan resource yang dipantau Google Cloud kolom.

Penerima Sinyal

Konfigurasi default hanya menyertakan otlp penerima. Lihat Memilih instrumentasi pendekatan untuk memperoleh petunjuk tentang cara menginstrumentasikan aplikasi Anda untuk mengirim pelacakan dan metrik OTLP ke titik akhir OTLP Kolektor.

Langkah berikutnya: mengumpulkan dan melihat telemetri

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

Jika Anda sudah memiliki aplikasi yang diinstrumentasi dengan OpenTelemetry SDK, maka 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 sudah ada yang menggunakan OpenTelemetry SDK di layanan Collector setel variabel lingkungan OTEL_EXPORTER_OTLP_ENDPOINT ke http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317.

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