Skip to content
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

add query expressions management by prom-adapter-config #560

Merged
merged 32 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
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
29 changes: 27 additions & 2 deletions cmd/craned/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/gocrane/crane/pkg/metrics"
"github.com/gocrane/crane/pkg/oom"
"github.com/gocrane/crane/pkg/predictor"
prometheus_adapter "github.com/gocrane/crane/pkg/prometheus-adapter"
"github.com/gocrane/crane/pkg/providers"
"github.com/gocrane/crane/pkg/providers/grpc"
"github.com/gocrane/crane/pkg/providers/metricserver"
Expand Down Expand Up @@ -269,17 +270,41 @@ func initControllers(oomRecorder oom.Recorder, mgr ctrl.Manager, opts *options.O
targetSelectorFetcher := target.NewSelectorFetcher(mgr.GetScheme(), mgr.GetRESTMapper(), scaleClient, mgr.GetClient())

if utilfeature.DefaultFeatureGate.Enabled(features.CraneAutoscaling) {
if err := (&ehpa.EffectiveHPAController{
var ehpaController = &ehpa.EffectiveHPAController{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
RestMapper: mgr.GetRESTMapper(),
Recorder: mgr.GetEventRecorderFor("effective-hpa-controller"),
ScaleClient: scaleClient,
Config: opts.EhpaControllerConfig,
}).SetupWithManager(mgr); err != nil {
}

if err := (ehpaController).SetupWithManager(mgr); err != nil {
klog.Exit(err, "unable to create controller", "controller", "EffectiveHPAController")
}

if opts.DataSourcePromConfig.AdapterConfigMapNS != "" && opts.DataSourcePromConfig.AdapterConfigMapName != "" && opts.DataSourcePromConfig.AdapterConfigMapKey != "" {
// PrometheusAdapterConfigFetcher
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if opts.DataSourcePromConfig.AdapterConfigMap != "" || opts.DataSourcePromConfig.AdapterConfig != "" {
init()
}

if err := (&prometheus_adapter.PrometheusAdapterConfigFetcher{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
RestMapper: mgr.GetRESTMapper(),
Recorder: mgr.GetEventRecorderFor("prometheus-adapter-configmap-controller"),
AdapterConfigMapNS: opts.DataSourcePromConfig.AdapterConfigMapNS,
AdapterConfigMapName: opts.DataSourcePromConfig.AdapterConfigMapName,
AdapterConfigMapKey: opts.DataSourcePromConfig.AdapterConfigMapKey,
}).SetupWithManager(mgr); err != nil {
klog.Exit(err, "unable to create controller", "controller", "PromAdapterConfigMapController")
}
} else if opts.DataSourcePromConfig.AdapterConfig != "" {
// PrometheusAdapterConfigFetcher
pac := &prometheus_adapter.PrometheusAdapterConfigFetcher{
AdapterConfig: opts.DataSourcePromConfig.AdapterConfig,
}

go pac.Reload()
}

if err := (&ehpa.SubstituteController{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Expand Down
4 changes: 4 additions & 0 deletions cmd/craned/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
"Specifies the update frequency of the prediction.")
flags.StringSliceVar(&o.DataSource, "datasource", []string{"prom"}, "data source of the predictor, prom, mock is available")
flags.StringVar(&o.DataSourcePromConfig.Address, "prometheus-address", "", "prometheus address")
flags.StringVar(&o.DataSourcePromConfig.AdapterConfigMapNS, "prometheus-adapter-configmap-namespace", "", "prometheus adapter-configmap namespace")
flags.StringVar(&o.DataSourcePromConfig.AdapterConfigMapName, "prometheus-adapter-configmap-name", "", "prometheus adapter-configmap name")
flags.StringVar(&o.DataSourcePromConfig.AdapterConfigMapKey, "prometheus-adapter-configmap-key", "", "prometheus adapter-configmap key")
flags.StringVar(&o.DataSourcePromConfig.AdapterConfig, "prometheus-adapter-config", "", "prometheus adapter-config path")
flags.StringVar(&o.DataSourcePromConfig.Auth.Username, "prometheus-auth-username", "", "prometheus auth username")
flags.StringVar(&o.DataSourcePromConfig.Auth.Password, "prometheus-auth-password", "", "prometheus auth password")
flags.StringVar(&o.DataSourcePromConfig.Auth.BearerToken, "prometheus-auth-bearertoken", "", "prometheus auth bearertoken")
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.26.0
github.com/shirou/gopsutil v3.21.10+incompatible
github.com/spf13/cobra v1.1.3
github.com/spf13/cobra v1.2.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
Expand All @@ -31,6 +31,7 @@ require (
k8s.io/metrics v0.22.3
sigs.k8s.io/controller-runtime v0.10.2
sigs.k8s.io/custom-metrics-apiserver v1.22.0
sigs.k8s.io/prometheus-adapter v0.9.0
sigs.k8s.io/yaml v1.2.0
)

Expand All @@ -45,7 +46,7 @@ require (
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/zsais/go-gin-prometheus v0.1.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
gopkg.in/gcfg.v1 v1.2.0
gopkg.in/gcfg.v1 v1.2.3
k8s.io/kube-openapi v0.0.0-20210817084001-7fbd8d59e5b8 // indirect
)

Expand Down Expand Up @@ -153,7 +154,7 @@ require (
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/warnings.v0 v0.1.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
howett.net/plist v1.0.0 // indirect
Expand All @@ -175,7 +176,6 @@ require (
github.com/lithammer/fuzzysearch v1.1.5
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/robfig/cron/v3 v3.0.1
github.com/spf13/afero v1.6.0 // indirect
go.etcd.io/etcd/client/v2 v2.305.1 // indirect
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
Expand Down
Loading