Skip to content
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

pkg/naming: shorten regexp when matching many similar names #670

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

abursavich
Copy link

@abursavich abursavich commented Jul 9, 2024

Fixes #668.

Pods from a deployment will have long names like:

  1. foobar-59c8d74c75-9gv24
  2. foobar-59c8d74c75-dhfbj
  3. foobar-59c8d74c75-kggvk
  4. foobar-59c8d74c75-nd8jm
  5. foobar-59c8d74c75-nqctr
  6. foobar-59c8d74c75-pxlnd
  7. foobar-59c8d74c75-rnxk7
  8. foobar-59c8d74c75-rpj7q
  9. foobar-59c8d74c75-vl6n6
  10. foobar-59c8d74c75-xhvp4

The naive regexp that matches these pods is foobar-59c8d74c75-9gv24|foobar-59c8d74c75-dhfbj|foobar-59c8d74c75-kggvk|foobar-59c8d74c75-nd8jm|foobar-59c8d74c75-nqctr|foobar-59c8d74c75-pxlnd|foobar-59c8d74c75-rnxk7|foobar-59c8d74c75-rpj7q|foobar-59c8d74c75-vl6n6|foobar-59c8d74c75-xhvp4 (len=239).

A shorter regexp that factors out the shared prefixes and matches the same pods is foobar-59c8d74c75-(9gv24|dhfbj|kggvk|n(d8jm|qctr)|pxlnd|r(nxk7|pj7q)|vl6n6|xhvp4) (len=81).

A similar set of only 5 pods achieves 59% compression. This example with 10 pods achieves 66% compression. At 20 pods it's ~71%, at 40 pods it's ~73%, at 80 pods it's ~74%, and at 200 pods it starts to converge to ~75%. The savings ultimately depend on the length of the deployment name, but even pods with short deployment names (e.g. foobar) still benefit because the replicaset hash (e.g. 59c8d74c75) contributes a lot of redundancy.

Instead of trying to implement this transformation directly, this change lets the regexp/syntax package do all the heavy lifting. In some cases this doesn't result in the shortest possible string (e.g. some short prefix repetitions are more optimal than complete prefix factoring: nd8jm|nqctr vs n(d8jm|qctr)), but writing and maintaining a separate implementation isn't worth it to get at these crumbs.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 9, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @abursavich!

It looks like this is your first PR to kubernetes-sigs/prometheus-adapter 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/prometheus-adapter has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @abursavich. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 9, 2024
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 9, 2024
Copy link
Member

@dgrisonnet dgrisonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any big issue with that feature. Even if the configuration is templated, I can hardly a scenario where a valid configuration that already expected a regex would break with the simplified version of the expression.

pkg/naming/metrics_query.go Outdated Show resolved Hide resolved
@dgrisonnet
Copy link
Member

/assign
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 25, 2024
@dgrisonnet
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 25, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: abursavich
Once this PR has been reviewed and has the lgtm label, please ask for approval from dgrisonnet. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@abursavich
Copy link
Author

/retest

@abursavich
Copy link
Author

Hey, @dgrisonnet! Please take another look. Tests are passing.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 18, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query too long
4 participants