File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package config
2
2
3
3
import (
4
4
"fmt"
5
+ "regexp"
5
6
"strconv"
6
7
"strings"
7
8
"time"
62
63
MetricFilterConfig struct {
63
64
Path string `yaml:"jsonPath" json:"jsonPath"`
64
65
_path * jsonpath.JSONPath
66
+
67
+ Regex string `yaml:"regex"`
68
+ _regex * regexp.Regexp
65
69
}
66
70
67
71
MetricJsonPath string
@@ -128,11 +132,22 @@ func (m *ConfigMetrics) Compile() error {
128
132
return fmt .Errorf (`jsonPath must be set for filters` )
129
133
}
130
134
135
+ // compile jsonPath
131
136
if path , err := compileJsonPath (filterConfig .Path ); err == nil {
132
137
filterConfig ._path = path
133
138
} else {
134
139
return err
135
140
}
141
+
142
+ // compile regex
143
+ if filterConfig .Regex != "" {
144
+ filterRegex , err := regexp .Compile (filterConfig .Regex )
145
+ if err != nil {
146
+ return err
147
+ }
148
+
149
+ filterConfig ._regex = filterRegex
150
+ }
136
151
}
137
152
138
153
// selector
@@ -280,6 +295,13 @@ func (m *ConfigMetrics) IsValidObject(object unstructured.Unstructured) bool {
280
295
if value == "" {
281
296
return false
282
297
}
298
+
299
+ // check regexp
300
+ if filterConfig ._regex != nil {
301
+ if ! filterConfig ._regex .MatchString (value ) {
302
+ return false
303
+ }
304
+ }
283
305
} else {
284
306
return false
285
307
}
Original file line number Diff line number Diff line change @@ -51,3 +51,5 @@ metrics:
51
51
# optional filters, must return a value, otherwise the resource is filtered
52
52
filters :
53
53
- jsonPath : .metadata.annotations.expiry
54
+ # filter value by regex, optional
55
+ regex : ^([0-9]{4}-[0-9]{2}-[0-9]{2}.*|[0-9]+)$
You can’t perform that action at this time.
0 commit comments