processor

package
v1.58.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package processor provides client functionality for the Agones allocation processor system

The allocation processor system enables batched game server allocation requests This package contains the client implementation that connects to the processor service batches allocation requests, and handles the stream-based communication protocol

Key components: - Client: Manages connection lifecycle and request batching - Config: Configuration for processor client behavior - Batch handling: Accumulates requests and sends them in batches to the processor

The client establishes a bidirectional gRPC stream with the processor service, registers itself, and then handles pull requests (to send batched allocations) and batch responses (containing allocation results)

Flow diagram:

┌─────────────────┐    ┌─────────────────────┐    ┌─────────────────────┐
│     Client      │    │  Processor Client   │    │  Processor Server   │
│  (Allocator/    │    │   (this package)    │    │                     │
│   Extension)    │    │                     │    │                     │
└─────────────────┘    └─────────────────────┘    └─────────────────────┘
         │                        │                          │
         │                        │ 1. Connect & Register    │
         │                        │    (bidirectional stream)│
         │                        ├──────────────────────────►
         │                        │                          │
         │ 2. Allocate(request)   │                          │
         ├────────────────────────►                          │
         │                        │                          │
         │                        │ 3. Add to hotBatch       │
         │                        │    (accumulate)          │
         │                        │                          │
         │                        │ 4. Pull Request          │
         │                        │    (to all clients)      │
         │                        ◄──────────────────────────┤
         │                        │ 5. Send BatchRequest     │
         │                        │    (hotBatch)            │
         │                        ├──────────────────────────►
         │                        │                          │
         │                        │                          │ 6. Process
         │                        │                          │    allocations
         │                        │                          │
         │                        │ 7. BatchResponse         │
         │                        │    (results)             │
         │                        ◄──────────────────────────┤
         │ 8. Return result       │                          │
         ◄────────────────────────┤                          │
         │                        │                          │

Note: Multiple Processor Clients can connect to one Processor Server
      The server sends pull requests to all connected clients

Legend:
- Client: Makes allocation requests (allocator, extensions, etc.)
- Processor Client: Batches requests and manages communication
- Processor Server: Processes batched allocations from multiple clients
- Pull Request: Server asks all connected clients for pending requests
- BatchRequest: Client sends accumulated allocation requests
- BatchResponse: Server returns allocation results

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GRPCCodeFromHTTPStatus

func GRPCCodeFromHTTPStatus(httpStatusCode int) codes.Code

GRPCCodeFromHTTPStatus converts an HTTP status code to the corresponding gRPC status code

Types

type Client

type Client interface {
	// Run starts the processor client
	Run(ctx context.Context) error

	// Allocate performs a batch allocation request
	Allocate(ctx context.Context, req *allocationpb.AllocationRequest) (*allocationpb.AllocationResponse, error)
}

Client interface for allocation operations Provides methods to run the processor client and perform allocation requests

func NewClient

func NewClient(config Config, logger logrus.FieldLogger) Client

NewClient creates a new processor client

type Config

type Config struct {
	// ClientID is a unique identifier for this processor client instance
	ClientID string

	// ProcessorAddress specifies the address of the processor service to connect to
	ProcessorAddress string

	// MaxBatchSize determines the maximum number of allocation requests to batch together
	MaxBatchSize int

	// AllocationTimeout is the maximum duration to wait for an allocation response
	AllocationTimeout time.Duration

	// ReconnectInterval is the time to wait before retrying a failed connection
	ReconnectInterval time.Duration
}

Config holds the processor client configuration

type GameServerAllocator

type GameServerAllocator interface {
	Allocate(ctx context.Context, gsa *allocationv1.GameServerAllocation) (k8sruntime.Object, error)
}

GameServerAllocator represents the interface to allocate game servers.

type Handler

type Handler struct {
	allocationpb.UnimplementedProcessorServer
	// contains filtered or unexported fields
}

Handler is the gRPC server for processing allocation requests.

func NewServiceHandler

func NewServiceHandler(allocator GameServerAllocator, pullInterval time.Duration, grpcUnallocatedStatusCode codes.Code) *Handler

NewServiceHandler creates a new ProcessorHandler with the given allocator.

func (*Handler) GetGRPCServerOptions

func (h *Handler) GetGRPCServerOptions() []grpc.ServerOption

GetGRPCServerOptions returns a list of gRPC server options.

func (*Handler) StartPullRequestTicker

func (h *Handler) StartPullRequestTicker(ctx context.Context)

StartPullRequestTicker periodically sends pull requests to all connected clients.

func (*Handler) StreamBatches

func (h *Handler) StreamBatches(stream allocationpb.Processor_StreamBatchesServer) error

StreamBatches handles a bidirectional stream for batch allocation requests from a client. Registers the client, processes incoming batches, and sends responses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL