Device Manager Project Overview

Device Manager is a Go-based microservice system designed to manage the lifecycle of device leases (both physical DUTs and virtual machines) within the ChromiumOS ecosystem. It provides a gRPC API for leasing, releasing, and querying devices, integrating with the Unified Fleet System (UFS) for device metadata and using Postgres (AlloyDB) for persistent storage.

Service Definition (API)

The DeviceLeaseService is defined in infra/go/src/go.chromium.org/chromiumos/config/proto/chromiumos/test/api/device_manager_service.proto.

Leasing RPCs

  • LeaseDevice: Leases a single device based on hardware or VM requirements. Requires an idempotency_key.
  • BulkLeaseDevices: Allows leasing multiple devices in a single request.
  • ReleaseDevice: Releases an active device lease using its lease_id.
  • ExtendLease: Modifies the expiration time of an existing lease.
  • GetDevice: Retrieves details for a specific device by its ID (Format: devices/{device_id}).
  • ListDevices: Lists devices managed by Device Manager, supporting filtering (AIP-160) and pagination.
  • ListDeviceLeases: Lists lease records for a specific device (by device_id or dut_id).

Key Data Structures

  • Device: Represents a managed device (ID, address, type, state, hardware requirements).
  • DeviceLeaseRecord: Tracks an active or past lease (ID, device info, timestamps, user payload).
  • LeaseDeviceRequest: Contains idempotency key, quota ID, duration, and requirements.

Architecture

The project is composed of several key services and internal components:

  • device_lease_service: The primary gRPC service (cmd/device_lease_service) that handles lease requests, extensions, and releases.
  • notifier_service: A background service (cmd/notifier_service) that monitors device changes and publishes events to Google Cloud Pub/Sub.
  • expirer_service: A service (cmd/expirer_service) responsible for identifying and processing expired leases.
  • internal/frontend: Implements the gRPC server and handles request routing.
  • internal/controller: Contains the core business logic for leasing and device management.
  • internal/model: Defines the database schema and provides data access objects (DAOs) for Postgres.
  • internal/jobs: Implements cron-like background tasks such as UFS device import, lease expiration, and BigQuery data persistence.
  • internal/external: Provides clients for interacting with external systems like UFS, Pub/Sub, and BigQuery.

Technologies

  • Language: Go
  • API: gRPC
  • Framework: LUCI server framework
  • Database: Postgres (AlloyDB)
  • Migrations: Alembic (Python-based)
  • Messaging: Google Cloud Pub/Sub
  • Analytics: BigQuery
  • Containerization: Docker & Docker Compose

Building and Running

The project uses a Makefile to streamline common development tasks.

Key Commands

  • Build: make build - Compiles the service binaries.
  • Local Development: make dev - Runs the Device Lease service locally with default flags.
  • Docker Compose:
    • make docker-db: Starts the Postgres database container.
    • make docker-pubsub: Starts the PubSub emulator.
    • make docker-service: Builds and runs the Device Lease service in Docker.
    • make docker-notifier: Builds and runs the Notifier service in Docker.
  • Database Migrations:
    • Setup: pip install -r requirements.txt
    • Run Migrations: ALEMBIC_ENV=alloydb.local alembic upgrade head
  • Testing:
    • Unit Tests: make test (runs go test ./...)
    • E2E Tests: make e2e

Development Conventions

  • API Standards: Follows AIP-160 for filtering syntax and AIP-131/AIP-132 for Get/List RPC patterns.
  • Authentication: Uses LUCI auth with support for Google ID tokens (OpenID Connect).
  • Logging: Uses go.chromium.org/luci/common/logging.
  • Idempotency: Lease and extension requests require an idempotency_key to prevent duplicate operations.
  • Database: Uses JSONB for flexible schedulable labels. Schema changes must be performed via Alembic migrations in database/versions/.