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 route domain error specific #15082

Merged
merged 5 commits into from Apr 11, 2024
Merged

Make route domain error specific #15082

merged 5 commits into from Apr 11, 2024

Conversation

skonto
Copy link
Contributor

@skonto skonto commented Apr 3, 2024

Fixes #12149

Proposed Changes

  • Makes route error propagation more specific.
    Instead of:
                    {
                        "lastTransitionTime": "2024-04-03T07:58:25Z",
                        "message": "invalid domain name \"wathola-receiver-test-continuous-events-propagation-with-prober-zxmkp.example.com\": url: Invalid value: \"wathola-receiver-test-continuous-events-propagation-with-prober-zxmkp\": must be no more than 63 characters",
                        "reason": "Unknown",
                        "status": "Unknown",
                        "type": "Ready"
                    }

we get:

                 {
                        "lastTransitionTime": "2024-04-03T10:07:57Z",
                        "message": "invalid domain name \"wathola-receiver-test-continuous-events-propagation-with-prober-zxmkp.example.com\": url: Invalid value: \"wathola-receiver-test-continuous-events-propagation-with-prober-zxmkp\": must be no more than 63 characters",
                        "reason": "ErrorConfig",
                        "status": "False",
                        "type": "Ready"
                    }
  • In the future we could make this way permanent errors more specific in other code paths too.

Release Note

Reason and status for domain errors is no more specific to indicate a permanent issue.

@knative-prow knative-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 3, 2024
Copy link

codecov bot commented Apr 3, 2024

Codecov Report

Attention: Patch coverage is 63.63636% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 84.89%. Comparing base (c2d0af1) to head (8dd8686).
Report is 32 commits behind head on main.

Files Patch % Lines
pkg/apis/serving/v1/route_lifecycle.go 0.00% 2 Missing ⚠️
pkg/reconciler/route/route.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15082      +/-   ##
==========================================
+ Coverage   84.11%   84.89%   +0.77%     
==========================================
  Files         213      213              
  Lines       16783    13107    -3676     
==========================================
- Hits        14117    11127    -2990     
+ Misses       2315     1623     -692     
- Partials      351      357       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -119,12 +129,12 @@ func DomainNameFromTemplate(ctx context.Context, r metav1.ObjectMeta, name strin
}

if err := templ.Execute(&buf, data); err != nil {
return "", fmt.Errorf("error executing the DomainTemplate: %w", err)
return "", DomainNameError{msg: fmt.Errorf("error executing the DomainTemplate: %w", err).Error()}
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need to use fmt.Errorf if we call .Error() on it anyway?

@@ -118,7 +118,11 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, r *v1.Route) pkgreconcil
traffic, err := c.configureTraffic(ctx, r)
if traffic == nil || err != nil {
if err != nil {
r.Status.MarkUnknownTrafficError(err.Error())
if errors.As(err, &domains.DomainNameError{}) {
r.Status.MarkRevisionTargetTrafficError("ErrorConfig", err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

Do we have constants for ErrorConfig somewhere? Or why do we even need the reason as there is only one value here?

@skonto skonto added this to the v1.14.0 milestone Apr 4, 2024
@skonto
Copy link
Contributor Author

skonto commented Apr 5, 2024

@dprotaso @izabelacg pls review.

@@ -118,7 +120,11 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, r *v1.Route) pkgreconcil
traffic, err := c.configureTraffic(ctx, r)
if traffic == nil || err != nil {
if err != nil {
r.Status.MarkUnknownTrafficError(err.Error())
if errors.As(err, &domains.DomainNameError{}) {
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 errors.Is is more apt since you're not using special fields in DomainNameError

Copy link
Contributor Author

@skonto skonto Apr 9, 2024

Choose a reason for hiding this comment

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

error.Is will not work in this case (custom error) as it does not check the type. It returns false. In its code it has:

		if isComparable && err == target {
			return true
		}

This will never be equal, unless we have a ref of some global error with a specific msg eg. created with errors.New().

errors.As does this check:

		if reflectlite.TypeOf(err).AssignableTo(targetType) {
			val.Elem().Set(reflectlite.ValueOf(err))
			return true
		}

that matches the error.
See also
https://stackoverflow.com/questions/39121172/how-to-compare-go-errors.
https://medium.com/@reetas/exploring-the-appropriate-use-cases-for-errors-is-and-errors-as-in-comparing-errors-in-golang-3584c6bc5417

Anyway I will use some predefined error to mark the tree, I can avoid the custom error if that is the goal (since it has no extra fields).

@skonto
Copy link
Contributor Author

skonto commented Apr 9, 2024

@dprotaso I changed the error stuff. Btw current error msg is:

                    {
                        "lastTransitionTime": "2024-04-09T13:10:13Z",
                        "message": "domain name error: invalid domain name \"helloworld-go-test-continuous-events-propagation-with-prober-zxmkp.example.com\": url: Invalid value: \"helloworld-go-test-continuous-events-propagation-with-prober-zxmkp\": must be no more than 63 characters",
                        "reason": "ErrorConfig",
                        "status": "False",
                        "type": "RoutesReady"
                    }

Is this now ok to go in?

@dprotaso
Copy link
Member

I think what you had before was fine (having the struct) you just need to add your own Is method

see: https://go.dev/play/p/d23KugysN38

@skonto
Copy link
Contributor Author

skonto commented Apr 10, 2024

I think what you had before was fine (having the struct) you just need to add your own Is method

That is just a type check at the end of the day, I was more in favor of reusing existing code but wfm.

@skonto
Copy link
Contributor Author

skonto commented Apr 11, 2024

@dprotaso your suggestion also makes things a bit restrictive for future use as error typecheck (as it is already known), does not support wrapped errors:

image

Could we avoid that and keep current implementaion?

@dprotaso
Copy link
Member

Could we avoid that and keep current implementaion?

Sure

@dprotaso
Copy link
Member

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Apr 11, 2024
Copy link

knative-prow bot commented Apr 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, skonto

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

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 11, 2024
@dprotaso
Copy link
Member

Can you update the PR body with a release note?

@knative-prow knative-prow bot merged commit dc8bf98 into knative:main Apr 11, 2024
55 checks passed
@skonto skonto added the kind/bug Categorizes issue or PR as related to a bug. label Apr 12, 2024
@skonto skonto removed the kind/bug Categorizes issue or PR as related to a bug. label Apr 12, 2024
skonto added a commit to skonto/serving that referenced this pull request Apr 22, 2024
* make route domain error specific

* fixes

* fix quote

* move to errors.Is

* lint
skonto added a commit to skonto/serving that referenced this pull request Apr 24, 2024
* make route domain error specific

* fixes

* fix quote

* move to errors.Is

* lint
openshift-merge-bot bot pushed a commit to openshift-knative/serving that referenced this pull request Apr 26, 2024
* make route domain error specific

* fixes

* fix quote

* move to errors.Is

* lint
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. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ksvc should have ready condition status eq 'False' and reason eq 'ErrorConfig' if failing
4 participants