Deploy Google-Built OpenTelemetry Collector on Google Kubernetes Engine

אתם יכולים לפרוס את Google-Built OpenTelemetry Collector ב-Google Kubernetes Engine ‏(GKE) כדי לאסוף יומנים, מדדים ומעקבים של OTLP מאפליקציות עם אינסטרומנטציה, ולייצא את נתוני הטלמטריה האלה אל Google Cloud.

לפני שמתחילים

כדי להריץ את Google-Built OpenTelemetry Collector, צריך את המשאבים הבאים:

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

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

  3. Enable the Telemetry, Cloud Logging, Cloud Monitoring, and Cloud Trace APIs, if any are not already enabled.

    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

  4. אשכול Kubernetes. אם אין לכם אשכול Kubernetes, פועלים לפי ההוראות במדריך תחילת השימוש ב-GKE.

  5. כלי שורת הפקודה הבאים:

    • gcloud
    • kubectl

    הכלים gcloud ו-kubectl הם חלק מ-Google Cloud CLI. מידע על התקנת הרכיבים מופיע במאמר ניהול רכיבי Google Cloud CLI. כדי לראות את רכיבי ה-CLI של gcloud שהתקנתם, מריצים את הפקודה הבאה:

            gcloud components list
            

הגדרת הרשאות ל-Collector

אם השבתתם את Workload Identity ב-GKE, אתם יכולים לדלג על החלק הזה.

כדי לוודא שלחשבון השירות של Kubernetes ב-OpenTelemetry Collector יש את ההרשאות הנדרשות לייצוא נתוני טלמטריה, בקשו מהאדמין להקצות לחשבון השירות של Kubernetes ב-OpenTelemetry Collector את תפקידי ה-IAM הבאים בפרויקט:

להסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

יכול להיות שהאדמין גם יוכל לתת לחשבון השירות של Kubernetes של OpenTelemetry Collector את ההרשאות שנדרשות באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש אחרים.

כדי להגדיר את ההרשאות, משתמשים בפקודות הבאות של 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./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./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./subject/ns/opentelemetry/sa/opentelemetry-collector

לפני שמריצים את הפקודות, מחליפים את המשתנים הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט.
  • ‫PROJECT_NUMBER: מספר הפרויקט ב- Google Cloud .

פריסת ה-Collector

אפשר לפרוס את פייפליין Collector ישירות מהדוגמאות שנבדקו, שמופיעות במאגר Self-Managed OTLP Kubernetes Ingestion בניהול עצמי. אפשר לפרוס ישירות מ-GitHub באמצעות הפקודות הבאות, אחרי שמחליפים את PROJECT_ID במזהה של הפרויקט ב- Google Cloud :

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 -

לפני שמריצים את הפקודות, מחליפים את המשתנים הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט.
  • ‫PROJECT_NUMBER: המזהה המספרי של הפרויקט.

הגדרת ה-Collector

אנחנו מספקים הגדרה של OpenTelemetry Collector לשימוש עם ה-Collector ש-Google פיתחה. ההגדרה הזו נועדה להעביר כמויות גדולות של מדדים, יומנים ומעקבים של OTLP, עם מטא-נתונים עקביים של GKE ו-Kubernetes. ההגדרה הזו גם נועדה למנוע בעיות נפוצות בהטמעה. אפשר להוסיף להגדרות, אבל מומלץ מאוד לא להסיר רכיבים.

בקטע הזה מתוארים ההגדרות שסופקו, הרכיבים העיקריים כמו מייצאים, מעבדים, מקלטים ורכיבים זמינים אחרים.

הגדרת Collector שסופקה

אפשר למצוא את הגדרת ה-Collector לסביבות Kubernetes במאגר 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: http://${env:MY_POD_IP}:14317
              insecure: true

יצואנים

הגדרת ה-Collector משתמשת בפרטים הבאים:

מעבדים

ההגדרות של Collector כוללות את המעבדים הבאים:

  • ‫batch: מוגדר לאסוף בקשות טלמטריה באצווה לפי Google Cloud המספר המקסימלי של רשומות לכל בקשה, או לפי Google Cloud המרווח המינימלי של כל 5 שניות (המוקדם מביניהם).

  • ‫memory_limiter: מגדירה את מגבלת השימוש בזיכרון של ה-Collector כדי למנוע קריסות בגלל מחסור בזיכרון, על ידי השמטת נקודות על הגרף כשחורגים מהמגבלה.

  • ‫resourcedetection: זיהוי אוטומטי Google Cloud של תוויות משאבים כמו , project_id ו-cluster_name.

  • ‫k8sattributes: ממפה באופן אוטומטי מאפייני משאבים ב-Kubernetes לתוויות טלמטריה.

  • ‫transform: שינוי השם של תוויות המדדים שמתנגשות עם תוויות במשאבים במעקב ב- Google Cloud.

