How to develop Recommender

Introduce how to develop and extend Recommender based on framework

Recommendation Framework provides an extensible framework for Recommender and supports several built-in Recommender. Users can implement a self-defined Recommender or modify the existing Recommenders.

Recommender Interface

  1. type Recommender interface {
  2. Name() string
  3. framework.Filter
  4. framework.PrePrepare
  5. framework.Prepare
  6. framework.PostPrepare
  7. framework.PreRecommend
  8. framework.Recommend
  9. framework.PostRecommend
  10. framework.Observe
  11. }
  12. // Phase: Filter
  13. // Filter interface
  14. type Filter interface {
  15. // The Filter will filter resource can`t be recommended via target recommender.
  16. Filter(ctx *RecommendationContext) error
  17. }
  18. // Phase: Prepare
  19. // PrePrepare interface
  20. type PrePrepare interface {
  21. CheckDataProviders(ctx *RecommendationContext) error
  22. }
  23. // Prepare interface
  24. type Prepare interface {
  25. CollectData(ctx *RecommendationContext) error
  26. }
  27. type PostPrepare interface {
  28. PostProcessing(ctx *RecommendationContext) error
  29. }
  30. // PreRecommend interface
  31. type PreRecommend interface {
  32. PreRecommend(ctx *RecommendationContext) error
  33. }
  34. // Phase: Recommend
  35. // Recommend interface
  36. type Recommend interface {
  37. Recommend(ctx *RecommendationContext) error
  38. }
  39. // PostRecommend interface
  40. type PostRecommend interface {
  41. Policy(ctx *RecommendationContext) error
  42. }
  43. // Phase: Observe
  44. // Observe interface
  45. type Observe interface {
  46. Observe(ctx *RecommendationContext) error
  47. }

Recommender interface defines four stages and eight extension points that need to be implemented in recommender. These extension points are called sequentially during the recommendation process. Some of these extension points can change recommendation decisions, while others are only give information.

Architecture

How to develop Recommender - 图1

Phases

The whole recommendation process is divided into four phases: Filter,Prepare,Recommend,Observe。Phase’s input is the Kubernetes resource to analysis,output is the recommendation advise. Let’s begin to introduce the inputs, outputs, and capabilities of each phase.

RecommendationContext saved the context for a recommended process, including recommended target, RecommendationConfiguration etc., the user can add more content as needed.

Filter

The Filter phase is used to preprocess the recommendation data. In general, it is necessary to decide whether the recommendation target matches Recommender during preprocessing. For example, the Resource Recommender only supports handling Workload (Deployment, StatefulSet). In addition, it can also determine whether the recommended target state is suitable for recommendation, such as whether it is being deleted or just created. The recommendation will be terminated when return error. BaseRecommender implements basic preprocessing functions and users can call it to inherit related functions.

Prepare

The Prepare phase is used for data preparation, requesting an external monitoring system and saving the timing data in the context. PrePrepare extension point used to check the connection status of the monitoring system. Prepare extension point used to query time series data. The PostPrepare extension point is used to process time series data, such as abnormal cold start data, partial data loss, data aggregation, and clearing abnormal data.

Recommend

The Recommend phase is used to optimize recommendations based on timing data and resource allocation. The type of optimization recommendation depends on the type of recommendation. For example, if it is a resource recommendation, then the output is the resource configuration for the kubernetes workload. The Recommend extension point is used to analyze and calculate the data using Crane’s algorithm module, and the analysis result is finally processed in the PostRecommend stage. Users can customize it by implement their Recommend phase.

Observe

The Observe phase is used to observe the recommendation result. For example, when recommending a resource, the information about the optimization proposal is saved to the monitoring system via Metric, and the revenue generated by the optimization proposal is observed through the Dashboard.