Skip to content

Commit a8071a7

Browse files
committed
Replace OptionalConsumes with ConsumesResult struct
Signed-off-by: Alok Behera <alokbeherak061@gmail.com>
1 parent c980277 commit a8071a7

26 files changed

Lines changed: 107 additions & 106 deletions

File tree

pkg/epp/datalayer/data_graph.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ func CreateMissingDataProducers(ctx context.Context, defaultProducerRegistry map
8484
// Warn about optional keys with no producer — no error, just a warning.
8585
for _, p := range handle.GetAllPlugins() {
8686
if consumer, ok := p.(plugin.ConsumerPlugin); ok {
87-
for key := range consumer.OptionalConsumes() {
87+
result := consumer.Consumes()
88+
for key := range result.Optional {
8889
if !producedKeys[key.String()] {
8990
logger.Info("Warning: optional data key has no producer, plugin will use fallback",
9091
"plugin", p.TypedName().Name, "dataKey", key.String())
@@ -97,7 +98,8 @@ func CreateMissingDataProducers(ctx context.Context, defaultProducerRegistry map
9798
missingKeys := make(map[string]string)
9899
for _, p := range handle.GetAllPlugins() {
99100
if consumer, ok := p.(plugin.ConsumerPlugin); ok {
100-
for key := range consumer.Consumes() {
101+
result := consumer.Consumes()
102+
for key := range result.Required {
101103
if !producedKeys[key.String()] {
102104
missingKeys[key.String()] = consumer.TypedName().Name
103105
}
@@ -203,9 +205,10 @@ func buildDAG(producers map[string]plugin.ProducerPlugin, consumers map[string]p
203205
if pName == cName {
204206
continue
205207
}
206-
if producer.Produces() != nil && consumer.Consumes() != nil {
208+
consumed := consumer.Consumes()
209+
if producer.Produces() != nil && consumed.Required != nil {
207210
for producedKey, producedData := range producer.Produces() {
208-
if consumedData, ok := consumer.Consumes()[producedKey]; ok {
211+
if consumedData, ok := consumed.Required[producedKey]; ok {
209212
// Check types are same.
210213
if reflect.TypeOf(producedData) != reflect.TypeOf(consumedData) {
211214
return nil, errors.New("data type mismatch between produced and consumed data for key: " + producedKey.String())

pkg/epp/datalayer/data_graph_test.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,10 @@ func (m *mockDataProducerP) Produces() map[fwkplugin.DataKey]any {
5858
return m.produces
5959
}
6060

61-
func (m *mockDataProducerP) Consumes() map[fwkplugin.DataKey]any {
62-
return m.consumes
61+
func (m *mockDataProducerP) Consumes() fwkplugin.ConsumesResult {
62+
return fwkplugin.ConsumesResult{Required: m.consumes}
6363
}
6464

65-
func (m *mockDataProducerP) OptionalConsumes() map[fwkplugin.DataKey]any { return nil }
66-
6765
func (m *mockDataProducerP) Produce(ctx context.Context, request *fwksched.InferenceRequest, endpoints []fwksched.Endpoint) error {
6866
endpoints[0].Put(mockProducedDataKey, &mockProducedDataType{value: 42})
6967
return nil
@@ -90,12 +88,10 @@ type MockConsumerFairnessPolicy struct {
9088
consumes map[fwkplugin.DataKey]any
9189
}
9290

93-
func (m *MockConsumerFairnessPolicy) Consumes() map[fwkplugin.DataKey]any {
94-
return m.consumes
91+
func (m *MockConsumerFairnessPolicy) Consumes() fwkplugin.ConsumesResult {
92+
return fwkplugin.ConsumesResult{Required: m.consumes}
9593
}
9694

97-
func (m *MockConsumerFairnessPolicy) OptionalConsumes() map[fwkplugin.DataKey]any { return nil }
98-
9995
type MockSchedulingPlugin struct {
10096
fwksched.Scorer
10197
consumes map[fwkplugin.DataKey]any
@@ -105,12 +101,10 @@ func (m *MockSchedulingPlugin) TypedName() fwkplugin.TypedName {
105101
return fwkplugin.TypedName{Name: "MockSchedulingPlugin", Type: "mock"}
106102
}
107103

108-
func (m *MockSchedulingPlugin) Consumes() map[fwkplugin.DataKey]any {
109-
return m.consumes
104+
func (m *MockSchedulingPlugin) Consumes() fwkplugin.ConsumesResult {
105+
return fwkplugin.ConsumesResult{Required: m.consumes}
110106
}
111107

112-
func (m *MockSchedulingPlugin) OptionalConsumes() map[fwkplugin.DataKey]any { return nil }
113-
114108
func TestValidatePluginExecutionOrder(t *testing.T) {
115109
dkA := fwkplugin.NewDataKey("keyA", "mock")
116110
// Request control plugin that produces data.
@@ -445,10 +439,8 @@ func (m *mockMayConsumerPlugin) TypedName() fwkplugin.TypedName {
445439
return fwkplugin.TypedName{Name: m.name, Type: "mock"}
446440
}
447441

448-
func (m *mockMayConsumerPlugin) Consumes() map[fwkplugin.DataKey]any { return nil }
449-
450-
func (m *mockMayConsumerPlugin) OptionalConsumes() map[fwkplugin.DataKey]any {
451-
return m.optionalConsumes
442+
func (m *mockMayConsumerPlugin) Consumes() fwkplugin.ConsumesResult {
443+
return fwkplugin.ConsumesResult{Optional: m.optionalConsumes}
452444
}
453445

454446
// mockMixedConsumerPlugin is a plugin that has both required Consumes and optional OptionalConsumes.
@@ -464,12 +456,8 @@ func (m *mockMixedConsumerPlugin) TypedName() fwkplugin.TypedName {
464456
return fwkplugin.TypedName{Name: m.name, Type: "mock"}
465457
}
466458

467-
func (m *mockMixedConsumerPlugin) Consumes() map[fwkplugin.DataKey]any {
468-
return m.consumes
469-
}
470-
471-
func (m *mockMixedConsumerPlugin) OptionalConsumes() map[fwkplugin.DataKey]any {
472-
return m.optionalConsumes
459+
func (m *mockMixedConsumerPlugin) Consumes() fwkplugin.ConsumesResult {
460+
return fwkplugin.ConsumesResult{Required: m.consumes, Optional: m.optionalConsumes}
473461
}
474462

475463
func TestCreateMissingDataProducers_MayConsume(t *testing.T) {

pkg/epp/framework/interface/plugin/plugins.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,24 @@ type Plugin interface {
2323
TypedName() TypedName
2424
}
2525

26+
// ConsumesResult holds the data keys a plugin consumes, split by whether they
27+
// are required (framework errors if no producer exists) or optional (framework
28+
// logs a warning but continues if no producer exists).
29+
type ConsumesResult struct {
30+
// Required keys — the framework will error at init time if no producer exists for any of these.
31+
Required map[DataKey]any
32+
// Optional keys — the framework logs a warning at init time but does NOT error if no producer exists.
33+
// The plugin must handle the case where this data is absent at runtime.
34+
Optional map[DataKey]any
35+
}
36+
2637
// ConsumerPlugin defines the interface for a consumer.
2738
type ConsumerPlugin interface {
2839
Plugin
29-
// Consumes returns data consumed by the plugin.
30-
// This is a map from DataKey produced to
31-
// the data type of the key (represented as data with default value casted as any field).
32-
Consumes() map[DataKey]any
33-
// OptionalConsumes returns data keys the plugin can optionally consume.
34-
// Unlike Consumes(), the framework will NOT error if no producer exists for these keys.
35-
// Instead it logs a warning at init time. The plugin must handle the case where this data is absent.
36-
// Return nil if there are no optional keys.
37-
OptionalConsumes() map[DataKey]any
40+
// Consumes returns the data keys consumed by this plugin, split into Required and Optional.
41+
// Required keys: the framework errors at init time if no producer exists.
42+
// Optional keys: the framework logs a warning but does not error; the plugin must handle absence.
43+
Consumes() ConsumesResult
3844
}
3945

4046
// ProducerPlugin defines the interface for a producer.

pkg/epp/framework/interface/plugin/plugins_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ type consumerImpl struct {
3333
consumes map[DataKey]any
3434
}
3535

36-
func (c *consumerImpl) Consumes() map[DataKey]any { return c.consumes }
37-
func (c *consumerImpl) OptionalConsumes() map[DataKey]any { return nil }
36+
func (c *consumerImpl) Consumes() ConsumesResult { return ConsumesResult{Required: c.consumes} }
3837

3938
type producerImpl struct {
4039
basePlugin
@@ -59,8 +58,8 @@ func TestConsumerPlugin_Contract(t *testing.T) {
5958
var cp ConsumerPlugin = c
6059

6160
got := cp.Consumes()
62-
assert.Len(t, got, 1)
63-
_, ok := got[key]
61+
assert.Len(t, got.Required, 1)
62+
_, ok := got.Required[key]
6463
assert.True(t, ok)
6564
assert.Equal(t, "queue-filter/filter", cp.TypedName().String())
6665
}
@@ -87,7 +86,7 @@ func TestConsumerPlugin_EmptyConsumes(t *testing.T) {
8786
basePlugin: basePlugin{name: TypedName{Type: "filter", Name: "noop"}},
8887
consumes: nil,
8988
}
90-
assert.Nil(t, c.Consumes())
89+
assert.Nil(t, c.Consumes().Required)
9190
}
9291

9392
func TestProducerPlugin_EmptyProduces(t *testing.T) {

pkg/epp/framework/plugins/flowcontrol/saturationdetector/concurrency/detector.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ func (d *detector) TypedName() fwkplugin.TypedName {
103103
return d.typedName
104104
}
105105

106-
func (d *detector) Consumes() map[fwkplugin.DataKey]any {
107-
return map[fwkplugin.DataKey]any{
108-
d.inFlightLoadDataKey: attrconcurrency.InFlightLoad{},
106+
func (d *detector) Consumes() fwkplugin.ConsumesResult {
107+
return fwkplugin.ConsumesResult{
108+
Required: map[fwkplugin.DataKey]any{d.inFlightLoadDataKey: attrconcurrency.InFlightLoad{}},
109109
}
110110
}
111111

pkg/epp/framework/plugins/requestcontrol/admitter/latencyslo/plugin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ func (p *LatencyAdmission) TypedName() fwkplugin.TypedName {
8989
}
9090

9191
// Consumes declares that this plugin reads latency prediction data from endpoints.
92-
func (p *LatencyAdmission) Consumes() map[fwkplugin.DataKey]any {
93-
return map[fwkplugin.DataKey]any{
94-
p.latencyPredictionInfoDataKey: attrlatency.LatencyPredictionInfo{},
92+
func (p *LatencyAdmission) Consumes() fwkplugin.ConsumesResult {
93+
return fwkplugin.ConsumesResult{
94+
Required: map[fwkplugin.DataKey]any{p.latencyPredictionInfoDataKey: attrlatency.LatencyPredictionInfo{}},
9595
}
9696
}
9797

pkg/epp/framework/plugins/requestcontrol/dataproducer/preciseprefixcache/producer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ func (p *Producer) Produces() map[plugin.DataKey]any {
209209

210210
// Consumes declares the TokenizedPrompt dependency from token-producer so
211211
// the data-layer DAG orders tokenization before this producer runs.
212-
func (p *Producer) Consumes() map[plugin.DataKey]any {
213-
return map[plugin.DataKey]any{tokenproducer.TokenizedPromptDataKey: scheduling.TokenizedPrompt{}}
212+
func (p *Producer) Consumes() plugin.ConsumesResult {
213+
return plugin.ConsumesResult{
214+
Required: map[plugin.DataKey]any{tokenproducer.TokenizedPromptDataKey: scheduling.TokenizedPrompt{}},
215+
}
214216
}
215217

216218
// Produce hashes the request's TokenizedPrompt into KV-block keys, looks

pkg/epp/framework/plugins/requestcontrol/dataproducer/preciseprefixcache/producer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func TestProduces_DeclaresPrefixCacheMatchInfo(t *testing.T) {
306306
func TestConsumes_DeclaresTokenizedPrompt(t *testing.T) {
307307
p := &Producer{typedName: plugin.TypedName{Type: PluginType, Name: "x"}}
308308
expected := plugin.NewDataKey("TokenizedPrompt", "token-producer")
309-
_, ok := p.Consumes()[expected]
309+
_, ok := p.Consumes().Required[expected]
310310
require.True(t, ok)
311311
}
312312

pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/dataproducer_hooks.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ func (pl *PredictedLatency) Produces() map[plugin.DataKey]any {
112112
}
113113
}
114114

115-
func (pl *PredictedLatency) Consumes() map[plugin.DataKey]any {
116-
return map[plugin.DataKey]any{pl.prefixMatchDataKey: attrprefix.PrefixCacheMatchInfo{}}
115+
func (pl *PredictedLatency) Consumes() plugin.ConsumesResult {
116+
return plugin.ConsumesResult{
117+
Required: map[plugin.DataKey]any{pl.prefixMatchDataKey: attrprefix.PrefixCacheMatchInfo{}},
118+
}
117119
}

pkg/epp/framework/plugins/requestcontrol/dataproducer/predictedlatency/dataproducer_hooks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestProducesConsumes(t *testing.T) {
3535
assert.Contains(t, produces, expectedProduceKey)
3636

3737
consumes := pl.Consumes()
38-
assert.Contains(t, consumes, attrprefix.PrefixCacheMatchInfoDataKey)
38+
assert.Contains(t, consumes.Required, attrprefix.PrefixCacheMatchInfoDataKey)
3939
}
4040

4141
// TestProduce_CancelledContextDoesNotPublish verifies that when the

0 commit comments

Comments
 (0)