מקלטים

ההגדרות של Collector כוללות רק את המקלט otlp. במאמר בחירת גישה למדידת ביצועים מוסבר איך להגדיר את האפליקציות כך שישלחו עקבות ומדדים של OTLP לנקודת הקצה של ה-Collector.

רכיבים זמינים

ה-Google-Built OpenTelemetry Collector מכיל את הרכיבים שרוב המשתמשים צריכים כדי להפעיל חוויה עשירה ב-Google Cloud Observability. רשימה מלאה של הרכיבים הזמינים מופיעה בקטע Components במאגר opentelemetry-operations-collector.

כדי לבקש שינויים או תוספות לרכיבים הזמינים, הגישו בקשה להוספת תכונה במאגר opentelemetry-operations-collector.

יצירת טלמטריה

בקטע הזה נתאר איך לפרוס אפליקציה לדוגמה, להפנות את האפליקציה לנקודת הקצה של OTLP ב-Collector ולצפות בנתוני הטלמטריה ב-Google Cloud. אפליקציית הדוגמה היא מחולל קטן שמייצא מעקבים, יומנים ומדדים ל-Collector.

אם כבר יש לכם אפליקציה עם OpenTelemetry SDK, אתם יכולים להפנות את האפליקציה לנקודת הקצה של ה-Collector.

כדי לפרוס את האפליקציה לדוגמה, מריצים את הפקודה הבאה:

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

כדי להפנות אפליקציות קיימות שמשתמשות ב-OpenTelemetry SDK לנקודת הקצה של ה-Collector, מגדירים את משתנה הסביבה OTEL_EXPORTER_OTLP_ENDPOINT לערך http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317.

אחרי כמה דקות, נתוני הטלמטריה שנוצרו על ידי האפליקציה מתחילים לזרום דרך ה-Collector למסוף Google Cloud לכל אות.

הצגת נתוני הטלמטריה

הכלי Google-Built OpenTelemetry Collector שולח מדדים, יומנים ומעקבים מהאפליקציות עם האינסטרומנטציה אל Google Cloud Observability. ה-Collector גם שולח מדדי תצפיתיות עצמית. בקטעים הבאים מוסבר איך לצפות בנתוני הטלמטריה האלה.

איך רואים את המדדים

הכלי Google-Built OpenTelemetry Collector אוסף מדדים של Prometheus, שאפשר לראות באמצעות Metrics Explorer. המדדים שנאספים תלויים במכשור של האפליקציה, אבל ה-Collector שנוצר על ידי Google כותב גם כמה מדדים עצמיים.

כדי לראות את המדדים שנאספו על ידי Google-Built OpenTelemetry Collector:
  1. במסוף Google Cloud , נכנסים לדף  Metrics explorer:

    כניסה לדף Metrics Explorer

    אם אתם משתמשים בשורת החיפוש כדי למצוא את הדף הזה, בחרו בתוצאה שכותרת המשנה שלה היא Monitoring.

  2. בסרגל הכלים של מסוף Google Cloud , בוחרים את הפרויקט ב- Google Cloud . בהגדרות של App Hub, בוחרים את הפרויקט המארח של App Hub או את פרויקט הניהול של התיקייה לניהול אפליקציות.
  3. ברכיב Metric, מרחיבים את התפריט Select a metric, מזינים Prometheus Target בסרגל הסינון ומשתמשים בתפריטי המשנה כדי לבחור את סוג המשאב הספציפי ואת המדד:
    1. בתפריט Active resources בוחרים באפשרות Prometheus Target.
    2. כדי לבחור מדד, משתמשים בתפריטים Active metric categories ו-Active metrics. למדדים שנאספים על ידי Google-Built OpenTelemetry Collector יש את הקידומת prometheus.googleapis.com.
    3. לוחצים על אישור.
  4. כדי להוסיף מסננים שמסירים סדרות זמנים מתוצאות השאילתה, משתמשים ברכיב Filter.

  5. מגדירים את אופן התצוגה של הנתונים.

    כשהמדידות של מדד מסוים הן מצטברות, הכלי Metrics Explorer מנרמל באופן אוטומטי את הנתונים שנמדדו לפי תקופת ההתאמה, וכתוצאה מכך בתרשים מוצג שיעור. למידע נוסף, ראו סוגים, טיפוסים והמרות.

    כשמודדים ערכים של מספרים שלמים או ערכים כפולים, כמו במדדי counter, הכלי Metrics Explorer מסכם באופן אוטומטי את כל סדרות הזמנים. כדי לשנות את ההתנהגות הזו, מגדירים את התפריט הראשון של הרשומה Aggregation לערך None.

    מידע נוסף על הגדרת תרשים זמין במאמר איך בוחרים מדדים כשמשתמשים ב-Metrics Explorer.

