Skip to content

Commit

Permalink
adapt go chassis 2.1.0 (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoliang authored Feb 25, 2021
1 parent 41b7e5e commit 7a65d1d
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 290 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
pull_request:
on: [push, pull_request]
jobs:
golangci:
name: lint
Expand All @@ -15,5 +9,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.29
args: --skip-dirs=examples --out-format=colored-line-number --skip-files=.*_test.go$
version: v1.37.1
args: --skip-dirs=examples,proxy/protocol/dubbo --out-format=colored-line-number --skip-files=.*_test.go$
2 changes: 1 addition & 1 deletion proxy/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func parseConfigFromCmd(args []string) (err error) {
cli.StringFlag{
Name: "service-ports",
EnvVar: common.EnvServicePorts,
Usage: fmt.Sprintf("service protocol and port,examples: --service-ports=http:3000,grpc:8000"),
Usage: "service protocol and port,examples: --service-ports=http:3000,grpc:8000",
Destination: &Configs.LocalServicePorts,
},
}
Expand Down
5 changes: 4 additions & 1 deletion proxy/handler/port_rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,8 @@ func New() handler.Handler {
}

func init() {
handler.RegisterHandler(PortMapForPilot, New)
err := handler.RegisterHandler(PortMapForPilot, New)
if err != nil {
openlog.Error(err.Error())
}
}
7 changes: 3 additions & 4 deletions proxy/handler/skywalking_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ func (sp *SkyWalkingProviderHandler) Handle(chain *handler.Chain, i *invocation.
chain.Next(i, func(r *invocation.Response) {
cb(r)
span.Tag(go2sky.TagHTTPMethod, i.Protocol)
span.Tag(go2sky.TagURL, HTTPPrefix+i.MicroServiceName+i.URLPathFormat)
span.Tag(go2sky.TagURL, HTTPPrefix+i.MicroServiceName+i.URLPath)
span.Tag(go2sky.TagStatusCode, strconv.Itoa(r.Status))
span.SetSpanLayer(skycom.SpanLayer_Http)
span.SetComponent(HTTPServerComponentID)
span.End()
return
})
}

Expand Down Expand Up @@ -89,13 +88,13 @@ func (sc *SkyWalkingConsumerHandler) Handle(chain *handler.Chain, i *invocation.
chain.Next(i, func(r *invocation.Response) {
cb(r)
span.Tag(go2sky.TagHTTPMethod, i.Protocol)
span.Tag(go2sky.TagURL, HTTPPrefix+i.MicroServiceName+i.URLPathFormat)
span.Tag(go2sky.TagURL, HTTPPrefix+i.MicroServiceName+i.URLPath)
span.Tag(go2sky.TagStatusCode, strconv.Itoa(r.Status))
span.SetSpanLayer(skycom.SpanLayer_Http)
span.SetComponent(HTTPServerComponentID)

spanExit.Tag(go2sky.TagHTTPMethod, i.Protocol)
spanExit.Tag(go2sky.TagURL, HTTPPrefix+i.MicroServiceName+i.URLPathFormat)
spanExit.Tag(go2sky.TagURL, HTTPPrefix+i.MicroServiceName+i.URLPath)
spanExit.Tag(go2sky.TagStatusCode, strconv.Itoa(r.Status))
spanExit.SetSpanLayer(skycom.SpanLayer_Http)
spanExit.SetComponent(HTTPClientComponentID)
Expand Down
2 changes: 1 addition & 1 deletion proxy/handler/skywalking_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func initInv() *invocation.Invocation {
i.MicroServiceName = "test"
i.Ctx = context.Background()
i.Endpoint = "calculator"
i.URLPathFormat = "/bmi"
i.URLPath = "/bmi"
return &i
}

Expand Down
8 changes: 1 addition & 7 deletions proxy/pkg/egress/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ import (
meshercontrol "github.com/apache/servicecomb-mesher/proxy/control"
"github.com/go-chassis/go-chassis/v2/control"
"regexp"
"sync"
)

var lock sync.RWMutex

var plainHosts = make(map[string]*config.EgressRule)
var regexHosts = make(map[string]*config.EgressRule)

//Egress return egress rule, you can also set custom egress rule
type Egress interface {
Init(Options) error
Expand Down Expand Up @@ -102,7 +96,7 @@ func Match(hostname string) (bool, *control.EgressConfig) {
} else if string(host[0]) == "*" {
substring := host[1:]
match, _ := regexp.MatchString(substring+"$", hostname)
if match == true {
if match {
return true, &egress
}
}
Expand Down
13 changes: 4 additions & 9 deletions proxy/pkg/egress/egress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

"github.com/apache/servicecomb-mesher/proxy/cmd"
mesherconfig "github.com/apache/servicecomb-mesher/proxy/config"
_ "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/v2/control"
Expand All @@ -44,7 +43,6 @@ func init() {
func BenchmarkMatch(b *testing.B) {
chassis := []byte(`
cse:
service:
registry:
#disabled: false optional:禁用注册发现选项,默认开始注册发现
type: servicecenter #optional:可选zookeeper/servicecenter,zookeeper供中软使用,不配置的情况下默认为servicecenter
Expand Down Expand Up @@ -101,8 +99,7 @@ egressRule:
func TestMatch(t *testing.T) {

b := []byte(`
cse:
service:
servicecomb:
registry:
#disabled: false optional:禁用注册发现选项,默认开始注册发现
type: servicecenter #optional:可选zookeeper/servicecenter,zookeeper供中软使用,不配置的情况下默认为servicecenter
Expand All @@ -118,11 +115,9 @@ cse:
_, err = f1.Write(b)
b = []byte(`
---
#微服务的私有属性
#APPLICATION_ID: CSE #optional
service_description:
name: Client
#version: 0.1 #optional
servicecomb
service:
name: Client
`)
d, _ = os.Getwd()
Expand Down
77 changes: 0 additions & 77 deletions proxy/pkg/infras/k8s/k8s.go

This file was deleted.

59 changes: 0 additions & 59 deletions proxy/pkg/infras/k8s/k8s_test.go

This file was deleted.

2 changes: 0 additions & 2 deletions proxy/pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ package metrics

import (
"github.com/go-chassis/go-chassis/v2/pkg/runtime"
"sync"
"time"
)

Expand All @@ -46,7 +45,6 @@ const (
var (
//LabelNames is a fixed list with service name, appID, version
LabelNames = []string{LServiceName, LApp, LVersion}
mutex = sync.Mutex{}
)

//Options define recorder options
Expand Down
3 changes: 0 additions & 3 deletions proxy/pkg/metrics/prom_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ package metrics
import (
"errors"
"net/http"
"sync"
"time"
)

var onceEnable sync.Once

//PromRecorder record metrics
type PromRecorder struct {
LabelNames []string
Expand Down
1 change: 0 additions & 1 deletion proxy/pkg/metrics/prometheus_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ type PrometheusMesherSinker struct {
var (
//DefaultPrometheusExporter stores value of default prometheus exporter type
DefaultPrometheusExporter = GetPrometheusExporter()
onceInit sync.Once
//DefaultPrometheusSinker stores value of default prometheus exporter type
DefaultPrometheusSinker *PrometheusMesherSinker
)
Expand Down
6 changes: 3 additions & 3 deletions proxy/pkg/skywalking/skywalking_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ var tracer *go2sky.Tracer

//CreateEntrySpan use tracer to create and start an entry span for incoming request
func CreateEntrySpan(i *invocation.Invocation) (go2sky.Span, context.Context, error) {
return tracer.CreateEntrySpan(i.Ctx, i.MicroServiceName+i.URLPathFormat, func() (string, error) {
return tracer.CreateEntrySpan(i.Ctx, i.MicroServiceName+i.URLPath, func() (string, error) {
return i.Headers()[CrossProcessProtocolV2], nil
})
}

//CreateExitSpan use tracer to create and start an exit span for client
func CreateExitSpan(ctx context.Context, i *invocation.Invocation) (go2sky.Span, error) {
return tracer.CreateExitSpan(ctx, i.MicroServiceName+i.URLPathFormat, i.Endpoint+i.URLPathFormat, func(header string) error {
return tracer.CreateExitSpan(ctx, i.MicroServiceName+i.URLPath, i.Endpoint+i.URLPath, func(header string) error {
i.SetHeader(CrossProcessProtocolV2, header)
return nil
})
Expand Down Expand Up @@ -76,5 +76,5 @@ func Init() {
openlog.Error(fmt.Sprintf("NewTracer error " + err.Error()))
}
//tracer.WaitUntilRegister()
openlog.Debug(fmt.Sprintf("SkyWalking manager Init end"))
openlog.Debug("SkyWalking manager Init end")
}
2 changes: 1 addition & 1 deletion proxy/pkg/skywalking/skywalking_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func initInv() *invocation.Invocation {
i.MicroServiceName = "test"
i.Ctx = context.Background()
i.Endpoint = "calculator"
i.URLPathFormat = "/bmi"
i.URLPath = "/bmi"
return &i
}

Expand Down
6 changes: 3 additions & 3 deletions proxy/protocol/dubbo/proxy/dubbo_proxy_ouput.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (e ProxyError) Error() string {
func SetLocalServiceAddress(inv *invocation.Invocation) error {
inv.Endpoint = cmd.Configs.PortsMap[inv.Protocol]
if inv.Endpoint == "" {
if inv.Port != "" {
inv.Endpoint = "127.0.0.1:" + inv.Port
if inv.PortName != "" {
inv.Endpoint = "127.0.0.1:" + inv.PortName
cmd.Configs.PortsMap[inv.Protocol] = inv.Endpoint
return nil
} else {
Expand All @@ -97,7 +97,7 @@ func Handle(ctx *dubbo.InvokeContext) error {
inv.MicroServiceName = svc.ServiceName
inv.RouteTags = utiltags.NewDefaultTag(svc.Version, svc.AppID)
inv.Protocol = "dubbo"
inv.URLPathFormat = ""
inv.URLPath = ""
inv.Reply = &dubboclient.WrapResponse{nil} //&rest.Response{Resp: &ctx.Response}
var err error
err = SetLocalServiceAddress(inv) //select local service
Expand Down
2 changes: 1 addition & 1 deletion proxy/protocol/dubbo/proxy/dubbo_proxy_ouput_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestSetLocalServiceAddress(t *testing.T) {
assert.Error(t, err)

// case port
inv.Port = "8080"
inv.PortName = "8080"
err = SetLocalServiceAddress(inv)
assert.NoError(t, err)
})
Expand Down
Loading

0 comments on commit 7a65d1d

Please sign in to comment.