aboutsummaryrefslogtreecommitdiff
path: root/pkg/util/filters.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/util/filters.go')
-rw-r--r--pkg/util/filters.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/pkg/util/filters.go b/pkg/util/filters.go
index 51b2c5331..90daef402 100644
--- a/pkg/util/filters.go
+++ b/pkg/util/filters.go
@@ -11,7 +11,7 @@ import (
"github.com/pkg/errors"
)
-// ComputeUntilTimestamp extracts unitil timestamp from filters
+// ComputeUntilTimestamp extracts until timestamp from filters
func ComputeUntilTimestamp(filter string, filterValues []string) (time.Time, error) {
invalid := time.Time{}
if len(filterValues) != 1 {
@@ -93,3 +93,24 @@ func PrepareFilters(r *http.Request) (*map[string][]string, error) {
}
return &filterMap, nil
}
+
+// MatchLabelFilters matches labels and returs true if they are valid
+func MatchLabelFilters(filterValues []string, labels map[string]string) bool {
+outer:
+ for _, filterValue := range filterValues {
+ filterArray := strings.SplitN(filterValue, "=", 2)
+ filterKey := filterArray[0]
+ if len(filterArray) > 1 {
+ filterValue = filterArray[1]
+ } else {
+ filterValue = ""
+ }
+ for labelKey, labelValue := range labels {
+ if labelKey == filterKey && (filterValue == "" || labelValue == filterValue) {
+ continue outer
+ }
+ }
+ return false
+ }
+ return true
+}