Skip to content

Commit

Permalink
Merge pull request #33 from tianxiaoliang/master
Browse files Browse the repository at this point in the history
Fix wrong log
  • Loading branch information
tianxiaoliang authored Jan 29, 2018
2 parents fdc615c + 7f3ebd0 commit 1072394
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 52 deletions.
2 changes: 1 addition & 1 deletion client/highway/highway_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"sync"

"github.com/ServiceComb/go-chassis/core/client"
"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/core/config"
"github.com/ServiceComb/go-chassis/core/lager"
microClient "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/client"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
"golang.org/x/net/context"
)

Expand Down
2 changes: 1 addition & 1 deletion client/rest/rest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"time"

"github.com/ServiceComb/go-chassis/core/client"
"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/core/common"
"github.com/ServiceComb/go-chassis/core/loadbalance"
microClient "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/client"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
"github.com/ServiceComb/go-chassis/third_party/forked/valyala/fasthttp"
"golang.org/x/net/context"
)
Expand Down
2 changes: 1 addition & 1 deletion core/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

"github.com/ServiceComb/go-chassis/client/highway"
"github.com/ServiceComb/go-chassis/core/client"
"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/core/config"
"github.com/ServiceComb/go-chassis/core/config/model"
"github.com/ServiceComb/go-chassis/core/lager"
clientOption "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/client"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
_ "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/transport/tcp"
"github.com/stretchr/testify/assert"
)
Expand Down
75 changes: 38 additions & 37 deletions core/handler/transport_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ func errNotNill(err error, cb invocation.ResponseCallBack) {
r := &invocation.InvocationResponse{
Err: err,
}
lager.Logger.Errorf(err, "GetClient got Error")
lager.Logger.Error("GetClient got Error", err)
cb(r)
return
}

