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 34 commits
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
51 changes: 51 additions & 0 deletions cdc/capture/http_errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package capture

import (
"strings"

"github.com/pingcap/errors"
cerror "github.com/pingcap/ticdc/pkg/errors"
)

// HTTPBadRequestError is some errors that will cause a BadRequestError in http handler
var HTTPBadRequestError = []*errors.Error{
asddongmen marked this conversation as resolved.
Show resolved Hide resolved
cerror.ErrAPIInvalidParam, cerror.ErrSinkURIInvalid, cerror.ErrStartTsBeforeGC,
cerror.ErrChangeFeedNotExists, cerror.ErrTargetTsBeforeStartTs, cerror.ErrTableIneligible,
cerror.ErrFilterRuleInvalid, cerror.ErrChangefeedUpdateRefused, cerror.ErrMySQLConnectionError,
cerror.ErrMySQLInvalidConfig,
}

// IsHTTPBadRequestError check if a error is a http bad request error
func IsHTTPBadRequestError(err error) bool {
if err == nil {
return false
}
for _, e := range HTTPBadRequestError {
if e.Equal(err) {
return true
}

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

if strings.Contains(err.Error(), string(e.RFCCode())) {
return true
}
}
return false
}
33 changes: 33 additions & 0 deletions cdc/capture/http_errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package capture

import (
"testing"

"github.com/pingcap/errors"
cerror "github.com/pingcap/ticdc/pkg/errors"
"github.com/stretchr/testify/require"
)

func TestIsHTTPBadRequestError(t *testing.T) {
err := cerror.ErrAPIInvalidParam.GenWithStack("aa")
require.Equal(t, true, IsHTTPBadRequestError(err))
err = cerror.ErrAPIInvalidParam.Wrap(errors.New("aa"))
require.Equal(t, true, IsHTTPBadRequestError(err))
err = cerror.ErrPDEtcdAPIError.GenWithStack("aa")
require.Equal(t, false, IsHTTPBadRequestError(err))
err = nil
require.Equal(t, false, IsHTTPBadRequestError(err))
}
Loading