@@ -17,59 +17,56 @@ limitations under the License.
1717package datalayer
1818
1919import (
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.
2928type 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).
5350type 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
6663var (
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 .
7370type 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.
149114func 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.
155120func 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
0 commit comments