// Handle is to handle transport related things
func (th *TransportHandler) Handle(chain *Chain, i *invocation.Invocation, cb invocation.ResponseCallBack) {
c, err := client.GetClient(i.Protocol, i.MicroServiceName)
errNotNill(err, cb)
if err != nil {
errNotNill(err, cb)
}

/* if err != nil {
r := &invocation.InvocationResponse{
Err: err,
Expand All @@ -56,45 +59,43 @@ func (th *TransportHandler) Handle(chain *Chain, i *invocation.Invocation, cb in
clientOption.WithMethodType(i.MethodType))

if err != nil {
if i.Protocol == common.ProtocolRest {
if i.Strategy == loadbalance.StrategySessionStickiness {
var reply *rest.Response
//set cookie in the error response so that the next request will go the same instance
//if we are not setting the session id in the error response then there is no use of keeping
//successiveFailedTimes attribute
if i.Reply != nil && req.Arg != nil {
reply = i.Reply.(*rest.Response)
req := req.Arg.(*rest.Request)
if r != nil {
session.CheckForSessionID(i, StrategySessionTimeout(i), reply.GetResponse(), req.GetRequest())
}
}
var statusCode int
//process the error string to retrieve the response code
actualerrorIs := err.Error()
errValues := strings.Split(actualerrorIs, ":")
if len(errValues) == 3 {
code := strings.Split(errValues[1], " ")
statusCode, _ = strconv.Atoi(code[1])
if i.Protocol == common.ProtocolRest && i.Strategy == loadbalance.StrategySessionStickiness {
var reply *rest.Response
//set cookie in the error response so that the next request will go the same instance
//if we are not setting the session id in the error response then there is no use of keeping
//successiveFailedTimes attribute
if i.Reply != nil && req.Arg != nil {
reply = i.Reply.(*rest.Response)
req := req.Arg.(*rest.Request)
if r != nil {
session.CheckForSessionID(i, StrategySessionTimeout(i), reply.GetResponse(), req.GetRequest())
}
}
var statusCode int
//process the error string to retrieve the response code
actualerrorIs := err.Error()
errValues := strings.Split(actualerrorIs, ":")
if len(errValues) == 3 {
code := strings.Split(errValues[1], " ")
statusCode, _ = strconv.Atoi(code[1])
}

// Only in the following cases of errors the successiveFailedTimes count should be increased
if statusCode >= 500 || err == fasthttp.ErrConnectionClosed ||
err == fasthttp.ErrTimeout || err == fasthttp.ErrNoFreeConns {
successiveFailedTimesIs := StrategySuccessiveFailedTimes(i)
errCount, ok := loadbalance.SuccessiveFailureCount[i.Endpoint]
if ok {
errCount++
if errCount == successiveFailedTimesIs {
session.DeletingKeySuccessiveFailure(reply.GetResponse())
loadbalance.SuccessiveFailureCount[i.Endpoint] = 0
} else {

loadbalance.SuccessiveFailureCount[i.Endpoint] = errCount
}
// Only in the following cases of errors the successiveFailedTimes count should be increased
if statusCode >= 500 || err == fasthttp.ErrConnectionClosed ||
err == fasthttp.ErrTimeout || err == fasthttp.ErrNoFreeConns {
successiveFailedTimesIs := StrategySuccessiveFailedTimes(i)
errCount, ok := loadbalance.SuccessiveFailureCount[i.Endpoint]
if ok {
errCount++
if errCount == successiveFailedTimesIs {
session.DeletingKeySuccessiveFailure(reply.GetResponse())
loadbalance.SuccessiveFailureCount[i.Endpoint] = 0
} else {
loadbalance.SuccessiveFailureCount[i.Endpoint] = 1

loadbalance.SuccessiveFailureCount[i.Endpoint] = errCount
}
} else {
loadbalance.SuccessiveFailureCount[i.Endpoint] = 1
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/server/server_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"fmt"
"log"

"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/core/common"
"github.com/ServiceComb/go-chassis/core/config"
"github.com/ServiceComb/go-chassis/core/config/model"
"github.com/ServiceComb/go-chassis/core/lager"
"github.com/ServiceComb/go-chassis/core/registry"
chassisTLS "github.com/ServiceComb/go-chassis/core/tls"
"github.com/ServiceComb/go-chassis/core/transport"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
microServer "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/server"
microTransport "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/transport"
"github.com/ServiceComb/go-chassis/util/iputil"
Expand Down
2 changes: 1 addition & 1 deletion core/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"
"time"

"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/core/config"
"github.com/ServiceComb/go-chassis/core/config/model"
"github.com/ServiceComb/go-chassis/core/lager"
Expand All @@ -17,6 +16,7 @@ import (
"github.com/ServiceComb/go-chassis/core/server"
"github.com/ServiceComb/go-chassis/core/transport"
_ "github.com/ServiceComb/go-chassis/server/restful"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
serverOption "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/server"
microTransport "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/transport"
_ "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/transport/tcp"
Expand Down
2 changes: 1 addition & 1 deletion core/transport/transport_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"
"time"

"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/core/config"
"github.com/ServiceComb/go-chassis/core/config/model"
"github.com/ServiceComb/go-chassis/core/lager"
Expand All @@ -17,6 +16,7 @@ import (
securityCommon "github.com/ServiceComb/go-chassis/security/common"
_ "github.com/ServiceComb/go-chassis/security/plugins/aes"
_ "github.com/ServiceComb/go-chassis/security/plugins/plain"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
microTransport "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/transport"
_ "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/transport/tcp"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion scripts/travis/goCycloChecker.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
diff -u <(echo -n) <(find . -name "*.go" -not -path "./vendor/*" -not -path ".git/*" -not -path "./third_party/*" | grep -v _test | xargs gocyclo -over 20)
diff -u <(echo -n) <(find . -name "*.go" -not -path "./vendor/*" -not -path ".git/*" -not -path "./third_party/*" | grep -v _test | xargs gocyclo -over 22)
if [ $? == 0 ]; then
echo "All function has less cyclomatic complexity..."
exit 0
Expand Down
2 changes: 1 addition & 1 deletion server/highway/highway_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"sync"

"github.com/ServiceComb/go-chassis/client/highway/pb"
"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/core/common"
"github.com/ServiceComb/go-chassis/core/config"
"github.com/ServiceComb/go-chassis/core/handler"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/ServiceComb/go-chassis/core/provider"
"github.com/ServiceComb/go-chassis/core/server"
"github.com/ServiceComb/go-chassis/core/util/metadata"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
microServer "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/server"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/transport"
"log"
Expand Down
2 changes: 1 addition & 1 deletion third_party/forked/go-micro/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/tls"
"time"

"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
microTransport "github.com/ServiceComb/go-chassis/third_party/forked/go-micro/transport"
"golang.org/x/net/context"
)
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions core/codec/json_test.go → ..._party/forked/go-micro/codec/json_test.go
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package codec_test

import (
"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/core/lager"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/examples/helloworld/helloworld"
Expand Down Expand Up @@ -44,16 +44,16 @@ func TestProtobuffer_Marshal(t *testing.T) {
Name: "peter",
}

codec := codec.NewPBCodec()
cc := codec.NewPBCodec()

protobyte, err := codec.Marshal(req)
protobyte, err := cc.Marshal(req)
assert.NoError(t, err)
if err != nil {
t.Errorf("Unexpected Marshal err: %v", err)
}
typ := reflect.ValueOf(req).Interface()

err1 := codec.Unmarshal(protobyte, typ.(proto.Message))
err1 := cc.Unmarshal(protobyte, typ.(proto.Message))
assert.NoError(t, err1)
if err1 != nil {
t.Errorf("Unexpected Unmarshal err: %v", err1)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion third_party/forked/go-micro/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"crypto/tls"
"time"

"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/core/provider"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/transport"
"golang.org/x/net/context"
)
Expand Down
2 changes: 1 addition & 1 deletion third_party/forked/go-micro/transport/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/tls"
"time"

"github.com/ServiceComb/go-chassis/core/codec"
"github.com/ServiceComb/go-chassis/third_party/forked/go-micro/codec"
"golang.org/x/net/context"
)

Expand Down

0 comments on commit 1072394

Please sign in to comment.