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

http_*: add log for http api and refine the err handle logic #2997

Merged
merged 38 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
00fa9cb
http_*: add log for http api and refine the err handle logic
asddongmen Oct 9, 2021
46d691d
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 9, 2021
87187e4
http_*: resolved comments
asddongmen Oct 11, 2021
9d54e40
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 11, 2021
218892f
http_*, config: add a config to switch on/off the http api request lo…
asddongmen Oct 12, 2021
b9b7d1d
Merge remote-tracking branch 'origin/add_log_for_http_api' into add_l…
asddongmen Oct 12, 2021
00fdfc8
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 12, 2021
04626f6
http_*: fix tests
asddongmen Oct 12, 2021
b1c0e4d
Merge remote-tracking branch 'origin/add_log_for_http_api' into add_l…
asddongmen Oct 12, 2021
a03cf47
*: fix check error
asddongmen Oct 12, 2021
05b471a
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 15, 2021
1a8d922
config: fix make check
asddongmen Oct 15, 2021
98f088c
Merge remote-tracking branch 'origin/add_log_for_http_api' into add_l…
asddongmen Oct 15, 2021
9ca37d6
sink_test: fix erroe
asddongmen Oct 15, 2021
c042a18
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 19, 2021
a89702d
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 20, 2021
c0b174c
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 21, 2021
09bd679
helper_test: fix make error
asddongmen Oct 21, 2021
3ce2dd7
helper_test: fix make error
asddongmen Oct 21, 2021
65ec30e
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 25, 2021
aaa26ef
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 25, 2021
2a35545
http_*: fix make check
asddongmen Oct 26, 2021
64554d6
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 26, 2021
2d3f7d0
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 26, 2021
ec00978
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 28, 2021
b26d66f
http_*: resolve conflict and comments
asddongmen Oct 28, 2021
f97d0b7
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 28, 2021
97c7c09
Merge branch 'master' into add_log_for_http_api
asddongmen Oct 31, 2021
2d68acb
Merge branch 'master' into add_log_for_http_api
asddongmen Nov 1, 2021
e672291
Merge branch 'master' into add_log_for_http_api
asddongmen Nov 2, 2021
61e055d
redo_test: fix unit test
asddongmen Nov 3, 2021
70ac3e9
Merge branch 'master' into add_log_for_http_api
asddongmen Nov 3, 2021
8a5cc4e
*: remove http_log config
asddongmen Nov 3, 2021
22a5187
*: resolved commentscd
asddongmen Nov 5, 2021
100cbf4
http_errors: resolve comments
asddongmen Nov 5, 2021
96b39bd
Merge branch 'master' into add_log_for_http_api
ti-chi-bot Nov 5, 2021
f5559be
Merge branch 'master' into add_log_for_http_api
ti-chi-bot Nov 5, 2021
28ed883
Merge branch 'master' into add_log_for_http_api
ti-chi-bot Nov 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
http_*: fix tests
  • Loading branch information
