Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
487 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# SkyWalking | ||
|
||
Skywalking-manager is a handler plugin of mesher, it reports tracing data to skywalking server. | ||
|
||
## Configurations | ||
**In conf/mesher.conf** | ||
|
||
**servicecomb.apm.tracing.enable** | ||
> *(optional, bool)* enable application performance manager | ||
**servicecomb.apm.tracing.serverUri** | ||
> *(optional, string)* server address of skywalking | ||
## Example | ||
```yaml | ||
servicecomb: | ||
apm: #application performance monitor | ||
tracing: | ||
enable: true #enable tracing ability | ||
serverUri: 127.0.0.1:11800 #url of skywalking | ||
``` | ||
## Step: | ||
|
||
# 1. SkyWawlking-Manager Init | ||
**You must init skywawlking manager pkg which will manage connection and report msg to skywalking** | ||
- For example: | ||
- [1] You can import skywalking manager proxy/pkg/skywalking in file proxy/bootstrap/bootstrap.go. | ||
- [2] Calling function Init() in proxy/pkg/skywalking manually to init skywalking manager. | ||
- [3] Adding skywalking's consumer handler name SkyWalkingConsumer defined in proxy/pkg/skywalking to consumerChain. | ||
- [4] Adding skywalking's provider handler name SkyWalkingProvider defined in proxy/pkg/skywalking to providerChain. | ||
- more details about handler chains in [go-chassis](https://github.com/go-chassis/go-chassis#readme) | ||
|
||
# 2. SkyWalking-Handler Init | ||
- You must import proxy/handler pkg to init skywalking handler. Not only skywalking handler, all the handlers which are customized for mesher are defined here. | ||
- For example you can import handler pkg in file cmd/mesher/mesher.go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* 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 handler | ||
|
||
import ( | ||
"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/tetratelabs/go2sky" | ||
skycom "github.com/tetratelabs/go2sky/reporter/grpc/common" | ||
"strconv" | ||
) | ||
|
||
const ( | ||
HTTPPrefix = "http://" | ||
) | ||
|
||
const ( | ||
HTTPClientComponentID = 2 | ||
ServiceCombComponentID = 28 | ||
HTTPServerComponentID = 49 | ||
) | ||
|
||
//SkyWalkingProviderHandler struct | ||
type SkyWalkingProviderHandler struct { | ||
} | ||
|
||
//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) | ||
span, _, err := skywalking.CreateEntrySpan(i) | ||
if err != nil { | ||
openlogging.GetLogger().Errorf("CreateEntrySpan error:%s", err.Error()) | ||
} | ||
chain.Next(i, func(r *invocation.Response) (err error) { | ||
err = cb(r) | ||
span.Tag(go2sky.TagHTTPMethod, i.Protocol) | ||
span.Tag(go2sky.TagURL, HTTPPrefix+i.MicroServiceName+i.URLPathFormat) | ||
span.Tag(go2sky.TagStatusCode, strconv.Itoa(r.Status)) | ||
span.SetSpanLayer(skycom.SpanLayer_Http) | ||
span.SetComponent(HTTPServerComponentID) | ||
span.End() | ||
return | ||
}) | ||
} | ||
|
||
//Name return provider name | ||
func (sp *SkyWalkingProviderHandler) Name() string { | ||
return skywalking.SkyWalkingProvider | ||
} | ||
|
||
//NewSkyWalkingProvier return provider handler for SkyWalking | ||
func NewSkyWalkingProvier() handler.Handler { | ||
return &SkyWalkingProviderHandler{} | ||
} | ||
|
||
//SkyWalkingConsumerHandler struct | ||
type SkyWalkingConsumerHandler struct { | ||
} | ||
|
||
//Handle is for consumer | ||
func (sc *SkyWalkingConsumerHandler) Handle(chain *handler.Chain, i *invocation.Invocation, cb invocation.ResponseCallBack) { | ||
openlogging.GetLogger().Debugf("SkyWalkingConsumerHandler begin:%#v", *i) | ||
span, ctx, err := skywalking.CreateEntrySpan(i) | ||
if err != nil { | ||
openlogging.GetLogger().Errorf("CreateEntrySpan error:%s", err.Error()) | ||
} | ||
spanExit, err := skywalking.CreateExitSpan(ctx, i) | ||
if err != nil { | ||
openlogging.GetLogger().Errorf("CreateExitSpan error:%s", err.Error()) | ||
} | ||
chain.Next(i, func(r *invocation.Response) (err error) { | ||
err = cb(r) | ||
span.Tag(go2sky.TagHTTPMethod, i.Protocol) | ||
span.Tag(go2sky.TagURL, HTTPPrefix+i.MicroServiceName+i.URLPathFormat) | ||
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.TagStatusCode, strconv.Itoa(r.Status)) | ||
spanExit.SetSpanLayer(skycom.SpanLayer_Http) | ||
spanExit.SetComponent(HTTPClientComponentID) | ||
|
||
spanExit.End() | ||
span.End() | ||
openlogging.GetLogger().Debugf("SkyWalkingConsumerHandler end.") | ||
return | ||
}) | ||
} | ||
|
||
//Name return consumer name | ||
func (sc *SkyWalkingConsumerHandler) Name() string { | ||
return skywalking.SkyWalkingConsumer | ||
} | ||
|
||
//NewSkyWalkingConsumer return consumer handler for SkyWalking | ||
func NewSkyWalkingConsumer() handler.Handler { | ||
return &SkyWalkingConsumerHandler{} | ||
} | ||
|
||
func init() { | ||
handler.RegisterHandler(skywalking.SkyWalkingProvider, NewSkyWalkingProvier) | ||
handler.RegisterHandler(skywalking.SkyWalkingConsumer, NewSkyWalkingConsumer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* 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 handler_test | ||
|
||
import ( | ||
"context" | ||
"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" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
const ( | ||
Port = ":49800" | ||
ServerUrl = "127.0.0.1:49800" | ||
) | ||
|
||
//initGcConfig | ||
func initGcConfig() { | ||
var micCfg model.MicroserviceCfg | ||
micCfg.ServiceDescription.Name = "TEST" | ||
gcconfig.MicroserviceDefinition = &micCfg | ||
} | ||
|
||
//initMesherConfig | ||
func initMesherConfig() { | ||
config.SetConfig(&config.MesherConfig{ServiceComb: &config.ServiceComb{config.APM{config.Tracing{Enable: true, ServerURI: "192.168.0.1:17289"}}}}) | ||
} | ||
|
||
//initInv | ||
func initInv() *invocation.Invocation { | ||
var i invocation.Invocation | ||
i.MicroServiceName = "test" | ||
i.Ctx = context.Background() | ||
i.Endpoint = "calculator" | ||
i.URLPathFormat = "/bmi" | ||
return &i | ||
} | ||
|
||
//TestProviderHandlerName | ||
func TestProviderHandlerName(t *testing.T) { | ||
h := mhandler.SkyWalkingProviderHandler{} | ||
assert.Equal(t, h.Name(), skywalking.SkyWalkingProvider) | ||
} | ||
|
||
//TestNewProvier | ||
func TestNewProvier(t *testing.T) { | ||
h := mhandler.NewSkyWalkingProvier() | ||
assert.NotEqual(t, h, nil) | ||
assert.Equal(t, h.Name(), skywalking.SkyWalkingProvider) | ||
} | ||
|
||
//TestProvierHandle | ||
func TestProvierHandle(t *testing.T) { | ||
initGcConfig() | ||
initMesherConfig() | ||
skywalking.Init() | ||
c := handler.Chain{} | ||
c.AddHandler(mhandler.NewSkyWalkingProvier()) | ||
|
||
gcconfig.GlobalDefinition = &model.GlobalCfg{} | ||
gcconfig.GlobalDefinition.Cse.Handler.Chain.Consumer = make(map[string]string) | ||
gcconfig.GlobalDefinition.Cse.Handler.Chain.Consumer["skywalking-provider"] = "skywalking-provider" | ||
|
||
c.Next(initInv(), func(r *invocation.Response) error { | ||
assert.Equal(t, r.Err, nil) | ||
return r.Err | ||
}) | ||
} | ||
|
||
//TestConsumerHandlerName | ||
func TestConsumerHandlerName(t *testing.T) { | ||
c := mhandler.SkyWalkingConsumerHandler{} | ||
assert.Equal(t, c.Name(), skywalking.SkyWalkingConsumer) | ||
} | ||
|
||
//TestNewConsumer | ||
func TestNewConsumer(t *testing.T) { | ||
h := mhandler.NewSkyWalkingConsumer() | ||
assert.NotEqual(t, h, nil) | ||
assert.Equal(t, h.Name(), skywalking.SkyWalkingConsumer) | ||
} | ||
|
||
//TestConsumerHandle | ||
func TestConsumerHandle(t *testing.T) { | ||
initGcConfig() | ||
initMesherConfig() | ||
skywalking.Init() | ||
c := handler.Chain{} | ||
c.AddHandler(mhandler.NewSkyWalkingConsumer()) | ||
|
||
gcconfig.GlobalDefinition = &model.GlobalCfg{} | ||
gcconfig.GlobalDefinition.Cse.Handler.Chain.Consumer = make(map[string]string) | ||
gcconfig.GlobalDefinition.Cse.Handler.Chain.Consumer["skywalking-consumer"] = "skywalking-consumer" | ||
|
||
c.Next(initInv(), func(r *invocation.Response) error { | ||
assert.Equal(t, r.Err, nil) | ||
return r.Err | ||
}) | ||
} |
Oops, something went wrong.