Skip to content

Commit cde0673

Browse files
committed
add docs for recommend, revert expression change
1 parent 8420917 commit cde0673

18 files changed

+405
-558
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ https://user-images.githubusercontent.com/35299017/186680122-d7756b47-06be-44cb-
3636

3737
**Recommendation Framework**
3838

39-
Provide a pluggable framework for analytics and give recommendation for cloud resources, support out-of-box recommenders: Workload Resources/Replicas, Idle Resources.
39+
Provide a pluggable framework for analytics and give recommendation for cloud resources, support out-of-box recommenders: Workload Resources/Replicas, Idle Resources. [learn more](https://gocrane.io/docs/tutorials/recommendation/).
4040

4141
**Prediction-driven Horizontal Autoscaling**
4242

43-
EffectiveHorizontalPodAutoscaler supports prediction-driven autoscaling. With this capability, user can forecast the incoming peak flow and scale up their application ahead, also user can know when the peak flow will end and scale down their application gracefully. [learn more](docs/tutorials/using-effective-hpa-to-scaling-with-effectiveness.md).
43+
EffectiveHorizontalPodAutoscaler supports prediction-driven autoscaling. With this capability, user can forecast the incoming peak flow and scale up their application ahead, also user can know when the peak flow will end and scale down their application gracefully. [learn more](https://gocrane.io/docs/tutorials/using-effective-hpa-to-scaling-with-effectiveness/).
4444

4545
**Load-Aware Scheduling**
4646

47-
Provide a simple but efficient scheduler that schedule pods based on actual node utilization data,and filters out those nodes with high load to balance the cluster. [learn more](docs/tutorials/scheduling-pods-based-on-actual-node-load.md).
47+
Provide a simple but efficient scheduler that schedule pods based on actual node utilization data,and filters out those nodes with high load to balance the cluster. [learn more](https://gocrane.io/docs/tutorials/scheduling-pods-based-on-actual-node-load/).
4848

4949
**Colocation with Enhanced QoS**
5050

README_zh.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ Crane Dashboard **在线 Demo**: http://dashboard.gocrane.io/
3636

3737
**推荐框架**
3838

39-
提供了一个可扩展的推荐框架以支持多种云资源的分析,内置了多种推荐器:资源推荐,副本推荐,闲置资源推荐。
39+
提供了一个可扩展的推荐框架以支持多种云资源的分析,内置了多种推荐器:资源推荐,副本推荐,闲置资源推荐。[了解更多](https://gocrane.io/zh-cn/docs/tutorials/recommendation/)
4040

4141
**基于预测的水平弹性器**
4242

43-
EffectiveHorizontalPodAutoscaler 支持了预测驱动的弹性。它基于社区 HPA 做底层的弹性控制,支持更丰富的弹性触发策略(预测,观测,周期),让弹性更加高效,并保障了服务的质量。[了解更多](docs/tutorials/using-effective-hpa-to-scaling-with-effectiveness.zh.md)
43+
EffectiveHorizontalPodAutoscaler 支持了预测驱动的弹性。它基于社区 HPA 做底层的弹性控制,支持更丰富的弹性触发策略(预测,观测,周期),让弹性更加高效,并保障了服务的质量。[了解更多](https://gocrane.io/zh-cn/docs/tutorials/using-effective-hpa-to-scaling-with-effectiveness/)
4444

4545
**负载感知的调度器**
4646

47-
动态调度器根据实际的节点利用率构建了一个简单但高效的模型,并过滤掉那些负载高的节点来平衡集群。[了解更多](docs/tutorials/scheduling-pods-based-on-actual-node-load.zh.md)
47+
动态调度器根据实际的节点利用率构建了一个简单但高效的模型,并过滤掉那些负载高的节点来平衡集群。[了解更多](https://gocrane.io/zh-cn/docs/tutorials/scheduling-pods-based-on-actual-node-load/)
4848

4949
**基于 QoS 的混部**
5050

pkg/utils/ehpa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ func GetExpressionQueryDefault(metric autoscalingv2.MetricSpec, namespace string
113113
labels = append(labels, k+"="+`"`+v+`"`)
114114
}
115115
}
116-
expressionQuery = GetCustumerExpression(metric.Pods.Metric.Name, strings.Join(labels, ","))
116+
expressionQuery = GetCustomerExpression(metric.Pods.Metric.Name, strings.Join(labels, ","))
117117
case autoscalingv2.ExternalMetricSourceType:
118118
var labels []string
119119
if metric.External.Metric.Selector != nil {
120120
for k, v := range metric.External.Metric.Selector.MatchLabels {
121121
labels = append(labels, k+"="+`"`+v+`"`)
122122
}
123123
}
124-
expressionQuery = GetCustumerExpression(metric.External.Metric.Name, strings.Join(labels, ","))
124+
expressionQuery = GetCustomerExpression(metric.External.Metric.Name, strings.Join(labels, ","))
125125
}
126126

127127
return expressionQuery

pkg/utils/expression_prom_default.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
// todo: later we change these templates to configurable like prometheus-adapter
88
const (
99
// WorkloadCpuUsageExprTemplate is used to query workload cpu usage by promql, param is namespace,workload-name,duration str
10-
WorkloadCpuUsageExprTemplate = `sum(irate(container_cpu_usage_seconds_total{namespace="%s",pod=~"^%s-%s"}[%s]))`
10+
WorkloadCpuUsageExprTemplate = `sum(irate(container_cpu_usage_seconds_total{namespace="%s",pod=~"^%s-.*$"}[%s]))`
1111
// WorkloadMemUsageExprTemplate is used to query workload mem usage by promql, param is namespace, workload-name
12-
WorkloadMemUsageExprTemplate = `sum(container_memory_working_set_bytes{namespace="%s",pod=~"^%s-%s"})`
12+
WorkloadMemUsageExprTemplate = `sum(container_memory_working_set_bytes{namespace="%s",pod=~"^%s-.*$"})`
1313

1414
// following is node exporter metric for node cpu/memory usage
1515
// NodeCpuUsageExprTemplate is used to query node cpu usage by promql, param is node name which prometheus scrape, duration str
@@ -23,35 +23,31 @@ const (
2323
PodMemUsageExprTemplate = `sum(container_memory_working_set_bytes{container!="POD",namespace="%s",pod="%s"})`
2424

2525
// ContainerCpuUsageExprTemplate is used to query container cpu usage by promql, param is namespace,pod,container duration str
26-
ContainerCpuUsageExprTemplate = `irate(container_cpu_usage_seconds_total{container!="POD",namespace="%s",pod=~"^%s-%s",container="%s"}[%s])`
26+
ContainerCpuUsageExprTemplate = `irate(container_cpu_usage_seconds_total{container!="POD",namespace="%s",pod=~"^%s.*$",container="%s"}[%s])`
2727
// ContainerMemUsageExprTemplate is used to query container cpu usage by promql, param is namespace,pod,container
28-
ContainerMemUsageExprTemplate = `container_memory_working_set_bytes{container!="POD",namespace="%s",pod=~"^%s-%s",container="%s"}`
28+
ContainerMemUsageExprTemplate = `container_memory_working_set_bytes{container!="POD",namespace="%s",pod=~"^%s.*$",container="%s"}`
2929

30-
CustumerExprTemplate = `sum(%s{%s})`
30+
CustomerExprTemplate = `sum(%s{%s})`
3131
)
3232

33-
const (
34-
RegMatchesPodName = `[a-z0-9]+-[a-z0-9]{5}$`
35-
)
36-
37-
func GetCustumerExpression(metricName string, labels string) string {
38-
return fmt.Sprintf(CustumerExprTemplate, metricName, labels)
33+
func GetCustomerExpression(metricName string, labels string) string {
34+
return fmt.Sprintf(CustomerExprTemplate, metricName, labels)
3935
}
4036

4137
func GetWorkloadCpuUsageExpression(namespace string, name string) string {
42-
return fmt.Sprintf(WorkloadCpuUsageExprTemplate, namespace, name, RegMatchesPodName, "3m")
38+
return fmt.Sprintf(WorkloadCpuUsageExprTemplate, namespace, name, "3m")
4339
}
4440

4541
func GetWorkloadMemUsageExpression(namespace string, name string) string {
46-
return fmt.Sprintf(WorkloadMemUsageExprTemplate, namespace, name, RegMatchesPodName)
42+
return fmt.Sprintf(WorkloadMemUsageExprTemplate, namespace, name)
4743
}
4844

4945
func GetContainerCpuUsageExpression(namespace string, workloadName string, containerName string) string {
50-
return fmt.Sprintf(ContainerCpuUsageExprTemplate, namespace, workloadName, RegMatchesPodName, containerName, "3m")
46+
return fmt.Sprintf(ContainerCpuUsageExprTemplate, namespace, workloadName, containerName, "3m")
5147
}
5248

5349
func GetContainerMemUsageExpression(namespace string, workloadName string, containerName string) string {
54-
return fmt.Sprintf(ContainerMemUsageExprTemplate, namespace, workloadName, RegMatchesPodName, containerName)
50+
return fmt.Sprintf(ContainerMemUsageExprTemplate, namespace, workloadName, containerName)
5551
}
5652

5753
func GetPodCpuUsageExpression(namespace string, name string) string {

site/content/en/docs/Contributing/developer-guide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ description: "Getting started to develop crane"
77
First, please make sure you've got a working [Go environment](https://golang.org/doc/install)
88
and [Docker environment](https://docs.docker.com/engine).
99

10+
## Prepare local crane environment
11+
12+
Please referring to [quick start](/docs/getting-started/quick-start)
13+
1014
## Clone crane
1115

1216
Clone the repository,

site/content/en/docs/Getting started/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="tru
2929

3030
**Recommendation Framework**
3131

32-
Provide a pluggable framework for analytics and give recommendation for cloud resources, support out-of-box recommenders: Workload Resources/Replicas, Idle Resources.
32+
Provide a pluggable framework for analytics and give recommendation for cloud resources, support out-of-box recommenders: Workload Resources/Replicas, Idle Resources. [learn more](/docs/tutorials/recommendation).
3333

3434
**Prediction-driven Horizontal Autoscaling**
3535

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
---
3+
title: "Recommendation"
4+
weight: 10
5+
description: >
6+
Docs for Recommendation.
7+
---
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: "How to develop Recommender"
3+
description: "Introduce how to develop and extend Recommender based on framework"
4+
weight: 100
5+
---
6+
7+
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.
8+
9+
## Recommender Interface
10+
11+
```go
12+
type Recommender interface {
13+
Name() string
14+
framework.Filter
15+
framework.PrePrepare
16+
framework.Prepare
17+
framework.PostPrepare
18+
framework.PreRecommend
19+
framework.Recommend
20+
framework.PostRecommend
21+
framework.Observe
22+
}
23+
24+
// Phase: Filter
25+
26+
// Filter interface
27+
type Filter interface {
28+
// The Filter will filter resource can`t be recommended via target recommender.
29+
Filter(ctx *RecommendationContext) error
30+
}
31+
32+
// Phase: Prepare
33+
34+
// PrePrepare interface
35+
type PrePrepare interface {
36+
CheckDataProviders(ctx *RecommendationContext) error
37+
}
38+
39+
// Prepare interface
40+
type Prepare interface {
41+
CollectData(ctx *RecommendationContext) error
42+
}
43+
44+
type PostPrepare interface {
45+
PostProcessing(ctx *RecommendationContext) error
46+
}
47+
48+
// PreRecommend interface
49+
type PreRecommend interface {
50+
PreRecommend(ctx *RecommendationContext) error
51+
}
52+
53+
// Phase: Recommend
54+
55+
// Recommend interface
56+
type Recommend interface {
57+
Recommend(ctx *RecommendationContext) error
58+
}
59+
60+
// PostRecommend interface
61+
type PostRecommend interface {
62+
Policy(ctx *RecommendationContext) error
63+
}
64+
65+
// Phase: Observe
66+
67+
// Observe interface
68+
type Observe interface {
69+
Observe(ctx *RecommendationContext) error
70+
}
71+
72+
```
73+
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.
74+
75+
## Architecture
76+
77+
![](/images/recommendation-framework.png)
78+
79+
## Phases
80+
81+
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.
82+
83+
`RecommendationContext` saved the context for a recommended process, including recommended target, RecommendationConfiguration etc., the user can add more content as needed.
84+
85+
### Filter
86+
87+
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.
88+
89+
### Prepare
90+
91+
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.
92+
93+
### Recommend
94+
95+
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.
96+
97+
### Observe
98+
99+
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.

0 commit comments

Comments
 (0)