Skip to main content

Overview

Handler endpoints provide specialized functionality beyond standard resource CRUD operations, including interactive terminal access, log streaming, file downloads, and advanced filtering.

Terminal Handler

The terminal handler enables interactive shell access to containers via WebSocket (SockJS) connections.

Initialize Terminal Session

endpoint
Initialize a shell session to a containerPath Parameters:
  • namespace: Pod namespace
  • pod: Pod name
  • container: Container name
Query Parameters:
  • shell: Preferred shell (optional: bash, sh, powershell, cmd)
string
Session ID for binding the WebSocket connection

Example Request

Example Response

WebSocket Connection

After obtaining the session ID, establish a SockJS connection:

Terminal Message Protocol

The terminal uses a JSON-based message protocol:

Bind Message (Client → Server)

Stdin Message (Client → Server)

Resize Message (Client → Server)

Stdout Message (Server → Client)

Toast Message (Server → Client)

Shell Selection

If no shell is specified or the specified shell is invalid, the system tries shells in this order:
  1. bash
  2. sh
  3. powershell
  4. cmd

Session Timeout

WebSocket connections must be established within 10 seconds of receiving the session ID, or the session will be automatically cleaned up.

Terminal Features

  • Full TTY support: Supports terminal control codes and formatting
  • Resize handling: Dynamic terminal resizing
  • Multiple shell support: Automatically detects available shells
  • Session isolation: Each session is uniquely identified and isolated

Log Handler

Retrieve and download container logs.

Get Logs

endpoint
Get logs from the first container in a Pod
endpoint
Get logs from a specific containerQuery Parameters:
  • previous: Get logs from previous container instance (boolean)
  • tailLines: Number of lines to show from the end of logs
  • timestamps: Include timestamps (boolean)
  • sinceTime: Show logs since timestamp (RFC3339)
string[]
Array of log lines
object
Log metadata including pod info and timestamps

Example Request

Example Response

Download Log File

endpoint
Download logs as a text fileResponse Type: text/plain

Get Log Sources

endpoint
Get available log sources for a resource (e.g., containers in a deployment)Path Parameters:
  • namespace: Resource namespace
  • resourceName: Name of the resource
  • resourceType: Type of resource (e.g., deployment, replicaset)
array
List of available log sources with pod and container information

Download Handler

The download handler provides file download functionality with proper content-type headers.

Implementation

The handler automatically sets the Content-Type header to text/plain and streams content to the client:
This is used internally by:
  • Log file downloads
  • Configuration exports
  • Custom resource exports

Filter Handler

The filter system processes query parameters for resource filtering, sorting, and pagination.

Request Logging

All requests are logged with the following information:
Sensitive URLs (e.g., /api/v1/login, /api/v1/csrftoken/login) have their content hidden unless debug logging is enabled.

Response Logging

CSRF Validation

POST requests are validated for CSRF tokens unless:
  • CSRF protection is disabled via --disable-csrf
  • The request is to a validation endpoint (/api/v1/appdeployment/validate/*)

Metrics Collection

All requests are automatically tracked with Prometheus metrics:
counter
Total API requests broken down by verb, resource, client, content type, and status code
histogram
Request latency distribution in microsecondsBuckets: 125ms to 8 seconds (exponential)
summary
Request latency summary with 1-hour sliding window

Client IP Detection

The filter extracts client IPs from proxy headers in this order:
  1. X-Original-Forwarded-For
  2. X-Forwarded-For
  3. X-Real-Ip
  4. Direct RemoteAddr

Integration Handler

Integration endpoints are managed through the Integration Manager for metrics and external services.

Metrics Integration Endpoints

See Metrics API for detailed metrics integration endpoints.

Health Check

Integrations expose health check endpoints through the integration handler:

WebSocket (SockJS) Handler

The SockJS handler is mounted at:

Connection Flow

  1. Client requests terminal session via REST API
  2. Server returns session ID
  3. Client establishes SockJS connection to /api/sockjs/
  4. Client sends “bind” message with session ID
  5. Server validates and binds the session
  6. Bidirectional communication begins

SockJS Configuration

The handler uses default SockJS options:
  • WebSocket support enabled
  • HTTP streaming enabled
  • XHR polling as fallback

Error Handling

All handlers use consistent error handling:

Success Response

Error Response

Common Error Codes

  • 400 - Bad Request (invalid parameters)
  • 401 - Unauthorized (missing or invalid token)
  • 403 - Forbidden (insufficient permissions)
  • 404 - Not Found (resource doesn’t exist)
  • 500 - Internal Server Error

Example: Complete Terminal Session

Step 1: Get Session ID

Response:

Step 2: Connect WebSocket

Step 3: Send Commands

Step 4: Handle Terminal Resize