asddongmen committed Oct 12, 2021
commit 04626f660169c4c7f42563102d5b7f219d5af99f
2 changes: 1 addition & 1 deletion cdc/capture/http_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func verifyCreateChangefeedConfig(ctx context.Context, changefeedConfig model.Ch

tz, err := util.GetTimezone(changefeedConfig.TimeZone)
if err != nil {
return nil, errors.Annotate(err, "invalid timezone:"+changefeedConfig.TimeZone)
return nil, cerror.ErrAPIInvalidParam.Wrap(errors.Annotate(err, "invalid timezone:"+changefeedConfig.TimeZone))
}
ctx = util.PutTimezoneInCtx(ctx, tz)
if err := sink.Validate(ctx, info.SinkURI, info.Config, info.Opts); err != nil {
Expand Down
15 changes: 6 additions & 9 deletions cdc/http_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ import (
"net/http/pprof"
"time"

"github.com/pingcap/ticdc/pkg/config"

"github.com/pingcap/errors"
"github.com/pingcap/ticdc/cdc/model"
cerror "github.com/pingcap/ticdc/pkg/errors"

"github.com/gin-gonic/gin"
"github.com/pingcap/log"
"github.com/pingcap/ticdc/cdc/capture"
"github.com/pingcap/ticdc/cdc/model"
"github.com/pingcap/ticdc/pkg/config"
cerror "github.com/pingcap/ticdc/pkg/errors"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"go.uber.org/zap"
Expand Down Expand Up @@ -141,10 +138,10 @@ func logMiddleware() gin.HandlerFunc {

cost := time.Since(start)

var errMessage string
err := c.Errors.Last()
var inErr error
if err != nil {
errMessage = errors.Trace(c.Errors.Last().Err).Error()
inErr = err.Err
}

log.Info(path,
Expand All @@ -154,7 +151,7 @@ func logMiddleware() gin.HandlerFunc {
zap.String("query", query),
zap.String("ip", c.ClientIP()),
zap.String("user-agent", c.Request.UserAgent()),
zap.String("errors", errMessage),
zap.Error(inErr),
zap.Duration("cost", cost),
)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (s *serverSuite) TestParseCfg(c *check.C) {
AdvertiseAddr: "127.5.5.1:7777",
LogFile: "/root/cdc.log",
LogLevel: "debug",
LogHTTP: true,
Log: &config.LogConfig{
File: &config.LogFileConfig{
MaxSize: 300,
Expand Down Expand Up @@ -240,6 +241,7 @@ sort-dir = "/tmp/just_a_test"
AdvertiseAddr: "127.0.0.1:1111",
LogFile: "/root/cdc1.log",
LogLevel: "warn",
LogHTTP: true,
Log: &config.LogConfig{
File: &config.LogFileConfig{
MaxSize: 200,
Expand Down Expand Up @@ -343,6 +345,7 @@ cert-allowed-cn = ["dd","ee"]
AdvertiseAddr: "127.0.0.1:1111",
LogFile: "/root/cdc.log",
LogLevel: "debug",
LogHTTP: true,
Log: &config.LogConfig{
File: &config.LogFileConfig{
MaxSize: 200,
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestReplicaConfigOutDated(t *testing.T) {

func TestServerConfigMarshal(t *testing.T) {
t.Parallel()
rawConfig := `{"addr":"192.155.22.33:8887","advertise-addr":"","log-file":"","log-level":"info","log":{"file":{"max-size":300,"max-days":0,"max-backups":0}},"data-dir":"","gc-ttl":86400,"tz":"System","capture-session-ttl":10,"owner-flush-interval":200000000,"processor-flush-interval":100000000,"sorter":{"num-concurrent-worker":4,"chunk-size-limit":999,"max-memory-percentage":30,"max-memory-consumption":17179869184,"num-workerpool-goroutine":16,"sort-dir":"/tmp/sorter"},"security":{"ca-path":"","cert-path":"","key-path":"","cert-allowed-cn":null},"per-table-memory-quota":20971520,"kv-client":{"worker-concurrent":8,"worker-pool-size":0,"region-scan-limit":40}}`
rawConfig := `{"addr":"192.155.22.33:8887","advertise-addr":"","log-file":"","log-level":"info","log_http":true,"log":{"file":{"max-size":300,"max-days":0,"max-backups":0}},"data-dir":"","gc-ttl":86400,"tz":"System","capture-session-ttl":10,"owner-flush-interval":200000000,"processor-flush-interval":100000000,"sorter":{"num-concurrent-worker":4,"chunk-size-limit":999,"max-memory-percentage":30,"max-memory-consumption":17179869184,"num-workerpool-goroutine":16,"sort-dir":"/tmp/sorter"},"security":{"ca-path":"","cert-path":"","key-path":"","cert-allowed-cn":null},"per-table-memory-quota":20971520,"kv-client":{"worker-concurrent":8,"worker-pool-size":0,"region-scan-limit":40}}`

conf := GetDefaultServerConfig()
conf.Addr = "192.155.22.33:8887"
Expand Down
13 changes: 12 additions & 1 deletion pkg/errors/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package errors

import (
"context"
"strings"

"github.com/pingcap/errors"
)
Expand Down Expand Up @@ -78,7 +79,8 @@ func IsRetryableError(err error) bool {
var BadRequestError = []*errors.Error{
ErrAPIInvalidParam, ErrSinkURIInvalid, ErrStartTsBeforeGC,
ErrChangeFeedNotExists, ErrTargetTsBeforeStartTs, ErrTableIneligible,
ErrFilterRuleInvalid, ErrChangefeedUpdateRefused,
ErrFilterRuleInvalid, ErrChangefeedUpdateRefused, ErrMySQLConnectionError,
ErrMySQLInvalidConfig,
}

func IsHTTPBadRequestError(err error) bool {
Expand All @@ -89,6 +91,15 @@ func IsHTTPBadRequestError(err error) bool {
if e.Equal(err) {
return true
}

rfcCode, ok := RFCCode(err)
if ok && e.RFCCode() == rfcCode {
return true
}

if strings.Contains(err.Error(), string(e.RFCCode())) {
return true
}
}
return false
}
2 changes: 2 additions & 0 deletions pkg/errors/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func TestIsRetryableError(t *testing.T) {
func TestIsBadRequestError(t *testing.T) {
err := ErrAPIInvalidParam.GenWithStack("aa")
require.Equal(t, true, IsHTTPBadRequestError(err))
err = ErrAPIInvalidParam.Wrap(errors.New("aa"))
require.Equal(t, true, IsHTTPBadRequestError(err))
err = ErrPDEtcdAPIError.GenWithStack("aa")
require.Equal(t, false, IsHTTPBadRequestError(err))
err = nil
Expand Down