Skip to content

Commit 5e55b1c

Browse files
committed
Address review comments:
- DataSource is no longer tracking Endpoints. - Removed unused interfaces. - Changes to exported scope. - Move Addressable to podinfo.go. Signed-off-by: Etai Lev Ran <[email protected]>
1 parent bd1ebe8 commit 5e55b1c

File tree

4 files changed

+35
-94
lines changed

4 files changed

+35
-94
lines changed

pkg/epp/datalayer/datasource.go

Lines changed: 29 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,56 @@ limitations under the License.
1717
package datalayer
1818

1919
import (
20-
"context"
2120
"errors"
2221
"fmt"
2322
"reflect"
2423
"sync"
2524
)
2625

27-
// DataSource is an interface required from all datalayer data collection
26+
// DataSource is an interface required from all data layer data collection
2827
// sources.
2928
type DataSource interface {
3029
// Name returns the name of this datasource.
3130
Name() string
3231

33-
// Start begins the collection process.
34-
Start(ctx context.Context) error
35-
36-
// Stop stops the collection process.
37-
Stop()
38-
3932
// AddExtractor adds an extractor to the data source.
40-
// The extractor will be called whenever the data source might
33+
// The extractor will be called whenever the Collector might
4134
// have some new raw information regarding an endpoint.
4235
// The Extractor's expected input type should be validated against
43-
// the data source output type upon registration.
36+
// the data source's output type upon registration.
4437
AddExtractor(extractor Extractor) error
4538

46-
// AddEndpoint adds an endpoint to collect from.
47-
AddEndpoint(ep Endpoint) error
48-
49-
// RemoveEndpoint removes an endpoint from collection.
50-
RemoveEndpoint(ep Endpoint) error
39+
// Collect is triggered by the data layer framework to fetch potentially new
40+
// data for an endpoint. It passes retrieved data to registered Extractors.
41+
Collect(ep Endpoint)
5142
}
5243

44+
// Extractor is used to convert raw data into relevant data layer information
45+
// for an endpoint. They are called by data sources whenever new data might be
46+
// be available. Multiple Extractors can be registered with a source. Extractors
47+
// are expected to save their output with an endpoint so it becomes accessible
48+
// to consumers in other subsystem of the inference gateway (e.g., when making
49+
// scheduling decisions).
5350
type Extractor interface {
5451
// Name returns the name of the extractor.
5552
Name() string
5653

5754
// ExpectedType defines the type expected by the extractor. It must match
58-
// the DataSource.OutputType() the extractor registers for.
59-
ExpectedType() reflect.Type
55+
// the output type of the data source where the extractor is registered.
56+
ExpectedInputType() reflect.Type
6057

6158
// Extract transforms the data source output into a concrete attribute that
6259
// is stored on the given endpoint.
6360
Extract(data any, ep Endpoint)
6461
}
6562

6663
var (
67-
// DefaultDataSources is the system default data source registry.
68-
DefaultDataSources = DataSourceRegistry{}
64+
// defaultDataSources is the system default data source registry.
65+
defaultDataSources = DataSourceRegistry{}
6966
)
7067

7168
// DataSourceRegistry stores named data sources and makes them
72-
// accessible to GIE subsystems.
69+
// accessible to other subsystems in the inference gateway.
7370
type DataSourceRegistry struct {
7471
sources sync.Map
7572
}
@@ -101,70 +98,32 @@ func (dsr *DataSourceRegistry) GetNamedSource(name string) (DataSource, bool) {
10198
return nil, false
10299
}
103100

