פריסת OpenTelemetry Collector מבית Google ב-Compute Engine

במאמר הזה נסביר איך להפעיל את Google-Built OpenTelemetry Collector ב-Compute Engine כדי לאסוף יומנים, מדדים ועקבות OTLP מאפליקציות עם אינסטרומנטציה, ואז לייצא את הנתונים האלה אל Google Cloud.

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

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

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  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 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 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 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. מכונה של Compute Engine. אם אין לכם מכונה של Compute Engine, אתם צריכים לפעול לפי ההוראות שבמאמר יצירת מכונה של Compute Engine והפעלה שלה.
  9. התקנה של gcloud. מידע על התקנה של gcloud זמין במאמר התקנה של gcloud CLI.

הגדרת הרשאות עבור הכלי לאיסוף נתונים

כברירת מחדל, מכונות ב-Compute Engine משתמשות בחשבון השירות שמוגדר כברירת מחדל של Compute Engine,‏ PROJECT_NUMBER-compute@developer.gserviceaccount.com. בדרך כלל לחשבון השירות הזה יש את התפקידים הנדרשים לניהול זהויות והרשאות גישה (IAM) כדי לכתוב את המדדים והיומנים שמתוארים במסמך הזה:

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

התקנת האוסף

כדי להתקין את Google-Built OpenTelemetry Collector כחבילה במכונה שלכם ב-Compute Engine, פועלים לפי השלבים הבאים.

‫Debian ו-Ubuntu

  1. פותחים חיבור לטרמינל של מופע המכונה הווירטואלית באמצעות SSH או כלי דומה, ומוודאים שיש לכם גישה sudo.

  2. מריצים את הפקודה הבאה כדי להגדיר את מאגר החבילות:

    sudo mkdir -p /etc/apt/keyrings
    sudo curl -o /etc/apt/keyrings/otelcol-google.asc https://packages.cloud.google.com/apt/doc/apt-key.gpg
    cat <<EOF | sudo tee /etc/apt/sources.list.d/otelcol-google.list
    deb [signed-by=/etc/apt/keyrings/otelcol-google.asc] https://us-apt.pkg.dev/projects/cloud-ops-agents-artifacts google-cloud-opentelemetry-collector-apt main
    EOF
    
  3. מרעננים את מנהל החבילות ומתקינים את החבילה:

    sudo apt update
    sudo apt install otelcol-google
    

    אחרי ההתקנה, Google-Built OpenTelemetry Collector מופעל באופן אוטומטי.

‫CentOS‏, RHEL ו-Rocky Linux

  1. פותחים חיבור לטרמינל של מופע המכונה הווירטואלית באמצעות SSH או כלי דומה, ומוודאים שיש לכם גישה sudo.

  2. מריצים את הפקודה הבאה כדי להגדיר את מאגר החבילות:

    cat <<EOF | sudo tee /etc/yum.repos.d/otelcol-google.repo
    [otelcol-google]
    name=Google Built OpenTelemetry Collector
    baseurl=https://us-yum.pkg.dev/projects/cloud-ops-agents-artifacts/google-cloud-opentelemetry-collector-yum
    autorefresh=0
    enabled=1
    type=rpm-md
    gpgcheck=1
    repo_gpgcheck=0
    gpgkey=http://dl.google.com/linux/linux_signing_key.pub
    EOF
    
  3. מתקינים את החבילה:

    sudo yum install otelcol-google
    

    אחרי ההתקנה, Google-Built OpenTelemetry Collector מופעל באופן אוטומטי.

