Documentation
¶
Overview ¶
Context utilities for passing batch metadata through the call stack. Allows downstream code to check if a request was batched and access batch info.
Coordinator executes batches against Azure. It transforms a PendingBatch into a single API call using a custom "BatchPutMachine" HTTP header that lists all machines. This turns N API calls into 1, improving throughput and allowing Azure to optimize placement.
Package batch groups VM creation requests to reduce Azure API calls.
Instead of creating VMs one-by-one, the Grouper collects requests with identical configurations and sends them as a single batched API call. This improves throughput, reduces rate limiting, and lets Azure optimize placement.
Flow:
Requests ──► Grouper (groups by template hash) ──► Coordinator (executes batch)
│
Batch 1: VMs with same config
Batch 2: VMs with different config
Data types for the batch system.
Flow: CreateRequest → PendingBatch → BatchPutMachineHeader → CreateResponse
Index ¶
- func ShouldSkipBatching(ctx context.Context) bool
- func WithBatchMetadata(ctx context.Context, meta *BatchMetadata) context.Context
- func WithFakeBatchEntries(ctx context.Context, entries []MachineEntry) context.Context
- func WithSkipBatching(ctx context.Context) context.Context
- type BatchMetadata
- type BatchPutMachineHeader
- type BatchingMachinesClient
- func (c *BatchingMachinesClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, resourceName string, ...) (*runtime.Poller[armcontainerservice.MachinesClientCreateOrUpdateResponse], ...)
- func (c *BatchingMachinesClient) Get(ctx context.Context, resourceGroupName string, resourceName string, ...) (armcontainerservice.MachinesClientGetResponse, error)
- func (c *BatchingMachinesClient) NewListPager(resourceGroupName string, resourceName string, agentPoolName string, ...) *runtime.Pager[armcontainerservice.MachinesClientListResponse]
- type Coordinator
- type CreateRequest
- type CreateResponse
- type Grouper
- type MachineEntry
- type Options
- type PendingBatch
- type VMSkus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ShouldSkipBatching ¶
ShouldSkipBatching checks if context is marked to bypass batching.
func WithBatchMetadata ¶
func WithBatchMetadata(ctx context.Context, meta *BatchMetadata) context.Context
WithBatchMetadata attaches BatchMetadata to a context.
func WithFakeBatchEntries ¶
func WithFakeBatchEntries(ctx context.Context, entries []MachineEntry) context.Context
WithFakeBatchEntries attaches per-machine entries to a context so the fake/test API client can see which machines are being created in this batch. This has NO production significance — the real Azure API reads per-machine data from the BatchPutMachine HTTP header, not from context.
Why this exists: policy.WithHTTPHeader stores the header using an unexported context key (internal/shared.CtxWithHTTPHeaderKey{}) and the SDK provides no public getter. Our fake implements the Go interface directly (no HTTP pipeline), so the header never materializes into an http.Request the fake could inspect. This context key mirrors the same []MachineEntry data so that in-process fakes can access it.
Types ¶
type BatchMetadata ¶
BatchMetadata is attached to context after batch execution.
func FromContext ¶
func FromContext(ctx context.Context) *BatchMetadata
FromContext retrieves BatchMetadata if present, nil otherwise.
type BatchPutMachineHeader ¶
type BatchPutMachineHeader struct {
VMSkus VMSkus `json:"vmSkus"`
BatchMachines []MachineEntry `json:"batchMachines"`
}
BatchPutMachineHeader is the JSON structure sent via HTTP header to Azure. It lists per-machine variations (name, zones, tags) while the API body contains the shared template.
type BatchingMachinesClient ¶
type BatchingMachinesClient struct {
// contains filtered or unexported fields
}
func NewBatchingMachinesClient ¶
func NewBatchingMachinesClient( realClient azclient.AKSMachinesAPI, grouper *Grouper, resourceGroup string, clusterName string, poolName string, ) *BatchingMachinesClient
func (*BatchingMachinesClient) BeginCreateOrUpdate ¶
func (c *BatchingMachinesClient) BeginCreateOrUpdate( ctx context.Context, resourceGroupName string, resourceName string, agentPoolName string, aksMachineName string, parameters armcontainerservice.Machine, options *armcontainerservice.MachinesClientBeginCreateOrUpdateOptions, ) (*runtime.Poller[armcontainerservice.MachinesClientCreateOrUpdateResponse], error)
func (*BatchingMachinesClient) Get ¶
func (c *BatchingMachinesClient) Get( ctx context.Context, resourceGroupName string, resourceName string, agentPoolName string, aksMachineName string, options *armcontainerservice.MachinesClientGetOptions, ) (armcontainerservice.MachinesClientGetResponse, error)
func (*BatchingMachinesClient) NewListPager ¶
func (c *BatchingMachinesClient) NewListPager( resourceGroupName string, resourceName string, agentPoolName string, options *armcontainerservice.MachinesClientListOptions, ) *runtime.Pager[armcontainerservice.MachinesClientListResponse]
type Coordinator ¶
type Coordinator struct {
// contains filtered or unexported fields
}
func NewCoordinator ¶
func NewCoordinator( realClient azclient.AKSMachinesAPI, resourceGroup string, clusterName string, poolName string, ) *Coordinator
func (*Coordinator) ExecuteBatch ¶
func (c *Coordinator) ExecuteBatch(batch *PendingBatch)
ExecuteBatch sends a batch to Azure as one API call, then distributes results (success or per-machine errors) back to each request's channel.
type CreateRequest ¶
type CreateRequest struct {
// contains filtered or unexported fields
}
CreateRequest is a single VM creation request. The caller waits on responseChan.
type CreateResponse ¶
type CreateResponse struct {
Poller *runtime.Poller[armcontainerservice.MachinesClientCreateOrUpdateResponse]
Err error
BatchID string // For log correlation
}
CreateResponse is sent back via the request's channel after batch execution. Contains either a Poller (success) or Err (failure).
type Grouper ¶
type Grouper struct {
// contains filtered or unexported fields
}
Grouper collects VM creation requests and groups them by template for batch execution.
It runs a background loop that waits for requests, gives them time to accumulate, then dispatches batches to the Coordinator. Requests with identical VM configs (same size, OS, network, etc.) land in the same batch.
func NewGrouper ¶
NewGrouper creates a Grouper. Call SetCoordinator() then Start() to begin processing.
func (*Grouper) EnqueueCreate ¶
func (g *Grouper) EnqueueCreate(req *CreateRequest) chan *CreateResponse
EnqueueCreate adds a request to the appropriate batch and returns a channel for the response. The caller should wait on the returned channel.
func (*Grouper) SetCoordinator ¶
func (g *Grouper) SetCoordinator(coordinator *Coordinator)
type MachineEntry ¶
type MachineEntry struct {
MachineName string `json:"machineName"`
Zones []string `json:"zones"`
Tags map[string]string `json:"tags"`
}
func FakeBatchEntriesFromContext ¶
func FakeBatchEntriesFromContext(ctx context.Context) []MachineEntry
FakeBatchEntriesFromContext retrieves per-machine batch entries if present. Only used by fakes/tests — see WithFakeBatchEntries.
type Options ¶
Options tunes the batching behavior.
Small timeouts = lower latency, more API calls Large timeouts = better batching, higher latency
type PendingBatch ¶
type PendingBatch struct {
// contains filtered or unexported fields
}
PendingBatch groups requests with the same template hash.