הצגת המעקבים

כדי להציג את נתוני המעקב:

  1. במסוף Google Cloud , נכנסים לדף Trace explorer:

    כניסה לדף Trace Explorer

    אפשר גם למצוא את הדף הזה באמצעות שורת החיפוש.

  2. בסרגל הכלים של מסוף Google Cloud , בוחרים את הפרויקט ב- Google Cloud . בהגדרות של App Hub, בוחרים את הפרויקט המארח או את פרויקט הניהול של App Hub.
  3. בקטע של הטבלה בדף, בוחרים שורה.
  4. בתרשים הגאנט שבחלונית Trace details, בוחרים span.

    נפתח חלון שבו מוצג מידע על הבקשה שבוצע לה מעקב. הפרטים האלה כוללים את השיטה, קוד הסטטוס, מספר הבייטים וסוכן המשתמש של מבצע הקריאה.

  5. כדי לראות את היומנים שמשויכים למעקב הזה, בוחרים בכרטיסייה Logs & Events.

    בכרטיסייה מוצגים יומנים נפרדים. כדי לראות את הפרטים של הרשומה ביומן, מרחיבים אותה. אפשר גם ללחוץ על View Logs כדי לראות את היומן באמצעות Logs Explorer.

מידע נוסף על השימוש ב-Cloud Trace Explorer מופיע במאמר חיפוש ועיון במעקבים.

הצגת רישומי היומן

ב-Logs Explorer אתם יכולים לבדוק את היומנים, וגם לראות את המעקבים שמשויכים אליהם, אם יש כאלה.

  1. במסוף Google Cloud , נכנסים לדף Logs Explorer של :

    נכנסים ל-Logs Explorer.

    אם אתם משתמשים בשורת החיפוש כדי למצוא את הדף הזה, בחרו בתוצאה עם כותרת המשנה Logging.

  2. מאתרים רשומת יומן מהאפליקציה עם כלי המדידה ומרחיבים את הרשומה כדי לראות את הפרטים.

  3. לוחצים על Traces ברשומת יומן עם הודעת מעקב, ובוחרים באפשרות View trace details.

    החלונית Trace details נפתחת ומוצג בה המעקב שנבחר.

למידע נוסף על השימוש ב-Logs Explorer, קראו את המאמר הצגת יומנים באמצעות Logs Explorer.

מעקב אחרי ה-Collector וניפוי באגים

הכלי Google-Built OpenTelemetry Collector מספק באופן אוטומטי מדדי תצפית עצמית, כדי לעזור לכם לעקוב אחרי הביצועים שלו ולוודא שצינור עיבוד הנתונים של הטמעת OTLP פועל באופן תקין.

כדי לעקוב אחרי ה-Collector, מתקינים את לוח הבקרה לדוגמה של ה-Collector. בלוח הבקרה הזה מוצגות תובנות במבט מהיר על כמה מדדים מה-Collector, כולל זמן פעולה תקינה, שימוש בזיכרון וקריאות ל-API אל Google Cloud Observability.

כדי להתקין את מרכז הבקרה:

  1. נכנסים לדף  Dashboards במסוף Google Cloud :

    עוברים אל מרכזי בקרה.

    אם אתם משתמשים בשורת החיפוש כדי למצוא את הדף הזה, בחרו בתוצאה שכותרת המשנה שלה היא Monitoring.

  2. לוחצים על תבניות של מרכזי בקרה.
  3. מחפשים את מרכז הבקרה OpenTelemetry Collector.
  4. אופציונלי: כדי לראות תצוגה מקדימה של מרכז הבקרה, בוחרים אותו.
  5. לוחצים על Add dashboard to your list וממלאים את הפרטים בתיבת הדו-שיח.

    בתיבת הדו-שיח אפשר לבחור את שם לוח הבקרה ולהוסיף לו תוויות.

מידע נוסף על התקנת מרכזי בקרה זמין במאמר התקנת תבנית של מרכז בקרה.