-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #472 from WangZzzhe/dev/overcommit-bindcpu
feat(overcommit): add realtime overcommit advisor plugin
- Loading branch information
Showing
42 changed files
with
4,242 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
cmd/katalyst-agent/app/options/sysadvisor/overcommit/overcommit_aware_plugin.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright 2022 The Katalyst Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package overcommit | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/util/errors" | ||
cliflag "k8s.io/component-base/cli/flag" | ||
|
||
"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/sysadvisor/overcommit/realtime" | ||
"github.com/kubewharf/katalyst-core/pkg/config/agent/sysadvisor/overcommit" | ||
) | ||
|
||
type OvercommitAwarePluginOptions struct { | ||
*realtime.RealtimeOvercommitOptions | ||
} | ||
|
||
// NewOvercommitAwarePluginOptions creates a new Options with a default config. | ||
func NewOvercommitAwarePluginOptions() *OvercommitAwarePluginOptions { | ||
return &OvercommitAwarePluginOptions{ | ||
RealtimeOvercommitOptions: realtime.NewRealtimeOvercommitOptions(), | ||
} | ||
} | ||
|
||
func (o *OvercommitAwarePluginOptions) AddFlags(fss *cliflag.NamedFlagSets) { | ||
fs := fss.FlagSet("overcommit_aware_plugin") | ||
|
||
o.RealtimeOvercommitOptions.AddFlags(fs) | ||
} | ||
|
||
func (o *OvercommitAwarePluginOptions) ApplyTo(c *overcommit.OvercommitAwarePluginConfiguration) error { | ||
var errList []error | ||
|
||
errList = append(errList, o.RealtimeOvercommitOptions.ApplyTo(c.RealtimeOvercommitConfiguration)) | ||
|
||
return errors.NewAggregate(errList) | ||
} |
94 changes: 94 additions & 0 deletions
94
cmd/katalyst-agent/app/options/sysadvisor/overcommit/realtime/realtime.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
Copyright 2022 The Katalyst Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package realtime | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/spf13/pflag" | ||
|
||
"github.com/kubewharf/katalyst-core/pkg/config/agent/sysadvisor/overcommit/realtime" | ||
) | ||
|
||
type RealtimeOvercommitOptions struct { | ||
SyncPeriod time.Duration | ||
SyncPodTimeout time.Duration | ||
|
||
TargetCPULoad float64 | ||
TargetMemoryLoad float64 | ||
EstimatedPodCPULoad float64 | ||
EstimatedPodMemoryLoad float64 | ||
|
||
CPUMetricsToGather []string | ||
MemoryMetricsToGather []string | ||
} | ||
|
||
func NewRealtimeOvercommitOptions() *RealtimeOvercommitOptions { | ||
return &RealtimeOvercommitOptions{ | ||
SyncPeriod: 10 * time.Second, | ||
SyncPodTimeout: 2 * time.Second, | ||
TargetCPULoad: 0.6, | ||
TargetMemoryLoad: 0.8, | ||
EstimatedPodCPULoad: 0.4, | ||
EstimatedPodMemoryLoad: 0.8, | ||
|
||
CPUMetricsToGather: []string{}, | ||
MemoryMetricsToGather: []string{}, | ||
} | ||
} | ||
|
||
func (r *RealtimeOvercommitOptions) AddFlags(fs *pflag.FlagSet) { | ||
fs.DurationVar(&r.SyncPeriod, "realtime-overcommit-sync-period", r.SyncPeriod, | ||
"period for realtime overcommit advisor to calculate node resource overcommit ratio") | ||
fs.DurationVar(&r.SyncPodTimeout, "realtime-overcommit-sync-pod-timeout", r.SyncPodTimeout, | ||
"timeout for realtime overcommit advisor to list pod") | ||
fs.Float64Var(&r.TargetCPULoad, "realtime-overcommit-CPU-targetload", r.TargetCPULoad, | ||
"target node load for realtime overcommit advisor to calculate node CPU overcommit ratio") | ||
fs.Float64Var(&r.TargetMemoryLoad, "realtime-overcommit-mem-targetload", r.TargetMemoryLoad, | ||
"target node load for realtime overcommit advisor to calculate node memory overcommit ratio") | ||
fs.Float64Var(&r.EstimatedPodCPULoad, "realtime-overcommit-estimated-cpuload", r.EstimatedPodCPULoad, | ||
"estimated pod load for realtime overcommit advisor to calculate node CPU overcommit ratio") | ||
fs.Float64Var(&r.EstimatedPodMemoryLoad, "realtime-overcommit-estimated-memload", r.EstimatedPodMemoryLoad, | ||
"estimated pod load for realtime overcommit advisor to calculate node memory overcommit ratio") | ||
fs.StringSliceVar(&r.CPUMetricsToGather, "CPU-metrics-to-gather", r.CPUMetricsToGather, | ||
"metrics list used to calculate node cpu overcommitment ratio") | ||
fs.StringSliceVar(&r.MemoryMetricsToGather, "memory-metrics-to-gather", r.MemoryMetricsToGather, | ||
"metrics list used to calculate node memory overcommitment ratio") | ||
} | ||
|
||
func (r *RealtimeOvercommitOptions) ApplyTo(o *realtime.RealtimeOvercommitConfiguration) error { | ||
o.SyncPeriod = r.SyncPeriod | ||
o.SyncPodTimeout = r.SyncPodTimeout | ||
|
||
if r.TargetCPULoad > 0.0 && r.TargetMemoryLoad < 1.0 { | ||
o.TargetCPULoad = r.TargetCPULoad | ||
} | ||
if r.TargetMemoryLoad > 0.0 && r.TargetMemoryLoad < 1.0 { | ||
o.TargetMemoryLoad = r.TargetMemoryLoad | ||
} | ||
if r.EstimatedPodCPULoad > 0.0 && r.EstimatedPodCPULoad < 1.0 { | ||
o.EstimatedPodCPULoad = r.EstimatedPodCPULoad | ||
} | ||
if r.EstimatedPodMemoryLoad > 0.0 && r.EstimatedPodMemoryLoad < 1.0 { | ||
o.EstimatedPodMemoryLoad = r.EstimatedPodMemoryLoad | ||
} | ||
|
||
o.CPUMetricsToGather = r.CPUMetricsToGather | ||
o.MemoryMetricsToGather = r.MemoryMetricsToGather | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
pkg/agent/sysadvisor/plugin/overcommitmentaware/overcommitment_aware.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright 2022 The Katalyst Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package overcommitmentaware | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" | ||
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin" | ||
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/overcommitmentaware/realtime" | ||
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/overcommitmentaware/reporter" | ||
"github.com/kubewharf/katalyst-core/pkg/config" | ||
"github.com/kubewharf/katalyst-core/pkg/metaserver" | ||
"github.com/kubewharf/katalyst-core/pkg/metrics" | ||
metricspool "github.com/kubewharf/katalyst-core/pkg/metrics/metrics-pool" | ||
) | ||
|
||
const ( | ||
PluginName = "overcommitment-aware-plugin" | ||
) | ||
|
||
// OvercommitmentAwarePlugin calculates node overcommitment ratio, | ||
// values will be reported to node KCNR annotations by the reporter. | ||
type OvercommitmentAwarePlugin struct { | ||
name string | ||
|
||
realtimeAdvisor *realtime.RealtimeOvercommitmentAdvisor | ||
reporter reporter.OvercommitRatioReporter | ||
|
||
emitter metrics.MetricEmitter | ||
} | ||
|
||
func NewOvercommitmentAwarePlugin( | ||
pluginName string, conf *config.Configuration, | ||
_ interface{}, | ||
emitterPool metricspool.MetricsEmitterPool, | ||
metaServer *metaserver.MetaServer, | ||
_ metacache.MetaCache, | ||
) (plugin.SysAdvisorPlugin, error) { | ||
emitter := emitterPool.GetDefaultMetricsEmitter() | ||
|
||
realtimeOvercommitmentAdvisor := realtime.NewRealtimeOvercommitmentAdvisor(conf, metaServer, emitter) | ||
|
||
overcommitRatioReporter, err := reporter.NewOvercommitRatioReporter(emitter, conf, realtimeOvercommitmentAdvisor, metaServer) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
op := &OvercommitmentAwarePlugin{ | ||
name: pluginName, | ||
|
||
realtimeAdvisor: realtimeOvercommitmentAdvisor, | ||
reporter: overcommitRatioReporter, | ||
} | ||
|
||
return op, nil | ||
} | ||
|
||
func (op *OvercommitmentAwarePlugin) Run(ctx context.Context) { | ||
go op.realtimeAdvisor.Run(ctx) | ||
|
||
go op.reporter.Run(ctx) | ||
} | ||
|
||
func (op *OvercommitmentAwarePlugin) Name() string { | ||
return op.name | ||
} | ||
|
||
func (op *OvercommitmentAwarePlugin) Init() error { | ||
return nil | ||
} |
Oops, something went wrong.