פריסת Google-Built OpenTelemetry Collector ב-Cloud Run

במאמר הזה מוסבר איך להפעיל את Google-Built OpenTelemetry Collector ב-Cloud Run כדי לאסוף יומנים, מדדים ועקבות 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. שירות Cloud Run. אם אין לכם שירות Cloud Run, אתם צריכים לפעול לפי ההוראות במאמר תכנון והכנה של השירות.
  9. התקנה של gcloud. מידע על התקנה של gcloud זמין במאמר התקנה של gcloud CLI.

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

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

צריך לבקש מהאדמין להקצות לכם בפרויקט את תפקידי ה-IAM הבאים:

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

פריסת ה-Collector

כדי להתקין את Google-Built OpenTelemetry Collector כ-sidecar ל-Cloud Run, קודם צריך ליצור סוד לאחסון ההגדרה של ה-Collector.

gcloud secrets create SECRET_NAME --data-file=config.yaml --project=PROJECT_ID

בשלב הבא, מוסיפים את Google-Built OpenTelemetry Collector כ-sidecar ל-service.yaml:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  annotations:
    run.googleapis.com/launch-stage: ALPHA
  name: google-otel-cloud-run-sample
spec:
  template:
    metadata:
      annotations:
        # [REQUIRED] set the collector as a parent to the app
        run.googleapis.com/container-dependencies: "{app:[collector]}"
        run.googleapis.com/secrets: 'SECRET_NAME:projects/PROJECT_ID/secrets/SECRET_NAME'
    spec:
      containers:
      - image: my-app
        name: app
        ports:
        - containerPort: 8080
        env:
        - name: "OTEL_EXPORTER_OTLP_ENDPOINT"
          value: "http://localhost:4317"
      - image: "us-docker.pkg.dev/cloud-ops-agents-artifacts/google-cloud-opentelemetry-collector/otelcol-google:0.155.0"
        args:
        - --config=/etc/otelcol-google/config.yaml
        name: collector
        startupProbe:
          httpGet:
            path: /
            port: 13133
          timeoutSeconds: 30
          periodSeconds: 30
        livenessProbe:
          httpGet:
            path: /
            port: 13133
          timeoutSeconds: 30
          periodSeconds: 30
        volumeMounts:
        - mountPath: /etc/otelcol-google/
          name: config
      volumes:
      - name: config
        secret:
          items:
          - key: latest
            path: config.yaml
          secretName: 'SECRET_NAME'

הגדרת האספן

אנחנו מספקים הגדרה של 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.

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

כדי ליצור טלמטריה, יוצרים אפליקציית Cloud Run עם קובץ עזר לאיסוף נתונים. במסמך Write OTLP metrics by using an OpenTelemetry sidecar יש הדרכה לשימוש ב-Google-Built OpenTelemetry Collector כ-sidecar. אתם יכולים להשתמש במדריך הזה כדי ליצור טלמטריה באמצעות כלי האיסוף שנוצר על ידי Google.

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

‫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. לוחצים על הוספת מרכז הבקרה לרשימה ומשלימים את תיבת הדו-שיח.

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

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