Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How We Use Cloud Run and its Friends

How We Use Cloud Run and its Friends

Yuki Ito

July 13, 2022
Tweet

More Decks by Yuki Ito

Other Decks in Technology

Transcript

  1. How We Use Cloud Run and its Friends!
    Yuki Ito (@mrno110)
    Kauche Tech Talk

    View Slide

  2. Kauche


    Architect
    Yuki Ito


    @mrno110

    View Slide

  3. View Slide

  4. Agenda
    ɾWhat is Cloud Run


    ɾArchitecture


    ɾObservability

    View Slide

  5. Agenda
    ɾWhat is Cloud Run


    ɾArchitecture


    ɾObservability

    View Slide

  6. What is Cloud Run
    Cloud Run is a managed compute
    platform that enables you to run
    containers that are invocable via
    requests or events.


    Cloud Run is serverless: it abstracts
    away all infrastructure management...
    https://cloud.google.com/run/docs

    View Slide

  7. Agenda
    ɾWhat is Cloud Run


    ɾArchitecture


    ɾObservability

    View Slide

  8. Agenda
    ɾWhat is Cloud Run


    ɾArchitecture


    ɾObservability

    View Slide

  9. Architecture
    Run
    Tasks
    Pub/Sub
    Mobile App External Service
    Mobile API Web Hook API Job API
    Scheduler

    View Slide

  10. Architecture - Key Concepts -
    ɾEverything runs on Cloud Run


    ɾEverything runs as a API

    View Slide

  11. Architecture - Key Concepts -
    e.g.) VS. Cloud Functions Trigger
    Run Pub/Sub Functions
    Run Firestore Functions

    View Slide

  12. Architecture
    Run
    Tasks
    Pub/Sub
    Mobile App External Service
    Mobile API Web Hook API Job API
    Scheduler

    View Slide

  13. Architecture
    ✅ Everything is Managed by API De
    fi
    nitions


    ✅ Reuse same implementation logic as APIs


    ✅ Use same Monitoring environments

    View Slide

  14. Architecture
    Run
    Tasks
    Pub/Sub
    Mobile App External Service
    Mobile API Web Hook API Job API
    Scheduler

    View Slide

  15. Job
    Run
    Pub/Sub

    View Slide

  16. Job
    resource "google_pubsub_topic" "foo" {
    name = "foo"
    }
    resource "google_pubsub_subscription" "job-foo" {
    name = "job-foo"
    topic = google_pubsub_topic.foo.name
    push_config {
    push_endpoint = ""
    }
    }

    View Slide

  17. Job
    Run
    Pub/Sub
    💀


    View Slide

  18. Job
    Run
    Pub/Sub
    Service Account

    View Slide

  19. Job
    Run
    Pub/Sub
    OIDC Token (JWT)

    View Slide

  20. Job
    resource "google_project_iam_member" "pubsub-is-sa-token-creator" {
    project = ""
    role = "roles/iam.serviceAccountTokenCreator"
    member = "serviceAccount:[email protected]
    }
    roles/iam.serviceAccountTokenCreator

    View Slide

  21. Job
    resource "google_service_account" "job-api-invoker" {
    // ...
    account_id = "job-api-invoker"
    }
    resource "google_pubsub_subscription" "job-foo" {
    name = "job-foo"
    topic = google_pubsub_topic.foo.name
    push_config {
    push_endpoint = ""
    oidc_token {
    service_account_email = "[email protected]"
    audience = ""
    }
    }
    }

    View Slide

  22. Job
    Run
    Pub/Sub Public Keys
    OIDC Token (JWT) JWKS
    🔑 JWT Veri
    fi
    cation

    View Slide

  23. Job
    Run
    Pub/Sub
    💀


    View Slide

  24. Architecture
    Run
    Tasks
    Pub/Sub
    Mobile App External Service
    Mobile API Web Hook API Job API
    Scheduler

    View Slide

  25. Agenda
    ɾWhat is Cloud Run


    ɾArchitecture


    ɾObservability

    View Slide

  26. Agenda
    ɾWhat is Cloud Run


    ɾArchitecture


    ɾObservability

    View Slide

  27. Observability
    • Logging


    • Trace


    • Monitoring Dashboard

    View Slide

  28. Observability
    • Logging


    • Trace

    View Slide

  29. Logging
    • Request logs


    • Container logs
    https://cloud.google.com/run/docs/logging
    Cloud Run has two types of
    logs:
    automatically sent to Cloud Logging

    View Slide

  30. Logging
    • Request logs


    • Container logs
    https://cloud.google.com/run/docs/logging
    Cloud Run has two types of
    logs:
    automatically sent to Cloud Logging

    View Slide

  31. Logging
    Cloud Run generates Request Logs

    View Slide

  32. Logging
    Cloud Run generates Request Logs
    Not enough...

    View Slide

  33. Logging
    • Request logs


    • Container logs
    https://cloud.google.com/run/docs/logging
    Cloud Run has two types of
    logs:
    automatically sent to Cloud Logging

    View Slide

  34. Logging
    Container (Application) logs

    View Slide

  35. Logging
    Container (Application) logs
    Structured Log

    View Slide

  36. Logging
    Request Logs


    +


    Container Logs
    https://cloud.google.com/run/docs/logging#correlate-logs
    Correlating

    View Slide

  37. Logging
    Correlating
    Request Logs
    Container Logs

    View Slide

  38. Logging
    Correlating

    View Slide

  39. Logging
    Container (Application) logs
    {
    "message": "grpc request",
    "logger": "grpc.request_logger",
    "method": "/customer.v1.CustomerService/GetXXX",
    "level": "info",
    "timestamp": 1613885945098.689
    "logging.googleapis.com/trace": "projects/.../traces/xxx",
    }
    https://cloud.google.com/logging/docs/structured-logging

    View Slide

  40. Logging
    Container
    X-Cloud-Trace-Context: projects/.../traces/xxx
    Header

    View Slide

  41. Logging
    Correlating

    View Slide

  42. Logging
    Correlating
    Request Logs
    Container Logs

    View Slide

  43. Observability
    • Logging


    • Trace

    View Slide

  44. Observability
    • Logging


    • Trace

    View Slide

  45. Trace
    Cloud Trace

    View Slide

  46. Trace
    OpenTelemetry
    OpenTelemetry is a collection of tools, APIs, and SDKs.
    Use it to instrument, generate, collect, and export
    telemetry data (metrics, logs, and traces) to help you
    analyze your software’s performance and behavior.
    https://opentelemetry.io/

    View Slide

  47. Trace
    OpenTelemetry

    View Slide

  48. Trace
    OpenCensus

    View Slide

  49. Trace
    OpenTelemetry + OpenCensus (Bridge)

    View Slide

  50. Agenda
    ɾWhat is Cloud Run


    ɾArchitecture


    ɾObservability

    View Slide

  51. Architecture
    Run
    Tasks
    Pub/Sub
    Mobile App External Service
    Mobile API Web Hook API Job API
    Scheduler

    View Slide

  52. AD
    https://kauche.connpass.com/event/252043/
    7/20 (Wed)

    View Slide