104-
// AddEndpoint adds a new endpoint to all registered sources.
105-
// Endpoints are not tracked and DataSources are only notified of
106-
// endpoints added after the data source has been registered.
107-
//
108-
// TODO: track endpoints and update on later source registrations? It seems safe
109-
// to assume that all sources are registered before endpoints are
110-
// discovered and added to the system.
111-
func (dsr *DataSourceRegistry) AddEndpoint(ep Endpoint) error {
112-
if ep == nil {
113-
return nil
114-
}
115-
116-
errs := []error{}
117-
dsr.sources.Range(func(_, val interface{}) bool {
118-
if ds, ok := val.(DataSource); ok {
119-
if err := ds.AddEndpoint(ep); err != nil {
120-
errs = append(errs, err)
121-
}
122-
}
123-
return true
124-
})
125-
return errors.Join(errs...)
126-
}
127-
128-
// RemoveEndpoint removes an endpoint from all registered sources.
129-
// A source may be called to remove an endpoint it has not added - this
130-
// is should not result in an error.
131-
func (dsr *DataSourceRegistry) RemoveEndpoint(ep Endpoint) error {
132-
if ep == nil {
133-
return nil
134-
}
135-
136-
errs := []error{}
137-
dsr.sources.Range(func(_, val interface{}) bool {
101+
// GetSources returns all sources registered.
102+
func (dsr *DataSourceRegistry) GetSources() []DataSource {
103+
sources := []DataSource{}
104+
dsr.sources.Range(func(_, val any) bool {
138105
if ds, ok := val.(DataSource); ok {
139-
if err := ds.RemoveEndpoint(ep); err != nil {
140-
errs = append(errs, err)
141-
}
106+
sources = append(sources, ds)
142107
}
143-
return true
108+
return true // continue iteration
144109
})
145-
return errors.Join(errs...)
110+
return sources
146111
}
147112

148113
// RegisterSource adds the data source to the default registry.
149114
func RegisterSource(src DataSource) error {
150-
return DefaultDataSources.Register(src)
115+
return defaultDataSources.Register(src)
151116
}
152117

153118
// GetNamedSource returns the named source from the default registry,
154119
// if found.
155120
func GetNamedSource(name string) (DataSource, bool) {
156-
return DefaultDataSources.GetNamedSource(name)
157-
}
158-
159-
// AddEndpoint adds an endpoint to all sources in the default source registry.
160-
func AddEndpoint(ep Endpoint) error {
161-
return DefaultDataSources.AddEndpoint(ep)
121+
return defaultDataSources.GetNamedSource(name)
162122
}
163123

164-
// RemoveEndpoint removes an endpoint from all sources in the default source
165-
// registry.
166-
func RemoveEndpoint(ep Endpoint) error {
167-
return DefaultDataSources.RemoveEndpoint(ep)
124+
// GetSources returns all sources in the default registry.
125+
func GetSources() []DataSource {
126+
return defaultDataSources.GetSources()
168127
}
169128

170129
// ValidateExtractorType checks if an extractor can handle

pkg/epp/datalayer/endpoint.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ import (
2020
corev1 "k8s.io/api/core/v1"
2121
)
2222

23-
// MetricsLoop is a temporary bridge interface to match backend.metrics.PodMetrics
24-
// collection of metrics. It will be phased out as we move towards decoupled collection
25-
// via a DataSource.
26-
type MetricsLoop interface {
27-
StopRefreshLoop()
28-
}
29-
3023
// EndpointPodState allows management of the Pod related attributes.
3124
type EndpointPodState interface {
3225
GetPod() *PodInfo
@@ -41,7 +34,6 @@ type EndpointMetricsState interface {
4134

4235
// Endpoint represents an inference serving endpoint and its related attributes.
4336
type Endpoint interface {
44-
MetricsLoop // TODO: remove once transition over to independent data source
4537
EndpointPodState
4638
EndpointMetricsState
4739
AttributeMap

pkg/epp/datalayer/metrics.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,10 @@ limitations under the License.
1717
package datalayer
1818

1919
import (
20-
"context"
2120
"fmt"
2221
"time"
23-
24-
"k8s.io/apimachinery/pkg/types"
2522
)
2623

27-
// Addressable supports getting an IP address and a namespaced name.
28-
type Addressable interface {
29-
GetIPAddress() string
30-
GetNamespacedName() types.NamespacedName
31-
}
32-
33-
// MetricsClient supports fetching the metrics of the endpoint. It is provided
34-
// with a snapshot of the last read metrics value (if any), under the assumption
35-
// that stale metrics are better than none.
36-
type MetricsClient interface {
37-
FetchMetrics(c context.Context, ep Addressable, last *Metrics, port int32) (*Metrics, error)
38-
}
39-
4024
// Metrics holds the latest metrics snapshot scraped from a pod.
4125
type Metrics struct {
4226
// ActiveModels is a set of models(including LoRA adapters) that are currently cached to GPU.

pkg/epp/datalayer/podinfo.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import (
2323
"k8s.io/apimachinery/pkg/types"
2424
)
2525

26+
// Addressable supports getting an IP address and a namespaced name.
27+
type Addressable interface {
28+
GetIPAddress() string
29+
GetNamespacedName() types.NamespacedName
30+
}
31+
2632
// PodInfo represents the relevant Kubernetes Pod state of an inference server.
2733
type PodInfo struct {
2834
NamespacedName types.NamespacedName

0 commit comments

Comments
 (0)