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

Use a smarter regexp for openapi tag detection #67

Merged
merged 1 commit into from
Apr 11, 2018

Conversation

ixdy
Copy link
Member

@ixdy ixdy commented Apr 11, 2018

I tried a few other options:

  • using go/parser to scan only comments
  • using regexp's multiline flag to try to better detect real comments

but both of these were significantly slower than this approach, taking 5-7s to run.

For comparison, both this implementation and the existing, buggy Contains() implementation take around 1.5s. (Using the regex seems to be about .1-.2s slower, but that is probably allowable.)

I've also this implementation a bit more generic in preparation for kazel learning how to handle additional codegen tags.

Fixes #66.

/assign @mikedanese

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 11, 2018
staging = "staging/src/"
var (
// Generator tags are specified using the format "// +k8s:name=value"
genTagRe = regexp.MustCompile(`//\s*\+k8s:([^\s=]+)?(?:=(\S+))?`)
Copy link
Member

Choose a reason for hiding this comment

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

does this have to be on an empty line alone? maybe prepend ^\s*?

Copy link
Member

Choose a reason for hiding this comment

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

and append $?

Copy link
Member Author

Choose a reason for hiding this comment

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

using the multiline flag (so ^ matches at the beginning of a line) slows this down to ~5-6 seconds to run.

adding \n\s* as a prefix makes this take about 2.3s, so a bit more than half a second slower.

adding \s*\n as a suffix doesn't seem to slow things down, though.

optimizing regular expressions is great.

@mikedanese
Copy link
Member

Mostly LGTM

@mikedanese
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 11, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ixdy, mikedanese

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

@k8s-ci-robot k8s-ci-robot merged commit d9bb9fd into kubernetes:master Apr 11, 2018
cblecker pushed a commit to cblecker/kubernetes that referenced this pull request Apr 18, 2018
Automatic merge from submit-queue (batch tested with PRs 62436, 62499, 62664, 62685, 62660). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Update kazel to include openapi tag detection fix

**What this PR does / why we need it**: includes the fix from kubernetes/repo-infra#67 for kubernetes/repo-infra#66, which was discovered in @thockin's PR https://github.com/kubernetes/kubernetes/pull/57600/files#r178665554.

**Special notes for your reviewer**: I'm not sure what's up with the large list of comment diffs in `Godeps.json`; it looks like the `git describe` strings were (unintentionally?) truncated in @brendanburns's PR kubernetes#61955.

**Release note**:

```release-note
NONE
```

/assign @brendanburns @thockin @mikedanese
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants