Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Commit

Permalink
Using skywalking goapi as protocol (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrproliu authored Apr 5, 2021
1 parent 9094186 commit 520133d
Show file tree
Hide file tree
Showing 21 changed files with 224 additions and 1,593 deletions.
16 changes: 2 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,14 @@ deps:
test:
go test -v -race -cover -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v github.com/SkyAPM/go2sky/reporter/grpc | grep -v github.com/SkyAPM/go2sky/test`

.PHONY: proto-gen
proto-gen:
cd $(GRPC_PATH) && \
protoc common/*.proto --go_out=plugins=grpc:$(GOPATH)/src && \
cp ${GOPATH}/src/github.com/SkyAPM/go2sky/reporter/grpc/common/*.go common/
cd $(GRPC_PATH) && \
protoc language-agent/*.proto --go_out=plugins=grpc:$(GOPATH)/src && \
cp ${GOPATH}/src/github.com/SkyAPM/go2sky/reporter/grpc/language-agent/*.go language-agent/
cd $(GRPC_PATH) && \
protoc management/*.proto --go_out=plugins=grpc:$(GOPATH)/src && \
cp ${GOPATH}/src/github.com/SkyAPM/go2sky/reporter/grpc/management/*.go management/

.PHONY: mock-gen
mock-gen:
cd $(GRPC_PATH)/language-agent && \
mkdir -p mock_trace && \
mockgen github.com/SkyAPM/go2sky/reporter/grpc/language-agent TraceSegmentReportServiceClient > mock_trace/Tracing.mock.go
mockgen skywalking.apache.org/repo/goapi/collect/language/agent/v3 TraceSegmentReportServiceClient > mock_trace/Tracing.mock.go
cd $(GRPC_PATH)/management && \
mkdir -p mock_management && \
mockgen github.com/SkyAPM/go2sky/reporter/grpc/management ManagementServiceClient > mock_management/Management.mock.go
mockgen skywalking.apache.org/repo/goapi/collect/management/v3 ManagementServiceClient > mock_management/Management.mock.go

LINTER := bin/golangci-lint
$(LINTER):
Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ module github.com/SkyAPM/go2sky
go 1.12

require (
github.com/golang/mock v1.2.0
github.com/golang/protobuf v1.3.2
github.com/google/uuid v1.1.1
github.com/golang/mock v1.5.0
github.com/google/uuid v1.1.2
github.com/pkg/errors v0.8.1
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 // indirect
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 // indirect
golang.org/x/text v0.3.1-0.20181010134911-4d1c5fb19474 // indirect
google.golang.org/grpc v1.27.0
google.golang.org/grpc v1.36.1
skywalking.apache.org/repo/goapi v0.0.0-20210401062122-a049ca15c62d
)
119 changes: 102 additions & 17 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package go2sky
import (
"time"

v3 "github.com/SkyAPM/go2sky/reporter/grpc/language-agent"
agentv3 "skywalking.apache.org/repo/goapi/collect/language/agent/v3"
)

type NoopSpan struct {
Expand All @@ -36,7 +36,7 @@ func (*NoopSpan) GetOperationName() string {
func (*NoopSpan) SetPeer(string) {
}

func (*NoopSpan) SetSpanLayer(v3.SpanLayer) {
func (*NoopSpan) SetSpanLayer(agentv3.SpanLayer) {
}

func (*NoopSpan) SetComponent(int32) {
Expand Down
4 changes: 2 additions & 2 deletions noop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"
"time"

v3 "github.com/SkyAPM/go2sky/reporter/grpc/language-agent"
agentv3 "skywalking.apache.org/repo/goapi/collect/language/agent/v3"
)

type createFunc func() (Span, context.Context, error)
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestNoopMethod(t *testing.T) {
n := NoopSpan{}
n.SetOperationName("aa")
n.SetPeer("localhost:1111")
n.SetSpanLayer(v3.SpanLayer_Database)
n.SetSpanLayer(agentv3.SpanLayer_Database)
n.SetComponent(2)
n.Tag("key", "value")
n.Log(time.Now(), "key", "value")
Expand Down
4 changes: 2 additions & 2 deletions plugins/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"time"

"github.com/SkyAPM/go2sky"
v3 "github.com/SkyAPM/go2sky/reporter/grpc/language-agent"
agentv3 "skywalking.apache.org/repo/goapi/collect/language/agent/v3"
)

const componentIDGOHttpClient = 5005
Expand Down Expand Up @@ -105,7 +105,7 @@ func (t *transport) RoundTrip(req *http.Request) (res *http.Response, err error)
}
span.Tag(go2sky.TagHTTPMethod, req.Method)
span.Tag(go2sky.TagURL, req.URL.String())
span.SetSpanLayer(v3.SpanLayer_Http)
span.SetSpanLayer(agentv3.SpanLayer_Http)
res, err = t.delegated.RoundTrip(req)
if err != nil {
span.Error(time.Now(), err.Error())
Expand Down
4 changes: 2 additions & 2 deletions plugins/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/SkyAPM/go2sky"
"github.com/SkyAPM/go2sky/internal/tool"
v3 "github.com/SkyAPM/go2sky/reporter/grpc/language-agent"
agentv3 "skywalking.apache.org/repo/goapi/collect/language/agent/v3"
)

const (
Expand Down Expand Up @@ -95,7 +95,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
span.Tag(go2sky.TagHTTPMethod, r.Method)
span.Tag(go2sky.TagURL, fmt.Sprintf("%s%s", r.Host, r.URL.Path))
span.SetSpanLayer(v3.SpanLayer_Http)
span.SetSpanLayer(agentv3.SpanLayer_Http)

rww := &responseWriterWrapper{w: w, statusCode: 200}
defer func() {
Expand Down
20 changes: 10 additions & 10 deletions reporter/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (

"github.com/SkyAPM/go2sky"
"github.com/SkyAPM/go2sky/internal/tool"
"github.com/SkyAPM/go2sky/reporter/grpc/common"
agentv3 "github.com/SkyAPM/go2sky/reporter/grpc/language-agent"
managementv3 "github.com/SkyAPM/go2sky/reporter/grpc/management"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
commonv3 "skywalking.apache.org/repo/goapi/collect/common/v3"
agentv3 "skywalking.apache.org/repo/goapi/collect/language/agent/v3"
managementv3 "skywalking.apache.org/repo/goapi/collect/management/v3"
)

const (
Expand Down Expand Up @@ -263,7 +263,7 @@ func (r *gRPCReporter) reportInstanceProperties() (err error) {
props := buildOSInfo()
if r.instanceProps != nil {
for k, v := range r.instanceProps {
props = append(props, &common.KeyStringValuePair{
props = append(props, &commonv3.KeyStringValuePair{
Key: k,
Value: v,
})
Expand Down Expand Up @@ -311,29 +311,29 @@ func (r *gRPCReporter) check() {
}()
}

func buildOSInfo() (props []*common.KeyStringValuePair) {
func buildOSInfo() (props []*commonv3.KeyStringValuePair) {
processNo := tool.ProcessNo()
if processNo != "" {
kv := &common.KeyStringValuePair{
kv := &commonv3.KeyStringValuePair{
Key: "Process No.",
Value: processNo,
}
props = append(props, kv)
}

hostname := &common.KeyStringValuePair{
hostname := &commonv3.KeyStringValuePair{
Key: "hostname",
Value: tool.HostName(),
}
props = append(props, hostname)

language := &common.KeyStringValuePair{
language := &commonv3.KeyStringValuePair{
Key: "language",
Value: "go",
}
props = append(props, language)

osName := &common.KeyStringValuePair{
osName := &commonv3.KeyStringValuePair{
Key: "OS Name",
Value: tool.OSName(),
}
Expand All @@ -342,7 +342,7 @@ func buildOSInfo() (props []*common.KeyStringValuePair) {
ipv4s := tool.AllIPV4()
if len(ipv4s) > 0 {
for _, ipv4 := range ipv4s {
kv := &common.KeyStringValuePair{
kv := &commonv3.KeyStringValuePair{
Key: "ipv4",
Value: ipv4,
}
Expand Down
Loading

0 comments on commit 520133d

Please sign in to comment.