Skip to content

Commit

Permalink
use keda's http client, fix capitalization
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Pinske <brandon.pinske@crowdstrike.com>
  • Loading branch information
Brandon Pinske committed Sep 10, 2021
1 parent 702f736 commit 54e0783
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions CREATE-NEW-SCALER.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ The constructor should have the following parameters:
The scaler is created and closed everytime KEDA or HPA wants to call `GetMetrics`, and everytime a new ScaledObject is created or updated that has a trigger for that scaler. Thus, a developer of a scaler should not assume that the scaler will maintain any state between these calls.

## Note
The scaler code is embedded into the two separate binaries comprising keda, the operator and the custom metrics server component. The metrics server must be occasionally rebuilt published and deployed to k8s for it to have the same code as your operator.
The scaler code is embedded into the two separate binaries comprising KEDA, the operator and the custom metrics server component. The metrics server must be occasionally rebuilt published and deployed to k8s for it to have the same code as your operator.

GetMetricSpecForScaling() is executed by the operator for the purposes of scaling up to and down to 0 replicas.
GetMetrics() is executed by the custom metrics server in response to a calls against the external metrics api, whether by the HPA loop or by curl
GetMetrics() is executed by the custom metrics server in response to a calls against the external metrics api, whether by the HPA loop or by curl
18 changes: 11 additions & 7 deletions pkg/scalers/graphite_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ const (
grapMetricName = "metricName"
grapQuery = "query"
grapThreshold = "threshold"
grapqueryTime = "queryTime"
grapQueryTime = "queryTime"
)

type graphiteScaler struct {
metadata *graphiteMetadata
metadata *graphiteMetadata
httpClient *http.Client
}

type graphiteMetadata struct {
Expand Down Expand Up @@ -61,8 +62,12 @@ func NewGraphiteScaler(config *ScalerConfig) (Scaler, error) {
if err != nil {
return nil, fmt.Errorf("error parsing graphite metadata: %s", err)
}

httpClient := kedautil.CreateHTTPClient(config.GlobalHTTPTimeout)

return &graphiteScaler{
metadata: meta,
metadata: meta,
httpClient: httpClient,
}, nil
}

Expand All @@ -87,10 +92,10 @@ func parseGraphiteMetadata(config *ScalerConfig) (*graphiteMetadata, error) {
return nil, fmt.Errorf("no %s given", grapMetricName)
}

if val, ok := config.TriggerMetadata[grapqueryTime]; ok && val != "" {
if val, ok := config.TriggerMetadata[grapQueryTime]; ok && val != "" {
meta.from = val
} else {
return nil, fmt.Errorf("no %s given", grapqueryTime)
return nil, fmt.Errorf("no %s given", grapQueryTime)
}

if val, ok := config.TriggerMetadata[grapThreshold]; ok && val != "" {
Expand Down Expand Up @@ -162,7 +167,6 @@ func (s *graphiteScaler) GetMetricSpecForScaling() []v2beta2.MetricSpec {
}

func (s *graphiteScaler) ExecuteGrapQuery() (float64, error) {
client := &http.Client{}
queryEscaped := url_pkg.QueryEscape(s.metadata.query)
url := fmt.Sprintf("%s/render?from=%s&target=%s&format=json", s.metadata.serverAddress, s.metadata.from, queryEscaped)
req, err := http.NewRequest("GET", url, nil)
Expand All @@ -172,7 +176,7 @@ func (s *graphiteScaler) ExecuteGrapQuery() (float64, error) {
if s.metadata.enableBasicAuth {
req.SetBasicAuth(s.metadata.username, s.metadata.password)
}
r, err := client.Do(req)
r, err := s.httpClient.Do(req)
if err != nil {
return -1, err
}
Expand Down

0 comments on commit 54e0783

Please sign in to comment.