SLES

  1. פותחים חיבור לטרמינל של מופע המכונה הווירטואלית באמצעות SSH או כלי דומה, ומוודאים שיש לכם גישה sudo.

  2. מריצים את הפקודה הבאה כדי להגדיר את מאגר החבילות:

    cat <<EOF | sudo tee /etc/zypp/repos.d/otelcol-google.repo
    [otelcol-google]
    name=Google Built OpenTelemetry Collector
    baseurl=https://us-yum.pkg.dev/projects/cloud-ops-agents-artifacts/google-cloud-opentelemetry-collector-yum
    autorefresh=0
    enabled=1
    type=rpm-md
    gpgkey=http://dl.google.com/linux/linux_signing_key.pub
    EOF
    
  3. מתקינים את החבילה:

    sudo zypper install otelcol-google
    

    אחרי ההתקנה, Google-Built OpenTelemetry Collector מופעל באופן אוטומטי.

Windows

  1. מתחברים למופע באמצעות RDP או כלי דומה ומתחברים ל-Windows.

  2. פותחים טרמינל ב-PowerShell עם הרשאות אדמין. לשם כך, לוחצים לחיצה ימנית על סמל PowerShell ובוחרים באפשרות הפעלה כמנהל מערכת.

  3. מריצים את פקודת PowerShell הבאה כדי להגדיר את מאגר החבילות:

    googet addrepo otelcol-google `
        https://us-googet.pkg.dev/projects/cloud-ops-agents-artifacts/repos/google-cloud-opentelemetry-collector-googet
    
  4. מתקינים את החבילה:

    googet install otelcol-google
    

    אחרי ההתקנה, Google-Built OpenTelemetry Collector מופעל באופן אוטומטי.

פריסת ה-Collector

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

  • ב-Linux: /etc/otelcol-google/config.yaml
  • ב-Windows: ‏ C:\Program Files\Google\OpenTelemetry Collector\config.yaml

הגדרת האספן

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

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

הגדרות של כלי האיסוף שסופקו

אפשר למצוא את ההגדרה של Collector בספרייה google-built-opentelemetry-collector במאגר opentelemetry-operations-collector:

receivers:
  # Open two OTLP servers:
  # - On port 4317, open an OTLP GRPC server
  # - On port 4318, open an OTLP HTTP server
  #
  # Docs:
  # https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver
  otlp:
    protocols:
      grpc:
        endpoint: localhost:4317
      http:
        cors:
          # This effectively allows any origin
          # to make requests to the HTTP server.
          allowed_origins:
          - http://*
          - https://*
        endpoint: localhost:4318

processors:
  # The batch processor is in place to regulate both the number of requests
  # being made and the size of those requests.
  #
  # Docs:
  # https://github.com/open-telemetry/opentelemetry-collector/tree/main/processor/batchprocessor
  batch:
    send_batch_max_size: 200
    send_batch_size: 200
    timeout: 5s

  # The memorylimiter will check the memory usage of the collector process.
  #
  # Docs:
  # https://github.com/open-telemetry/opentelemetry-collector/tree/main/processor/memorylimiterprocessor
  memory_limiter:
    check_interval: 1s
    limit_percentage: 65
    spike_limit_percentage: 20

  # The resourcedetection processor is configured to detect GCP resources.
  # Resource attributes that represent the GCP resource the collector is
  # running on will be attached to all telemetry that goes through this
  # processor.
  #
  # Docs:
  # https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor
  # https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#gcp-metadata
  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")

  transform/set_project_id:
    error_mode: ignore
    trace_statements:
    - set(resource.attributes["gcp.project_id"], resource.attributes["gcp.project.id"]) where resource.attributes["gcp.project.id"] != nil
    - set(resource.attributes["gcp.project_id"], resource.attributes["cloud.account.id"]) where resource.attributes["gcp.project_id"] == nil and resource.attributes["cloud.account.id"] != nil

exporters:
  # The googlecloud exporter will export telemetry to different
  # Google Cloud services:
  # Logs -> Cloud Logging
  # Metrics -> Cloud Monitoring
  #
  # Docs:
  # https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/googlecloudexporter
  googlecloud:
    log:
      default_log_name: opentelemetry-collector

  # The googlemanagedprometheus exporter will send metrics to
  # Google Managed Service for Prometheus.
  #
  # Docs:
  # https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/googlemanagedprometheusexporter
  googlemanagedprometheus:

  # The otlp exporter is used to send traces to GCP Telemetry API using OTLP gRPC
  otlp:
    endpoint: telemetry.googleapis.com:443
    compression: none
    balancer_name: pick_first
    auth:
      authenticator: googleclientauth

extensions:
  # Opens an endpoint on 13133 that can be used to check the
  # status of the collector. Since this does not configure the
  # `path` config value, the endpoint will default to `/`.
  #
  # When running on Cloud Run, this extension is required and not optional.
  # In other environments it is recommended but may not be required for operation
  # (i.e. in Container-Optimized OS or other GCE environments).
  #
  # Docs:
  # https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/healthcheckextension
  health_check:
    endpoint: 0.0.0.0:13133
  googleclientauth:

service:
  extensions:
  - health_check
  - googleclientauth
  pipelines:
    logs:
      receivers:
      - otlp
      processors:
      - resourcedetection
      - memory_limiter
      - batch
      exporters:
      - googlecloud
    metrics/otlp:
      receivers:
      - otlp
      processors:
      - resourcedetection
      - transform/collision
      - memory_limiter
      - batch
      exporters:
      - googlemanagedprometheus
    traces:
      receivers:
      - otlp
      processors:
      - resourcedetection
      - memory_limiter
      - transform/set_project_id
      - batch
      exporters:
      - otlp
  # Internal telemetry for the collector supports both push and pull-based telemetry data transmission.
  # Leveraging the pre-configured OTLP receiver eliminates the need for an additional port.
  #
  # Docs:
  # https://opentelemetry.io/docs/collector/internal-telemetry/
  telemetry:
    metrics:
      readers:
        - periodic:
            exporter:
              otlp:
                protocol: grpc
                endpoint: http://localhost:4317
                insecure: true

יצואנים

ההגדרות של Collector כוללות את האקספורטרים הבאים:

  • googlecloud exporter, for logs and traces. כלי הייצוא הזה מוגדר עם שם יומן ברירת מחדל.

  • googlemanagedprometheus exporter, למדדים. לא צריך להגדיר את הכלי הזה לייצוא, אבל יש אפשרויות הגדרה. מידע על אפשרויות ההגדרה של googlemanagedprometheus exporter זמין במאמר תחילת העבודה עם OpenTelemetry Collector במסמכי התיעוד של השירות המנוהל של Google Cloud ל-Prometheus.

מעבדים

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

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

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

  • resourcedetection: מזהה באופן אוטומטי Google Cloud תוויות משאבים כמו project_id.

מקלטים

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

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

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

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

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

אתם יכולים לבדוק את ההגדרה באמצעות הכלי telemetrygen בקוד פתוח. הוראות להורדה ולהרצה של הכלי מופיעות בקישור. כדי להריץ את הכלי, צריך להתקין את Go או את Docker.

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

צפייה בטלמטריה

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

הצגת המדדים

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

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

    כניסה אל Metrics Explorer

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

  2. בסרגל הכלים של מסוף Google Cloud , בוחרים את Google Cloud הפרויקט. בהגדרות של מרכז האפליקציות, בוחרים את הפרויקט המארח של מרכז האפליקציות או את פרויקט הניהול של התיקייה לניהול אפליקציות.
  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 מבצע נרמול אוטומטי של הנתונים שנמדדו לפי תקופת ההתאמה, וכתוצאה מכך התרשים מציג קצב. מידע נוסף זמין במאמר סוגים, סוגים והמרות.

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

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

הצגת העקבות

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

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

    כניסה אל Trace explorer

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

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

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

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

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

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

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

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

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

    כניסה אל Logs Explorer

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

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

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

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

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

צפייה ב-Collector וניפוי באגים שלו

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

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

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

  1. במסוף Google Cloud , עוברים לדף  Dashboards:

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

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

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

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

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