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

Index arbitrary labels #317

Open
wants to merge 53 commits into
base: main
Choose a base branch
from

Conversation

ericpromislow
Copy link
Contributor

@ericpromislow ericpromislow commented Nov 7, 2024

Related to #46333

pkg/resources/virtual/common/common.go Outdated Show resolved Hide resolved
pkg/resources/virtual/common/common.go Outdated Show resolved Hide resolved
pkg/resources/virtual/common/common.go Outdated Show resolved Hide resolved
pkg/resources/virtual/common/common.go Outdated Show resolved Hide resolved
pkg/stores/sqlpartition/listprocessor/processor_test.go Outdated Show resolved Hide resolved
@ericpromislow ericpromislow force-pushed the 46333-index-arbitrary-labels branch 2 times, most recently from 697fdee to 3bbfa55 Compare December 7, 2024 00:04
@moio moio requested a review from bigkevmcd December 17, 2024 14:57
Copy link

@bigkevmcd bigkevmcd left a comment

Choose a reason for hiding this comment

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

Mostly fine, I would much prefer to see some real tests against SQLite rather than the continued use of mocks.

pkg/stores/sqlpartition/listprocessor/processor.go Outdated Show resolved Hide resolved
pkg/resources/virtual/common/common.go Outdated Show resolved Hide resolved
pkg/stores/sqlpartition/listprocessor/processor.go Outdated Show resolved Hide resolved
pkg/stores/sqlpartition/listprocessor/processor_test.go Outdated Show resolved Hide resolved
@ericpromislow ericpromislow force-pushed the 46333-index-arbitrary-labels branch from 3bbfa55 to cfdeafd Compare January 6, 2025 21:50
@ericpromislow
Copy link
Contributor Author

"I would much prefer to see some real tests against SQLite rather than the continued use of mocks."

This is covered in tech-debt item
rancher/rancher#48263
(I edited the subject to include steve)

@ericpromislow ericpromislow force-pushed the 46333-index-arbitrary-labels branch 2 times, most recently from 607d208 to 3ea8184 Compare January 16, 2025 00:16
@ericpromislow ericpromislow marked this pull request as ready for review January 16, 2025 00:16
moio
moio previously approved these changes Jan 16, 2025
Copy link
Contributor

@moio moio left a comment

Choose a reason for hiding this comment

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

Thanks @ericpromislow, I do not see big issues either. Most comments from my part are really suggestions and should be quick to address.

Ready to approve as soon as they are dealt with.

👀 from @tomleb would also be helpful

