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

switch from juju/errors to pingcap/errors #360

Closed
gregwebs opened this issue Sep 30, 2018 · 9 comments
Closed

switch from juju/errors to pingcap/errors #360

gregwebs opened this issue Sep 30, 2018 · 9 comments

Comments

@gregwebs
Copy link
Contributor

I tried to do this switch, but what held me back is that tidb is vendored and still using juju/errors, including some of its esoteric APIs.
The latest version of tidb has switched to using pingcap/errors. Similarly, pd has switched to pkg/errors.
So I am hoping that the vendored tidb can be updated.

One of the main motivations for me to prompt tidb-binlog to do this change is that juju/errors is LGPL code, which makes proper distribution of tidb-binlog more difficult.

@iamxy
Copy link
Member

iamxy commented Oct 5, 2018

Please update the related vendored codes. @GregoryIan

@gregwebs
Copy link
Contributor Author

gregwebs commented Oct 6, 2018

These changes are in 2.1: you may need to wait for the stable 2.1 release

@kennytm
Copy link
Contributor

kennytm commented Oct 17, 2018

tidb-binlog has two LGPL dependencies: juju/errors and ngaut/log. Replacing juju/errors is straightforward with TiDB ≥ v2.1.0-rc.3, but ngaut/log is more difficult.

In TiDB the replacement is sirupsen/logrus for logging, and gopkg.in/natefinch/lumberjack.v2 for log rotation. However, binlog supports rotating by hours, whereas the minimum granularity for lumberjack is days. This makes lumberjack not a suitable replacement of ngaut/log.

@gregwebs
Copy link
Contributor Author

gregwebs commented Oct 17, 2018

Thanks for looking into this. I am trying out the zap logger now also :).

I much prefer to leave log rotation to an external tool. In general I prefer to log to stdout and leave it up to the deployment details what happens next. Assuming logging to the machine where it is running is not cloud friendly. We would want the option to ship the log elsewhere. Still its just as possible for the deployment to redirect stdout to a file and use a log rotation tool.

@gregwebs
Copy link
Contributor Author

Would we need to coordinate with the ansible based deployment to see how we can have that deployment ensure log rotation? @LinuxGit

@gregwebs
Copy link
Contributor Author

Although in the long-run I do think it is best to avoid coupling log rotation to the binlog process, I did see that zap mentions integration with lumberjack.

@kennytm
Copy link
Contributor

kennytm commented Oct 18, 2018

Applied lumberjack's recommendation on how to do time-based rotation, so ngaut/log is no longer the blocking issue.

// see https://github.com/natefinch/lumberjack/issues/17#issuecomment-185846531 for how to do time-based rotation
if rotateLog, ok := log.StandardLogger().Out.(*lumberjack.Logger); ok {
var interval time.Duration
if rotateBy == "hour" {
interval = time.Hour
} else {
interval = 24 * time.Hour
}
go func() {
for range time.Tick(interval) {
rotateLog.Rotate()
}
}()
}

The next issue is that drainer depends on zanmato1984/clickhouse (MIT), which itself depends on juju/errors

https://github.com/zanmato1984/clickhouse/blob/6c32f7b4cd79451e23e7369c500d082815380b3e/lib/column/decimal.go#L9

The only feature used is errors.Trace so it can be entirely replaced by pingcap/errors in go.mod, but I'm not sure if this is "legal".

replace github.com/juju/errors => github.com/pingcap/errors v0.10.1

@gregwebs
Copy link
Contributor Author

Thanks for figuring out the log rotation!

Replacing a dependency is perfectly legal. We use Gopkg to replace pkg/errors, but you could do the same to replace juju/errors: https://github.com/pingcap/tidb/blob/master/Gopkg.toml#L101.
I don't know how to do that technique with go modules yet.

We could also send a pull request to the clickhouse driver. pingcap/errors offers stack traces, which could be very helpful.

@july2993
Copy link
Contributor

Thanks gregwebs
have switch juju/errors to pingcap/error in #464
drop juju/errors in zanmato1984/clickhouse by zanmato1984/clickhouse#1
for ngaut/log, will switch to pingcap/log later.
so close this first.

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

No branches or pull requests

4 participants