Skip to content

Commit

Permalink
lints
Browse files Browse the repository at this point in the history
  • Loading branch information
nikodemrafalski committed Jan 16, 2024
1 parent 29e1533 commit b41d4de
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ words:
- stimeslice
- strconv
- structs
- submatches
- sumologic
- testutils
- timeseries
Expand Down
15 changes: 7 additions & 8 deletions manifest/v1alpha/slo/metrics_sumo_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,31 +145,30 @@ func validateSumoLogicTimeslice(query string) error {
return nil
}

func getTimeSliceFromSumoLogicQuery(query string) (time.Duration, string, bool, error) {
func getTimeSliceFromSumoLogicQuery(query string) (
tsDuration time.Duration, durationString string, containsAlias bool, err error,
) {
r := regexp.MustCompile(`\stimeslice\s([-+]?(\d+[a-z]+\s?)+)\s(?:as n9_time)?`)
matchResults := r.FindAllStringSubmatch(query, 2)

if len(matchResults) == 0 {
return 0, "", false, fmt.Errorf("query must contain a 'timeslice' operator")
}

if len(matchResults) > 1 {
return 0, "", false, fmt.Errorf("exactly one 'timeslice' declaration is required in the query")
}

submatches := matchResults[0]

if submatches[1] != submatches[2] {
return 0, "", false, fmt.Errorf("timeslice interval must be in a NumberUnit form - for example '30s'")
}

// https://help.sumologic.com/05Search/Search-Query-Language/Search-Operators/timeslice#syntax
durationString := strings.TrimSpace(submatches[1])
containsAlias := strings.Contains(submatches[0][1:], "as n9_time")
timeslice, err := time.ParseDuration(durationString)
durationString = strings.TrimSpace(submatches[1])
containsAlias = strings.Contains(submatches[0][1:], "as n9_time")
tsDuration, err = time.ParseDuration(durationString)
if err != nil {
return 0, "", containsAlias, fmt.Errorf("error parsing timeslice duration: %s", err.Error())
}

return timeslice, durationString, containsAlias, nil
return tsDuration, durationString, containsAlias, nil
}
2 changes: 1 addition & 1 deletion manifest/v1alpha/slo/metrics_sumo_logic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ _collector="n9-dev-tooling-cluster" _source="logs"
| sort by time asc`,
Error: testutils.ExpectedError{
Prop: "spec.objectives[0].rawMetric.query.sumoLogic.query",
ContainsMessage: "imeslice operator requires an n9_time alias",
ContainsMessage: "timeslice operator requires an n9_time alias",
},
},
"missing aggregation function": {
Expand Down

0 comments on commit b41d4de

Please sign in to comment.