-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Use dlclark/regexp2
over standard library's package
#2616
Conversation
This issue is currently awaiting triage. If kube-state-metrics contributors determine this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
2c20c68
to
76d3788
Compare
pkg/allowdenylist/allowdenylist.go
Outdated
// Use ECMAScript as the default regexp spec to support lookarounds (#2594). | ||
var regexpDefaultSpec regexp.RegexOptions = regexp.ECMAScript | ||
|
||
func init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not make use of an init() function here and instead wrap the regexp.Compile into a function that sets this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to initialize upstream package variables at downstream package init()
-time, is this an anti-pattern? This should also help avoid missing out on setting such values in any new functions in the future that may need to initialize the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in general init() is a bad pattern that we should avoid introducing because of side effects, import order etc.
Can we add this to the New()
func instead?
https://github.com/kubernetes/kube-state-metrics/pull/2616/files#diff-b14b1102ef04d884e648b90166b5d35ee63edac2a544ef311770f5f289df48f4L36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, PTAL.
772822d
to
e8b298b
Compare
@@ -124,22 +140,38 @@ func TestInclude(t *testing.T) { | |||
t.Fatal("expected New() to not fail") | |||
} | |||
|
|||
denylist.Exclude([]string{"kube_node_.*_cores", "kube_pod_.*_bytes"}) | |||
denylist.Exclude([]string{"kube_(?=node.*cores|pod.*bytes)"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it compatible with "denylist.Exclude([]string{"kube_node_.cores", "kube_pod._bytes"})"?
Lookaround feature is more complicated. I will prefer using the legacy one unless performance is much better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is. The library being introduced here is a superset of go's regexp one, and will only incur expensive perf operations for exponential matches, that go's library doesn't support since it has to guarantee linear-time operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also these operations are capped at a minute, so no leaks.
Changes look good to me, thanks for the work. One small ask: Can you add some more documentation to the README on how to use this? Thanks! |
@@ -58,7 +58,7 @@ Flags: | |||
--logtostderr log to standard error instead of files (default true) | |||
--metric-allowlist string Comma-separated list of metrics to be exposed. This list comprises of exact metric names and/or regex patterns. The allowlist and denylist are mutually exclusive. | |||
--metric-annotations-allowlist string Comma-separated list of Kubernetes annotations keys that will be used in the resource' labels metric. By default the annotations metrics are not exposed. To include them, provide a list of resource names in their plural form and Kubernetes annotation keys you would like to allow for them (Example: '=namespaces=[kubernetes.io/team,...],pods=[kubernetes.io/team],...)'. A single '*' can be provided per resource instead to allow any annotations, but that has severe performance implications (Example: '=pods=[*]'). | |||
--metric-denylist string Comma-separated list of metrics not to be enabled. This list comprises of exact metric names and/or regex patterns. The allowlist and denylist are mutually exclusive. | |||
--metric-denylist string Comma-separated list of metrics not to be enabled. This list comprises of exact metric names and/or *ECMAScript-based* regex patterns. The allowlist and denylist are mutually exclusive. | |||
--metric-labels-allowlist string Comma-separated list of additional Kubernetes label keys that will be used in the resource' labels metric. By default the labels metrics are not exposed. To include them, provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them (Example: '=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)'. A single '*' can be provided per resource instead to allow any labels, but that has severe performance implications (Example: '=pods=[*]'). Additionally, an asterisk (*) can be provided as a key, which will resolve to all resources, i.e., assuming '--resources=deployments,pods', '=*=[*]' will resolve to '=deployments=[*],pods=[*]'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to extend this to the labels and annotations allowlists in a later PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep this exclusive to the allowdeny
lists for now, and expand once we start to see positive results in the near future.
7219efe
to
aab4eb5
Compare
Signed-off-by: Pranshu Srivastava <[email protected]>
/lgtm Thanks for your work on this! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mrueg, rexagod The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixes #2594.
Please refer to the aforementioned issue for more details.