Skip to content

Commit aa1b6bb

Browse files
(feat): fix typo + readability improvements
Signed-off-by: mittalvaibhav1 <[email protected]>
1 parent ceeaa96 commit aa1b6bb

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

pkg/scalers/sumologic/logs.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import (
1010
)
1111

1212
const (
13-
searchJobPath = "api/v1/search/jobs"
13+
searchJobPath = "api/v1/search/jobs"
14+
stateDone = "DONE GATHERING RESULTS"
15+
stateCancelled = "CANCELLED"
16+
statePaused = "FORCE PAUSED"
1417
)
1518

1619
func (c *Client) createLogSearchJob(query, from, to, tz string) (string, error) {
@@ -23,7 +26,7 @@ func (c *Client) createLogSearchJob(query, from, to, tz string) (string, error)
2326

2427
payload, err := json.Marshal(requestPayload)
2528
if err != nil {
26-
return "", fmt.Errorf("failed to marshal log search request: %v", err)
29+
return "", fmt.Errorf("failed to marshal log search request: %w", err)
2730
}
2831

2932
url := fmt.Sprintf("%s/%s", c.config.Host, searchJobPath)
@@ -56,9 +59,9 @@ func (c *Client) waitForLogSearchJobCompletion(jobID string) (*LogSearchJobStatu
5659

5760
c.logger.Debug("log search job state", zap.String("state", status.State), zap.Int("recordCount", status.RecordCount))
5861

59-
if status.State == "DONE GATHERING RESULTS" {
62+
if status.State == stateDone {
6063
return &status, nil
61-
} else if status.State == "CANCELLED" || status.State == "FORCE PAUSED" {
64+
} else if status.State == stateCancelled || status.State == statePaused {
6265
return nil, fmt.Errorf("search job failed, state: %s", status.State)
6366
}
6467

pkg/scalers/sumologic_scaler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type sumologicMetadata struct {
3636
queryType string `keda:"name=queryType, order=triggerMetadata"`
3737
query string `keda:"name=query, order=triggerMetadata"`
3838
queries map[string]string `keda:"name=query.*, order=triggerMetadata"` // Only for metrics queries
39-
resultQueryRowId string `keda:"name=query.*, order=triggerMetadata"` // Only for metrics queries
39+
resultQueryRowId string `keda:"name=resultQueryRowId, order=triggerMetadata"` // Only for metrics queries
4040
quantization time.Duration `keda:"name=quantization, order=triggerMetadata"` // Only for metrics queries
4141
rollup string `keda:"name=rollup, order=triggerMetadata, optional"` // Only for metrics queries
4242
resultField string `keda:"name=resultField, order=triggerMetadata"` // Only for logs queries
@@ -180,7 +180,7 @@ func parseSumoMetadata(config *scalersconfig.ScalerConfig) (*sumologicMetadata,
180180
if val, ok := config.TriggerMetadata["activationThreshold"]; ok {
181181
activationThreshold, err := strconv.ParseFloat(val, 64)
182182
if err != nil {
183-
return nil, fmt.Errorf("activationThreshold parsing error %w", err)
183+
return nil, fmt.Errorf("activationThreshold parsing error: %w", err)
184184
}
185185
meta.activationThreshold = activationThreshold
186186
}
@@ -197,7 +197,7 @@ func parseSumoMetadata(config *scalersconfig.ScalerConfig) (*sumologicMetadata,
197197
if val, ok := config.TriggerMetadata["threshold"]; ok {
198198
threshold, err := strconv.ParseFloat(val, 64)
199199
if err != nil {
200-
return nil, fmt.Errorf("threshold parsing error %w", err)
200+
return nil, fmt.Errorf("threshold parsing error: %w", err)
201201
}
202202
meta.threshold = threshold
203203
}
@@ -209,7 +209,7 @@ func parseMultiMetricsQueries(triggerMetadata map[string]string) (map[string]str
209209
queries := make(map[string]string)
210210
for key, value := range triggerMetadata {
211211
if strings.HasPrefix(key, multiMetricsQueryPrefix) {
212-
rowId := strings.Replace(key, multiMetricsQueryPrefix, "", -1)
212+
rowId := strings.TrimPrefix(key, multiMetricsQueryPrefix)
213213
if rowId == "" {
214214
return nil, fmt.Errorf("malformed metadata, unable to parse rowId from key: %s", key)
215215
}

0 commit comments

Comments
 (0)