Skip to content

Commit

Permalink
fix merge comments
Browse files Browse the repository at this point in the history
Signed-off-by: alex60217101990 <[email protected]>
  • Loading branch information
alex60217101990 committed Jan 10, 2022
1 parent ce38702 commit 84ff032
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/scalers/predictkube_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (

const (
predictKubeMetricType = "External"

invalidMetricTypeErr = "metric type is invalid"
)

var (
Expand Down Expand Up @@ -135,7 +137,7 @@ func (pks *PredictKubeScaler) setupClientConn() error {
}

// NewPredictKubeScaler creates a new PredictKube scaler
func NewPredictKubeScaler(_ context.Context, config *ScalerConfig) (*PredictKubeScaler, error) {
func NewPredictKubeScaler(ctx context.Context, config *ScalerConfig) (*PredictKubeScaler, error) {
s := &PredictKubeScaler{}

meta, err := parsePredictKubeMetadata(config)
Expand All @@ -146,7 +148,7 @@ func NewPredictKubeScaler(_ context.Context, config *ScalerConfig) (*PredictKube

s.metadata = meta

err = s.initPredictKubePrometheusConn()
err = s.initPredictKubePrometheusConn(ctx)
if err != nil {
predictKubeLog.Error(err, "error create Prometheus client and API objects")
return nil, fmt.Errorf("error create Prometheus client and API objects: %3s", err)
Expand All @@ -164,7 +166,6 @@ func NewPredictKubeScaler(_ context.Context, config *ScalerConfig) (*PredictKube
// IsActive returns true if we are able to get metrics from PredictKube
func (pks *PredictKubeScaler) IsActive(ctx context.Context) (bool, error) {
results, err := pks.doQuery(ctx)
// TODO:
if err != nil {
return false, err
}
Expand Down Expand Up @@ -350,6 +351,8 @@ func (pks *PredictKubeScaler) parsePrometheusResult(result model.Value) (out []*
MetricName: metricName,
})
}
default:
return nil, errors.New(invalidMetricTypeErr)
}

return out, nil
Expand Down Expand Up @@ -423,7 +426,7 @@ func parsePredictKubeMetadata(config *ScalerConfig) (result *predictKubeMetadata

err = validate.Var(val, "ascii")
if err != nil {
return nil, fmt.Errorf("invalid apiKey")
return nil, fmt.Errorf("invalid metricName")
}

meta.metricName = val
Expand Down Expand Up @@ -453,7 +456,7 @@ func (pks *PredictKubeScaler) ping(ctx context.Context) (err error) {
}

// initPredictKubePrometheusConn init prometheus client and setup connection to API
func (pks *PredictKubeScaler) initPredictKubePrometheusConn() (err error) {
func (pks *PredictKubeScaler) initPredictKubePrometheusConn(ctx context.Context) (err error) {
pks.transport = http_transport.NewTransport(&libs.HTTPTransport{
MaxIdleConnDuration: 10,
ReadTimeout: time.Second * 15,
Expand All @@ -472,5 +475,5 @@ func (pks *PredictKubeScaler) initPredictKubePrometheusConn() (err error) {

pks.api = v1.NewAPI(pks.prometheusClient)

return pks.ping(context.Background())
}
return pks.ping(ctx)
}

0 comments on commit 84ff032

Please sign in to comment.