Skip to content

[Proposal] Enhanced Lease Statuses for Hooks #25

@kirkbrauer

Description

@kirkbrauer

Problem

Jumpstarter PR #606 adds new before/after lease hooks, but the client experience is poor due to lack of visibility into hook execution.

Current Issues

  1. Poor User Experience: When a client connects to an exporter running beforeLease hooks, the exporter appears to "freeze" - clients can connect but all driver calls are blocked by the _before_lease_ready Event until the before lease hook is complete.

  2. No Progress Indication: Users have no way to know that hooks are running, how long they might take, or what's happening during execution.

  3. Confusing Availability: During after lease hook execution, the exporter appears unavailable for new leases, which can confuse users.

  4. No Monitoring: Users cannot monitor after lease hook execution after releasing a lease from the CLI.

Current Implementation

  • Exporters use an async Event to block all driver calls until the hook is complete
  • Hook execution happens silently with only internal logging to the exporter console
  • Clients have no indication that hooks are running or their progress
  • The j CLI provides no feedback during hook execution

Proposed Solution

1. Protocol Changes

Add Exporter Status Enum to client.proto

message Exporter {
  // ... existing fields ...
  optional ExporterStatus status = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
}

enum ExporterStatus {
  EXPORTER_STATUS_UNSPECIFIED = 0;
  EXPORTER_STATUS_AVAILABLE = 1;           // No lease, ready for connections
  EXPORTER_STATUS_BEFORE_LEASE_HOOK = 2;   // Running beforeLease hooks
  EXPORTER_STATUS_LEASED = 3;              // Leased and ready for commands
  EXPORTER_STATUS_AFTER_LEASE_HOOK = 4;    // Running afterLease hooks
}

Add Log Source to jumpstarter.proto

message LogStreamResponse {
  string uuid = 1;
  string severity = 2;
  string message = 3;
  optional LogSource source = 4;  // New optional field
}

enum LogSource {
  LOG_SOURCE_UNSPECIFIED = 0;
  LOG_SOURCE_EXPORTER = 1;       // System/exporter logs
  LOG_SOURCE_DRIVER = 2;          // Driver/device logs
  LOG_SOURCE_HOOK = 3;            // Hook execution logs
  LOG_SOURCE_MESSAGE = 4;        // Message (reserved for future MOTD use)
}

2. Implementation Changes

Exporter Updates

  • Track current status using ExporterStatus enum
  • Report status through existing GetReport and Status RPCs
  • Stream hook logs through LogStream with appropriate LogSource
  • Continue blocking driver calls for existing clients, new clients can see status

Hook Executor Updates

  • Send hook output to LogStream with correct LogSource field
  • Maintain existing execution logic
  • Add progress indication in log messages

Client Updates

  • Check exporter status when connecting
  • Display appropriate waiting messages based on status
  • Subscribe to LogStream and filter by source for hook progress
  • Allow optional monitoring of after lease hooks (Ctrl+C ends lease, but waits)

3. User Experience Improvements

Before

$ j shell -l device=rpi4
Connecting to exporter...
[Connection appears to hang with no feedback]

After

$ j shell -l device=rpi4
Connecting to exporter...
Waiting for beforeLease hooks to complete...
[Hook INFO] Powering on device...
[Hook INFO] Initializing network interface...
[Hook INFO] Configuring storage...
beforeLease hooks completed successfully!
Connected to device.

[User works with device...]

Releasing lease...
afterLease hooks running (press Ctrl+C to disconnect):
[Hook Output] Saving logs to archive...
[Hook Output] Cleaning up workspace...
afterLease hooks completed.

Hooks Example

Hooks will be able to log messages by adding the JMP_INFO, JMP_WARN, or JMP_ERROR prefix to log messages.

Example hook shell script:

echo "JMP_INFO: This is informational"
echo "JMP_ERROR: This is an error message"
echo "JMP_WARN: This is a warning"

echo "If the type is not specified, it will be an info-level message"

Example client CLI output:

$ j shell -l device=rpi4
Connecting to exporter...
Waiting for beforeLease hooks to complete...
[Hook INFO] This is informational
[Hook ERROR] This is an error message
[Hook WARN] This is a warning
[Hook INFO] If the type is not specified, it will be an info-level message'
beforeLease hooks completed successfully!
Connected to device.

4. Backward Compatibility

  • All new protocol fields are optional
  • Existing clients continue to work without changes (calls are blocked)
  • Graceful degradation for clients that don't understand new status
  • No breaking changes to existing APIs

Implementation Plan

Phase 1: Protocol Updates

  1. Add enums to client.proto and jumpstarter.proto in the jumpstarter-protocol.
  2. Regenerate protobuf code and migrate existing client/exporter
  3. Update exporter to track and report status

Phase 2: Hook Integration (#606)

  1. Modify hook executor to use LogStream
  2. Update exporter status transitions
  3. Test status reporting

Phase 3: Client Updates

  1. Update j CLI to check and display status
  2. Add LogStream filtering by source
  3. Implement progress indication

Phase 4: Documentation

  1. Update user documentation
  2. Add examples of hook status handling
  3. Update API documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions