Skip to content

Commit 517490c

Browse files
committed
flowcontrol: add metadata support to request type
Updates the FlowControlRequest interface to carry request metadata instead of a pre-resolved list of candidate pods. This prepares the system for lazy pod resolution. - Adds GetMetadata() to FlowControlRequest. - Removes CandidatePodsForScheduling() from FlowControlRequest. - Updates mocks in flowcontrol/types and contracts.
1 parent 5c91cc2 commit 517490c

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

pkg/epp/flowcontrol/contracts/mocks/mocks.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import (
4141
typesmocks "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/types/mocks"
4242
)
4343

44+
// --- RegistryShard Mocks ---
45+
4446
// MockRegistryShard is a simple "stub-style" mock for testing.
4547
// Its methods are implemented as function fields (e.g., `IDFunc`). A test can inject behavior by setting the desired
4648
// function field in the test setup. If a func is nil, the method will return a zero value.
@@ -111,6 +113,8 @@ func (m *MockRegistryShard) Stats() contracts.ShardStats {
111113
return contracts.ShardStats{}
112114
}
113115

116+
// --- Dependency Mocks ---
117+
114118
// MockSaturationDetector is a simple "stub-style" mock for testing.
115119
type MockSaturationDetector struct {
116120
IsSaturatedFunc func(ctx context.Context, candidatePods []metrics.PodMetrics) bool
@@ -123,6 +127,30 @@ func (m *MockSaturationDetector) IsSaturated(ctx context.Context, candidatePods
123127
return false
124128
}
125129

130+
// MockPodLocator provides a mock implementation of the contracts.PodLocator interface.
131+
// It allows tests to control the exact set of pods returned for a given request.
132+
type MockPodLocator struct {
133+
// LocateFunc allows injecting custom logic.
134+
LocateFunc func(ctx context.Context, requestMetadata map[string]any) []metrics.PodMetrics
135+
// Pods is a static return value used if LocateFunc is nil.
136+
Pods []metrics.PodMetrics
137+
}
138+
139+
func (m *MockPodLocator) Locate(ctx context.Context, requestMetadata map[string]any) []metrics.PodMetrics {
140+
if m.LocateFunc != nil {
141+
return m.LocateFunc(ctx, requestMetadata)
142+
}
143+
// Return copy to be safe
144+
if m.Pods == nil {
145+
return nil
146+
}
147+
result := make([]metrics.PodMetrics, len(m.Pods))
148+
copy(result, m.Pods)
149+
return result
150+
}
151+
152+
// --- ManagedQueue Mock ---
153+
126154
// MockManagedQueue is a high-fidelity, thread-safe mock of the `contracts.ManagedQueue` interface, designed
127155
// specifically for testing the concurrent `controller/internal.ShardProcessor`.
128156
//

pkg/epp/flowcontrol/types/mocks/mocks.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,19 @@ package mocks
2121
import (
2222
"time"
2323

24-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
2524
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/flowcontrol/types"
2625
)
2726

28-
// MockFlowControlRequest provides a mock implementation of the `types.FlowControlRequest` interface.
27+
// MockFlowControlRequest provides a mock implementation of the types.FlowControlRequest interface.
2928
type MockFlowControlRequest struct {
30-
FlowKeyV types.FlowKey
31-
ByteSizeV uint64
32-
InitialEffectiveTTLV time.Duration
33-
IDV string
34-
CandidatePodsForSchedulingV []*metrics.FakePodMetrics
29+
FlowKeyV types.FlowKey
30+
ByteSizeV uint64
31+
InitialEffectiveTTLV time.Duration
32+
IDV string
33+
MetadataV map[string]any
3534
}
3635

37-
// NewMockFlowControlRequest creates a new `MockFlowControlRequest` instance.
36+
// NewMockFlowControlRequest creates a new MockFlowControlRequest instance.
3837
func NewMockFlowControlRequest(
3938
byteSize uint64,
4039
id string,
@@ -44,21 +43,15 @@ func NewMockFlowControlRequest(
4443
ByteSizeV: byteSize,
4544
IDV: id,
4645
FlowKeyV: key,
46+
MetadataV: make(map[string]any),
4747
}
4848
}
4949

5050
func (m *MockFlowControlRequest) FlowKey() types.FlowKey { return m.FlowKeyV }
5151
func (m *MockFlowControlRequest) ByteSize() uint64 { return m.ByteSizeV }
5252
func (m *MockFlowControlRequest) InitialEffectiveTTL() time.Duration { return m.InitialEffectiveTTLV }
5353
func (m *MockFlowControlRequest) ID() string { return m.IDV }
54-
55-
func (m *MockFlowControlRequest) CandidatePodsForScheduling() []metrics.PodMetrics {
56-
pods := make([]metrics.PodMetrics, 0, len(m.CandidatePodsForSchedulingV))
57-
for i, pod := range m.CandidatePodsForSchedulingV {
58-
pods[i] = pod
59-
}
60-
return pods
61-
}
54+
func (m *MockFlowControlRequest) GetMetadata() map[string]any { return m.MetadataV }
6255

6356
var _ types.FlowControlRequest = &MockFlowControlRequest{}
6457

pkg/epp/flowcontrol/types/request.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package types
1818

1919
import (
2020
"time"
21-
22-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
2321
)
2422

2523
// FlowControlRequest is the contract for an incoming request submitted to the `controller.FlowController`. It
@@ -45,15 +43,15 @@ type FlowControlRequest interface {
4543
// applied.
4644
InitialEffectiveTTL() time.Duration
4745

48-
// CandidatePodsForScheduling passes through a set of candidate pods a request may be admitted to.
49-
// This is necessary for invoking `contracts.SaturationDetector.IsSaturated`, but it is otherwise unused in the Flow
50-
// Control system.
51-
CandidatePodsForScheduling() []metrics.PodMetrics
52-
5346
// ID returns an optional, user-facing unique identifier for this specific request. It is intended for logging,
5447
// tracing, and observability. The `controller.FlowController` does not use this ID for dispatching decisions; it uses
5548
// the internal, opaque `QueueItemHandle`.
5649
ID() string
50+
51+
// GetMetadata returns the opaque metadata associated with the request (e.g., header-derived context, subset filters).
52+
// This data is passed transparently to components like the contracts.PodLocator to resolve resources (candidate pods)
53+
// lazily during the dispatch cycle.
54+
GetMetadata() map[string]any
5755
}
5856

5957
// QueueItemHandle is an opaque handle to an item that has been successfully added to a `framework.SafeQueue`. It acts

0 commit comments

Comments
 (0)