-
Notifications
You must be signed in to change notification settings - Fork 806
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Justin Jung <[email protected]>
- Loading branch information
1 parent
28977ea
commit 6ec2ada
Showing
12 changed files
with
265 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package query | ||
|
||
import ( | ||
"net/url" | ||
"regexp" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/cortexproject/cortex/pkg/util/validation" | ||
) | ||
|
||
func IsHighPriority(requestParams url.Values, highPriorityQueries []validation.HighPriorityQuery) bool { | ||
queryParam := requestParams.Get("query") | ||
timeParam := requestParams.Get("time") | ||
startParam := requestParams.Get("start") | ||
endParam := requestParams.Get("end") | ||
|
||
for _, highPriorityQuery := range highPriorityQueries { | ||
regex := highPriorityQuery.Regex | ||
|
||
if match, err := regexp.MatchString(regex, queryParam); !match || err != nil { | ||
continue | ||
} | ||
|
||
now := time.Now() | ||
startTimeThreshold := now.Add(-1 * highPriorityQuery.StartTime).UnixMilli() | ||
endTimeThreshold := now.Add(-1 * highPriorityQuery.EndTime).UnixMilli() | ||
|
||
if time, err := strconv.ParseInt(timeParam, 10, 64); err == nil { | ||
if isBetweenThresholds(time, time, startTimeThreshold, endTimeThreshold) { | ||
return true | ||
} | ||
} | ||
|
||
if startTime, err := strconv.ParseInt(startParam, 10, 64); err == nil { | ||
if endTime, err := strconv.ParseInt(endParam, 10, 64); err == nil { | ||
if isBetweenThresholds(startTime, endTime, startTimeThreshold, endTimeThreshold) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func isBetweenThresholds(start, end, startThreshold, endThreshold int64) bool { | ||
return start >= startThreshold && end <= endThreshold | ||
} |
Oops, something went wrong.