pkg/stores/sqlpartition/listprocessor/processor.go Outdated Show resolved Hide resolved
pkg/stores/sqlpartition/listprocessor/processor.go Outdated Show resolved Hide resolved
return false
}
s1 := values[0][0:1]
if !strings.Contains(`"'`, s1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

When filtering for exact matches, do we want the string to be single quoted, double quoted, or support both? I am asking because the current behavior seem to be single quote:

https://github.com/rancher/steve/blame/d05a48f9cfa6a43a5fbb840cc5da00a92b229009/pkg/stores/sqlpartition/listprocessor/processor.go#L80

and IIUC this change would make it either single or double quote. Alas, we never documented the choice on the README.

@richard-cox do you have a preference?

@ericpromislow can you amend the README so that whatever we decide is documented please?

Copy link
Member

Choose a reason for hiding this comment

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

Currently

  • ' denotes exact match
  • no quotes denotes partial match

From my interpretation of docs the proposal would be the following?

  • ' denotes exact match
  • " denotes partial match
  • no quotes syntax has been removed?

I think ideally we would continue as currently. all other params, include those that contain text, do not require "

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, quotes are still optional. And I've implemented single quotes indicate an exact match, and double quotes don't (they're just used to delimit the contents, but because of the syntax of k8s labels, they're never required because characters like spaces aren't allowed).

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need double quotes at all?

Copy link
Contributor

Choose a reason for hiding this comment

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

My first thought was it should probably be the operator that decides if its an exact match equality or a substring match. Something like: = is exact (stay closer to k8s), =~ is substring. !~ is not equal substring.

Imo we should have only one way per matching strategy, I don't see a reason to have both double quotes and no quotes denote substring match. That should simplify the logic a bit too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, double quotes are gone and trigger a syntax error

pkg/stores/sqlpartition/queryparser/labels.go Outdated Show resolved Hide resolved
pkg/stores/sqlpartition/queryparser/selector.go Outdated Show resolved Hide resolved
pkg/stores/sqlproxy/proxy_store.go Outdated Show resolved Hide resolved
@ericpromislow ericpromislow requested a review from moio January 16, 2025 18:47
@ericpromislow ericpromislow force-pushed the 46333-index-arbitrary-labels branch 2 times, most recently from 87eea56 to 7dd7067 Compare January 17, 2025 21:49
moio
moio previously approved these changes Jan 20, 2025
Copy link
Contributor

@moio moio left a comment

Choose a reason for hiding this comment

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

Looks good from my perspective.

We definitely need:

pkg/stores/sqlpartition/queryparser/selector.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tomleb tomleb left a comment

Choose a reason for hiding this comment

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

Mostly nits / styling, one question about the deepcopy, but overall LGTM

@@ -0,0 +1,48 @@
//go:build !ignore_autogenerated
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT stripping this out as well? We're unlikely to be able to regenerate it if we make changes to Requirements. Do we need it to be deepcopy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have any opinion on this. All this code came as-is from kubectl.

Copy link
Contributor

Choose a reason for hiding this comment

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

So imo if we don't have anything to regenerate the file we shouldn't add the autogenerated file ourselves if we don't need it. In this case I don't think we need the deepcopy code (I might be wrong, you'll have to try to remove it see if things still compile), so I'd suggest just removing it.

pkg/stores/sqlproxy/proxy_store.go Outdated Show resolved Hide resolved
pkg/stores/sqlproxy/proxy_store.go Outdated Show resolved Hide resolved
Comment on lines +367 to +362
SingleQuoteToken
DoubleQuoteToken
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure those are necessary as they aren't used anywhere. For example, the tests passed even with them removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, dropped in an earlier commit

Copy link
Contributor

Choose a reason for hiding this comment

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

But I still see them so it looks like they were brought back? Unless I misunderstand. (eg: I'm fairly sure we can remove both SingleQuoteToken and DoubleQuoteToken here.

Comment on lines +385 to +380
"'": SingleQuoteToken,
"\"": DoubleQuoteToken,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure those are necessary as they aren't used anywhere. For example, the tests passed even with them removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, dropped

pkg/stores/sqlpartition/queryparser/selector.go Outdated Show resolved Hide resolved
return false
}
s1 := values[0][0:1]
if !strings.Contains(`"'`, s1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

My first thought was it should probably be the operator that decides if its an exact match equality or a substring match. Something like: = is exact (stay closer to k8s), =~ is substring. !~ is not equal substring.

Imo we should have only one way per matching strategy, I don't see a reason to have both double quotes and no quotes denote substring match. That should simplify the logic a bit too.

The UI team wasn't sure whether the event fields should go in the empty-string group or in 'events.k8s.io',
so let's go with both until/unless specified otherwise.
I see both types of operators being bandied about -- it's easy to support the aliases.
Also reduce the case where there's no namespace function.
- Stricter processing of m.l.name keys:
  Require ending close-bracket for a start-bracket

- Comment fix

- Moving sql processing from lasso to steve: some changes missed in rebase
For now on only single-quotes (or none where possible) are allowed.
@ericpromislow
Copy link
Contributor Author

My first thought was it should probably be the operator that decides if its an exact match equality or a substring match. Something like: = is exact (stay closer to k8s), =~ is substring. !~ is not equal substring.

Imo we should have only one way per matching strategy, I don't see a reason to have both double quotes and no quotes denote substring match. That should simplify the logic a bit too.

The requirements come form the dashboard, and they're the main consumer of this. So they'll need to weigh in on these operators. But I added the double-quotes as a sort of symmetric thing and they're easily dropped.

@ericpromislow ericpromislow force-pushed the 46333-index-arbitrary-labels branch from 3f6a70a to 67a44aa Compare January 21, 2025 22:07
@moio
Copy link
Contributor

moio commented Jan 22, 2025

My first thought was it should probably be the operator that decides if its an exact match equality or a substring match. Something like: = is exact (stay closer to k8s), =~ is substring. !~ is not equal substring.

Imo we should have only one way per matching strategy, I don't see a reason to have both double quotes and no quotes denote substring match. That should simplify the logic a bit too.

The requirements come form the dashboard, and they're the main consumer of this. So they'll need to weigh in on these operators. But I added the double-quotes as a sort of symmetric thing and they're easily dropped.

From an architectural perspective “defaulting to Kubernetes standards and extending them when needed” seems like the most sensible thing to do, but I’ll leave the final decision to the UI team (cc @richard-cox).

string(selection.GreaterThan), string(selection.LessThan),
}
validRequirementOperators = append(binaryOperators, unaryOperators...)
labelSelectorRegex = regexp.MustCompile(`^metadata.labels(?:\.\w[-a-zA-Z0-9_./]*|\[.*])$`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Per previous discussion:

Suggested change
labelSelectorRegex = regexp.MustCompile(`^metadata.labels(?:\.\w[-a-zA-Z0-9_./]*|\[.*])$`)
labelSelectorRegex = regexp.MustCompile(`^metadata\.labels((\.\w[-a-zA-Z0-9_./]*)|(\[.*\]))$`)
  • quotes the first literal dot
  • separates the "dot + identifier" case from the "square brackets with anything inside" case in two parenthesized groups for readability
  • quotes the ] for readability

https://go.dev/play/p/ybN1HHir7oY

Does that make sense?

@richard-cox
Copy link
Member

My first thought was it should probably be the operator that decides if its an exact match equality or a substring match. Something like: = is exact (stay closer to k8s), =~ is substring. !~ is not equal substring.

Imo we should have only one way per matching strategy, I don't see a reason to have both double quotes and no quotes denote substring match. That should simplify the logic a bit too.

The requirements come form the dashboard, and they're the main consumer of this. So they'll need to weigh in on these operators. But I added the double-quotes as a sort of symmetric thing and they're easily dropped.

From an architectural perspective “defaulting to Kubernetes standards and extending them when needed” seems like the most sensible thing to do, but I’ll leave the final decision to the UI team (cc @richard-cox).

Dashboard side as long as we can execute equals or not equals operators and exact or partial matching of the value we're pretty free on the syntax. Implementation side the usage is abstracted away from the api syntax, so it's an easy update either way

Changing the operator will make the type of match much more obvious. I had some minor concerns with tilde (this used to be a reserved character relating to the home directory and used when locating assets), though looks fine now https://datatracker.ietf.org/doc/html/rfc3986#section-2.3

For url brevity i would go with the following

  • = exact
  • ~ partial
  • != not exact
  • !~ not partial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants