Skip to content

support recommend with pod metric #923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ jobs:

# Cache go build cache, used to speedup go test
- name: Go Build Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

# Cache go mod cache, used to speedup builds
- name: Go Mod Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}

- name: Go Lint Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cache/golangci-lint
Expand All @@ -66,7 +66,7 @@ jobs:
sed -i 's/black/whitesmoke/g' coverage.html

- name: Upload a Build Artifact
uses: actions/upload-artifact@v3.0.0
uses: actions/upload-artifact@v4
with:
# Artifact name
name: coverage.html # optional, default is artifact
Expand All @@ -92,14 +92,14 @@ jobs:

# Cache go build cache, used to speedup go test
- name: Go Build Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

# Cache go mod cache, used to speedup builds
- name: Go Mod Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
Expand All @@ -125,14 +125,14 @@ jobs:

# Cache go build cache, used to speedup go test
- name: Go Build Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

# Cache go mod cache, used to speedup builds
- name: Go Mod Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
Expand All @@ -158,14 +158,14 @@ jobs:

# Cache go build cache, used to speedup go test
- name: Go Build Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

# Cache go mod cache, used to speedup builds
- name: Go Mod Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/recommendation/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (c *RecommendationController) UpdateRecommendation(ctx context.Context, rec
switch string(recommendation.Spec.Type) {
case recommender.ResourceRecommender:
if proposedRecommendation.ResourceRequest != nil {
proposedRecommendation.ResourceRequest.Pod = nil
resourceValue, err := yaml.Marshal(proposedRecommendation.ResourceRequest)
if err != nil {
return false, fmt.Errorf("marshal ResourceRequest failed: %v. ", err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const (

// QOSInitializer enables the qos initialization featrues.
QOSInitializer featuregate.Feature = "QOSInitializer"

// EnablePodRecommendation enables the pod recommendation features.
EnablePodRecommendation featuregate.Feature = "EnablePodRecommendation"
)

var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
Expand All @@ -49,6 +52,7 @@ var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
CraneCPUManager: {Default: false, PreRelease: featuregate.Alpha},
QOSInitializer: {Default: false, PreRelease: featuregate.Alpha},
CraneDashboardControl: {Default: false, PreRelease: featuregate.Alpha},
EnablePodRecommendation: {Default: false, PreRelease: featuregate.Alpha},
}

func init() {
Expand Down
16 changes: 16 additions & 0 deletions pkg/metricnaming/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ func ResourceToWorkloadMetricNamer(target *corev1.ObjectReference, resourceName
}
}

func ResourceToPodMetricNamer(namespace, podName string, resourceName corev1.ResourceName, caller string) MetricNamer {
// pod
return &GeneralMetricNamer{
CallerName: caller,
Metric: &metricquery.Metric{
Type: metricquery.PodMetricType,
MetricName: resourceName.String(),
Pod: &metricquery.PodNamerInfo{
Namespace: namespace,
Name: podName,
Selector: labels.Everything(),
},
},
}
}

func ResourceToContainerMetricNamer(namespace, apiVersion, workloadKind, workloadName, containerName string, resourceName corev1.ResourceName, caller string) MetricNamer {
// container
return &GeneralMetricNamer{
Expand Down
2 changes: 1 addition & 1 deletion pkg/prediction/percentile/prediction.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (p *percentilePrediction) getPredictedValuesFromSignals(queryExpr string, s

if cfg.aggregated {
signal := signals[keyAll]
if signal != nil {
if signal != nil && signal.totalSamplesCount > 0 {
sample := common.Sample{
Value: estimator.GetEstimation(signal.histogram),
Timestamp: now,
Expand Down
6 changes: 6 additions & 0 deletions pkg/recommend/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type EffectiveHorizontalPodAutoscalerRecommendation struct {
}

type ResourceRequestRecommendation struct {
Pod *PodRecommendation `json:"pod,omitempty"`
Containers []ContainerRecommendation `json:"containers,omitempty"`
}

Expand All @@ -61,4 +62,9 @@ type ContainerRecommendation struct {
Target ResourceList `json:"target,omitempty"`
}

type PodRecommendation struct {
PodName string `json:"podName,omitempty"`
Target ResourceList `json:"target,omitempty"`
}

type ResourceList map[corev1.ResourceName]string
Loading
Loading