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

integrate error codes with pkg/errors to provide error tracing #1200

Merged
merged 26 commits into from
Sep 30, 2018

Conversation

gregwebs
Copy link
Contributor

@gregwebs gregwebs commented Aug 16, 2018

What have you changed? (required)

integrate error codes with pkg/errors to provide error tracing

  • add the Causer interface and show any previous error codes in the json response
  • internal errors now record a StackTrace

Note that while this PR was open we switched from juju/errors to pkg/errors. The Causer interface is the same, but pkg/errors provides a stack trace, which is what I wanted for internal errors.

What are the type of the changes (required)?

  • New feature (non-breaking change which adds functionality)
  • Error code json responses may have additional fields of previous and stack

How has this PR been tested (required)?

go test pkg/error_code/error_code_test.go && make && make check

@gregwebs gregwebs requested a review from disksing August 16, 2018 00:59
@gregwebs gregwebs force-pushed the gregwebs/error-code-tracing branch 5 times, most recently from b70f5f6 to 3a42fba Compare August 16, 2018 21:42
add the Causer interface
internal errors record a StackTrace
@@ -35,3 +35,7 @@
[[constraint]]
name = "github.com/etcd-io/gofail"
branch = "master"

[[constraint]]
name = "github.com/pkg/errors"
Copy link
Contributor

Choose a reason for hiding this comment

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

seem we have already used juju errors, conflicted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the conflict? Both packages work together fine by using the same Causer interface. The rest of the API is the same, but with slightly different names (but pkg/errors can record a stack trace). See:

I am happy to send a PR to make the switch in PD when we are ready.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gregwebs

I suggest only using one errors, so it is better to remove juju at first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I can send a PR for that. Would you like to continue to review this PR in the mean time since that PR won't affect this one (other than both adding pkg/errors in Gopkg)?

Copy link
Contributor

Choose a reason for hiding this comment

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

of course, we can go on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#1210 is merged: we are now using pkg/errors

return e.GetStackTrace
}

// NewStackCode constrcuts a StackCode, which is an ErrorCode with stack trace information
Copy link
Member

Choose a reason for hiding this comment

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

constructs

return e.Err.Error()
}

// Code returns the unerlying Code of Err.
Copy link
Member

Choose a reason for hiding this comment

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

underlying

Data interface{} `json:"data"`
Operation string `json:"operation,omitempty"`
Previous *JSONFormat `json:"previous,omitempty"`
Stack errors.StackTrace `json:"stack,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you show me an example about after marshal? And so many filed, do we need such detailed information?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As per the documentation Previous is normally empty. Actually, now that we switched error packages, Stack will be present. I will add a change to remove it for non-internal errors. After that, there is no change for non-internal errors in PD after this PR. Previous is designed to be most useful in the future for the case of seeing the original error returned from another service (e.g. TiKV or TiDB SQL contacting PD, etc).

Get rid of vertical error cobination and just use multi errors.
vertical composition is just being used for annotation.
For multiple errors, we always use horizontal composition.
@disksing
Copy link
Contributor

@gregwebs Since you have closed #1246. Would you like to rollback pingcap/errors to pkg/errors in this PR too?

@disksing
Copy link
Contributor

Hi @gregwebs , it looks the error code package has become more and more complex and hard for us to understand which direction it will evolve. There are also some utilities in this PR that seem to be unnecessary for the PD.
Maybe you can first share a design document that explains what the final form of the error code package looks like. It will help us reach a consensus and allow PR to be reviewed faster.

@gregwebs
Copy link
Contributor Author

gregwebs commented Sep 25, 2018

PR Is updated now. errcode is now its own package since I need it for other projects.
If you want to understand how it is evolving, just ask! It is now code complete now with no changes planned. I will add more documentation pointed to from the errcode repo itself, including design documentation. I am also happy to do code review over there.

Note that errcode depends on generic error functionality present in pingcap/errors (not in pkg/errors).

@disksing
Copy link
Contributor

LGTM. PTAL @nolouch @rleungx

@nolouch nolouch merged commit 744c3a6 into master Sep 30, 2018
@nolouch nolouch deleted the gregwebs/error-code-tracing branch September 30, 2018 06:10
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