Documentation ¶
Index ¶
- func IsTemporary(err error) bool
- func PrefixSwaggerUrls(prefix string, swagger model_types.Swagger2) (result model_types.Swagger2, err error)
- func SetUPMainServer(mrc *ModelRouteCatalog, config config.ServiceCatalog) (*http.Server, error)
- func TagSwaggerMethods(tags []string, swagger model_types.Swagger2) (result model_types.Swagger2, err error)
- type Catalog
- type EventFetcher
- type EventHandler
- type GenericEvent
- type LatestGenericEvents
- type ModelRouteCatalog
- func (mdc *ModelRouteCatalog) CreateOrUpdate(route Route) error
- func (mdc *ModelRouteCatalog) Delete(routeID string, log *zap.SugaredLogger)
- func (mdc *ModelRouteCatalog) GetDeployedModel(deploymentID string) (model_types.DeployedModel, error)
- func (mdc *ModelRouteCatalog) ProcessSwaggerJSON() (string, error)
- type Reflector
- type ReflectorOpts
- type Route
- type RouteEventFetcher
- type RouteEventsAPIClient
- type UpdateHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTemporary ¶
func PrefixSwaggerUrls ¶
func PrefixSwaggerUrls(prefix string, swagger model_types.Swagger2) (result model_types.Swagger2, err error)
PrefixSwaggerUrls prefix all URLs in swagger using prefix
func SetUPMainServer ¶
func SetUPMainServer( mrc *ModelRouteCatalog, config config.ServiceCatalog, ) (*http.Server, error)
@license.name Apache 2.0 @license.url http://www.apache.org/licenses/LICENSE-2.0.html
func TagSwaggerMethods ¶
func TagSwaggerMethods(tags []string, swagger model_types.Swagger2) (result model_types.Swagger2, err error)
TagSwaggerMethods add tags into swagger
Types ¶
type Catalog ¶
type Catalog interface { Delete(RouteID string, log *zap.SugaredLogger) CreateOrUpdate(route Route) error }
type EventFetcher ¶
type EventFetcher interface { // GetLastEvents get last events from event source using cursor to determine offset of events // If returned error implements interface with func Temporary() and Temporary() == true // then attempt to fetch events will be retried GetLastEvents(cursor int) (LatestGenericEvents, error) }
EventFetcher fetch events from event source
type EventHandler ¶
type EventHandler interface { // Handle function will be called for each new event that was fetched by EventFetcher // Type assertion can be applied to event to get access for underlying concrete event value. // // if error is returned that event will be rescheduled for further processing using // exponential backoff algorithm Handle(event interface{}, logger *zap.SugaredLogger) (err error) }
EventHandler process event somehow
type GenericEvent ¶
type GenericEvent struct { EntityID string Event interface{} }
type LatestGenericEvents ¶
type LatestGenericEvents struct { Cursor int Events []GenericEvent }
type ModelRouteCatalog ¶
func NewModelRouteCatalog ¶
func NewModelRouteCatalog(log *zap.SugaredLogger) *ModelRouteCatalog
func (*ModelRouteCatalog) CreateOrUpdate ¶
func (mdc *ModelRouteCatalog) CreateOrUpdate(route Route) error
CreateOrUpdate create or update route in catalog All URLs of original swagger of model behind the route will be prefixed by route.Prefix
func (*ModelRouteCatalog) Delete ¶
func (mdc *ModelRouteCatalog) Delete(routeID string, log *zap.SugaredLogger)
Delete delete route from catalog
func (*ModelRouteCatalog) GetDeployedModel ¶
func (mdc *ModelRouteCatalog) GetDeployedModel(deploymentID string) (model_types.DeployedModel, error)
GetDeployedModel returns information about deployed model
func (*ModelRouteCatalog) ProcessSwaggerJSON ¶
func (mdc *ModelRouteCatalog) ProcessSwaggerJSON() (string, error)
ProcessSwaggerJSON combine URLs of all models in catalog. It separates endpoints by tagging them using route.ID
type Reflector ¶
type Reflector struct {
// contains filtered or unexported fields
}
Reflector periodically fetches new events using EventFetcher and planning them for handling by EventHandler. The main goal of reflector is to provide ability to reflect changes in external system. The same idea as in Kubernetes Reconciliation (level-based triggering) https://hackernoon.com/level-triggering-and-reconciliation-in-kubernetes-1f17fe30333d
Reflector assumes that only last event with concrete GenericEvent.EntityID makes sense to reflect external system state changes.
For example If more than one event with the same GenericEvent.EntityID was fetched before worker is able to process them then only last one will be processed using EventHandler.Handle.
Another example (with retry). If some event with GenericEvent.EntityID was re-enqueued because of failing (EventHandler.Handle returned error) but new event was fetched after that then only the last one event will be processed in next time.
func NewReflector ¶
func NewReflector(log *zap.SugaredLogger, handler EventHandler, fetcher EventFetcher, opts ReflectorOpts) Reflector
type ReflectorOpts ¶
type ReflectorOpts struct { // How many concurrent workers will process event using EventHandler.Handle WorkersCount int // How often EventFetcher will fetch new events from source FetchTimeout time.Duration }
ReflectorOpts are options for Reflector
type Route ¶
type Route struct { ID string Prefix string IsDefault bool // If route serves more than one model than model is chosen randomly Model model_types.DeployedModel }
type RouteEventFetcher ¶
type RouteEventFetcher struct {
APIClient RouteEventsAPIClient
}
func (RouteEventFetcher) GetLastEvents ¶
func (d RouteEventFetcher) GetLastEvents(cursor int) (LatestGenericEvents, error)
type RouteEventsAPIClient ¶
type RouteEventsAPIClient interface {
GetLastEvents(cursor int) (event_types.LatestRouteEvents, error)
}
type UpdateHandler ¶
type UpdateHandler struct { Inspectors map[string]inspectors.ModelServerInspector Catalog Catalog DeploymentClient deployment.Client }
func (UpdateHandler) Handle ¶
func (r UpdateHandler) Handle(object interface{}, log *zap.SugaredLogger) (err error)