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

Make cel2sql generic using View abstraction #495

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RafaeLeal
Copy link
Contributor

@RafaeLeal RafaeLeal commented Jun 7, 2023

Changes

This PR makes the cel2sql package more generic, introducing a new View abstraction. This allows us to decouple what we expose for the Results' API filters and the database structure.

I believe it also makes changes in our database safer since we don't have to think of all kinds of filters that would use each column of the db table. The idea is to make the changes and support in the CEL filters more deliberate.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you review them:

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Tested your changes locally (if this is a code change)
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user-facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings)
  • Release notes contain the string "action required" if the change requires additional action from users switching to the new release

Release Notes

Refactor cel2sql into a generic and extensible View abstraction

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jun 7, 2023
@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jun 7, 2023
@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 23, 2023
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't understand why exactly these tests are exercising the conversions if, in practice, they aren't being performed by the records.go file. This seems counterintuitive for collaborators.

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've initially moved to this file to avoid a cyclic dependency..
I've changed to different approach by having a test view that has all the fields that we need to test

pkg/api/server/cel/view/results_test.go Outdated Show resolved Hide resolved
pkg/api/server/cel2sql/convert.go Outdated Show resolved Hide resolved
"github.com/google/go-cmp/cmp"
)

func TestConvertRecordExpressions(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned previously, I recommend keeping these tests here instead of moving them to a different package.

pkg/api/server/cel2sql/doc.go Outdated Show resolved Hide resolved
pkg/api/server/cel2sql/select.go Outdated Show resolved Hide resolved
pkg/api/server/cel2sql/view_types.go Outdated Show resolved Hide resolved
@alan-ghelardi
Copy link
Contributor

/kind misc

@tekton-robot tekton-robot added the kind/misc Categorizes issue or PR as a miscellaneuous one. label Jul 1, 2023
@alan-ghelardi
Copy link
Contributor

@RafaeLeal I left a few comments mostly about style and some parts of the code that I'd prefer to leave as before (tests, for example). You need to rebase the pr and write down release notes.

@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 7, 2023
Copy link
Contributor

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

/approve

The intent here is good - this lays a good foundation for making cel2sql an external library.

I recommend that the changes to convert_test.go be reverted, and replaced with only the necessary refactorings to convert the existing tests to use the new View type. The current set of changes make it difficult to verify that our test logic remains in place (and this PR doesn't break anything).

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adambkaplan

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 24, 2023
)

func TestConvertRecordExpressions(t *testing.T) {
func newTestView() *View {
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't we use the actual view rather than building a new one for testing? Asking because by doing so, we might forget to configure the actual view properly and do that only in the test one or vice-versa and ultimately, we might end up not exercising the actual interpreter's logic.

name: "contains string function",
in: `data.metadata.name.contains("foo")`,
want: "POSITION('foo' IN (data->'metadata'->>'name')) <> 0",
name: "able to match strings exactly",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that this "able to..." sounds redundant in the test descriptions. I'd recommend keeping the descriptions in the original style.

@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 29, 2023
@tekton-robot
Copy link

@RafaeLeal: PR needs rebase.

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/test-infra repository.

@tekton-robot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale with a justification.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/lifecycle stale

Send feedback to tektoncd/plumbing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/misc Categorizes issue or PR as a miscellaneuous one. lifecycle/stale needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants