upgrade go chassis (#126)
diff --git a/cmd/mesher/mesher.go b/cmd/mesher/mesher.go
index 06d8a85..afef17f 100644
--- a/cmd/mesher/mesher.go
+++ b/cmd/mesher/mesher.go
@@ -34,15 +34,14 @@
"github.com/apache/servicecomb-mesher/proxy/server"
_ "github.com/apache/servicecomb-mesher/proxy/pkg/egress/archaius"
- _ "github.com/apache/servicecomb-mesher/proxy/pkg/egress/pilot"
_ "github.com/apache/servicecomb-mesher/proxy/control/istio"
_ "github.com/apache/servicecomb-mesher/proxy/handler/oauth2"
//middle wares
- _ "github.com/go-chassis/go-chassis/middleware/circuit"
- _ "github.com/go-chassis/go-chassis/middleware/ratelimiter"
+ _ "github.com/go-chassis/go-chassis/v2/middleware/circuit"
+ _ "github.com/go-chassis/go-chassis/v2/middleware/ratelimiter"
)
func main() {
diff --git a/conf/egress.yaml b/conf/egress.yaml
deleted file mode 100644
index de36a85..0000000
--- a/conf/egress.yaml
+++ /dev/null
@@ -1,17 +0,0 @@
-#egress:
-# infra: cse # pilot or cse
-# address: http://istio-pilot.istio-system:15010
-#egressRule:
-# google-ext:
-# - hosts:
-# - "google.com"
-# - "*.yahoo.com"
-# ports:
-# - port: 80
-# protocol: HTTP
-# facebook-ext:
-# - hosts:
-# - "www.facebook.com"
-# ports:
-# - port: 80
-# protocol: HTTP
diff --git a/conf/router.yaml b/conf/router.yaml
deleted file mode 100644
index 1146860..0000000
--- a/conf/router.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-#routeRule:
-# ShoppingCart: #service name
-# - precedence: 2 #precedence of route rule
-# route: #route rule list
-# - tags:
-# version: 0.2
-# app: HelloWorld
-# weight: 80 #weight of 80%
-# - tags:
-# version: 1.2
-# app: HelloWorld
-# weight: 20 #weight of 20%
\ No newline at end of file
diff --git a/docs/development/cloud-provider.md b/docs/development/cloud-provider.md
index 6432a92..82ae8ff 100644
--- a/docs/development/cloud-provider.md
+++ b/docs/development/cloud-provider.md
@@ -21,7 +21,7 @@
Import config center in cmd/mesher/mesher.go.
```go
-_ "github.com/go-chassis/go-chassis-config/configcenter"
+_ "github.com/go-chassis/go-chassis/v2-config/configcenter"
```
Set the config center in chassis.yaml
```yaml
diff --git a/go.mod b/go.mod
index ac8bdd6..2a2607c 100644
--- a/go.mod
+++ b/go.mod
@@ -1,13 +1,13 @@
module github.com/apache/servicecomb-mesher
require (
- github.com/envoyproxy/go-control-plane v0.6.0
+ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473
github.com/ghodss/yaml v1.0.0
github.com/go-chassis/foundation v0.1.1-0.20200825060850-b16bf420f7b3
github.com/go-chassis/go-archaius v1.3.3
- github.com/go-chassis/go-chassis v1.8.2-0.20200831084354-7ac56be1a686
+ github.com/go-chassis/go-chassis/v2 v2.0.3-0.20200916043058-7a753c9f1471
github.com/go-chassis/gohessian v0.0.0-20180702061429-e5130c25af55
- github.com/go-chassis/openlog v1.1.1
+ github.com/go-chassis/openlog v1.1.2
github.com/go-mesh/openlogging v1.0.1
github.com/gogo/googleapis v1.3.1 // indirect
github.com/gogo/protobuf v1.3.0
diff --git a/proxy/bootstrap/bootstrap.go b/proxy/bootstrap/bootstrap.go
index 60bb876..6a378dc 100644
--- a/proxy/bootstrap/bootstrap.go
+++ b/proxy/bootstrap/bootstrap.go
@@ -34,13 +34,11 @@
"github.com/apache/servicecomb-mesher/proxy/pkg/runtime"
"github.com/apache/servicecomb-mesher/proxy/resource/v1"
"github.com/apache/servicecomb-mesher/proxy/resource/v1/version"
- "github.com/go-chassis/go-chassis"
- "github.com/go-chassis/go-chassis/core/handler"
- chassisHandler "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/metadata"
+ "github.com/go-chassis/go-chassis/v2"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ chassisHandler "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/metadata"
"github.com/go-chassis/openlog"
- "github.com/go-mesh/openlogging"
)
// Start initialize configs and components
@@ -58,7 +56,7 @@
return err
}
if err := metrics.Init(); err != nil {
- lager.Logger.Info("metrics init error", openlog.WithTags(openlog.Tags{"err": err}))
+ openlog.Info("metrics init error", openlog.WithTags(openlog.Tags{"err": err}))
}
if err := v1.Init(); err != nil {
log.Println("Error occurred in starting admin server", err)
@@ -67,9 +65,9 @@
return err
}
if cmd.Configs.LocalServicePorts == "" {
- lager.Logger.Warn("local service ports is missing, service can not be called by mesher")
+ openlog.Warn("local service ports is missing, service can not be called by mesher")
} else {
- lager.Logger.Info(fmt.Sprintf("local service ports is [%v]", cmd.Configs.PortsMap))
+ openlog.Info(fmt.Sprintf("local service ports is [%v]", cmd.Configs.PortsMap))
}
err := egress.Init()
if err != nil {
@@ -87,7 +85,7 @@
//DecideMode get config mode
func DecideMode() error {
runtime.Role = cmd.Configs.Role
- openlogging.GetLogger().Info("Running as " + runtime.Role)
+ openlog.Info("Running as " + runtime.Role)
return nil
}
diff --git a/proxy/bootstrap/bootstrap_test.go b/proxy/bootstrap/bootstrap_test.go
index 29df15c..acd75f2 100644
--- a/proxy/bootstrap/bootstrap_test.go
+++ b/proxy/bootstrap/bootstrap_test.go
@@ -22,10 +22,10 @@
"github.com/apache/servicecomb-mesher/proxy/common"
_ "github.com/apache/servicecomb-mesher/proxy/pkg/egress/archaius"
"github.com/go-chassis/go-archaius"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/pkg/util/fileutil"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/fileutil"
"github.com/stretchr/testify/assert"
"io"
"os"
@@ -33,7 +33,7 @@
"sync"
"testing"
// rate limiter handler
- _ "github.com/go-chassis/go-chassis/middleware/ratelimiter"
+ _ "github.com/go-chassis/go-chassis/v2/middleware/ratelimiter"
)
var o sync.Once = sync.Once{}
diff --git a/proxy/cmd/cmd.go b/proxy/cmd/cmd.go
index b0bb140..2e66e22 100644
--- a/proxy/cmd/cmd.go
+++ b/proxy/cmd/cmd.go
@@ -20,7 +20,7 @@
import (
"fmt"
"github.com/apache/servicecomb-mesher/proxy/common"
- chassiscommon "github.com/go-chassis/go-chassis/core/common"
+ chassiscommon "github.com/go-chassis/go-chassis/v2/core/common"
"github.com/urfave/cli"
"log"
"os"
diff --git a/proxy/cmd/cmd_test.go b/proxy/cmd/cmd_test.go
index 2063c71..c413009 100644
--- a/proxy/cmd/cmd_test.go
+++ b/proxy/cmd/cmd_test.go
@@ -20,7 +20,7 @@
import (
"github.com/apache/servicecomb-mesher/proxy/cmd"
"github.com/apache/servicecomb-mesher/proxy/common"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
"github.com/stretchr/testify/assert"
"os"
"testing"
diff --git a/proxy/config/config.go b/proxy/config/config.go
index 60e1d1f..3b757dd 100644
--- a/proxy/config/config.go
+++ b/proxy/config/config.go
@@ -18,6 +18,7 @@
package config
import (
+ "github.com/go-chassis/openlog"
"io/ioutil"
"os"
"path/filepath"
@@ -25,12 +26,10 @@
"github.com/apache/servicecomb-mesher/proxy/cmd"
"github.com/apache/servicecomb-mesher/proxy/common"
"github.com/go-chassis/go-archaius"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/server"
- "github.com/go-chassis/go-chassis/pkg/util/fileutil"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/server"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/fileutil"
"gopkg.in/yaml.v2"
)
@@ -137,18 +136,18 @@
func SetKeyValueByFile(key, f string) string {
var contents string
if _, err := os.Stat(f); err != nil {
- openlogging.GetLogger().Warn(err.Error())
+ openlog.Warn(err.Error())
return ""
}
b, err := ioutil.ReadFile(f)
if err != nil {
- lager.Logger.Error("Can not read yaml file" + err.Error())
+ openlog.Error("Can not read yaml file" + err.Error())
return ""
}
contents = string(b)
err = archaius.Set(key, contents)
if err != nil {
- lager.Logger.Error("Archaius set error: " + err.Error())
+ openlog.Error("Archaius set error: " + err.Error())
}
return contents
}
diff --git a/proxy/config/config_test.go b/proxy/config/config_test.go
index 76fac98..3e6a23a 100644
--- a/proxy/config/config_test.go
+++ b/proxy/config/config_test.go
@@ -18,14 +18,14 @@
package config_test
import (
- // "github.com/go-chassis/go-chassis/core/archaius"
- // cConfig "github.com/go-chassis/go-chassis/core/config"
- // "github.com/go-chassis/go-chassis/core/lager"
- // "github.com/go-chassis/go-chassis/pkg/util/fileutil"
+ // "github.com/go-chassis/go-chassis/v2/core/archaius"
+ // cConfig "github.com/go-chassis/go-chassis/v2/core/config"
+ // "github.com/go-chassis/go-chassis/v2/core/lager"
+ // "github.com/go-chassis/go-chassis/v2/pkg/util/fileutil"
"github.com/apache/servicecomb-mesher/proxy/cmd"
"github.com/apache/servicecomb-mesher/proxy/config"
"github.com/go-chassis/go-archaius"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
// "os"
diff --git a/proxy/control/istio/panel.go b/proxy/control/istio/panel.go
index ae3621d..f869824 100644
--- a/proxy/control/istio/panel.go
+++ b/proxy/control/istio/panel.go
@@ -20,10 +20,10 @@
import (
meshercontrol "github.com/apache/servicecomb-mesher/proxy/control"
"github.com/apache/servicecomb-mesher/proxy/pkg/egress"
- "github.com/go-chassis/go-chassis/control"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
+ "github.com/go-chassis/go-chassis/v2/control"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/third_party/forked/afex/hystrix-go/hystrix"
)
func init() {
diff --git a/proxy/control/istio/transfer.go b/proxy/control/istio/transfer.go
index 0765a72..ed6bd88 100644
--- a/proxy/control/istio/transfer.go
+++ b/proxy/control/istio/transfer.go
@@ -19,7 +19,7 @@
import (
"github.com/apache/servicecomb-mesher/proxy/config"
- "github.com/go-chassis/go-chassis/control"
+ "github.com/go-chassis/go-chassis/v2/control"
)
//SaveToEgressCache save the egress rules in the cache
diff --git a/proxy/control/panel.go b/proxy/control/panel.go
index c191be4..21db4e6 100644
--- a/proxy/control/panel.go
+++ b/proxy/control/panel.go
@@ -19,8 +19,8 @@
import (
"fmt"
- "github.com/go-chassis/go-chassis/control"
- "github.com/go-chassis/go-chassis/core/config"
+ "github.com/go-chassis/go-chassis/v2/control"
+ "github.com/go-chassis/go-chassis/v2/core/config"
)
var panelPlugin = make(map[string]func(options Options) control.Panel)
diff --git a/proxy/handler/oauth2/oauth2_handler.go b/proxy/handler/oauth2/oauth2_handler.go
index bc0b444..0071133 100644
--- a/proxy/handler/oauth2/oauth2_handler.go
+++ b/proxy/handler/oauth2/oauth2_handler.go
@@ -20,9 +20,9 @@
import (
"context"
"errors"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/openlog"
"net/http"
"time"
)
@@ -64,7 +64,7 @@
accessToken, err := getToken(code, cb)
if err != nil {
- openlogging.Error("authorization error: " + err.Error())
+ openlog.Error("authorization error: " + err.Error())
WriteBackErr(ErrInvalidToken, http.StatusUnauthorized, cb)
return
}
@@ -72,7 +72,7 @@
if auth.Authenticate != nil {
err = auth.Authenticate(accessToken, req)
if err != nil {
- openlogging.Error("authentication error: " + err.Error())
+ openlog.Error("authentication error: " + err.Error())
WriteBackErr(ErrInvalidAuth, http.StatusUnauthorized, cb)
return
}
@@ -90,7 +90,7 @@
config := auth.UseConfig
token, err := config.Exchange(context.Background(), code)
if err != nil {
- openlogging.Error("get token failed, errors: " + err.Error())
+ openlog.Error("get token failed, errors: " + err.Error())
WriteBackErr(ErrInvalidCode, http.StatusUnauthorized, cb)
return "", err
}
@@ -119,7 +119,7 @@
func init() {
err := handler.RegisterHandler(AuthName, NewOAuth2)
if err != nil {
- openlogging.Error("register handler error: " + err.Error())
+ openlog.Error("register handler error: " + err.Error())
return
}
}
diff --git a/proxy/handler/oauth2/oauth2_handler_test.go b/proxy/handler/oauth2/oauth2_handler_test.go
index 95d6d95..3c09a39 100644
--- a/proxy/handler/oauth2/oauth2_handler_test.go
+++ b/proxy/handler/oauth2/oauth2_handler_test.go
@@ -18,10 +18,10 @@
package oauth2
import (
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
"github.com/stretchr/testify/assert"
"golang.org/x/oauth2"
"net/http"
diff --git a/proxy/handler/port_rewrite.go b/proxy/handler/port_rewrite.go
index d157c99..c19172f 100644
--- a/proxy/handler/port_rewrite.go
+++ b/proxy/handler/port_rewrite.go
@@ -22,9 +22,9 @@
"strings"
"github.com/apache/servicecomb-mesher/proxy/pkg/ports"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/openlog"
)
//PortMapForPilot is a constant
@@ -39,7 +39,7 @@
var err error
inv.Endpoint, err = replacePort(inv.Protocol, inv.Endpoint)
if err != nil {
- openlogging.Error("can not replace port: " + err.Error())
+ openlog.Error("can not replace port: " + err.Error())
}
if inv.Endpoint == "" {
r := &invocation.Response{
diff --git a/proxy/handler/port_rewrite_test.go b/proxy/handler/port_rewrite_test.go
index 846879f..269fd6b 100644
--- a/proxy/handler/port_rewrite_test.go
+++ b/proxy/handler/port_rewrite_test.go
@@ -20,11 +20,11 @@
import (
"testing"
- "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
"github.com/stretchr/testify/assert"
)
diff --git a/proxy/handler/skywalking_handler.go b/proxy/handler/skywalking_handler.go
index 33dd811..db67b3f 100644
--- a/proxy/handler/skywalking_handler.go
+++ b/proxy/handler/skywalking_handler.go
@@ -18,10 +18,11 @@
package handler
import (
+ "fmt"
"github.com/apache/servicecomb-mesher/proxy/pkg/skywalking"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/openlog"
"github.com/tetratelabs/go2sky"
skycom "github.com/tetratelabs/go2sky/reporter/grpc/common"
"strconv"
@@ -43,10 +44,10 @@
//Handle is for provider
func (sp *SkyWalkingProviderHandler) Handle(chain *handler.Chain, i *invocation.Invocation, cb invocation.ResponseCallBack) {
- openlogging.GetLogger().Debugf("SkyWalkingProviderHandler begin. inv:%#v", *i)
+ openlog.Debug(fmt.Sprintf("SkyWalkingProviderHandler begin. inv:%#v", *i))
span, _, err := skywalking.CreateEntrySpan(i)
if err != nil {
- openlogging.GetLogger().Errorf("CreateEntrySpan error:%s", err.Error())
+ openlog.Error(fmt.Sprintf("CreateEntrySpan error:%s", err.Error()))
}
chain.Next(i, func(r *invocation.Response) {
cb(r)
@@ -76,14 +77,14 @@
//Handle is for consumer
func (sc *SkyWalkingConsumerHandler) Handle(chain *handler.Chain, i *invocation.Invocation, cb invocation.ResponseCallBack) {
- openlogging.GetLogger().Debugf("SkyWalkingConsumerHandler begin:%#v", *i)
+ openlog.Debug(fmt.Sprintf("SkyWalkingConsumerHandler begin:%#v", *i))
span, ctx, err := skywalking.CreateEntrySpan(i)
if err != nil {
- openlogging.GetLogger().Errorf("CreateEntrySpan error:%s", err.Error())
+ openlog.Error(fmt.Sprintf("CreateEntrySpan error:%s", err.Error()))
}
spanExit, err := skywalking.CreateExitSpan(ctx, i)
if err != nil {
- openlogging.GetLogger().Errorf("CreateExitSpan error:%s", err.Error())
+ openlog.Error(fmt.Sprintf("CreateExitSpan error:%s", err.Error()))
}
chain.Next(i, func(r *invocation.Response) {
cb(r)
@@ -101,7 +102,7 @@
spanExit.End()
span.End()
- openlogging.GetLogger().Debugf("SkyWalkingConsumerHandler end.")
+ openlog.Debug("SkyWalkingConsumerHandler end.")
})
}
@@ -118,10 +119,10 @@
func init() {
err := handler.RegisterHandler(skywalking.SkyWalkingProvider, NewSkyWalkingProvier)
if err != nil {
- openlogging.GetLogger().Errorf("Handler [%s] register error: ", skywalking.SkyWalkingProvider, err.Error())
+ openlog.Error(fmt.Sprintf("Handler [%s] register error: %s", skywalking.SkyWalkingProvider, err.Error()))
}
err = handler.RegisterHandler(skywalking.SkyWalkingConsumer, NewSkyWalkingConsumer)
if err != nil {
- openlogging.GetLogger().Errorf("Handler [%s] register error: ", skywalking.SkyWalkingConsumer, err.Error())
+ openlog.Error(fmt.Sprintf("Handler [%s] register error: %s", skywalking.SkyWalkingConsumer, err.Error()))
}
}
diff --git a/proxy/handler/skywalking_handler_test.go b/proxy/handler/skywalking_handler_test.go
index efc1cb5..350d8cd 100644
--- a/proxy/handler/skywalking_handler_test.go
+++ b/proxy/handler/skywalking_handler_test.go
@@ -22,10 +22,10 @@
"github.com/apache/servicecomb-mesher/proxy/config"
mhandler "github.com/apache/servicecomb-mesher/proxy/handler"
"github.com/apache/servicecomb-mesher/proxy/pkg/skywalking"
- gcconfig "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
+ gcconfig "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
"github.com/stretchr/testify/assert"
"testing"
)
diff --git a/proxy/health/health.go b/proxy/health/health.go
index 2eb673f..17a50ab 100644
--- a/proxy/health/health.go
+++ b/proxy/health/health.go
@@ -21,10 +21,9 @@
"errors"
"fmt"
"github.com/apache/servicecomb-mesher/proxy/config"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/registry"
- "github.com/go-chassis/go-chassis/pkg/runtime"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/core/registry"
+ "github.com/go-chassis/go-chassis/v2/pkg/runtime"
+ "github.com/go-chassis/openlog"
"net"
"regexp"
"strconv"
@@ -60,18 +59,18 @@
//UpdateInstanceStatus update status in registrator, it just works in client side discovery
func UpdateInstanceStatus(err error) {
if registry.DefaultRegistrator == nil {
- lager.Logger.Warn("Registrator is nil, can not update instance status")
+ openlog.Warn("Registrator is nil, can not update instance status")
return
}
if err != nil {
if runtime.InstanceStatus == runtime.StatusRunning {
- lager.Logger.Info("service is not healthy, update status")
+ openlog.Info("service is not healthy, update status")
ChangeStatus(runtime.StatusDown)
}
} else {
if runtime.InstanceStatus == runtime.StatusDown {
- lager.Logger.Info("service is healthy, update status")
+ openlog.Info("service is healthy, update status")
ChangeStatus(runtime.StatusRunning)
}
}
@@ -81,11 +80,11 @@
//ChangeStatus change status in local and remote
func ChangeStatus(status string) {
if err := registry.DefaultRegistrator.UpdateMicroServiceInstanceStatus(runtime.ServiceID, runtime.InstanceID, status); err != nil {
- lager.Logger.Error("update instance status failed:" + err.Error())
+ openlog.Error("update instance status failed:" + err.Error())
return
}
runtime.InstanceStatus = status
- lager.Logger.Info("update instance status to: " + runtime.InstanceStatus)
+ openlog.Info("update instance status to: " + runtime.InstanceStatus)
}
//runCheckers run check routines
@@ -102,7 +101,7 @@
for range ticker.C {
err := CheckService(c, l7check, address)
if err != nil {
- lager.Logger.Error(fmt.Sprintf("health check failed for service port[%s]: %s", c.Port, err))
+ openlog.Error(fmt.Sprintf("health check failed for service port[%s]: %s", c.Port, err))
}
deal(err)
}
@@ -112,7 +111,7 @@
//CheckService check service health based on config
func CheckService(c *config.HealthCheck, l7check L7Check, address string) error {
- lager.Logger.Debug(fmt.Sprintf("check port [%s]", c.Port))
+ openlog.Debug(fmt.Sprintf("check port [%s]", c.Port))
if l7check != nil {
if err := l7check(c, address); err != nil {
return err
@@ -122,7 +121,7 @@
return err
}
}
- lager.Logger.Debug("service is healthy: " + address)
+ openlog.Debug("service is healthy: " + address)
return nil
}
@@ -140,12 +139,12 @@
//Run Launch go routines to check service health
func Run() error {
- openlogging.Info("local health manager start")
+ openlog.Info("local health manager start")
for _, v := range config.GetConfig().HealthCheck {
- lager.Logger.Debug(fmt.Sprintf("check local health [%s],protocol [%s]", v.Port, v.Protocol))
+ openlog.Debug(fmt.Sprintf("check local health [%s],protocol [%s]", v.Port, v.Protocol))
address, check, err := ParseConfig(v)
if err != nil {
- lager.Logger.Warn("Health keeper can not check health")
+ openlog.Warn("Health keeper can not check health")
return err
}
//TODO make pluggable Deal
diff --git a/proxy/health/health_test.go b/proxy/health/health_test.go
index 1273be7..ed31a53 100644
--- a/proxy/health/health_test.go
+++ b/proxy/health/health_test.go
@@ -21,7 +21,7 @@
"context"
"github.com/apache/servicecomb-mesher/proxy/config"
"github.com/apache/servicecomb-mesher/proxy/health"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
"github.com/stretchr/testify/assert"
"net"
"net/http"
diff --git a/proxy/health/l7check.go b/proxy/health/l7check.go
index 871ab00..652f7d9 100644
--- a/proxy/health/l7check.go
+++ b/proxy/health/l7check.go
@@ -22,7 +22,7 @@
"errors"
"github.com/apache/servicecomb-mesher/proxy/config"
"github.com/go-chassis/foundation/httpclient"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/openlog"
"io/ioutil"
"regexp"
"strconv"
@@ -32,7 +32,7 @@
func HTTPCheck(check *config.HealthCheck, address string) error {
c, err := httpclient.New(&httpclient.DefaultOptions)
if err != nil {
- openlogging.Error("can not get http client: " + err.Error())
+ openlog.Error("can not get http client: " + err.Error())
//must not return error, because it is mesher error
return nil
}
@@ -42,7 +42,7 @@
}
resp, err := c.Get(context.Background(), url, nil)
if err != nil {
- openlogging.Error("server can not be connected: " + err.Error())
+ openlog.Error("server can not be connected: " + err.Error())
return err
}
body, err := ioutil.ReadAll(resp.Body)
diff --git a/proxy/ingress/servicecomb/listener.go b/proxy/ingress/servicecomb/listener.go
index d41051a..64bce81 100644
--- a/proxy/ingress/servicecomb/listener.go
+++ b/proxy/ingress/servicecomb/listener.go
@@ -20,8 +20,8 @@
import (
"github.com/apache/servicecomb-mesher/proxy/config"
"github.com/go-chassis/go-archaius/event"
- "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/openlog"
)
type ingressRuleEventListener struct{}
@@ -29,17 +29,17 @@
//Event update ingress rule
func (r *ingressRuleEventListener) Event(e *event.Event) {
if e == nil {
- openlogging.Warn("Event pointer is nil")
+ openlog.Warn("Event pointer is nil")
return
}
- openlogging.Info("dark launch event", openlogging.WithTags(openlogging.Tags{
+ openlog.Info("dark launch event", openlog.WithTags(openlog.Tags{
"key": e.Key,
"event": e.EventType,
"rule": e.Value,
}))
raw, ok := e.Value.(string)
if !ok {
- openlogging.Error("invalid ingress rule", openlogging.WithTags(openlogging.Tags{
+ openlog.Error("invalid ingress rule", openlog.WithTags(openlog.Tags{
"value": raw,
}))
}
@@ -50,8 +50,8 @@
saveRules(raw)
case common.Delete:
rulesData = nil
- openlogging.Info("ingress rule is removed", openlogging.WithTags(
- openlogging.Tags{
+ openlog.Info("ingress rule is removed", openlog.WithTags(
+ openlog.Tags{
"key": e.Key,
}))
}
@@ -61,12 +61,12 @@
func saveRules(raw string) {
rules, err := config.NewRules(raw)
if err != nil {
- openlogging.Error("invalid ingress rule", openlogging.WithTags(openlogging.Tags{
+ openlog.Error("invalid ingress rule", openlog.WithTags(openlog.Tags{
"value": raw,
}))
}
rulesData = rules.Value()
- openlogging.Info("update ingress rule", openlogging.WithTags(openlogging.Tags{
+ openlog.Info("update ingress rule", openlog.WithTags(openlog.Tags{
"value": raw,
}))
}
diff --git a/proxy/pkg/egress/archaius/egress_manager.go b/proxy/pkg/egress/archaius/egress_manager.go
index 4c48c65..59dc4c6 100644
--- a/proxy/pkg/egress/archaius/egress_manager.go
+++ b/proxy/pkg/egress/archaius/egress_manager.go
@@ -21,6 +21,7 @@
"fmt"
"github.com/go-chassis/go-archaius/event"
"github.com/go-chassis/go-archaius/source/util"
+ "github.com/go-chassis/openlog"
"gopkg.in/yaml.v2"
"path/filepath"
"strings"
@@ -28,8 +29,7 @@
"github.com/apache/servicecomb-mesher/proxy/config"
"github.com/apache/servicecomb-mesher/proxy/pkg/egress"
"github.com/go-chassis/go-archaius"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/pkg/util/fileutil"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/fileutil"
)
//EgressYaml egress yaml file name
@@ -40,7 +40,7 @@
// update egress rule of a service
func (r *egressRuleEventListener) Event(e *event.Event) {
if e == nil {
- lager.Logger.Warn("Event pointer is nil", nil)
+ openlog.Warn("Event pointer is nil", nil)
return
}
if !strings.Contains(e.Key, EgressYaml) {
@@ -48,14 +48,14 @@
}
v := archaius.Get(e.Key)
if v == nil {
- lager.Logger.Info(fmt.Sprintf("[%s] Error getting egress key", e.Key))
+ openlog.Info(fmt.Sprintf("[%s] Error getting egress key", e.Key))
return
}
var egressconfig config.EgressConfig
if err := yaml.Unmarshal([]byte(v.([]byte)), &egressconfig); err != nil {
- lager.Logger.Error("yaml unmarshal failed", nil)
+ openlog.Error("yaml unmarshal failed", nil)
return
}
var egressRules []*config.EgressRule
@@ -63,7 +63,7 @@
for key, value := range egressconfig.Destinations {
ok, _ := egress.ValidateEgressRule(map[string][]*config.EgressRule{key: value})
if !ok {
- lager.Logger.Warn("Validating Egress Rule Failed")
+ openlog.Warn("Validating Egress Rule Failed")
return
}
@@ -71,7 +71,7 @@
}
SetEgressRule(map[string][]*config.EgressRule{e.Key: egressRules})
- lager.Logger.Info(fmt.Sprintf("Update [%s] egress rule SUCCESS", e.Key))
+ openlog.Info(fmt.Sprintf("Update [%s] egress rule SUCCESS", e.Key))
}
// initialize the config mgr and add several sources
@@ -79,11 +79,11 @@
egressListener := &egressRuleEventListener{}
err := archaius.AddFile(filepath.Join(fileutil.GetConfDir(), EgressYaml), archaius.WithFileHandler(util.UseFileNameAsKeyContentAsValue))
if err != nil {
- lager.Logger.Info(fmt.Sprint("Archaius add file failed: ", err))
+ openlog.Info(fmt.Sprint("Archaius add file failed: ", err))
}
err = archaius.RegisterListener(egressListener, ".*")
if err != nil {
- lager.Logger.Info(fmt.Sprint("Archaius add file failed: ", err))
+ openlog.Info(fmt.Sprint("Archaius add file failed: ", err))
}
return nil
}
diff --git a/proxy/pkg/egress/egress.go b/proxy/pkg/egress/egress.go
index c027c9f..ae712a6 100644
--- a/proxy/pkg/egress/egress.go
+++ b/proxy/pkg/egress/egress.go
@@ -21,7 +21,7 @@
"errors"
"github.com/apache/servicecomb-mesher/proxy/config"
meshercontrol "github.com/apache/servicecomb-mesher/proxy/control"
- "github.com/go-chassis/go-chassis/control"
+ "github.com/go-chassis/go-chassis/v2/control"
"regexp"
"sync"
)
diff --git a/proxy/pkg/egress/egress_config.go b/proxy/pkg/egress/egress_config.go
index 0abfe1f..a75eae4 100644
--- a/proxy/pkg/egress/egress_config.go
+++ b/proxy/pkg/egress/egress_config.go
@@ -25,10 +25,10 @@
"strings"
"github.com/apache/servicecomb-mesher/proxy/config"
- gochassisconfig "github.com/go-chassis/go-chassis/core/config"
- chassisTLS "github.com/go-chassis/go-chassis/core/tls"
- "github.com/go-chassis/go-chassis/pkg/util/iputil"
- "github.com/go-mesh/openlogging"
+ gochassisconfig "github.com/go-chassis/go-chassis/v2/core/config"
+ chassisTLS "github.com/go-chassis/go-chassis/v2/core/tls"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/iputil"
+ "github.com/go-chassis/openlog"
)
const (
@@ -61,7 +61,7 @@
if err != nil {
return err
}
- openlogging.Info("Egress init success")
+ openlog.Info("Egress init success")
return nil
}
diff --git a/proxy/pkg/egress/egress_test.go b/proxy/pkg/egress/egress_test.go
index 850f77f..5703ce2 100644
--- a/proxy/pkg/egress/egress_test.go
+++ b/proxy/pkg/egress/egress_test.go
@@ -19,7 +19,7 @@
import (
"fmt"
- "github.com/go-chassis/go-chassis/pkg/util/fileutil"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/fileutil"
"github.com/stretchr/testify/assert"
"io"
"os"
@@ -31,10 +31,10 @@
_ "github.com/apache/servicecomb-mesher/proxy/control/istio"
"github.com/apache/servicecomb-mesher/proxy/pkg/egress"
"github.com/apache/servicecomb-mesher/proxy/pkg/egress/archaius"
- "github.com/go-chassis/go-chassis/control"
- _ "github.com/go-chassis/go-chassis/control/servicecomb"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/go-chassis/v2/control"
+ _ "github.com/go-chassis/go-chassis/v2/control/servicecomb"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
"gopkg.in/yaml.v2"
)
diff --git a/proxy/pkg/egress/pilot/egress.go b/proxy/pkg/egress/pilot/egress.go
deleted file mode 100644
index 678772d..0000000
--- a/proxy/pkg/egress/pilot/egress.go
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package pilot
-
-import (
- "fmt"
- "github.com/apache/servicecomb-mesher/proxy/config"
- "github.com/apache/servicecomb-mesher/proxy/pkg/egress"
- "sync"
-)
-
-func init() { egress.InstallEgressService("pilot", newPilotEgress) }
-
-func newPilotEgress() (egress.Egress, error) { return &PilotEgress{}, nil }
-
-//PilotEgress is pilot egress service
-type PilotEgress struct{}
-
-//FetchEgressRule return all rules
-func (r *PilotEgress) FetchEgressRule() map[string][]*config.EgressRule {
- return GetEgressRule()
-}
-
-//SetEgressRule set rules
-func (r *PilotEgress) SetEgressRule(rr map[string][]*config.EgressRule) {
- SetEgressRule(rr)
-}
-
-//Init init egress config
-func (r *PilotEgress) Init(o egress.Options) error {
- // the manager use dests to init, so must init after dests
- if err := InitPilotFetcher(o); err != nil {
- return err
- }
- return refresh()
-}
-
-// refresh all the egress config
-func refresh() error {
- configs := pilotfetcher.Configs()
-
- d := make(map[string][]*config.EgressRule)
- for k, v := range configs {
- rules, ok := v.([]*config.EgressRule)
- if !ok {
- err := fmt.Errorf("egress rule type assertion fail, key: %s", k)
- return err
- }
- d[k] = rules
- }
- ok, _ := egress.ValidateEgressRule(d)
- if ok {
- dests = d
- }
- return nil
-}
-
-var dests = make(map[string][]*config.EgressRule)
-var lock sync.RWMutex
-
-// GetEgressRule get egress rule
-func GetEgressRule() map[string][]*config.EgressRule {
- lock.RLock()
- defer lock.RUnlock()
- return dests
-}
-
-// SetEgressRule set egress rule
-func SetEgressRule(rule map[string][]*config.EgressRule) {
- lock.RLock()
- defer lock.RUnlock()
- dests = rule
-}
diff --git a/proxy/pkg/egress/pilot/pilotsource.go b/proxy/pkg/egress/pilot/pilotsource.go
deleted file mode 100644
index 46d0a82..0000000
--- a/proxy/pkg/egress/pilot/pilotsource.go
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package pilot
-
-import (
- "errors"
- "fmt"
- "github.com/go-chassis/go-archaius/event"
- "github.com/go-chassis/go-archaius/source"
- "github.com/go-chassis/openlog"
- "os"
- "reflect"
- "strconv"
- "strings"
- "sync"
- "time"
-
- "github.com/apache/servicecomb-mesher/proxy/config"
- "github.com/apache/servicecomb-mesher/proxy/control/istio"
- "github.com/apache/servicecomb-mesher/proxy/pkg/egress"
- istioinfra "github.com/apache/servicecomb-mesher/proxy/pkg/infras/istio"
- "github.com/go-chassis/go-chassis/core/lager"
-)
-
-const egressPilotSourceName = "EgressPilotSource"
-const egressPilotSourcePriority = 8
-
-//OUTBOUND outbound
-const OUTBOUND = "outbound"
-
-//clusteroriginaldst cluster type
-const clusteroriginaldst = 4
-
-// DefaultPilotRefresh is default pilot refresh time
-// TODO: use stream instead
-var DefaultPilotRefresh = 10 * time.Second
-
-var pilotfetcher *source.Manager
-var pilotChan = make(chan string, 10)
-
-func setChanForPilot(k string) bool {
- select {
- case pilotChan <- k:
- return true
- default:
- return false
- }
-}
-
-// InitPilotFetcher init the config mgr and add several sources
-func InitPilotFetcher(o egress.Options) error {
- // register and init pilot fetcher
- pilotfetcher = source.NewManager()
- pilotfetcher.RegisterListener(&pilotEventListener{}, ".*")
- return addEgressPilotSource(o)
-}
-
-// addEgressPilotSource adds a config source to pilotfetcher
-func addEgressPilotSource(o egress.Options) error {
- if pilotfetcher == nil {
- return errors.New("pilotfetcher is nil, please init it first")
- }
-
- s, err := newPilotSource(o)
- if err != nil {
- return err
- }
- lager.Logger.Info(fmt.Sprintf("New [%s] source success", s.GetSourceName()))
- return pilotfetcher.AddSource(s)
-}
-
-// pilotSource keeps the egress rule in istio
-type pilotSource struct {
- refreshInverval time.Duration
- fetcher istioinfra.XdsClient
- priority int
- mu sync.RWMutex
- pmu sync.RWMutex
- Configurations map[string]interface{}
- PortToService map[string]string
-}
-
-func newPilotSource(o egress.Options) (*pilotSource, error) {
- pilotAddr := o.Endpoints[0]
- nodeInfo := getNodeInfo()
- xdsClient, err := istioinfra.NewXdsClient(pilotAddr, nil, nodeInfo, o.ConfigPath)
- if err != nil {
- return nil, fmt.Errorf("connect to pilot failed: %v", err)
- }
-
- return &pilotSource{
- // TODO: read from config
- refreshInverval: DefaultPilotRefresh,
- Configurations: map[string]interface{}{},
- PortToService: map[string]string{},
- fetcher: *xdsClient,
- priority: egressPilotSourcePriority,
- }, nil
-}
-
-func getNodeInfo() *istioinfra.NodeInfo {
- PodName := os.Getenv("POD_NAME")
- PodNamespace := os.Getenv("POD_NAMESPACE")
- InstanceIP := os.Getenv("INSTANCE_IP")
-
- nodeInfo := &istioinfra.NodeInfo{
- PodName: PodName,
- Namespace: PodNamespace,
- InstanceIP: InstanceIP,
- }
- return nodeInfo
-}
-
-func (r *pilotSource) GetSourceName() string { return egressPilotSourceName }
-func (r *pilotSource) GetPriority() int { return r.priority }
-func (r *pilotSource) Cleanup() error { return nil }
-
-//AddDimensionInfo no use
-func (r *pilotSource) AddDimensionInfo(labels map[string]string) error {
- return nil
-}
-
-func (r *pilotSource) GetConfigurations() (map[string]interface{}, error) {
- egressConfigs, err := r.getEgressConfigFromPilot()
- if err != nil {
- lager.Logger.Error("Get egress config from pilot failed" + err.Error())
- return nil, err
- }
- d := make(map[string]interface{}, 0)
- d["pilotEgress"] = egressConfigs
- r.mu.Lock()
- r.Configurations = d
- r.mu.Unlock()
- return d, nil
-}
-
-func (r *pilotSource) GetConfigurationByKey(k string) (interface{}, error) {
- r.mu.RLock()
- defer r.mu.RUnlock()
- if value, ok := r.Configurations[k]; ok {
- return value, nil
- }
- return nil, fmt.Errorf("not found %s", k)
-}
-
-//Set no use
-func (r *pilotSource) Set(key string, value interface{}) error {
- return nil
-}
-
-//Delete no use
-func (r *pilotSource) Delete(key string) error {
- return nil
-}
-
-// get egress config from pilot
-func (r *pilotSource) getEgressConfigFromPilot() ([]*config.EgressRule, error) {
- clusters, _ := r.fetcher.CDS()
- var egressRules []*config.EgressRule
- for _, cluster := range clusters {
-
- if cluster.GetType() == clusteroriginaldst {
- data := strings.Split(cluster.Name, "|")
- if len(data) > 1 && data[0] == OUTBOUND {
- intport, err := strconv.Atoi(data[1])
- if err != nil {
- return nil, nil
- }
- var rule config.EgressRule
- rule.Hosts = []string{data[len(data)-1]}
- rule.Ports = []*config.EgressPort{
- {Port: int32(intport),
- Protocol: "http"}}
-
- egressRules = append(egressRules, &rule)
- }
-
- }
-
- }
-
- return egressRules, nil
-}
-
-func (r *pilotSource) setPortForDestination(service, port string) {
- r.pmu.RLock()
- r.PortToService[port] = service
- r.pmu.RUnlock()
-}
-
-//SetPriority custom priority
-func (r *pilotSource) SetPriority(priority int) {
- r.priority = priority
-}
-func (r *pilotSource) Watch(callback source.EventHandler) error {
- // Periodically refresh configurations
- ticker := time.NewTicker(r.refreshInverval)
- for {
- select {
- case <-pilotChan:
- data, err := r.GetConfigurations()
- if err != nil {
- lager.Logger.Error("pilot pull configuration error" + err.Error())
- continue
- }
- for k, d := range data {
- istio.SaveToEgressCache(map[string][]*config.EgressRule{k: d.([]*config.EgressRule)})
- }
-
- case <-ticker.C:
- data, err := r.refreshConfigurations()
- if err != nil {
- lager.Logger.Error("pilot refresh configuration error" + err.Error())
- continue
- }
- events, err := r.populateEvents(data)
- if err != nil {
- lager.Logger.Warn("populate event error", openlog.WithTags(openlog.Tags{"err": err}))
- return err
- }
- //Generate OnEvent Callback based on the events created
- lager.Logger.Debug(fmt.Sprintf("event On receive %+v", events))
- for _, event := range events {
- callback.OnEvent(event)
- }
- }
- }
- return nil
-}
-
-func (r *pilotSource) refreshConfigurations() (map[string]interface{}, error) {
- data := make(map[string]interface{}, 0)
-
- egressConfigs, err := r.getEgressConfigFromPilot()
- if err != nil {
- lager.Logger.Error("Get egress config from pilot failed" + err.Error())
- return nil, err
- }
-
- data["pilotEgress"] = egressConfigs
- return data, nil
-}
-
-func (r *pilotSource) populateEvents(updates map[string]interface{}) ([]*event.Event, error) {
- events := make([]*event.Event, 0)
- new := make(map[string]interface{})
-
- // generate create and update event
- r.mu.RLock()
- current := r.Configurations
- r.mu.RUnlock()
-
- for key, value := range updates {
- new[key] = value
- currentValue, ok := current[key]
- if !ok { // if new configuration introduced
- events = append(events, constructEvent(event.Create, key, value))
- } else if !reflect.DeepEqual(currentValue, value) {
- events = append(events, constructEvent(event.Update, key, value))
- }
- }
- // generate delete event
- for key, value := range current {
- _, ok := new[key]
- if !ok { // when old config not present in new config
- events = append(events, constructEvent(event.Delete, key, value))
- }
- }
-
- // update with latest config
- r.mu.Lock()
- r.Configurations = new
- r.mu.Unlock()
- return events, nil
-}
-
-func constructEvent(eventType string, key string, value interface{}) *event.Event {
- return &event.Event{
- EventType: eventType,
- EventSource: egressPilotSourceName,
- Value: value,
- Key: key,
- }
-}
-
-// pilotEventListener handle event dispatcher
-type pilotEventListener struct{}
-
-// update egress rule of a service
-func (r *pilotEventListener) Event(e *event.Event) {
- if e == nil {
- lager.Logger.Warn("pilot event pointer is nil", nil)
- return
- }
-
- v := pilotfetcher.GetConfig(e.Key)
- if v == nil {
- istio.SaveToEgressCache(nil)
- return
- }
- egressRules, ok := v.([]*config.EgressRule)
- if !ok {
- lager.Logger.Error("value of pilot is not type []*EgressRule", nil)
- return
- }
-
- ok, _ = egress.ValidateEgressRule(map[string][]*config.EgressRule{e.Key: egressRules})
- if ok {
- istio.SaveToEgressCache(map[string][]*config.EgressRule{e.Key: egressRules})
- lager.Logger.Info(fmt.Sprintf("Update [%s] egress rule of pilot success", e.Key))
- }
-}
diff --git a/proxy/pkg/infras/istio/xds.go b/proxy/pkg/infras/istio/xds.go
deleted file mode 100644
index 8a57ba9..0000000
--- a/proxy/pkg/infras/istio/xds.go
+++ /dev/null
@@ -1,475 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package pilotv2
-
-import (
- "context"
- "crypto/tls"
- "encoding/json"
- "fmt"
- "strings"
-
- k8sinfra "github.com/apache/servicecomb-mesher/proxy/pkg/infras/k8s"
- apiv2 "github.com/envoyproxy/go-control-plane/envoy/api/v2"
- apiv2core "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
- apiv2endpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
- apiv2route "github.com/envoyproxy/go-control-plane/envoy/api/v2/route"
-
- v2 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v2"
- "github.com/go-mesh/openlogging"
- "github.com/gogo/protobuf/proto"
- "google.golang.org/grpc"
- "google.golang.org/grpc/credentials"
- "k8s.io/client-go/rest"
-)
-
-//XdsClient provides the XDS API calls.
-type XdsClient struct {
- PilotAddr string
- TlsConfig *tls.Config
- ReqCaches map[XdsType]*XdsReqCache
- nodeInfo *NodeInfo
- NodeID string
- NodeCluster string
- k8sClient *rest.RESTClient
-}
-
-//XdsType is the wrapper of string, the wrapper type should be "cds", "eds", "lds" or "rds"
-type XdsType string
-
-const (
- TypeCds XdsType = "cds"
- TypeEds XdsType = "eds"
- TypeLds XdsType = "lds"
- TypeRds XdsType = "rds"
-)
-
-//XdsReqCache stores the VersionInfo and Nonce for the XDS calls
-type XdsReqCache struct {
- Nonce string
- VersionInfo string
-}
-
-//NodeInfo stores the info of the node, which will be used to make a
-//XDS call
-type NodeInfo struct {
- PodName string
- Namespace string
- InstanceIP string
-}
-
-//XdsClusterInfo stores all the infos from a cluster name, which is in
-//the format direction|port|subset|hostName
-type XdsClusterInfo struct {
- ClusterName string
- Direction string
- Port string
- Subset string
- HostName string
- ServiceName string
- Namespace string
- DomainSuffix string // DomainSuffix might not be used
- Tags map[string]string
- Addrs []string // The accessible addresses of the endpoints
-}
-
-//NewXdsClient returns the new XDS client.
-func NewXdsClient(pilotAddr string, tlsConfig *tls.Config, nodeInfo *NodeInfo, kubeconfigPath string) (*XdsClient, error) {
- // TODO Handle the array
- xdsClient := &XdsClient{
- PilotAddr: pilotAddr,
- nodeInfo: nodeInfo,
- }
- xdsClient.NodeID = "sidecar~" + nodeInfo.InstanceIP + "~" + nodeInfo.PodName + "~" + nodeInfo.Namespace
- xdsClient.NodeCluster = nodeInfo.PodName
-
- xdsClient.ReqCaches = map[XdsType]*XdsReqCache{
- TypeCds: {},
- TypeEds: {},
- TypeLds: {},
- TypeRds: {},
- }
-
- if k8sClient, err := k8sinfra.CreateK8SRestClient(kubeconfigPath, "apis", "networking.istio.io", "v1alpha3"); err != nil {
- return nil, err
- } else {
- xdsClient.k8sClient = k8sClient
- }
-
- return xdsClient, nil
-}
-
-//GetSubsetTags returns the tags of the specified subset.
-func (client *XdsClient) GetSubsetTags(namespace, hostName, subsetName string) (map[string]string, error) {
- req := client.k8sClient.Get()
- req.Resource("destinationrules")
- req.Namespace(namespace)
-
- result := req.Do()
- rawBody, err := result.Raw()
- if err != nil {
- return nil, err
- }
-
- var drResult k8sinfra.DestinationRuleResult
- if err := json.Unmarshal(rawBody, &drResult); err != nil {
- return nil, err
- }
-
- // Find the subset
- tags := map[string]string{}
- for _, dr := range drResult.Items {
- if dr.Spec.Host == hostName {
- for _, subset := range dr.Spec.Subsets {
- if subset.Name == subsetName {
- for k, v := range subset.Labels {
- tags[k] = v
- }
- break
- }
- }
- break
- }
- }
-
- return tags, nil
-}
-
-func (client *XdsClient) getGrpcConn() (*grpc.ClientConn, error) {
- var conn *grpc.ClientConn
- var err error
- if client.TlsConfig != nil {
- creds := credentials.NewTLS(client.TlsConfig)
- conn, err = grpc.Dial(client.PilotAddr, grpc.WithTransportCredentials(creds))
- } else {
- conn, err = grpc.Dial(client.PilotAddr, grpc.WithInsecure())
- }
-
- return conn, err
-}
-
-func getAdsResClient(client *XdsClient) (v2.AggregatedDiscoveryService_StreamAggregatedResourcesClient, *grpc.ClientConn, error) {
- conn, err := client.getGrpcConn()
- if err != nil {
- return nil, nil, err
- }
-
- adsClient := v2.NewAggregatedDiscoveryServiceClient(conn)
- adsResClient, err := adsClient.StreamAggregatedResources(context.Background())
- if err != nil {
- return nil, nil, err
- }
-
- return adsResClient, conn, nil
-}
-
-func (client *XdsClient) getRouterClusters(clusterName string) ([]string, error) {
- virtualHosts, err := client.RDS(clusterName)
- if err != nil {
- return nil, err
- }
-
- routerClusters := []string{}
- for _, h := range virtualHosts {
- for _, r := range h.Routes {
- routerClusters = append(routerClusters, r.GetRoute().GetCluster())
- }
- }
-
- return routerClusters, nil
-}
-
-func (client *XdsClient) getVersionInfo(resType XdsType) string {
- return client.ReqCaches[resType].VersionInfo
-}
-func (client *XdsClient) getNonce(resType XdsType) string {
- return client.ReqCaches[resType].Nonce
-}
-
-func (client *XdsClient) setVersionInfo(resType XdsType, versionInfo string) {
- client.ReqCaches[resType].VersionInfo = versionInfo
-}
-
-func (client *XdsClient) setNonce(resType XdsType, nonce string) {
- client.ReqCaches[resType].Nonce = nonce
-}
-
-//CDS s the Clsuter Discovery Service API, which fetches all the clusters from istio pilot
-func (client *XdsClient) CDS() ([]apiv2.Cluster, error) {
- adsResClient, conn, err := getAdsResClient(client)
- if err != nil {
- return nil, err
- }
- defer conn.Close()
-
- req := &apiv2.DiscoveryRequest{
- TypeUrl: "type.googleapis.com/envoy.api.v2.Cluster",
- VersionInfo: client.getVersionInfo(TypeCds),
- ResponseNonce: client.getNonce(TypeCds),
- }
- req.Node = &apiv2core.Node{
- // Sample taken from istio: router~172.30.77.6~istio-egressgateway-84b4d947cd-rqt45.istio-system~istio-system.svc.cluster.local-2
- // The Node.Id should be in format {nodeType}~{ipAddr}~{serviceId~{domain}, splitted by '~'
- // The format is required by pilot
- Id: client.NodeID,
- Cluster: client.NodeCluster,
- }
-
- if err := adsResClient.Send(req); err != nil {
- return nil, err
- }
-
- resp, err := adsResClient.Recv()
- if err != nil {
- return nil, err
- }
-
- client.setNonce(TypeCds, resp.GetNonce())
- client.setVersionInfo(TypeCds, resp.GetVersionInfo())
- resources := resp.GetResources()
-
- var cluster apiv2.Cluster
- clusters := []apiv2.Cluster{}
- for _, res := range resources {
- if err := proto.Unmarshal(res.GetValue(), &cluster); err != nil {
- openlogging.GetLogger().Warnf("Failed to unmarshal cluster resource: %s", err.Error())
- } else {
- clusters = append(clusters, cluster)
- }
- }
- return clusters, nil
-}
-
-//EDS is the Endpoint Discovery Service API, the API takes the cluster's name and return all its endpoints(which provide address and port)
-func (client *XdsClient) EDS(clusterName string) (*apiv2.ClusterLoadAssignment, error) {
- adsResClient, conn, err := getAdsResClient(client)
- if err != nil {
- return nil, err
- }
- defer conn.Close()
-
- req := &apiv2.DiscoveryRequest{
- TypeUrl: "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment",
- VersionInfo: client.getVersionInfo(TypeEds),
- ResponseNonce: client.getNonce(TypeEds),
- }
-
- req.Node = &apiv2core.Node{
- Id: client.NodeID,
- Cluster: client.NodeCluster,
- }
- req.ResourceNames = []string{clusterName}
- if err := adsResClient.Send(req); err != nil {
- return nil, err
- }
-
- resp, err := adsResClient.Recv()
- if err != nil {
- return nil, err
- }
-
- resources := resp.GetResources()
- client.setNonce(TypeEds, resp.GetNonce())
- client.setVersionInfo(TypeEds, resp.GetVersionInfo())
-
- var loadAssignment apiv2.ClusterLoadAssignment
- var e error
- // endpoints := []apiv2.ClusterLoadAssignment{}
-
- for _, res := range resources {
- if err := proto.Unmarshal(res.GetValue(), &loadAssignment); err != nil {
- e = err
- } else {
- // The cluster's LoadAssignment will always be ONE, with Endpoints as its field
- break
- }
- }
- return &loadAssignment, e
-}
-
-//GetEndpointsByTags fetches the cluster's endpoints with tags. The tags is usually specified in a DestinationRule.
-func (client *XdsClient) GetEndpointsByTags(serviceName string, tags map[string]string) ([]*apiv2endpoint.LbEndpoint, string, error) {
- clusters, err := client.CDS()
- if err != nil {
- return nil, "", err
- }
-
- lbendpoints := []*apiv2endpoint.LbEndpoint{}
- clusterName := ""
- for _, cluster := range clusters {
- clusterInfo := ParseClusterName(cluster.Name)
- if clusterInfo == nil || clusterInfo.Subset == "" || clusterInfo.ServiceName != serviceName {
- continue
- }
- // So clusterInfo is not nil and subset is not empty
- if subsetTags, err := client.GetSubsetTags(clusterInfo.Namespace, clusterInfo.ServiceName, clusterInfo.Subset); err == nil {
- // filter with tags
- matched := true
- for k, v := range tags {
- if subsetTagValue, exists := subsetTags[k]; exists == false || subsetTagValue != v {
- matched = false
- break
- }
- }
-
- if matched { // We got the cluster!
- clusterName = cluster.Name
- loadAssignment, err := client.EDS(cluster.Name)
- if err != nil {
- return nil, clusterName, err
- }
-
- for _, item := range loadAssignment.Endpoints {
- lbendpoints = append(lbendpoints, item.LbEndpoints...)
- }
-
- return lbendpoints, clusterName, nil
- }
- }
- }
-
- return lbendpoints, clusterName, nil
-}
-
-//RDS is the Router Discovery Service API, it returns the virtual hosts which contains Routes
-func (client *XdsClient) RDS(clusterName string) ([]*apiv2route.VirtualHost, error) {
- clusterInfo := ParseClusterName(clusterName)
- if clusterInfo == nil {
- return nil, fmt.Errorf("Invalid clusterName for routers: %s", clusterName)
- }
-
- adsResClient, conn, err := getAdsResClient(client)
- if err != nil {
- return nil, err
- }
- defer conn.Close()
-
- req := &apiv2.DiscoveryRequest{
- TypeUrl: "type.googleapis.com/envoy.api.v2.RouteConfiguration",
- VersionInfo: client.getVersionInfo(TypeRds),
- ResponseNonce: client.getNonce(TypeRds),
- }
-
- req.Node = &apiv2core.Node{
- Id: client.NodeID,
- Cluster: client.NodeCluster,
- }
- req.ResourceNames = []string{clusterName}
- if err := adsResClient.Send(req); err != nil {
- return nil, err
- }
-
- resp, err := adsResClient.Recv()
- if err != nil {
- return nil, err
- }
-
- resources := resp.GetResources()
- client.setNonce(TypeRds, resp.GetNonce())
- client.setVersionInfo(TypeRds, resp.GetVersionInfo())
-
- var route apiv2.RouteConfiguration
- virtualHosts := []*apiv2route.VirtualHost{}
-
- for _, res := range resources {
- if err := proto.Unmarshal(res.GetValue(), &route); err != nil {
- openlogging.GetLogger().Warnf("Failed to unmarshal router resource: ", err.Error())
- } else {
- vhosts := route.GetVirtualHosts()
- for _, vhost := range vhosts {
- if vhost.Name == clusterInfo.ServiceName+":"+clusterInfo.Port {
- virtualHosts = append(virtualHosts, vhost)
- }
- }
- }
- }
- return virtualHosts, nil
-}
-
-//LDS is the Listener Discovery Service API, which returns all the listerns
-func (client *XdsClient) LDS() ([]apiv2.Listener, error) {
- adsResClient, conn, err := getAdsResClient(client)
- if err != nil {
- return nil, err
- }
- defer conn.Close()
-
- req := &apiv2.DiscoveryRequest{
- TypeUrl: "type.googleapis.com/envoy.api.v2.Listener",
- VersionInfo: client.getVersionInfo(TypeLds),
- ResponseNonce: client.getNonce(TypeLds),
- }
-
- req.Node = &apiv2core.Node{
- Id: client.NodeID,
- Cluster: client.NodeCluster,
- }
- if err := adsResClient.Send(req); err != nil {
- return nil, err
- }
-
- resp, err := adsResClient.Recv()
- if err != nil {
- return nil, err
- }
-
- resources := resp.GetResources()
- client.setNonce(TypeLds, resp.GetNonce())
- client.setVersionInfo(TypeLds, resp.GetVersionInfo())
-
- var listener apiv2.Listener
- listeners := []apiv2.Listener{}
-
- for _, res := range resources {
- if err := proto.Unmarshal(res.GetValue(), &listener); err != nil {
- openlogging.GetLogger().Warnf("Failed to unmarshal listener resource: ", err.Error())
- } else {
- listeners = append(listeners, listener)
- }
- }
- return listeners, nil
-}
-
-//ParseClusterName parse the cluster's name, which is in the format direction|port|subset|hostName, the 4 items will be parsed into different fields. The hostName item will also be parsed into ServcieName, Namespace etc.
-func ParseClusterName(clusterName string) *XdsClusterInfo {
- // clusterName format: direction|port|subset|hostName
- // hostName format: |svc.namespace.svc.cluster.local
-
- parts := strings.Split(clusterName, "|")
- if len(parts) != 4 {
- return nil
- }
-
- hostnameParts := strings.Split(parts[3], ".")
- if len(hostnameParts) < 2 {
- return nil
- }
-
- cluster := &XdsClusterInfo{
- Direction: parts[0],
- Port: parts[1],
- Subset: parts[2],
- HostName: parts[3],
- ServiceName: hostnameParts[0],
- Namespace: hostnameParts[1],
- DomainSuffix: strings.Join(hostnameParts[2:], "."),
- ClusterName: clusterName,
- }
-
- return cluster
-}
diff --git a/proxy/pkg/infras/istio/xds_test.go b/proxy/pkg/infras/istio/xds_test.go
deleted file mode 100644
index 2f1c1b2..0000000
--- a/proxy/pkg/infras/istio/xds_test.go
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package pilotv2
-
-import (
- "github.com/go-chassis/go-chassis/core/lager"
- "os"
- "os/user"
- "testing"
- "time"
-
- apiv2 "github.com/envoyproxy/go-control-plane/envoy/api/v2"
- "github.com/go-chassis/go-chassis/pkg/util/iputil"
-)
-
-const (
- TEST_POD_NAME = "testpod"
- NAMESPACE_DEFAULT = "default"
-)
-
-var (
- ValidXdsClient *XdsClient
- TestClusters []apiv2.Cluster
-)
-var (
- KubeConfig string
- ValidPilotAddr string
- LocalIPAddress string
- nodeInfo *NodeInfo
-
- err error
-)
-
-func init() {
- lager.Init(&lager.Options{LoggerLevel: "DEBUG"})
-}
-func TestXdsClient_CDS(t *testing.T) {
- // Get kube config path and local ip
- if KUBE_CONFIG := os.Getenv("KUBE_CONFIG"); KUBE_CONFIG != "" {
- KubeConfig = KUBE_CONFIG
- } else {
- usr, err := user.Current()
- if err != nil {
- panic("Failed to get current user info: " + err.Error())
- } else {
- KubeConfig = usr.HomeDir + "/" + ".kube/config"
- }
- }
- ValidPilotAddr = "localhost:15010"
- if PILOT_ADDR := os.Getenv("PILOT_ADDR"); PILOT_ADDR != "" {
- ValidPilotAddr = PILOT_ADDR
- }
-
- if INSTANCE_IP := os.Getenv("INSTANCE_IP"); INSTANCE_IP != "" {
- LocalIPAddress = INSTANCE_IP
- } else if LocalIPAddress = iputil.GetLocalIP(); LocalIPAddress == "" {
- panic("Failed to get the local ip address, please check the network environment")
- }
-
- nodeInfo = &NodeInfo{
- PodName: TEST_POD_NAME,
- Namespace: NAMESPACE_DEFAULT,
- InstanceIP: LocalIPAddress,
- }
-}
-
-func TestNewXdsClient(t *testing.T) {
- client, err := NewXdsClient(ValidPilotAddr, nil, nodeInfo, KubeConfig)
-
- if err != nil {
- t.Errorf("Failed to create xds client: %s", err.Error())
- }
-
- ValidXdsClient = client
-}
-
-func TestCDS(t *testing.T) {
- clusters, err := ValidXdsClient.CDS()
- if err != nil {
- t.Errorf("Failed to get clusters by CDS: %s", err.Error())
- }
-
- t.Logf("Got %d clusters\n", len(clusters))
- TestClusters = clusters
-}
-
-func TestEDS(t *testing.T) {
- if len(TestClusters) == 0 { // With istio, there should always be clusters
- t.Errorf("No clusters found")
- }
-
- loadAssignment, err := ValidXdsClient.EDS(TestClusters[0].Name)
- if err != nil {
- t.Errorf("Failed to get endpoints by EDS: %s", err.Error())
- }
-
- if loadAssignment == nil {
- t.Errorf("Failed to get load assginment with EDS: %s", err.Error())
- }
-}
-
-func TestRDS(t *testing.T) {
- targetClusterName := ""
- for _, c := range TestClusters {
- info := ParseClusterName(c.Name)
- if info != nil {
- targetClusterName = c.Name
- break
- }
- }
-
- if targetClusterName == "" {
- t.Log("We don't find a valid cluster")
- }
-
- _, err := ValidXdsClient.RDS(targetClusterName)
- if err != nil {
- t.Errorf("Failed to get routers: %s", err.Error())
- }
-}
-
-func TestLDS(t *testing.T) {
- listeners, err := ValidXdsClient.LDS()
- if err != nil {
- t.Errorf("Failed to get listeners with LDS: %s", err.Error())
- }
-
- t.Logf("%d listeners found\n", len(listeners))
-}
-
-func TestNonce(t *testing.T) {
- nowStr := time.Now().String()
- ValidXdsClient.setNonce(TypeCds, nowStr)
- ValidXdsClient.setNonce(TypeEds, nowStr)
- ValidXdsClient.setNonce(TypeRds, nowStr)
- ValidXdsClient.setNonce(TypeLds, nowStr)
-
- cdsNonce := ValidXdsClient.getNonce(TypeCds)
- if cdsNonce != nowStr {
- t.Errorf("Failed to test nonce: %s should be equal to %s", cdsNonce, nowStr)
- }
-
- edsNonce := ValidXdsClient.getNonce(TypeEds)
- if edsNonce != nowStr {
- t.Errorf("Failed to test nonce: %s should be equal to %s", edsNonce, nowStr)
- }
-
- ldsNonce := ValidXdsClient.getNonce(TypeLds)
- if ldsNonce != nowStr {
- t.Errorf("Failed to test nonce: %s should be equal to %s", ldsNonce, nowStr)
- }
-
- rdsNonce := ValidXdsClient.getNonce(TypeRds)
- if rdsNonce != nowStr {
- t.Errorf("Failed to test nonce: %s should be equal to %s", rdsNonce, nowStr)
- }
-}
-
-func TestVersionInfo(t *testing.T) {
- nowStr := time.Now().String()
- ValidXdsClient.setVersionInfo(TypeCds, nowStr)
- ValidXdsClient.setVersionInfo(TypeEds, nowStr)
- ValidXdsClient.setVersionInfo(TypeRds, nowStr)
- ValidXdsClient.setVersionInfo(TypeLds, nowStr)
-
- cdsVersionInfo := ValidXdsClient.getVersionInfo(TypeCds)
- if cdsVersionInfo != nowStr {
- t.Errorf("Failed to test VersionInfo: %s should be equal to %s", cdsVersionInfo, nowStr)
- }
-
- edsVersionInfo := ValidXdsClient.getVersionInfo(TypeEds)
- if edsVersionInfo != nowStr {
- t.Errorf("Failed to test VersionInfo: %s should be equal to %s", edsVersionInfo, nowStr)
- }
-
- ldsVersionInfo := ValidXdsClient.getVersionInfo(TypeLds)
- if ldsVersionInfo != nowStr {
- t.Errorf("Failed to test VersionInfo: %s should be equal to %s", ldsVersionInfo, nowStr)
- }
-
- rdsVersionInfo := ValidXdsClient.getVersionInfo(TypeRds)
- if rdsVersionInfo != nowStr {
- t.Errorf("Failed to test VersionInfo: %s should be equal to %s", rdsVersionInfo, nowStr)
- }
-}
-
-func TestGetSubsetTags(t *testing.T) {
- var targetClusterInfo *XdsClusterInfo = nil
- for _, c := range TestClusters {
- if info := ParseClusterName(c.Name); info != nil && info.Subset != "" {
- targetClusterInfo = info
- break
- }
- }
-
- if targetClusterInfo == nil {
- t.Log("No tagged services in test environment, skip")
- } else {
- tags, err := ValidXdsClient.GetSubsetTags(targetClusterInfo.Namespace, targetClusterInfo.ServiceName, targetClusterInfo.Subset)
- if err != nil {
- t.Logf("Failed to get subset tags: %s", err.Error())
- } else if len(tags) == 0 {
- t.Logf("Should not return empty tags %s", targetClusterInfo.ClusterName)
- }
- }
-}
-
-func TestGetAdsResClient(t *testing.T) {
- _, conn, err := getAdsResClient(ValidXdsClient)
-
- if err != nil {
- t.Errorf("Failed to get ads resource client: %s", err.Error())
- }
- conn.Close()
-}
-
-func TestParseClusterName(t *testing.T) {
- validClusterName := "inbound|3030||client.default.svc.cluster.local"
-
- clusterInfo := ParseClusterName(validClusterName)
-
- if clusterInfo == nil {
- t.Errorf("Failed to parse cluster name: %s, should return cluster info", validClusterName)
- }
- if clusterInfo.Direction != "inbound" {
- t.Errorf("Failed to parse cluster name: %s, direction should be inbound", validClusterName)
- }
- if clusterInfo.Port != "3030" {
- t.Errorf("Failed to parse cluster name: %s, port should be 3030", validClusterName)
- }
- if clusterInfo.ServiceName != "client" {
- t.Errorf("Failed to parse cluster name: %s, servicename should be client", validClusterName)
- }
-
- invalidClusterName := "BlackHoleCluster"
- clusterInfo = ParseClusterName(invalidClusterName)
- if clusterInfo != nil {
- t.Errorf("Failed to parse cluster name: %s, should return nil", validClusterName)
- }
-
- invalidClusterName = "outbound|9080|v2|black"
- clusterInfo = ParseClusterName(invalidClusterName)
- if clusterInfo != nil {
- t.Errorf("Failed to parse cluster name: %s, should return nil", validClusterName)
- }
-}
diff --git a/proxy/pkg/metrics/metrics.go b/proxy/pkg/metrics/metrics.go
index ffd4859..07d11aa 100644
--- a/proxy/pkg/metrics/metrics.go
+++ b/proxy/pkg/metrics/metrics.go
@@ -23,7 +23,7 @@
package metrics
import (
- "github.com/go-chassis/go-chassis/pkg/runtime"
+ "github.com/go-chassis/go-chassis/v2/pkg/runtime"
"sync"
"time"
)
diff --git a/proxy/pkg/metrics/metrics_test.go b/proxy/pkg/metrics/metrics_test.go
index f61acbe..302d6ca 100644
--- a/proxy/pkg/metrics/metrics_test.go
+++ b/proxy/pkg/metrics/metrics_test.go
@@ -25,7 +25,7 @@
"testing"
"github.com/apache/servicecomb-mesher/proxy/pkg/metrics"
- "github.com/go-chassis/go-chassis/pkg/runtime"
+ "github.com/go-chassis/go-chassis/v2/pkg/runtime"
)
func TestInit(t *testing.T) {
diff --git a/proxy/pkg/metrics/prometheus_exporter.go b/proxy/pkg/metrics/prometheus_exporter.go
index 864e611..f0cfe2e 100644
--- a/proxy/pkg/metrics/prometheus_exporter.go
+++ b/proxy/pkg/metrics/prometheus_exporter.go
@@ -19,8 +19,8 @@
import (
"fmt"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/pkg/metrics"
+ "github.com/go-chassis/go-chassis/v2/pkg/metrics"
+ "github.com/go-chassis/openlog"
"github.com/prometheus/client_golang/prometheus"
"runtime"
"sync"
@@ -128,6 +128,6 @@
if r := recover(); r != nil {
pc := make([]uintptr, 10)
runtime.Callers(1, pc)
- lager.Logger.Warn(fmt.Sprintf("panics while registering metric [%s] to prometheus %s", metricName, r))
+ openlog.Warn(fmt.Sprintf("panics while registering metric [%s] to prometheus %s", metricName, r))
}
}
diff --git a/proxy/pkg/ports/protocol.go b/proxy/pkg/ports/protocol.go
index 179cb20..91fd0a9 100644
--- a/proxy/pkg/ports/protocol.go
+++ b/proxy/pkg/ports/protocol.go
@@ -17,7 +17,7 @@
package ports
-import "github.com/go-chassis/go-chassis/core/common"
+import "github.com/go-chassis/go-chassis/v2/core/common"
var defaultProtocolPort = map[string]string{
common.ProtocolRest: "30101",
diff --git a/proxy/pkg/skywalking/skywalking_manager.go b/proxy/pkg/skywalking/skywalking_manager.go
index a660528..ed0b742 100644
--- a/proxy/pkg/skywalking/skywalking_manager.go
+++ b/proxy/pkg/skywalking/skywalking_manager.go
@@ -19,10 +19,11 @@
import (
"context"
+ "fmt"
"github.com/apache/servicecomb-mesher/proxy/config"
- gcconfig "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-mesh/openlogging"
+ gcconfig "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/openlog"
"github.com/tetratelabs/go2sky"
"github.com/tetratelabs/go2sky/reporter"
)
@@ -60,7 +61,7 @@
//Init skywalking manager
func Init() {
- openlogging.GetLogger().Debugf("SkyWalking manager Init begin config:%#v", config.GetConfig().ServiceComb.APM)
+ openlog.Debug(fmt.Sprintf("SkyWalking manager Init begin config:%#v", config.GetConfig().ServiceComb.APM))
var err error
serverURI := DeafaultSWServerURI
if config.GetConfig().ServiceComb.APM.Tracing.ServerURI != "" && config.GetConfig().ServiceComb.APM.Tracing.Enable {
@@ -68,12 +69,12 @@
}
r, err = reporter.NewGRPCReporter(serverURI)
if err != nil {
- openlogging.GetLogger().Errorf("NewGRPCReporter error:%s ", err.Error())
+ openlog.Error(fmt.Sprintf("NewGRPCReporter error:%s ", err.Error()))
}
tracer, err = go2sky.NewTracer(gcconfig.MicroserviceDefinition.Name, go2sky.WithReporter(r))
if err != nil {
- openlogging.GetLogger().Errorf("NewTracer error " + err.Error())
+ openlog.Error(fmt.Sprintf("NewTracer error " + err.Error()))
}
//tracer.WaitUntilRegister()
- openlogging.GetLogger().Debugf("SkyWalking manager Init end")
+ openlog.Debug(fmt.Sprintf("SkyWalking manager Init end"))
}
diff --git a/proxy/pkg/skywalking/skywalking_manager_test.go b/proxy/pkg/skywalking/skywalking_manager_test.go
index 19e143c..4d04d6a 100644
--- a/proxy/pkg/skywalking/skywalking_manager_test.go
+++ b/proxy/pkg/skywalking/skywalking_manager_test.go
@@ -21,9 +21,9 @@
"context"
"github.com/apache/servicecomb-mesher/proxy/config"
"github.com/apache/servicecomb-mesher/proxy/pkg/skywalking"
- gcconfig "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/invocation"
+ gcconfig "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
"github.com/stretchr/testify/assert"
"testing"
)
diff --git a/proxy/plugins/registry/README.md b/proxy/plugins/registry/README.md
deleted file mode 100644
index 49e13df..0000000
--- a/proxy/plugins/registry/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# registry
\ No newline at end of file
diff --git a/proxy/plugins/registry/istiov2/cache.go b/proxy/plugins/registry/istiov2/cache.go
deleted file mode 100644
index 9d7c07f..0000000
--- a/proxy/plugins/registry/istiov2/cache.go
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package istiov2
-
-import (
- "fmt"
- "strconv"
- "strings"
- "sync"
- "time"
-
- istioinfra "github.com/apache/servicecomb-mesher/proxy/pkg/infras/istio"
- apiv2endpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
-
- "github.com/go-chassis/go-archaius"
- "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/registry"
-)
-
-const (
- DefaultRefreshInterval = time.Second * 30
-)
-
-var simpleCache *EndpointCache
-
-func init() {
- simpleCache = &EndpointCache{
- cache: map[string]EndpointSubset{},
- }
-}
-
-//CacheManager manages the caches for istio pilot results.
-type CacheManager struct {
- xdsClient *istioinfra.XdsClient
-}
-
-//AutoSync fetches and updates the cluster and endpoint info periodically
-func (cm *CacheManager) AutoSync() {
- cm.refreshCache()
-
- var ticker *time.Ticker
- refreshInterval := config.GetServiceDiscoveryRefreshInterval()
- if refreshInterval == "" {
- ticker = time.NewTicker(DefaultRefreshInterval)
- } else {
- timeValue, err := time.ParseDuration(refreshInterval)
- if err != nil {
- lager.Logger.Error(fmt.Sprintf("refeshInterval is invalid. So use Default value: %s", err.Error()))
- timeValue = DefaultRefreshInterval
- }
-
- ticker = time.NewTicker(timeValue)
- }
- go func() {
- for range ticker.C {
- cm.refreshCache()
- }
- }()
-}
-
-func (cm *CacheManager) refreshCache() {
- // TODO What is the design of autodiscovery
- if archaius.GetBool("cse.service.registry.autodiscovery", false) {
- lager.Logger.Error("SyncPilotEndpoints failed: not supported")
- }
-
- err := cm.pullMicroserviceInstance()
- if err != nil {
- lager.Logger.Error(fmt.Sprintf("AutoUpdateMicroserviceInstance failed: %s", err.Error()))
- }
-
- if archaius.GetBool("cse.service.registry.autoSchemaIndex", false) {
- lager.Logger.Error("MakeSchemaIndex failed: Not support operation")
- }
-
- if archaius.GetBool("cse.service.registry.autoIPIndex", false) {
- err = cm.MakeIPIndex()
- if err != nil {
- lager.Logger.Error(fmt.Sprintf("Auto Update IP index failed: %s", err.Error()))
- }
- }
-}
-
-func (cm *CacheManager) pullMicroserviceInstance() error {
- clusterInfos, err := cm.getClusterInfos()
- if err != nil {
- return err
- }
-
- for _, clusterInfo := range clusterInfos {
- if clusterInfo.Subset != "" {
- // Update the cache
- instances := []*registry.MicroServiceInstance{}
- for _, addr := range clusterInfo.Addrs {
- msi := ®istry.MicroServiceInstance{}
- msi.InstanceID = strings.Replace(addr, ":", "_", 0)
- msi.HostName = clusterInfo.ClusterName
- msi.EndpointsMap = map[string]*registry.Endpoint{
- common.ProtocolRest: {Address: addr},
- }
- msi.DefaultEndpoint = addr
- msi.DefaultProtocol = common.ProtocolRest
- msi.Metadata = clusterInfo.Tags
-
- instances = append(instances, msi)
- }
-
- endpointSubset := EndpointSubset{
- tags: clusterInfo.Tags,
- instances: instances,
- subsetName: clusterInfo.Subset,
- }
- simpleCache.Set(clusterInfo.ClusterName, endpointSubset)
- }
- }
-
- return nil
-}
-
-//MakeIPIndex caches the cluster info with address as the key
-func (cm *CacheManager) MakeIPIndex() error {
- // TODO Use getClusterInfo to replace the logic
- clusterInfos, err := cm.getClusterInfos()
- if err != nil {
- return err
- }
-
- for _, clusterInfo := range clusterInfos {
- for _, addr := range clusterInfo.Addrs {
- si := ®istry.SourceInfo{}
- // TODO Get tags by subset and put them into si.Tags
- si.Name = clusterInfo.ClusterName
- si.Tags = clusterInfo.Tags
- registry.SetIPIndex(addr, si)
- // TODO Why don't we have to index every endpoint?
- // break
- }
- }
-
- return nil
-}
-
-//NewCacheManager creates the CacheManager instance.
-func NewCacheManager(xdsClient *istioinfra.XdsClient) (*CacheManager, error) {
- cacheManager := &CacheManager{
- xdsClient: xdsClient,
- }
-
- return cacheManager, nil
-}
-
-func (cm *CacheManager) getClusterInfos() ([]istioinfra.XdsClusterInfo, error) {
- clusterInfos := []istioinfra.XdsClusterInfo{}
-
- clusters, err := cm.xdsClient.CDS()
- if err != nil {
- return nil, err
- }
-
- for _, cluster := range clusters {
- // xDS v2 API: CDS won't obtain the cluster's endpoints, call EDS to get the endpoints
-
- clusterInfo := istioinfra.ParseClusterName(cluster.Name)
- if clusterInfo == nil {
- continue
- }
-
- // Get Tags
- if clusterInfo.Subset != "" { // Only clusters with subset contain labels
- if tags, err := cm.xdsClient.GetSubsetTags(clusterInfo.Namespace, clusterInfo.ServiceName, clusterInfo.Subset); err == nil {
- clusterInfo.Tags = tags
- }
- }
-
- // Get cluster instances' addresses
- loadAssignment, err := cm.xdsClient.EDS(cluster.Name)
- if err != nil {
- return nil, err
- }
- endpoints := loadAssignment.Endpoints
- for _, endpoint := range endpoints {
- for _, lbendpoint := range endpoint.LbEndpoints {
- socketAddress := lbendpoint.Endpoint.Address.GetSocketAddress()
- addr := socketAddress.GetAddress()
- port := socketAddress.GetPortValue()
- ipAddr := addr + ":" + strconv.FormatUint(uint64(port), 10)
- clusterInfo.Addrs = append(clusterInfo.Addrs, ipAddr)
- }
- }
-
- clusterInfos = append(clusterInfos, *clusterInfo)
- }
- return clusterInfos, nil
-}
-
-// TODO Cache with registry index cache
-func updateInstanceIndexCache(lbendpoints []apiv2endpoint.LbEndpoint, clusterName string, tags map[string]string) {
- if len(lbendpoints) == 0 {
- simpleCache.Delete(clusterName)
- return
- }
-
- instances := make([]*registry.MicroServiceInstance, 0, len(lbendpoints))
- for _, lbendpoint := range lbendpoints {
- msi := toMicroServiceInstance(clusterName, &lbendpoint, tags)
- instances = append(instances, msi)
- }
- subset := EndpointSubset{
- tags: tags,
- instances: instances,
- }
-
- info := istioinfra.ParseClusterName(clusterName)
- if info != nil {
- subset.subsetName = info.Subset
- }
-
- simpleCache.Set(clusterName, subset)
-}
-
-//EndpointCache caches the clusters' endpoint and tags
-type EndpointCache struct {
- mux sync.Mutex
- cache map[string]EndpointSubset
-}
-
-//EndpointSubset stores the tags and instances of a service
-type EndpointSubset struct {
- subsetName string
- tags map[string]string
- instances []*registry.MicroServiceInstance
-}
-
-//Delete removes the cached instances of the specified cluster
-func (c *EndpointCache) Delete(clusterName string) {
- c.mux.Lock()
- delete(c.cache, clusterName)
- c.mux.Unlock()
-}
-
-//Set updates the cluster's instance info
-func (c *EndpointCache) Set(clusterName string, subset EndpointSubset) {
- c.mux.Lock()
- c.cache[clusterName] = subset
- c.mux.Unlock()
-}
-
-//GetWithTags returns the instances of the service, filtered with tags
-func (c *EndpointCache) GetWithTags(serviceName string, tags map[string]string) []*registry.MicroServiceInstance {
- // Get subsets whose clusterName matches the service name
- matchedSubsets := []EndpointSubset{}
- c.mux.Lock()
- for clusterName, subset := range c.cache {
- info := istioinfra.ParseClusterName(clusterName)
- if info != nil && info.ServiceName == serviceName {
- matchedSubsets = append(matchedSubsets, subset)
- }
- }
- c.mux.Unlock()
-
- if len(matchedSubsets) == 0 {
- return nil
- }
-
- var instances []*registry.MicroServiceInstance
-
- for _, subset := range matchedSubsets {
- if tagsMatch(subset.tags, tags) {
- instances = subset.instances
- break
- }
-
- }
- return instances
-}
-
-// TODO There might be some utils in go-chassis doing the same thing
-func tagsMatch(tags, targetTags map[string]string) bool {
- matched := true
- for k, v := range targetTags {
- if val, exists := tags[k]; !exists || val != v {
- matched = false
- break
- }
- }
- return matched
-}
diff --git a/proxy/plugins/registry/istiov2/cache_test.go b/proxy/plugins/registry/istiov2/cache_test.go
deleted file mode 100644
index 7f26707..0000000
--- a/proxy/plugins/registry/istiov2/cache_test.go
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package istiov2
-
-import (
- "os"
- "os/user"
- "testing"
-
- istioinfra "github.com/apache/servicecomb-mesher/proxy/pkg/infras/istio"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/registry"
- "github.com/go-chassis/go-chassis/pkg/util/iputil"
-)
-
-const (
- TEST_POD_NAME = "testpod"
- NAMESPACE_DEFAULT = "default"
-)
-
-var (
- KubeConfig string
- ValidPilotAddr string
- LocalIPAddress string
- nodeInfo *istioinfra.NodeInfo
-
- testXdsClient *istioinfra.XdsClient
- testCacheManager *CacheManager
- err error
-)
-
-func init() {
- lager.Init(&lager.Options{LoggerLevel: "DEBUG"})
-}
-func TestNewCacheManager2(t *testing.T) {
- // Get kube config path and local ip
- if KUBE_CONFIG := os.Getenv("KUBE_CONFIG"); KUBE_CONFIG != "" {
- KubeConfig = KUBE_CONFIG
- } else {
- usr, err := user.Current()
- if err != nil {
- panic("Failed to get current user info: " + err.Error())
- } else {
- KubeConfig = usr.HomeDir + "/" + ".kube/config"
- }
- }
-
- ValidPilotAddr = "localhost:15010"
- if PILOT_ADDR := os.Getenv("PILOT_ADDR"); PILOT_ADDR != "" {
- ValidPilotAddr = PILOT_ADDR
- }
-
- if INSTANCE_IP := os.Getenv("INSTANCE_IP"); INSTANCE_IP != "" {
- LocalIPAddress = INSTANCE_IP
- } else if LocalIPAddress = iputil.GetLocalIP(); LocalIPAddress == "" {
- panic("Failed to get the local ip address, please check the network environment")
- }
-
- nodeInfo = &istioinfra.NodeInfo{
- PodName: TEST_POD_NAME,
- Namespace: NAMESPACE_DEFAULT,
- InstanceIP: LocalIPAddress,
- }
-
- testXdsClient, err = istioinfra.NewXdsClient(ValidPilotAddr, nil, nodeInfo, KubeConfig)
- if err != nil {
- panic("Failed to prepare test, xds client creation failed: " + err.Error())
- }
-}
-
-func TestNewCacheManager(t *testing.T) {
- testCacheManager, err = NewCacheManager(testXdsClient)
- if err != nil {
- t.Errorf("Failed to create CacheManager: %s", err.Error())
- }
-}
-
-// func TestAutoSync(t *testing.T) {
-// testCacheManager.AutoSync()
-// }
-
-func TestPullMicroserviceInstance(t *testing.T) {
- err = testCacheManager.pullMicroserviceInstance()
- if err != nil {
- t.Errorf("Failed to pull microservice instances: %s", err.Error())
- }
-}
-
-// func TestMakeIPIndex(t *testing.T) {
-// err := testCacheManager.MakeIPIndex()
-// if err != nil {
-// t.Errorf("Failed to make ip index: %s", err.Error())
-// }
-// }
-
-func TestEndpointCache(t *testing.T) {
- ec := EndpointCache{
- cache: map[string]EndpointSubset{},
- }
-
- subset := EndpointSubset{
- subsetName: "foo",
- tags: map[string]string{},
- instances: []*registry.MicroServiceInstance{},
- }
-
- defer func() {
- if r := recover(); r != nil {
- t.Error("should not panic")
- }
- }()
-
- waitChannel := make(chan int)
- for i := 0; i < 1000; i++ {
- go func() {
- ec.Set("foo", subset)
- waitChannel <- 0
-
- }()
- }
-
- for i := 0; i < 1000; i++ {
- <-waitChannel
- }
-}
diff --git a/proxy/plugins/registry/istiov2/registry.go b/proxy/plugins/registry/istiov2/registry.go
deleted file mode 100644
index da46c7f..0000000
--- a/proxy/plugins/registry/istiov2/registry.go
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package istiov2
-
-import (
- "fmt"
- "log"
- "os"
- "strconv"
- "strings"
-
- istioinfra "github.com/apache/servicecomb-mesher/proxy/pkg/infras/istio"
- apiv2 "github.com/envoyproxy/go-control-plane/envoy/api/v2"
- apiv2endpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
-
- "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/metadata"
- "github.com/go-chassis/go-chassis/core/registry"
- "github.com/go-chassis/go-chassis/pkg/util/iputil"
- "github.com/go-chassis/go-chassis/pkg/util/tags"
- "github.com/go-mesh/openlogging"
-)
-
-var (
- //PodName is the name of the pod that mesher runs in
- PodName string
- //PodNamespace is the namespace which the pod belongs to
- PodNamespace string
- //InstanceIP is the IP of the pod(the IP of the first network adaptor)
- InstanceIP string
-)
-
-const (
- PilotV2Registry = "pilotv2"
-)
-
-//ServiceDiscovery is the discovery service for istio pilot with xDS v2 API
-type ServiceDiscovery struct {
- Name string
- client *istioinfra.XdsClient
- options registry.Options
-}
-
-//GetMicroServiceID returns the id of the micro service
-func (discovery *ServiceDiscovery) GetMicroServiceID(appID, microServiceName, version, env string) (string, error) {
- return microServiceName, nil
-}
-
-//GetAllMicroServices returns all the micro services, which is mapped from xDS clusters
-func (discovery *ServiceDiscovery) GetAllMicroServices() ([]*registry.MicroService, error) {
- clusters, err := discovery.client.CDS()
- if err != nil {
- return nil, err
- }
- microServices := []*registry.MicroService{}
- for _, cluster := range clusters {
- microServices = append(microServices, toMicroService(&cluster))
- }
- return microServices, nil
-}
-
-func toMicroService(cluster *apiv2.Cluster) *registry.MicroService {
- svc := ®istry.MicroService{}
- svc.ServiceID = cluster.Name
- svc.ServiceName = cluster.Name
- svc.Version = common.DefaultVersion
- svc.AppID = common.DefaultApp
- svc.Level = "BACK"
- svc.Status = "UP"
- svc.Framework = ®istry.Framework{
- Name: "Istio",
- Version: common.LatestVersion,
- }
- svc.RegisterBy = metadata.PlatformRegistrationComponent
-
- return svc
-}
-
-func toMicroServiceInstance(clusterName string, lbendpoint *apiv2endpoint.LbEndpoint, tags map[string]string) *registry.MicroServiceInstance {
- socketAddress := lbendpoint.Endpoint.Address.GetSocketAddress()
- addr := socketAddress.Address
- port := socketAddress.GetPortValue()
- portStr := strconv.FormatUint(uint64(port), 10)
- msi := ®istry.MicroServiceInstance{}
- msi.InstanceID = addr + "_" + portStr
- msi.HostName = clusterName
- msi.DefaultEndpoint = addr + ":" + portStr
- msi.EndpointsMap = map[string]*registry.Endpoint{
- common.ProtocolRest: {Address: msi.DefaultEndpoint},
- }
- msi.DefaultProtocol = common.ProtocolRest
- msi.Metadata = tags
-
- return msi
-}
-
-//GetMicroService returns the micro service info
-func (discovery *ServiceDiscovery) GetMicroService(microServiceID string) (*registry.MicroService, error) {
- // If the service is in the clusters, return it, or nil
-
- clusters, err := discovery.client.CDS()
- if err != nil {
- return nil, err
- }
-
- var targetCluster apiv2.Cluster
- for _, cluster := range clusters {
- parts := strings.Split(cluster.Name, "|")
- if len(parts) < 4 {
- openlogging.GetLogger().Warnf("Invalid cluster name: %s", cluster.Name)
- continue
- }
-
- svcName := parts[3]
- if strings.Index(svcName, microServiceID+".") == 0 {
- targetCluster = cluster
- break
- }
- }
-
- if &targetCluster == nil {
- return nil, nil
- }
-
- return toMicroService(&targetCluster), nil
-}
-
-//GetMicroServiceInstances returns the instances of the micro service
-func (discovery *ServiceDiscovery) GetMicroServiceInstances(consumerID, providerID string) ([]*registry.MicroServiceInstance, error) {
- // TODO Handle the registry.MicroserviceIndex cache
- // TODO Handle the microServiceName
- service, err := discovery.GetMicroService(providerID)
- if err != nil {
- return nil, err
- }
-
- loadAssignment, err := discovery.client.EDS(service.ServiceName)
- if err != nil {
- return nil, err
- }
-
- instances := []*registry.MicroServiceInstance{}
- endpionts := loadAssignment.Endpoints
- for _, item := range endpionts {
- for _, lbendpoint := range item.LbEndpoints {
- msi := toMicroServiceInstance(loadAssignment.ClusterName, &lbendpoint, nil) // The cluster without subset doesn't have tags
- instances = append(instances, msi)
- }
- }
-
- return instances, nil
-}
-
-//FindMicroServiceInstances returns the micro service's instances filtered with tags
-func (discovery *ServiceDiscovery) FindMicroServiceInstances(consumerID, microServiceName string, tags utiltags.Tags) ([]*registry.MicroServiceInstance, error) {
- if tags.KV == nil || tags.Label == "" { // Chassis might pass an empty tags
- return discovery.GetMicroServiceInstances(consumerID, microServiceName)
- }
-
- instances := simpleCache.GetWithTags(microServiceName, tags.KV)
- if len(instances) == 0 {
- var lbendpoints []apiv2endpoint.LbEndpoint
- var err error
- lbendpoints, clusterName, err := discovery.client.GetEndpointsByTags(microServiceName, tags.KV)
- if err != nil {
- return nil, err
- }
-
- updateInstanceIndexCache(lbendpoints, clusterName, tags.KV)
-
- instances = simpleCache.GetWithTags(microServiceName, tags.KV)
- if instances == nil {
- return nil, fmt.Errorf("Failed to find microservice instances of %s from cache", microServiceName)
- }
- }
- return instances, nil
-}
-
-var cacheManager *CacheManager
-
-//AutoSync updates the services' info periodically in the background
-func (discovery *ServiceDiscovery) AutoSync() {
- var err error
- cacheManager, err = NewCacheManager(discovery.client)
- if err != nil {
- openlogging.GetLogger().Errorf("Failed to create cache manager, indexing will not work: %s", err.Error())
- } else {
- cacheManager.AutoSync()
- }
-}
-
-//Close closes the discovery service
-func (discovery *ServiceDiscovery) Close() error {
- return nil
-}
-
-//NewDiscoveryService creates the new ServiceDiscovery instance
-func NewDiscoveryService(options registry.Options) registry.ServiceDiscovery {
- if len(options.Addrs) == 0 {
- panic("Failed to create discovery service: Address not specified")
- }
- pilotAddr := options.Addrs[0]
- nodeInfo := &istioinfra.NodeInfo{
- PodName: PodName,
- Namespace: PodNamespace,
- InstanceIP: InstanceIP,
- }
- xdsClient, err := istioinfra.NewXdsClient(pilotAddr, options.TLSConfig, nodeInfo, options.ConfigPath)
- if err != nil {
- panic("Failed to create XDS client: " + err.Error())
- }
-
- discovery := &ServiceDiscovery{
- client: xdsClient,
- Name: PilotV2Registry,
- options: options,
- }
-
- return discovery
-}
-
-func init() {
- // Init the node info
- PodName = os.Getenv("POD_NAME")
- PodNamespace = os.Getenv("POD_NAMESPACE")
- InstanceIP = os.Getenv("INSTANCE_IP")
-
- // TODO Handle the default value
- if PodName == "" {
- PodName = "pod_name_default"
- }
- if PodNamespace == "" {
- PodNamespace = "default"
- }
- if InstanceIP == "" {
- log.Println("[WARN] Env var INSTANCE_IP not set, try to get instance ip from local network, the service might not work properly.")
- InstanceIP = iputil.GetLocalIP()
- if InstanceIP == "" {
- // Won't work without instance ip
- panic("Failed to get instance ip")
- }
- }
-
- registry.InstallServiceDiscovery(PilotV2Registry, NewDiscoveryService)
-}
diff --git a/proxy/plugins/registry/istiov2/registry_test.go b/proxy/plugins/registry/istiov2/registry_test.go
deleted file mode 100644
index 9c31cba..0000000
--- a/proxy/plugins/registry/istiov2/registry_test.go
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package istiov2
-
-import (
- "os"
- "strconv"
- "testing"
-
- istioinfra "github.com/apache/servicecomb-mesher/proxy/pkg/infras/istio"
- apiv2 "github.com/envoyproxy/go-control-plane/envoy/api/v2"
- apiv2core "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
- apiv2endpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
-
- "github.com/go-chassis/go-chassis/core/registry"
- "github.com/go-chassis/go-chassis/pkg/util/tags"
-)
-
-var VaildServiceDiscovery registry.ServiceDiscovery
-var AllServices []*registry.MicroService
-
-func TestNewDiscoveryService(t *testing.T) {
- options := registry.Options{
- Addrs: []string{ValidPilotAddr},
- ConfigPath: KubeConfig,
- }
-
- // Explicitly set the env vars, though this is checkd in the init of cache_test
- os.Setenv("POD_NAME", TEST_POD_NAME)
- os.Setenv("NAMESPACE", NAMESPACE_DEFAULT)
- os.Setenv("INSTANCE_IP", LocalIPAddress)
-
- // No panic should happen
- VaildServiceDiscovery = NewDiscoveryService(options)
-
-}
-
-// func TestAutoSync(t *testing.T) {
-// archaius.Init()
-// VaildServiceDiscovery.AutoSync()
-// }
-
-func TestEmptyPilotAddrs(t *testing.T) {
- defer func() {
- if err := recover(); err == nil {
- t.Errorf("Panic should be caught")
- }
- }()
-
- emptyAddrsOptions := registry.Options{
- Addrs: []string{},
- ConfigPath: KubeConfig,
- }
- NewDiscoveryService(emptyAddrsOptions)
-}
-
-func TestGetMicroService(t *testing.T) {
- serviceName := "istio-pilot"
- svc, err := VaildServiceDiscovery.GetMicroService(serviceName)
- if err != nil {
- t.Errorf("Failed to get micro service: %s", err.Error())
- }
- if svc == nil {
- t.Errorf("istio-pilot service should not be nil")
- }
-}
-
-func TestFindMicroServiceInstances(t *testing.T) {
- discovery, ok := VaildServiceDiscovery.(*ServiceDiscovery)
- if !ok {
- t.Errorf("Failed to convert discovery into type istiov2.ServiceDiscovery")
- return
- }
- client := discovery.client
-
- clusters, err := client.CDS()
- if err != nil {
- t.Errorf("Failed to teset FindMicroServiceInstances, CDS failed: %s", err.Error())
- }
-
- var clusterWithSubset *istioinfra.XdsClusterInfo = nil
- for _, c := range clusters {
- if info := istioinfra.ParseClusterName(c.Name); info != nil && info.Subset != "" {
- clusterWithSubset = info
- }
- }
-
- if clusterWithSubset != nil {
- // an empty tags will make sure target tag always match
- emptyTags := utiltags.Tags{
- KV: map[string]string{},
- Label: "",
- }
- instances, err := VaildServiceDiscovery.FindMicroServiceInstances("pilotv2client", clusterWithSubset.ServiceName, emptyTags)
- if err != nil {
- t.Errorf("Failed to FindMicroServiceInstances of %s: %s", clusterWithSubset.ServiceName, err.Error())
- }
- if len(instances) == 0 {
- t.Logf("%s's service instances is empty\n", clusterWithSubset.ServiceName)
- t.Logf("Pls check if the destinationrule and corresponding pod tags are matching")
- }
- } else if len(clusters) != 0 {
- t.Log("No clusters are with subsets")
- targetCluster := clusters[0]
-
- tags := utiltags.Tags{
- KV: map[string]string{
- "version": "v1",
- },
- Label: "version=v1",
- }
- _, err := VaildServiceDiscovery.FindMicroServiceInstances("pilotv2client", targetCluster.Name, tags)
- if err == nil {
- t.Errorf("Should caught error to get the endpoints of cluster without tags")
- }
- }
-
-}
-
-func TestToMicroService(t *testing.T) {
- cluster := &apiv2.Cluster{
- Name: "pilotv2server",
- }
-
- svc := toMicroService(cluster)
-
- if svc.ServiceID != cluster.Name {
- t.Errorf("service id should be equal to cluster name(%s != %s)", svc.ServiceID, cluster.Name)
- }
-}
-
-func TestToMicroServiceInstance(t *testing.T) {
- lbendpoint := &apiv2endpoint.LbEndpoint{
- Endpoint: &apiv2endpoint.Endpoint{
- Address: &apiv2core.Address{
- Address: &apiv2core.Address_SocketAddress{
- SocketAddress: &apiv2core.SocketAddress{
- Address: "192.168.0.10:8822",
- },
- },
- },
- },
- }
- clusterName := "pilotv2server"
- tags := map[string]string{
- "version": "v1",
- }
- msi := toMicroServiceInstance(clusterName, lbendpoint, tags)
-
- socketAddr := lbendpoint.Endpoint.Address.GetSocketAddress()
- addr := socketAddr.GetAddress()
- port := socketAddr.GetPortValue()
-
- if msi.InstanceID != addr+"_"+strconv.FormatUint(uint64(port), 10) {
- t.Errorf("Invalid msi.InstanceID: %s should be equal to %s_%d", msi.InstanceID, addr, port)
- }
-
- if msi.HostName != clusterName {
- t.Errorf("Invalid msi.HostName: %s should be equal to %s", msi.HostName, clusterName)
- }
-
- // Test if the tags match
- if !tagsMatch(tags, msi.Metadata) {
- t.Errorf("Tags not match, %v should be subset of %s", tags, msi.Metadata)
- }
-}
-
-func TestClose(t *testing.T) {
- if err := VaildServiceDiscovery.Close(); err != nil {
- t.Error(err)
- }
-}
diff --git a/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client.go b/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client.go
index f3cb59f..9fb45f9 100644
--- a/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client.go
+++ b/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client.go
@@ -20,6 +20,7 @@
import (
"context"
"fmt"
+ "github.com/go-chassis/openlog"
"os"
"sync"
@@ -29,9 +30,8 @@
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/proxy"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/utils"
- "github.com/go-chassis/go-chassis/core/client"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/client"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
)
//Name is a constant
@@ -79,14 +79,14 @@
dubboCli, err := dubboClient.CachedClients.GetClient(endPoint, c.opts.Timeout)
if err != nil {
resp.Resp.DubboRPCResult.SetException(fmt.Sprintf("Invalid Request addr %s %s", endPoint, err))
- lager.Logger.Error(fmt.Sprintf("Invalid Request addr %s %s", endPoint, err))
+ openlog.Error(fmt.Sprintf("Invalid Request addr %s %s", endPoint, err))
return err
}
dubboRsp, err := dubboCli.Send(dubboReq)
if err != nil {
resp.Resp.DubboRPCResult.SetException(fmt.Sprintf("Dubbo server exception: " + err.Error()))
- lager.Logger.Error("Dubbo server exception: " + err.Error())
+ openlog.Error("Dubbo server exception: " + err.Error())
return err
}
diff --git a/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client_test.go b/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client_test.go
index f4310fb..204d733 100644
--- a/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client_test.go
+++ b/proxy/protocol/dubbo/client/chassis/dubbo_chassis_client_test.go
@@ -25,9 +25,9 @@
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/dubbo"
dubboproxy "github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/proxy"
util "github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/utils"
- "github.com/go-chassis/go-chassis/core/client"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/client"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
"github.com/stretchr/testify/assert"
"net"
"net/http"
@@ -39,7 +39,7 @@
)
func init() {
- lager.Init(&lager.Options{LoggerLevel: "INFO", RollingPolicy: "size"})
+ lager.Init(&lager.Options{LoggerLevel: "INFO"})
}
func TestDubboChassisClient(t *testing.T) {
diff --git a/proxy/protocol/dubbo/client/client_conn.go b/proxy/protocol/dubbo/client/client_conn.go
index 4f0c0d0..6d3f2bb 100644
--- a/proxy/protocol/dubbo/client/client_conn.go
+++ b/proxy/protocol/dubbo/client/client_conn.go
@@ -21,7 +21,7 @@
"fmt"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/dubbo"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/utils"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/openlog"
"net"
"sync"
)
@@ -79,7 +79,7 @@
tmp := new(DubboClientConnection)
err := conn.SetKeepAlive(true)
if err != nil {
- lager.Logger.Error("TCPConn SetKeepAlive error:" + err.Error())
+ openlog.Error("TCPConn SetKeepAlive error:" + err.Error())
}
tmp.conn = conn
tmp.codec = dubbo.DubboCodec{}
@@ -109,7 +109,7 @@
this.msgque.Deavtive()
err := this.conn.Close()
if err != nil {
- lager.Logger.Error("Dubbo client connection close error:" + err.Error())
+ openlog.Error("Dubbo client connection close error:" + err.Error())
}
}
@@ -122,11 +122,11 @@
size, err := this.conn.Read(buf)
if err != nil {
if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
- lager.Logger.Error("client Recv head time err:" + err.Error())
+ openlog.Error("client Recv head time err:" + err.Error())
//time.Sleep(time.Second * 3)
continue
}
- lager.Logger.Error("client Recv head err:" + err.Error())
+ openlog.Error("client Recv head err:" + err.Error())
break
}
@@ -137,7 +137,7 @@
bodyLen := 0
ret := this.codec.DecodeDubboRsqHead(rsp, buf, &bodyLen)
if ret != dubbo.Success {
- lager.Logger.Info("Recv DecodeDubboRsqHead failed")
+ openlog.Info("Recv DecodeDubboRsqHead failed")
continue
}
body := make([]byte, bodyLen)
@@ -150,7 +150,7 @@
continue
}
//通知关闭连接
- lager.Logger.Error("Recv client body err:" + err.Error())
+ openlog.Error("Recv client body err:" + err.Error())
goto exitloop
}
count += size
@@ -182,7 +182,7 @@
//这里发送Rest请求以及收发送应答
err := this.msgque.Enqueue(req)
if err != nil {
- lager.Logger.Error("Msg Enqueue:" + err.Error())
+ openlog.Error("Msg Enqueue:" + err.Error())
}
}
@@ -191,7 +191,7 @@
for {
msg, err := this.msgque.Dequeue()
if err != nil {
- lager.Logger.Error("MsgSndLoop Dequeue:" + err.Error())
+ openlog.Error("MsgSndLoop Dequeue:" + err.Error())
break
}
var buffer util.WriteBuffer
@@ -199,7 +199,7 @@
this.codec.EncodeDubboReq(msg.(*dubbo.Request), &buffer)
_, err = this.conn.Write(buffer.GetValidData())
if err != nil {
- lager.Logger.Error("Send exception:" + err.Error())
+ openlog.Error("Send exception:" + err.Error())
break
}
}
diff --git a/proxy/protocol/dubbo/client/dubbo_client.go b/proxy/protocol/dubbo/client/dubbo_client.go
index eefdf7d..259fa25 100644
--- a/proxy/protocol/dubbo/client/dubbo_client.go
+++ b/proxy/protocol/dubbo/client/dubbo_client.go
@@ -21,7 +21,6 @@
"fmt"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/dubbo"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/utils"
- "github.com/go-chassis/go-chassis/core/lager"
"github.com/go-chassis/openlog"
"net"
"sync"
@@ -84,11 +83,11 @@
this.clients[addr] = tmp
}
if !tmp.Closed() {
- lager.Logger.Info("GetClient from cached addr:" + addr)
+ openlog.Info("GetClient from cached addr:" + addr)
return tmp, nil
} else {
err := tmp.ReOpen()
- lager.Logger.Info("GetClient repopen addr:" + addr)
+ openlog.Info("GetClient repopen addr:" + addr)
if err != nil {
delete(this.clients, addr)
return nil, err
@@ -97,7 +96,7 @@
}
}
}
- lager.Logger.Info("GetClient from new open addr:" + addr)
+ openlog.Info("GetClient from new open addr:" + addr)
tmp := NewDubboClient(addr, nil, timeout)
err := tmp.Open()
if err != nil {
@@ -145,7 +144,7 @@
func (this *DubboClient) open() error {
c, errDial := net.DialTimeout("tcp", this.addr, this.Timeout)
if errDial != nil {
- lager.Logger.Error("tcp dial failed", openlog.WithTags(openlog.Tags{
+ openlog.Error("tcp dial failed", openlog.WithTags(openlog.Tags{
"addr": this.addr,
"err": errDial,
}))
@@ -231,13 +230,13 @@
timeout = true
}
if this.closed {
- lager.Logger.Info("Client been closed.")
+ openlog.Info("Client been closed.")
return nil, &util.BaseError{"Client been closed."}
}
this.RemoveWaitMsg(msgID)
if timeout {
dubboReq.SetBroken(true)
- lager.Logger.Info("Client send timeout.")
+ openlog.Info("Client send timeout.")
return nil, &util.BaseError{"timeout"}
} else {
return result.Rsp, nil
diff --git a/proxy/protocol/dubbo/client/dubbo_client_test.go b/proxy/protocol/dubbo/client/dubbo_client_test.go
index 49d75b3..e5630e8 100644
--- a/proxy/protocol/dubbo/client/dubbo_client_test.go
+++ b/proxy/protocol/dubbo/client/dubbo_client_test.go
@@ -19,7 +19,7 @@
import (
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/dubbo"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
@@ -30,8 +30,7 @@
func init() {
lager.Init(&lager.Options{
- LoggerLevel: "INFO",
- RollingPolicy: "size",
+ LoggerLevel: "INFO",
})
}
diff --git a/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput.go b/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput.go
index 9aaec2d..b7ffc03 100755
--- a/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput.go
+++ b/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput.go
@@ -29,16 +29,15 @@
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/schema"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/utils"
"github.com/apache/servicecomb-mesher/proxy/resolver"
- "github.com/go-chassis/go-chassis/core/common"
- chassisCommon "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/loadbalancer"
- "github.com/go-chassis/go-chassis/pkg/runtime"
- "github.com/go-chassis/go-chassis/pkg/util/tags"
- "github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/core/common"
+ chassisCommon "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/core/loadbalancer"
+ "github.com/go-chassis/go-chassis/v2/pkg/runtime"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/tags"
+ "github.com/go-chassis/go-chassis/v2/third_party/forked/afex/hystrix-go/hystrix"
+ "github.com/go-chassis/openlog"
)
var dr = resolver.GetDestinationResolver("http")
@@ -103,7 +102,7 @@
var err error
err = SetLocalServiceAddress(inv) //select local service
if err != nil {
- openlogging.GetLogger().Warn(err.Error())
+ openlog.Warn(err.Error())
IsProvider = false
} else {
IsProvider = true
@@ -119,7 +118,7 @@
if mesherRuntime.Role == mesherCommon.RoleSidecar {
c, err = handler.GetChain(common.Consumer, mesherCommon.ChainConsumerOutgoing)
if err != nil {
- openlogging.Error("Get Consumer chain failed: " + err.Error())
+ openlog.Error("Get Consumer chain failed: " + err.Error())
return err
}
}
@@ -130,7 +129,7 @@
ctx.Req.SetAttachment(ProxyTag, "")
c, err = handler.GetChain(common.Provider, mesherCommon.ChainProviderIncoming)
if err != nil {
- openlogging.Error("Get Provider Chain failed: " + err.Error())
+ openlog.Error("Get Provider Chain failed: " + err.Error())
return err
}
c.Next(inv, func(ir *invocation.Response) {
@@ -171,7 +170,7 @@
ctx.Rsp = ir.Result.(*dubboclient.WrapResponse).Resp
} else {
err := protocol.ErrNilResult
- lager.Logger.Error("CAll Chain failed: " + err.Error())
+ openlog.Error("CAll Chain failed: " + err.Error())
return err
}
diff --git a/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput_test.go b/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput_test.go
index dfab1a3..24750ea 100644
--- a/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput_test.go
+++ b/proxy/protocol/dubbo/proxy/dubbo_proxy_ouput_test.go
@@ -26,16 +26,16 @@
mesherRuntime "github.com/apache/servicecomb-mesher/proxy/pkg/runtime"
dubboclient "github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/client"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/dubbo"
- "github.com/go-chassis/go-chassis"
- chassisCommon "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/loadbalancer"
- "github.com/go-chassis/go-chassis/core/registry"
- "github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
+ "github.com/go-chassis/go-chassis/v2"
+ chassisCommon "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/loadbalancer"
+ "github.com/go-chassis/go-chassis/v2/core/registry"
+ "github.com/go-chassis/go-chassis/v2/third_party/forked/afex/hystrix-go/hystrix"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"os"
@@ -43,7 +43,7 @@
"testing"
// rate limiter handler
- _ "github.com/go-chassis/go-chassis/middleware/ratelimiter"
+ _ "github.com/go-chassis/go-chassis/v2/middleware/ratelimiter"
)
func init() {
diff --git a/proxy/protocol/dubbo/schema/cache.go b/proxy/protocol/dubbo/schema/cache.go
index d6e9479..04b818b 100644
--- a/proxy/protocol/dubbo/schema/cache.go
+++ b/proxy/protocol/dubbo/schema/cache.go
@@ -19,12 +19,12 @@
import (
"fmt"
+ "github.com/go-chassis/openlog"
"strings"
"sync"
"time"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/registry"
+ "github.com/go-chassis/go-chassis/v2/core/registry"
"github.com/patrickmn/go-cache"
)
@@ -52,7 +52,7 @@
svc := registry.DefaultContractDiscoveryService.GetMicroServicesByInterface(interfaceName)
if svc != nil {
svcKey := strings.Join([]string{svc[0].ServiceName, svc[0].Version, svc[0].AppID}, "/")
- lager.Logger.Info(fmt.Sprintf("refresh cache svc [%s] for interface %s", svcKey, interfaceName))
+ openlog.Info(fmt.Sprintf("refresh cache svc [%s] for interface %s", svcKey, interfaceName))
svcToInterfaceCache.Set(interfaceName, svc[0], 0)
}
}}
diff --git a/proxy/protocol/dubbo/schema/schema.go b/proxy/protocol/dubbo/schema/schema.go
index eff96e4..cdedfb2 100644
--- a/proxy/protocol/dubbo/schema/schema.go
+++ b/proxy/protocol/dubbo/schema/schema.go
@@ -19,10 +19,10 @@
import (
"fmt"
+ "github.com/go-chassis/openlog"
"strings"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/registry"
+ "github.com/go-chassis/go-chassis/v2/core/registry"
)
const (
@@ -179,11 +179,11 @@
func GetSvcByInterface(interfaceName string) *registry.MicroService {
value, ok := svcToInterfaceCache.Get(interfaceName)
if !ok || value == nil {
- lager.Logger.Info(fmt.Sprintf("Get svc from remote, interface: %s", interfaceName))
+ openlog.Info(fmt.Sprintf("Get svc from remote, interface: %s", interfaceName))
svc := registry.DefaultContractDiscoveryService.GetMicroServicesByInterface(interfaceName)
if svc != nil {
svcKey := strings.Join([]string{svc[0].ServiceName, svc[0].Version, svc[0].AppID}, "/")
- lager.Logger.Info(fmt.Sprintf("Cached svc [%s] for interface %s", svcKey, interfaceName))
+ openlog.Info(fmt.Sprintf("Cached svc [%s] for interface %s", svcKey, interfaceName))
svcToInterfaceCache.Set(interfaceName, svc[0], 0)
refresher.Add(newInterfaceJob(interfaceName))
} else {
diff --git a/proxy/protocol/dubbo/schema/schema_test.go b/proxy/protocol/dubbo/schema/schema_test.go
index 362e94e..eb9f391 100644
--- a/proxy/protocol/dubbo/schema/schema_test.go
+++ b/proxy/protocol/dubbo/schema/schema_test.go
@@ -18,9 +18,9 @@
package schema
import (
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/registry"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/registry"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"testing"
diff --git a/proxy/protocol/dubbo/server/dubbo_conn.go b/proxy/protocol/dubbo/server/dubbo_conn.go
index aa846f3..d06a084 100644
--- a/proxy/protocol/dubbo/server/dubbo_conn.go
+++ b/proxy/protocol/dubbo/server/dubbo_conn.go
@@ -22,7 +22,7 @@
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/dubbo"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/proxy"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/utils"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/openlog"
"net"
"sync"
)
@@ -115,22 +115,22 @@
size, err := this.conn.Read(buf)
if err != nil {
if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
- lager.Logger.Error("Dubbo server Recv head: " + err.Error())
+ openlog.Error("Dubbo server Recv head: " + err.Error())
continue
}
- lager.Logger.Error("Dubbo server Recv head: " + err.Error())
+ openlog.Error("Dubbo server Recv head: " + err.Error())
break
}
if size < dubbo.HeaderLength {
- lager.Logger.Info("Invalid msg head")
+ openlog.Info("Invalid msg head")
continue
}
req := new(dubbo.Request)
bodyLen := 0
ret := this.codec.DecodeDubboReqHead(req, buf, &bodyLen)
if ret != dubbo.Success {
- lager.Logger.Info("Invalid msg head")
+ openlog.Info("Invalid msg head")
continue
}
body := make([]byte, bodyLen)
@@ -141,7 +141,7 @@
if err != nil {
//通知关闭连接
- lager.Logger.Error("Recv: " + err.Error())
+ openlog.Error("Recv: " + err.Error())
goto exitloop
}
count += size
@@ -177,12 +177,12 @@
//这里重新分配MSGID
srcMsgID := ctx.Req.GetMsgID()
dstMsgID := dubbo.GenerateMsgID()
- //lager.Logger.Info(fmt.Sprintf("dubbo2dubbo srcMsgID=%d, newMsgID=%d", srcMsgID, dstMsgID))
+ //openlog.Info(fmt.Sprintf("dubbo2dubbo srcMsgID=%d, newMsgID=%d", srcMsgID, dstMsgID))
ctx.Req.SetMsgID(dstMsgID)
err := dubboproxy.Handle(ctx)
if err != nil {
ctx.Rsp.SetErrorMsg(err.Error())
- lager.Logger.Error("request: " + err.Error())
+ openlog.Error("request: " + err.Error())
ctx.Rsp.SetStatus(dubbo.ServerError)
}
ctx.Req.SetMsgID(srcMsgID)
@@ -199,7 +199,7 @@
for {
msg, err := this.msgque.Dequeue()
if err != nil {
- lager.Logger.Error("MsgSndLoop Dequeue: " + err.Error())
+ openlog.Error("MsgSndLoop Dequeue: " + err.Error())
break
}
var buffer util.WriteBuffer
@@ -208,7 +208,7 @@
bs := buffer.GetValidData()
_, err = this.conn.Write(bs /*buffer.GetValidData()*/)
if err != nil {
- lager.Logger.Error("Send exception: " + err.Error())
+ openlog.Error("Send exception: " + err.Error())
break
}
}
diff --git a/proxy/protocol/dubbo/server/server.go b/proxy/protocol/dubbo/server/server.go
index 867fdb2..9e026a9 100644
--- a/proxy/protocol/dubbo/server/server.go
+++ b/proxy/protocol/dubbo/server/server.go
@@ -19,9 +19,9 @@
import (
"fmt"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/schema"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/schema"
+ "github.com/go-chassis/openlog"
"gopkg.in/yaml.v2"
"net"
"sync"
@@ -29,8 +29,7 @@
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/proxy"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/utils"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/server"
+ "github.com/go-chassis/go-chassis/v2/core/server"
)
const (
@@ -98,7 +97,7 @@
func (d *DubboServer) Init() error {
initSchema()
d.connMgr = NewConnectMgr()
- lager.Logger.Info("Dubbo server init success.")
+ openlog.Info("Dubbo server init success.")
return nil
}
@@ -131,12 +130,12 @@
}
tcpAddr, err := net.ResolveTCPAddr("tcp", d.opts.Address)
if err != nil {
- lager.Logger.Error("ResolveTCPAddr err: " + err.Error())
+ openlog.Error("ResolveTCPAddr err: " + err.Error())
return err
}
l, err := net.ListenTCP("tcp", tcpAddr)
if err != nil {
- lager.Logger.Error("listening failed, reason: " + err.Error())
+ openlog.Error("listening failed, reason: " + err.Error())
return err
}
d.routineMgr.Spawn(d, l, "Acceptloop")
@@ -156,7 +155,7 @@
if err != nil {
select {
case <-time.After(time.Second * 3):
- lager.Logger.Info("Sleep three second")
+ openlog.Info("Sleep three second")
}
}
dubbConn := d.connMgr.GetConnection(conn)
@@ -176,7 +175,7 @@
for _, inter := range service.Schemas {
if len(inter) == 0 {
- openlogging.GetLogger().Warnf("interfaces is empty")
+ openlog.Warn("interfaces is empty")
break
}
schemaContent := struct {
@@ -201,6 +200,6 @@
err := schema.SetSchemaInfoByMap(m)
if err != nil {
- openlogging.Error("Set schemaInfo failed: " + err.Error())
+ openlog.Error("Set schemaInfo failed: " + err.Error())
}
}
diff --git a/proxy/protocol/dubbo/server/server_test.go b/proxy/protocol/dubbo/server/server_test.go
index 2fba42a..85112d4 100644
--- a/proxy/protocol/dubbo/server/server_test.go
+++ b/proxy/protocol/dubbo/server/server_test.go
@@ -24,11 +24,11 @@
"time"
//_ "github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/client"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/server"
- //"github.com/go-chassis/go-chassis/core/client
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/server"
+ //"github.com/go-chassis/go-chassis/v2/core/client
"github.com/stretchr/testify/assert"
"testing"
)
diff --git a/proxy/protocol/dubbo/simpleRegistry/simple_registry_server.go b/proxy/protocol/dubbo/simpleRegistry/simple_registry_server.go
index 8c49c15..25e37ef 100644
--- a/proxy/protocol/dubbo/simpleRegistry/simple_registry_server.go
+++ b/proxy/protocol/dubbo/simpleRegistry/simple_registry_server.go
@@ -21,8 +21,8 @@
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/dubbo"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/proxy"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/utils"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/server"
+ "github.com/go-chassis/go-chassis/v2/core/server"
+ "github.com/go-chassis/openlog"
"net"
"sync"
)
@@ -56,7 +56,7 @@
//Init is a method which initialized server config
func (d *SimDubboRegistryServer) Init(opts ...server.Options) error {
- lager.Logger.Info("Dubbo Simple Registry server init.")
+ openlog.Info("Dubbo Simple Registry server init.")
return nil
}
@@ -86,12 +86,12 @@
}
tcpAddr, err := net.ResolveTCPAddr("tcp", d.opts.Address)
if err != nil {
- lager.Logger.Error("ResolveTCPAddr err: " + err.Error())
+ openlog.Error("ResolveTCPAddr err: " + err.Error())
return err
}
l, err := net.ListenTCP("tcp", tcpAddr)
if err != nil {
- lager.Logger.Error("listening falied, reason: " + err.Error())
+ openlog.Error("listening falied, reason: " + err.Error())
return err
}
go d.AcceptLoop(l)
@@ -104,11 +104,11 @@
for {
conn, err := l.Accept()
if err != nil {
- lager.Logger.Error("tcp conn error: " + err.Error())
+ openlog.Error("tcp conn error: " + err.Error())
continue
}
- lager.Logger.Debug("Received message")
+ openlog.Debug("Received message")
go handleConn(conn)
}
diff --git a/proxy/protocol/dubbo/simpleRegistry/simple_registry_server_test.go b/proxy/protocol/dubbo/simpleRegistry/simple_registry_server_test.go
index d99f115..e08e947 100644
--- a/proxy/protocol/dubbo/simpleRegistry/simple_registry_server_test.go
+++ b/proxy/protocol/dubbo/simpleRegistry/simple_registry_server_test.go
@@ -21,10 +21,10 @@
dubboclient "github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/client"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/dubbo"
"github.com/apache/servicecomb-mesher/proxy/protocol/dubbo/proxy"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/server"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/server"
"github.com/stretchr/testify/assert"
"sync"
"testing"
diff --git a/proxy/protocol/dubbo/utils/buffer.go b/proxy/protocol/dubbo/utils/buffer.go
index ef69af5..b6d150b 100644
--- a/proxy/protocol/dubbo/utils/buffer.go
+++ b/proxy/protocol/dubbo/utils/buffer.go
@@ -22,7 +22,7 @@
"reflect"
"fmt"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/openlog"
)
//BaseError is a struct
@@ -166,7 +166,7 @@
var tmp interface{}
tmp, err := b.ReadObject()
if err != nil {
- openlogging.Error(err.Error())
+ openlog.Error(err.Error())
return byte(0), err
}
return byte(tmp.(int32)), nil
diff --git a/proxy/protocol/grpc/client.go b/proxy/protocol/grpc/client.go
index 01cdedd..0291fcf 100644
--- a/proxy/protocol/grpc/client.go
+++ b/proxy/protocol/grpc/client.go
@@ -24,10 +24,10 @@
"net"
"net/http"
- "github.com/go-chassis/go-chassis/core/client"
- "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-chassis/go-chassis/pkg/util/httputil"
+ "github.com/go-chassis/go-chassis/v2/core/client"
+ "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/httputil"
"golang.org/x/net/http2"
)
diff --git a/proxy/protocol/grpc/reverse_proxy.go b/proxy/protocol/grpc/reverse_proxy.go
index 0b2fd92..e0b8e91 100755
--- a/proxy/protocol/grpc/reverse_proxy.go
+++ b/proxy/protocol/grpc/reverse_proxy.go
@@ -30,15 +30,14 @@
"github.com/apache/servicecomb-mesher/proxy/protocol"
"github.com/apache/servicecomb-mesher/proxy/resolver"
"github.com/apache/servicecomb-mesher/proxy/util"
- "github.com/go-chassis/go-chassis/client/rest"
- chassisCommon "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/pkg/runtime"
- "github.com/go-chassis/go-chassis/pkg/string"
- "github.com/go-chassis/go-chassis/pkg/util/tags"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/client/rest"
+ chassisCommon "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/pkg/runtime"
+ "github.com/go-chassis/go-chassis/v2/pkg/string"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/tags"
+ "github.com/go-chassis/openlog"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
@@ -120,7 +119,7 @@
c, err := handler.GetChain(chassisCommon.Consumer, common.ChainConsumerOutgoing)
if err != nil {
WriteErrorResponse(inv, w, r, http.StatusBadGateway, err)
- lager.Logger.Error("Get chain failed: " + err.Error())
+ openlog.Error("Get chain failed: " + err.Error())
return
}
defer func(begin time.Time) {
@@ -135,7 +134,7 @@
})
resp, err := handleRequest(w, r, inv, invRsp)
if err != nil {
- lager.Logger.Error("Handle request failed: " + err.Error())
+ openlog.Error("Handle request failed: " + err.Error())
return
}
RecordStatus(inv, resp.StatusCode)
@@ -163,7 +162,7 @@
c, err := handler.GetChain(chassisCommon.Provider, common.ChainProviderIncoming)
if err != nil {
WriteErrorResponse(inv, w, r, http.StatusBadGateway, err)
- lager.Logger.Error("Get chain failed: " + err.Error())
+ openlog.Error("Get chain failed: " + err.Error())
return
}
if err = util.SetLocalServiceAddress(inv, r.Header.Get("X-Forwarded-Port")); err != nil {
@@ -179,20 +178,20 @@
invRsp = ir
})
if _, err = handleRequest(w, r, inv, invRsp); err != nil {
- lager.Logger.Error("Handle request failed: " + err.Error())
+ openlog.Error("Handle request failed: " + err.Error())
}
}
func copyChassisResp2HttpResp(w http.ResponseWriter, resp *http.Response) {
if resp == nil || resp.StatusCode == 0 {
- lager.Logger.Warn("response is nil or empty because of unknown reason, plz report issue")
+ openlog.Warn("response is nil or empty because of unknown reason, plz report issue")
return
}
copyHeader(w.Header(), resp.Header)
w.WriteHeader(resp.StatusCode)
_, err := io.Copy(w, resp.Body)
if err != nil {
- openlogging.Error("can not copy resp: " + err.Error())
+ openlog.Error("can not copy resp: " + err.Error())
}
resp.Body.Close()
}
@@ -237,7 +236,7 @@
if !ok {
stat = status.New(codes.Unknown, err.Error())
}
- openlogging.GetLogger().Errorf("grpc error: [%s]: [%s]", stat.Code().String(), stat.Message())
+ openlog.Error(fmt.Sprintf("grpc error: [%s]: [%s]", stat.Code().String(), stat.Message()))
w.Header().Set("Content-Type", r.Header.Get("content-type"))
w.Header().Set("User-Agent", r.Header.Get("User-Agent"))
w.Header().Set("Grpc-Status", fmt.Sprintf("%d", stat.Code()))
diff --git a/proxy/protocol/grpc/server.go b/proxy/protocol/grpc/server.go
index e009818..8f5b8b8 100644
--- a/proxy/protocol/grpc/server.go
+++ b/proxy/protocol/grpc/server.go
@@ -23,16 +23,16 @@
"fmt"
"github.com/apache/servicecomb-mesher/proxy/common"
"github.com/apache/servicecomb-mesher/proxy/resolver"
- chassisRuntime "github.com/go-chassis/go-chassis/pkg/runtime"
+ chassisRuntime "github.com/go-chassis/go-chassis/v2/pkg/runtime"
+ "github.com/go-chassis/openlog"
"net"
"net/http"
"strings"
"github.com/apache/servicecomb-mesher/proxy/pkg/runtime"
- chassisCom "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/server"
- chassisTLS "github.com/go-chassis/go-chassis/core/tls"
+ chassisCom "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/server"
+ chassisTLS "github.com/go-chassis/go-chassis/v2/core/tls"
"golang.org/x/net/http2"
)
@@ -94,7 +94,7 @@
}
} else {
sslTag := genTag(common.ComponentName, chassisCom.Provider)
- lager.Logger.Warn(fmt.Sprintf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
+ openlog.Warn(fmt.Sprintf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
sslTag, mesherSSLConfig.VerifyPeer, mesherSSLConfig.CipherPlugin))
}
@@ -108,7 +108,7 @@
case "0.0.0.0":
return errors.New("in sidecar mode, forbidden to listen on 0.0.0.0")
case "127.0.0.1":
- lager.Logger.Warn("Mesher listen on 127.0.0.1, it can only proxy for consumer. " +
+ openlog.Warn("Mesher listen on 127.0.0.1, it can only proxy for consumer. " +
"for provider, mesher must listen on external ip.")
return nil
default:
@@ -120,7 +120,7 @@
}
} else {
sslTag := genTag(chassisRuntime.ServiceName, chassisCom.ProtocolRest, chassisCom.Provider)
- lager.Logger.Warn(fmt.Sprintf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
+ openlog.Warn(fmt.Sprintf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
sslTag, serverSSLConfig.VerifyPeer, serverSSLConfig.CipherPlugin))
}
@@ -142,7 +142,7 @@
return err
}
} else {
- lager.Logger.Warn(fmt.Sprintf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
+ openlog.Warn(fmt.Sprintf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
sslTag, mesherSSLConfig.VerifyPeer, mesherSSLConfig.CipherPlugin))
}
diff --git a/proxy/protocol/http/gateway.go b/proxy/protocol/http/gateway.go
index add3521..fcd7988 100644
--- a/proxy/protocol/http/gateway.go
+++ b/proxy/protocol/http/gateway.go
@@ -20,18 +20,18 @@
import (
"github.com/apache/servicecomb-mesher/proxy/common"
"github.com/apache/servicecomb-mesher/proxy/ingress"
- "github.com/go-chassis/go-chassis/client/rest"
- chassiscommon "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/client/rest"
+ chassiscommon "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/openlog"
"net/http"
)
func handleIncomingTraffic(inv *invocation.Invocation) (*invocation.Response, error) {
c, err := handler.GetChain(chassiscommon.Provider, common.ChainProviderIncoming)
if err != nil {
- openlogging.Error("Get chain failed: " + err.Error())
+ openlog.Error("Get chain failed: " + err.Error())
return nil, err
}
var invRsp *invocation.Response
@@ -83,7 +83,7 @@
c, err := handler.GetChain(chassiscommon.Consumer, common.ChainConsumerOutgoing)
if err != nil {
handleErrorResponse(inv, w, http.StatusBadGateway, err)
- openlogging.Error("Get chain failed: " + err.Error())
+ openlog.Error("Get chain failed: " + err.Error())
return
}
var invRsp *invocation.Response
@@ -93,7 +93,7 @@
})
resp, err := handleRequest(w, inv, invRsp)
if err != nil {
- openlogging.Error("Handle request failed: " + err.Error())
+ openlog.Error("Handle request failed: " + err.Error())
return
}
RecordStatus(inv, resp.StatusCode)
diff --git a/proxy/protocol/http/gateway_test.go b/proxy/protocol/http/gateway_test.go
index 2b0b6e3..a4ca069 100644
--- a/proxy/protocol/http/gateway_test.go
+++ b/proxy/protocol/http/gateway_test.go
@@ -5,12 +5,12 @@
_ "github.com/apache/servicecomb-mesher/proxy/ingress/servicecomb"
"github.com/apache/servicecomb-mesher/proxy/pkg/metrics"
"github.com/go-chassis/go-archaius"
- "github.com/go-chassis/go-chassis/control"
- _ "github.com/go-chassis/go-chassis/control/servicecomb"
- "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/handler"
+ "github.com/go-chassis/go-chassis/v2/control"
+ _ "github.com/go-chassis/go-chassis/v2/control/servicecomb"
+ "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
diff --git a/proxy/protocol/http/http_server.go b/proxy/protocol/http/http_server.go
index aa51eee..cad8881 100644
--- a/proxy/protocol/http/http_server.go
+++ b/proxy/protocol/http/http_server.go
@@ -30,12 +30,11 @@
"github.com/apache/servicecomb-mesher/proxy/common"
"github.com/apache/servicecomb-mesher/proxy/resolver"
- chassisCom "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/server"
- chassisTLS "github.com/go-chassis/go-chassis/core/tls"
- chassisRuntime "github.com/go-chassis/go-chassis/pkg/runtime"
- "github.com/go-mesh/openlogging"
+ chassisCom "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/server"
+ chassisTLS "github.com/go-chassis/go-chassis/v2/core/tls"
+ chassisRuntime "github.com/go-chassis/go-chassis/v2/pkg/runtime"
+ "github.com/go-chassis/openlog"
)
const (
@@ -95,7 +94,7 @@
}
} else {
sslTag := genTag(common.ComponentName, chassisCom.Provider)
- lager.Logger.Warn(fmt.Sprintf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
+ openlog.Warn(fmt.Sprintf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
sslTag, mesherSSLConfig.VerifyPeer, mesherSSLConfig.CipherPlugin))
}
@@ -109,7 +108,7 @@
case "0.0.0.0":
return errors.New("in sidecar mode, forbidden to listen on 0.0.0.0")
case "127.0.0.1":
- lager.Logger.Warn("Mesher listen on 127.0.0.1, it can only proxy for consumer. " +
+ openlog.Warn("Mesher listen on 127.0.0.1, it can only proxy for consumer. " +
"for provider, mesher must listen on external ip.")
return nil
default:
@@ -121,7 +120,7 @@
}
} else {
sslTag := genTag(chassisRuntime.ServiceName, chassisCom.ProtocolRest, chassisCom.Provider)
- lager.Logger.Warn(fmt.Sprintf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
+ openlog.Warn(fmt.Sprintf("%s TLS mode, verify peer: %t, cipher plugin: %s.",
sslTag, serverSSLConfig.VerifyPeer, serverSSLConfig.CipherPlugin))
}
@@ -145,7 +144,7 @@
return err
}
} else {
- lager.Logger.Warn(fmt.Sprintf("TLS mode, verify peer: %t, cipher plugin: %s.",
+ openlog.Warn(fmt.Sprintf("TLS mode, verify peer: %t, cipher plugin: %s.",
mesherSSLConfig.VerifyPeer, mesherSSLConfig.CipherPlugin))
}
@@ -162,7 +161,7 @@
return err
}
if t != nil {
- openlogging.Info("run as https")
+ openlog.Info("run as https")
lnTLS := tls.NewListener(ln, t)
ln = lnTLS
}
@@ -181,13 +180,13 @@
func (hs *httpServer) Stop() error {
//go 1.8+ drain connections handleIncomingTraffic stop server
if hs.server == nil {
- openlogging.Info("http server don't need to be stopped")
+ openlog.Info("http server don't need to be stopped")
return nil
}
if err := hs.server.Shutdown(context.TODO()); err != nil {
panic(err)
}
- openlogging.Info("Mesher gracefully stopped")
+ openlog.Info("Mesher gracefully stopped")
return nil
}
diff --git a/proxy/protocol/http/http_server_test.go b/proxy/protocol/http/http_server_test.go
index d2ee3fb..4c8fb41 100644
--- a/proxy/protocol/http/http_server_test.go
+++ b/proxy/protocol/http/http_server_test.go
@@ -21,10 +21,10 @@
"errors"
"github.com/apache/servicecomb-mesher/proxy/common"
"github.com/apache/servicecomb-mesher/proxy/pkg/runtime"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/server"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/server"
"github.com/stretchr/testify/assert"
"net"
"net/http"
@@ -34,7 +34,7 @@
)
func init() {
- lager.Init(&lager.Options{LoggerLevel: "INFO", RollingPolicy: "size"})
+ lager.Init(&lager.Options{LoggerLevel: "INFO"})
}
func externalIP() (net.IP, error) {
diff --git a/proxy/protocol/http/sidecar.go b/proxy/protocol/http/sidecar.go
index 35bff87..b3c2c94 100755
--- a/proxy/protocol/http/sidecar.go
+++ b/proxy/protocol/http/sidecar.go
@@ -32,18 +32,17 @@
"github.com/apache/servicecomb-mesher/proxy/protocol"
"github.com/apache/servicecomb-mesher/proxy/resolver"
"github.com/apache/servicecomb-mesher/proxy/util"
- "github.com/go-chassis/go-chassis/client/rest"
- chassisCommon "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/fault"
- "github.com/go-chassis/go-chassis/core/handler"
- "github.com/go-chassis/go-chassis/core/invocation"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/loadbalancer"
- "github.com/go-chassis/go-chassis/pkg/runtime"
- "github.com/go-chassis/go-chassis/pkg/string"
- "github.com/go-chassis/go-chassis/pkg/util/tags"
- "github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/client/rest"
+ chassisCommon "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/fault"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/core/loadbalancer"
+ "github.com/go-chassis/go-chassis/v2/pkg/runtime"
+ "github.com/go-chassis/go-chassis/v2/pkg/string"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/tags"
+ "github.com/go-chassis/go-chassis/v2/third_party/forked/afex/hystrix-go/hystrix"
+ "github.com/go-chassis/openlog"
)
var dr = resolver.GetDestinationResolver("http")
@@ -129,7 +128,7 @@
c, err = handler.GetChain(common.ConsumerEgress, common.ChainConsumerEgress)
if err != nil {
handleErrorResponse(inv, w, http.StatusBadGateway, err)
- openlogging.Error("Get chain failed" + err.Error())
+ openlog.Error("Get chain failed" + err.Error())
return
}
@@ -137,7 +136,7 @@
c, err = handler.GetChain(chassisCommon.Consumer, common.ChainConsumerOutgoing)
if err != nil {
handleErrorResponse(inv, w, http.StatusBadGateway, err)
- openlogging.Error("Get chain failed: " + err.Error())
+ openlog.Error("Get chain failed: " + err.Error())
return
}
}
@@ -153,7 +152,7 @@
})
resp, err := handleRequest(w, inv, invRsp)
if err != nil {
- openlogging.Error("handle request failed: " + err.Error())
+ openlog.Error("handle request failed: " + err.Error())
return
}
RecordStatus(inv, resp.StatusCode)
@@ -181,7 +180,7 @@
c, err := handler.GetChain(chassisCommon.Provider, common.ChainProviderIncoming)
if err != nil {
handleErrorResponse(inv, w, http.StatusBadGateway, err)
- lager.Logger.Error("Get chain failed: " + err.Error())
+ openlog.Error("Get chain failed: " + err.Error())
return
}
if err = util.SetLocalServiceAddress(inv, r.Header.Get("X-Forwarded-Port")); err != nil {
@@ -197,7 +196,7 @@
invRsp = ir
})
if _, err = handleRequest(w, inv, invRsp); err != nil {
- lager.Logger.Error("Handle request failed: " + err.Error())
+ openlog.Error("Handle request failed: " + err.Error())
}
}
@@ -206,16 +205,16 @@
copyHeader(w.Header(), resp.Header)
w.WriteHeader(resp.StatusCode)
if resp == nil {
- openlogging.GetLogger().Warn("response is nil because of unknown reason")
+ openlog.Warn("response is nil because of unknown reason")
return
}
_, err := io.Copy(w, resp.Body)
if err != nil {
- openlogging.Error("can not copy: " + err.Error())
+ openlog.Error("can not copy: " + err.Error())
}
err = resp.Body.Close()
if err != nil {
- openlogging.Error("Http response close error: " + err.Error())
+ openlog.Error("Http response close error: " + err.Error())
}
}
func handleRequest(w http.ResponseWriter, inv *invocation.Invocation, ir *invocation.Response) (*http.Response, error) {
@@ -288,7 +287,7 @@
if err != nil {
_, err := w.Write([]byte(err.Error()))
if err != nil {
- openlogging.Error("can not write err to client: " + err.Error())
+ openlog.Error("can not write err to client: " + err.Error())
}
}
RecordStatus(inv, statusCode)
diff --git a/proxy/protocol/http/sidercar_test.go b/proxy/protocol/http/sidercar_test.go
index 3a37432..533781d 100644
--- a/proxy/protocol/http/sidercar_test.go
+++ b/proxy/protocol/http/sidercar_test.go
@@ -20,9 +20,9 @@
import (
"bytes"
"github.com/apache/servicecomb-mesher/proxy/cmd"
- "github.com/go-chassis/go-chassis/client/rest"
- "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/handler"
+ "github.com/go-chassis/go-chassis/v2/client/rest"
+ "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/handler"
"io/ioutil"
"net/http"
"net/http/httptest"
@@ -30,13 +30,12 @@
"testing"
"github.com/apache/servicecomb-mesher/proxy/pkg/metrics"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
)
func init() {
lager.Init(&lager.Options{
- LoggerLevel: "INFO",
- RollingPolicy: "size",
+ LoggerLevel: "INFO",
})
cmd.Init()
diff --git a/proxy/register/register.go b/proxy/register/register.go
index ae59825..c5fa664 100644
--- a/proxy/register/register.go
+++ b/proxy/register/register.go
@@ -19,12 +19,12 @@
import (
"github.com/apache/servicecomb-mesher/proxy/common"
- chassisCommon "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/config"
- chassisModel "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/registry"
- "github.com/go-chassis/go-chassis/pkg/util/iputil"
- "github.com/go-mesh/openlogging"
+ chassisCommon "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ chassisModel "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/registry"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/iputil"
+ "github.com/go-chassis/openlog"
"strings"
)
@@ -64,6 +64,6 @@
}
}
- openlogging.Debug("adapt endpoints success")
+ openlog.Debug("adapt endpoints success")
return nil
}
diff --git a/proxy/register/register_test.go b/proxy/register/register_test.go
index 78957c3..540f98b 100644
--- a/proxy/register/register_test.go
+++ b/proxy/register/register_test.go
@@ -21,11 +21,11 @@
"testing"
"github.com/apache/servicecomb-mesher/proxy/common"
- chassisCommon "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/config/model"
- "github.com/go-chassis/go-chassis/core/lager"
- "github.com/go-chassis/go-chassis/core/registry"
+ chassisCommon "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/config/model"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/registry"
"github.com/stretchr/testify/assert"
)
diff --git a/proxy/resolver/authority/destination.go b/proxy/resolver/authority/destination.go
index 577a503..1acf490 100644
--- a/proxy/resolver/authority/destination.go
+++ b/proxy/resolver/authority/destination.go
@@ -20,7 +20,7 @@
import (
"fmt"
"github.com/apache/servicecomb-mesher/proxy/resolver"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/openlog"
"strings"
)
@@ -33,7 +33,7 @@
s := strings.Split(rawURI, ":")
if len(s) != 2 {
err := fmt.Errorf("can not parse [%s]", rawURI)
- openlogging.Error(err.Error())
+ openlog.Error(err.Error())
return "", "", err
}
diff --git a/proxy/resolver/authority/destination_test.go b/proxy/resolver/authority/destination_test.go
index baa29e2..4e5c260 100644
--- a/proxy/resolver/authority/destination_test.go
+++ b/proxy/resolver/authority/destination_test.go
@@ -22,7 +22,7 @@
"github.com/apache/servicecomb-mesher/proxy/resolver"
"github.com/apache/servicecomb-mesher/proxy/resolver/authority"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
"github.com/stretchr/testify/assert"
"net/http"
)
diff --git a/proxy/resolver/destination.go b/proxy/resolver/destination.go
index 1432186..b613d24 100644
--- a/proxy/resolver/destination.go
+++ b/proxy/resolver/destination.go
@@ -24,7 +24,7 @@
"fmt"
"github.com/apache/servicecomb-mesher/proxy/config"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/openlog"
)
var drMap = make(map[string]DestinationResolver)
@@ -56,7 +56,7 @@
func (dr *DefaultDestinationResolver) Resolve(remoteIP, host, rawURI string, header map[string]string) (string, string, error) {
u, err := url.Parse(rawURI)
if err != nil {
- openlogging.Error("Can not parse url: " + err.Error())
+ openlog.Error("Can not parse url: " + err.Error())
return "", "", err
}
diff --git a/proxy/resolver/destination_test.go b/proxy/resolver/destination_test.go
index 6b90ae7..fee67bc3 100644
--- a/proxy/resolver/destination_test.go
+++ b/proxy/resolver/destination_test.go
@@ -20,16 +20,16 @@
import (
"testing"
- // "github.com/go-chassis/go-chassis/core/archaius"
- // cConfig "github.com/go-chassis/go-chassis/core/config"
- // "github.com/go-chassis/go-chassis/core/lager"
- // "github.com/go-chassis/go-chassis/pkg/util/fileutil"
+ // "github.com/go-chassis/go-chassis/v2/core/archaius"
+ // cConfig "github.com/go-chassis/go-chassis/v2/core/config"
+ // "github.com/go-chassis/go-chassis/v2/core/lager"
+ // "github.com/go-chassis/go-chassis/v2/pkg/util/fileutil"
// "github.com/apache/servicecomb-mesher/cmd"
// "github.com/apache/servicecomb-mesher/config"
"net/http"
// "os"
// "path/filepath"
- "github.com/go-chassis/go-chassis/core/lager"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
"github.com/stretchr/testify/assert"
)
diff --git a/proxy/resolver/source.go b/proxy/resolver/source.go
index afebb04..14e6e14 100644
--- a/proxy/resolver/source.go
+++ b/proxy/resolver/source.go
@@ -19,7 +19,7 @@
import (
"errors"
- "github.com/go-chassis/go-chassis/core/registry"
+ "github.com/go-chassis/go-chassis/v2/core/registry"
)
var (
diff --git a/proxy/resource/v1/health/instances.go b/proxy/resource/v1/health/instances.go
index 08f4e06..ab40c98 100644
--- a/proxy/resource/v1/health/instances.go
+++ b/proxy/resource/v1/health/instances.go
@@ -18,7 +18,7 @@
package health
import (
- "github.com/go-chassis/go-chassis/pkg/runtime"
+ "github.com/go-chassis/go-chassis/v2/pkg/runtime"
)
//GetMesherHealth returns health
diff --git a/proxy/resource/v1/init.go b/proxy/resource/v1/init.go
index 5bf674e..b4881bf 100644
--- a/proxy/resource/v1/init.go
+++ b/proxy/resource/v1/init.go
@@ -19,8 +19,8 @@
import (
"github.com/apache/servicecomb-mesher/proxy/config"
- "github.com/go-chassis/go-chassis"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2"
+ "github.com/go-chassis/openlog"
)
//RegisterWebService creates route and returns all admin APIs
@@ -32,10 +32,10 @@
//Init function initiates admin API
func Init() (err error) {
if !config.GetConfig().Admin.Enable {
- openlogging.Info("admin API is disabled")
+ openlog.Info("admin API is disabled")
return nil
}
- openlogging.Info("admin API is enabled")
+ openlog.Info("admin API is enabled")
RegisterWebService()
return
}
diff --git a/proxy/resource/v1/init_test.go b/proxy/resource/v1/init_test.go
index 2413190..fe769cd 100644
--- a/proxy/resource/v1/init_test.go
+++ b/proxy/resource/v1/init_test.go
@@ -21,8 +21,8 @@
"testing"
mesherconfig "github.com/apache/servicecomb-mesher/proxy/config"
- "github.com/go-chassis/go-chassis/core/lager"
- _ "github.com/go-chassis/go-chassis/core/router/servicecomb"
+ "github.com/go-chassis/go-chassis/v2/core/lager"
+ _ "github.com/go-chassis/go-chassis/v2/core/router/servicecomb"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
)
diff --git a/proxy/resource/v1/route.go b/proxy/resource/v1/route.go
index 7c264a4..24f43a3 100644
--- a/proxy/resource/v1/route.go
+++ b/proxy/resource/v1/route.go
@@ -19,12 +19,12 @@
import (
"fmt"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/openlog"
"net/http"
- "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/core/router"
- "github.com/go-chassis/go-chassis/server/restful"
+ "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/core/router"
+ "github.com/go-chassis/go-chassis/v2/server/restful"
)
// RouteResource is rest api to manage route rule
@@ -37,13 +37,13 @@
if routeRule == nil {
err := context.WriteHeaderAndJSON(http.StatusNotFound, fmt.Sprintf("%s routeRule not found", serviceName), common.JSON)
if err != nil {
- openlogging.Error(fmt.Sprintf("Write HeaderAndJSON error %s: ", err.Error()))
+ openlog.Error(fmt.Sprintf("Write HeaderAndJSON error %s: ", err.Error()))
}
return
}
err := context.WriteHeaderAndJSON(http.StatusOK, routeRule, "text/vnd.yaml")
if err != nil {
- openlogging.Error(fmt.Sprintf("Write HeaderAndJSON error %s: ", err.Error()))
+ openlog.Error(fmt.Sprintf("Write HeaderAndJSON error %s: ", err.Error()))
}
}
diff --git a/proxy/resource/v1/route/route.go b/proxy/resource/v1/route/route.go
index e04a223..ff1cbc2 100644
--- a/proxy/resource/v1/route/route.go
+++ b/proxy/resource/v1/route/route.go
@@ -18,8 +18,8 @@
package route
import (
- "github.com/go-chassis/go-chassis/core/config"
- "github.com/go-chassis/go-chassis/core/router"
+ "github.com/go-chassis/go-chassis/v2/core/config"
+ "github.com/go-chassis/go-chassis/v2/core/router"
)
//Rules is the struct for route rule
diff --git a/proxy/resource/v1/status.go b/proxy/resource/v1/status.go
index 34dcec7..0416b25 100644
--- a/proxy/resource/v1/status.go
+++ b/proxy/resource/v1/status.go
@@ -21,10 +21,10 @@
"fmt"
"github.com/apache/servicecomb-mesher/proxy/resource/v1/health"
"github.com/apache/servicecomb-mesher/proxy/resource/v1/version"
- "github.com/go-chassis/go-chassis/core/common"
- "github.com/go-chassis/go-chassis/pkg/metrics"
- "github.com/go-chassis/go-chassis/server/restful"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2/core/common"
+ "github.com/go-chassis/go-chassis/v2/pkg/metrics"
+ "github.com/go-chassis/go-chassis/v2/server/restful"
+ "github.com/go-chassis/openlog"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
)
@@ -38,13 +38,13 @@
if healthResp.Status == health.Red {
err := context.WriteHeaderAndJSON(http.StatusInternalServerError, healthResp, common.JSON)
if err != nil {
- openlogging.Error(fmt.Sprintf("Write HeaderAndJSON error %s: ", err.Error()))
+ openlog.Error(fmt.Sprintf("Write HeaderAndJSON error %s: ", err.Error()))
}
return
}
err := context.WriteHeaderAndJSON(http.StatusOK, healthResp, common.JSON)
if err != nil {
- openlogging.Error(fmt.Sprintf("Write HeaderAndJSON error %s: ", err.Error()))
+ openlog.Error(fmt.Sprintf("Write HeaderAndJSON error %s: ", err.Error()))
}
}
@@ -60,7 +60,7 @@
versions := version.Ver()
err := context.WriteHeaderAndJSON(http.StatusOK, versions, common.JSON)
if err != nil {
- openlogging.Error(fmt.Sprintf("Write HeaderAndJSON error %s: ", err.Error()))
+ openlog.Error(fmt.Sprintf("Write HeaderAndJSON error %s: ", err.Error()))
}
}
diff --git a/proxy/resource/v1/version/version.go b/proxy/resource/v1/version/version.go
index 40640d9..e238f33 100644
--- a/proxy/resource/v1/version/version.go
+++ b/proxy/resource/v1/version/version.go
@@ -23,7 +23,7 @@
"os"
"path/filepath"
- "github.com/go-chassis/go-chassis/pkg/util/fileutil"
+ "github.com/go-chassis/go-chassis/v2/pkg/util/fileutil"
"gopkg.in/yaml.v2"
)
diff --git a/proxy/server/server.go b/proxy/server/server.go
index e8a895c..e1bb5cc 100644
--- a/proxy/server/server.go
+++ b/proxy/server/server.go
@@ -26,43 +26,43 @@
"github.com/apache/servicecomb-mesher/proxy/health"
"github.com/apache/servicecomb-mesher/proxy/resource/v1/version"
- "github.com/go-chassis/go-chassis"
- "github.com/go-mesh/openlogging"
+ "github.com/go-chassis/go-chassis/v2"
+ "github.com/go-chassis/openlog"
)
// Run run mesher proxy server
func Run() {
// server init
if err := cmd.Init(); err != nil {
- openlogging.Fatal(err.Error())
+ openlog.Fatal(err.Error())
}
if err := cmd.Configs.GeneratePortsMap(); err != nil {
- openlogging.Fatal(err.Error())
+ openlog.Fatal(err.Error())
}
bootstrap.RegisterFramework()
bootstrap.SetHandlers()
if err := chassis.Init(); err != nil {
- openlogging.Fatal("Go chassis init failed, Mesher is not available: " + err.Error())
+ openlog.Fatal("Go chassis init failed, Mesher is not available: " + err.Error())
}
if err := bootstrap.InitEgressChain(); err != nil {
- openlogging.Error("egress chain int failed: %s", openlogging.WithTags(openlogging.Tags{
+ openlog.Error("egress chain int failed: %s", openlog.WithTags(openlog.Tags{
"err": err.Error(),
}))
- openlogging.Fatal(err.Error())
+ openlog.Fatal(err.Error())
}
if err := bootstrap.Start(); err != nil {
- openlogging.Fatal("Bootstrap failed: " + err.Error())
+ openlog.Fatal("Bootstrap failed: " + err.Error())
}
- openlogging.Info("server start complete", openlogging.WithTags(openlogging.Tags{
+ openlog.Info("server start complete", openlog.WithTags(openlog.Tags{
"version": version.Ver().Version,
}))
if err := health.Run(); err != nil {
- openlogging.Fatal("Health manager start failed: " + err.Error())
+ openlog.Fatal("Health manager start failed: " + err.Error())
}
profile()
if err := chassis.Run(); err != nil {
- openlogging.Fatal("Chassis failed: " + err.Error())
+ openlog.Fatal("Chassis failed: " + err.Error())
}
}
@@ -78,8 +78,8 @@
if config.GetConfig().PProf.Listen == "" {
config.GetConfig().PProf.Listen = "127.0.0.1:6060"
}
- openlogging.Warn("Enable pprof on " + config.GetConfig().PProf.Listen)
+ openlog.Warn("Enable pprof on " + config.GetConfig().PProf.Listen)
if err := http.ListenAndServe(config.GetConfig().PProf.Listen, nil); err != nil {
- openlogging.Error("Can not enable pprof: " + err.Error())
+ openlog.Error("Can not enable pprof: " + err.Error())
}
}
diff --git a/proxy/util/util.go b/proxy/util/util.go
index 22b083a..f1582e7 100644
--- a/proxy/util/util.go
+++ b/proxy/util/util.go
@@ -21,7 +21,7 @@
"fmt"
"github.com/apache/servicecomb-mesher/proxy/cmd"
"github.com/apache/servicecomb-mesher/proxy/common"
- "github.com/go-chassis/go-chassis/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
)
//SetLocalServiceAddress assign invocation endpoint a local service address
diff --git a/proxy/util/util_test.go b/proxy/util/util_test.go
index 4461b9e..5f406f8 100755
--- a/proxy/util/util_test.go
+++ b/proxy/util/util_test.go
@@ -20,7 +20,7 @@
import (
"github.com/apache/servicecomb-mesher/proxy/cmd"
"github.com/apache/servicecomb-mesher/proxy/util"
- "github.com/go-chassis/go-chassis/core/invocation"
+ "github.com/go-chassis/go-chassis/v2/core/invocation"
"github.com/stretchr/testify/assert"
"testing"
)