Skip to content

Conversation

@chuangw6
Copy link
Member

@chuangw6 chuangw6 commented Jun 1, 2022

Changes

Prior to this commit:

  1. MustCompile sometimes is used inside a function though it is meant for
    initializing global variables holding compiled regular expressions
    according to this (docs). Using
    it in a function could possibly panic.
  2. function extractExpressionFromString and extractVariablesFromString
    return too many values i.e. extracted value (slice/string), present (bool)
    and errorMessage (string)

In this fix:

  1. regex compiled from from MustCompile is changed to be global, or
    MustCompile is replaced with Compile so that we can return error rather
    than causing potential panic.
  2. the two functions signatures are simplified to just return extracted
    value and error.

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Docs included if any changes are user facing
  • Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been filled in
    (if there are no user facing changes, use release note "NONE")

Release Notes

@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 1, 2022
@tekton-robot tekton-robot requested review from jerop and lbernick June 1, 2022 21:10
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 1, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.7% 97.7% -0.0
pkg/substitution/substitution.go 57.9% 52.9% -5.0

@chuangw6
Copy link
Member Author

chuangw6 commented Jun 1, 2022

/assign @lbernick

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.7% 97.7% -0.0
pkg/substitution/substitution.go 57.9% 52.9% -5.0

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester

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 Jun 2, 2022
Prior to this commit:
1. MustCompile sometimes is used inside a function though it is meant for
initializing global variables holding compiled regular expressions
according to this ([docs](https://pkg.go.dev/regexp#MustCompile)). Using
it in a function could possibly panic.
2. function `extractExpressionFromString` and `extractVariablesFromString`
return too many values i.e. extracted value (slice/string), present (bool)
and errorMessage (string)

In this fix:
- 1. regex compiled from from MustCompile is changed to be global, or
MustCompile is replaced with Compile so that we can return error rather
than causing potential panic.
- 2. the two functions signatures are simplified to just return extracted
value and error.
@chuangw6 chuangw6 force-pushed the change-mustcompile branch from 0a7871e to 2c7ad87 Compare June 2, 2022 17:44
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.7% 97.7% -0.0
pkg/substitution/substitution.go 57.9% 52.9% -5.0

@chuangw6
Copy link
Member Author

chuangw6 commented Jun 2, 2022

/test tekton-pipeline-unit-tests

@chuangw6 chuangw6 requested a review from lbernick June 2, 2022 18:29
@chuangw6
Copy link
Member Author

chuangw6 commented Jun 2, 2022

/test pull-tekton-pipeline-integration-tests

@chuangw6
Copy link
Member Author

chuangw6 commented Jun 2, 2022

/test pull-tekton-pipeline-alpha-integration-tests

1 similar comment
@chuangw6
Copy link
Member Author

chuangw6 commented Jun 3, 2022

/test pull-tekton-pipeline-alpha-integration-tests

return nil
}

// Extract a the first full string expressions found (e.g "$(input.params.foo)"). Return
Copy link
Member

Choose a reason for hiding this comment

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

nit: typo in this docstring (extra "a")

vs, err := extractVariablesFromString(value, prefix)
if err != nil {
return &apis.FieldError{
Message: fmt.Sprintf("fail to extract variables from string: %v", err),
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just use the error message as is (here and at the other call sites)

}
}

firstMatch, _ := extractExpressionFromString(value, prefix)
Copy link
Member

Choose a reason for hiding this comment

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

probably best to handle the error being returned by this function

@pritidesai
Copy link
Member

The following is the coverage report on the affected files. Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 97.7% 97.7% -0.0
pkg/substitution/substitution.go 57.9% 52.9% -5.0

@chuangw6 thank you for this 🙏

I recommend adding more unit test. Impacting 5% coverage during the refactor is not ideal specially with such low coverage to begin with 🔅 .

Please try to make sure we at least maintain the code coverage as is in a refactoring PRs. substitution has been one of the packages with very low coverage 😞.

@vdemeester @lbernick thoughts?

@lbernick
Copy link
Member

lbernick commented Jun 7, 2022

I recommend adding more unit test. Impacting 5% coverage during the refactor is not ideal specially with such low coverage to begin with 🔅 .

Please try to make sure we at least maintain the code coverage as is in a refactoring PRs. substitution has been one of the packages with very low coverage 😞.

Definitely agree more testing would be nice here for these helpers! Not sure how much to read into the coverage tool output or how much testing of this package is appropriate to tackle for a refactor-- will leave that up to Chuang

@abayer
Copy link
Contributor

abayer commented Jun 7, 2022

/retest

@pritidesai
Copy link
Member

I recommend adding more unit test. Impacting 5% coverage during the refactor is not ideal specially with such low coverage to begin with 🔅 .
Please try to make sure we at least maintain the code coverage as is in a refactoring PRs. substitution has been one of the packages with very low coverage 😞.

Definitely agree more testing would be nice here for these helpers! Not sure how much to read into the coverage tool output or how much testing of this package is appropriate to tackle for a refactor-- will leave that up to Chuang

Thanks @lbernick!

Please look for the no coverage represented by the code in red 🟥
Screen Shot 2022-06-08 at 10 33 58 AM

Thanks @chuangw6 for your understanding 👍 Appreciate all the simplifications here, the substitution package is much more clean now 👏 Please add more coverage for the changes you are introducing.

An alternative could be to introduce the unit tests first in a separate PR to bump the existing coverage.

@lbernick
Copy link
Member

lbernick commented Jun 8, 2022

thanks @pritidesai, sgtm!

@tekton-robot
Copy link
Collaborator

@chuangw6: 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 tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 14, 2022
@chuangw6
Copy link
Member Author

Thanks @pritidesai @lbernick . sgtm! I'll add that!

@lbernick
Copy link
Member

@pritidesai in light of our discussion yesterday at the pipelines WG around not testing non-exported functions, what do you think is the best way forward here?

@vdemeester
Copy link
Member

@pritidesai in light of our discussion yesterday at the pipelines WG around not testing non-exported functions, what do you think is the best way forward here?

Ideally even if we are not testing non exported functions, we should cover / aim to cover them (through exported ones). If we can’t, this usually mean the unexported function covers more cases that what is exported (and thus is more complex that it needs to be 🤭).

@tekton-robot
Copy link
Collaborator

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.

@tekton-robot tekton-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 18, 2022
@lbernick
Copy link
Member

@chuangw6 are you still working on this? would you mind rebasing or closing?

@chuangw6 chuangw6 marked this pull request as draft September 27, 2022 20:00
@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 27, 2022
@chuangw6
Copy link
Member Author

@chuangw6 are you still working on this? would you mind rebasing or closing?

Sorry I saw this as non-urgent and switched to other stuff before. Happy to get this cleaned up and move it forward.

@chuangw6 chuangw6 closed this Sep 27, 2022
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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants