-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resource-recommend): add resource recommend controller
- Loading branch information
1 parent
b24c422
commit b7791f0
Showing
72 changed files
with
10,505 additions
and
65 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
cmd/katalyst-controller/app/controller/resourcerecommender.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 controller | ||
|
||
import ( | ||
"context" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
katalyst "github.com/kubewharf/katalyst-core/cmd/base" | ||
"github.com/kubewharf/katalyst-core/pkg/config" | ||
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/controller" | ||
) | ||
|
||
const ( | ||
ResourceRecommenderControllerName = "resourcerecommender" | ||
) | ||
|
||
func StartResourceRecommenderController( | ||
ctx context.Context, | ||
_ *katalyst.GenericContext, | ||
conf *config.Configuration, | ||
_ interface{}, | ||
_ string, | ||
) (bool, error) { | ||
resourceRecommenderController, err := controller.NewResourceRecommenderController(ctx, | ||
conf.GenericConfiguration, | ||
conf.ControllersConfiguration.ResourceRecommenderConfig) | ||
if err != nil { | ||
klog.Errorf("failed to new ResourceRecommender controller") | ||
return false, err | ||
} | ||
|
||
go resourceRecommenderController.Run() | ||
return true, 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
100 changes: 100 additions & 0 deletions
100
cmd/katalyst-controller/app/options/resourcerecommender.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,100 @@ | ||
/* | ||
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 options | ||
|
||
import ( | ||
"time" | ||
|
||
cliflag "k8s.io/component-base/cli/flag" | ||
|
||
"github.com/kubewharf/katalyst-core/pkg/config/controller" | ||
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/datasource/prometheus" | ||
) | ||
|
||
type ResourceRecommenderOptions struct { | ||
OOMRecordMaxNumber int `desc:"max number for oom record"` | ||
|
||
HealthProbeBindPort string `desc:"The port the health probe binds to."` | ||
MetricsBindPort string `desc:"The port the metric endpoint binds to."` | ||
|
||
// available datasource: prom | ||
DataSource []string | ||
// DataSourcePromConfig is the prometheus datasource config | ||
DataSourcePromConfig prometheus.PromConfig | ||
|
||
// LogVerbosityLevel to specify log verbosity level. (The default level is 4) | ||
// Set it to something larger than 4 if more detailed logs are needed. | ||
LogVerbosityLevel string | ||
} | ||
|
||
// NewResourceRecommenderOptions creates a new Options with a default config. | ||
func NewResourceRecommenderOptions() *ResourceRecommenderOptions { | ||
return &ResourceRecommenderOptions{ | ||
OOMRecordMaxNumber: 5000, | ||
HealthProbeBindPort: "8080", | ||
MetricsBindPort: "8081", | ||
DataSource: []string{"prom"}, | ||
DataSourcePromConfig: prometheus.PromConfig{ | ||
KeepAlive: 60 * time.Second, | ||
Timeout: 3 * time.Minute, | ||
BRateLimit: false, | ||
MaxPointsLimitPerTimeSeries: 11000, | ||
}, | ||
LogVerbosityLevel: "4", | ||
} | ||
} | ||
|
||
// AddFlags adds flags to the specified FlagSet | ||
func (o *ResourceRecommenderOptions) AddFlags(fss *cliflag.NamedFlagSets) { | ||
fs := fss.FlagSet("resource-recommend") | ||
fs.IntVar(&o.OOMRecordMaxNumber, "oom-record-max-number", 5000, "Max number for oom records to store in configmap") | ||
|
||
fs.StringVar(&o.HealthProbeBindPort, "resourcerecommend-health-probe-bind-port", "8080", "The port the health probe binds to.") | ||
fs.StringVar(&o.MetricsBindPort, "resourcerecommend-metrics-bind-port", "8081", "The port the metric endpoint binds to.") | ||
|
||
fs.StringSliceVar(&o.DataSource, "resourcerecommend-datasource", []string{"prom"}, "available datasource: prom") | ||
fs.StringVar(&o.DataSourcePromConfig.Address, "resourcerecommend-prometheus-address", "", "prometheus address") | ||
fs.StringVar(&o.DataSourcePromConfig.Auth.Type, "resourcerecommend-prometheus-auth-type", "", "prometheus auth type") | ||
fs.StringVar(&o.DataSourcePromConfig.Auth.Username, "resourcerecommend-prometheus-auth-username", "", "prometheus auth username") | ||
fs.StringVar(&o.DataSourcePromConfig.Auth.Password, "resourcerecommend-prometheus-auth-password", "", "prometheus auth password") | ||
fs.StringVar(&o.DataSourcePromConfig.Auth.BearerToken, "resourcerecommend-prometheus-auth-bearertoken", "", "prometheus auth bearertoken") | ||
fs.DurationVar(&o.DataSourcePromConfig.KeepAlive, "resourcerecommend-prometheus-keepalive", 60*time.Second, "prometheus keep alive") | ||
fs.DurationVar(&o.DataSourcePromConfig.Timeout, "resourcerecommend-prometheus-timeout", 3*time.Minute, "prometheus timeout") | ||
fs.BoolVar(&o.DataSourcePromConfig.BRateLimit, "resourcerecommend-prometheus-bratelimit", false, "prometheus bratelimit") | ||
fs.IntVar(&o.DataSourcePromConfig.MaxPointsLimitPerTimeSeries, "resourcerecommend-prometheus-maxpoints", 11000, "prometheus max points limit per time series") | ||
fs.StringVar(&o.DataSourcePromConfig.BaseFilter, "resourcerecommend-prometheus-promql-base-filter", "", ""+ | ||
"Get basic filters in promql for historical usage data. This filter is added to all promql statements. "+ | ||
"Supports filters format of promql, e.g: group=\\\"Katalyst\\\",cluster=\\\"cfeaf782fasdfe\\\"") | ||
} | ||
|
||
func (o *ResourceRecommenderOptions) ApplyTo(c *controller.ResourceRecommenderConfig) error { | ||
c.OOMRecordMaxNumber = o.OOMRecordMaxNumber | ||
c.HealthProbeBindPort = o.HealthProbeBindPort | ||
c.MetricsBindPort = o.MetricsBindPort | ||
c.DataSource = o.DataSource | ||
c.DataSourcePromConfig = o.DataSourcePromConfig | ||
c.LogVerbosityLevel = o.LogVerbosityLevel | ||
return nil | ||
} | ||
|
||
func (o *ResourceRecommenderOptions) Config() (*controller.ResourceRecommenderConfig, error) { | ||
c := &controller.ResourceRecommenderConfig{} | ||
if err := o.ApplyTo(c); err != nil { | ||
return nil, err | ||
} | ||
return c, 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
Oops, something went wrong.