[ 
https://issues.apache.org/jira/browse/SCB-332?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16355132#comment-16355132
 ] 

ASF GitHub Bot commented on SCB-332:
------------------------------------

little-cui closed pull request #278: SCB-332 Wrong json output format in zipkin 
file collector
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/278
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pkg/util/net.go b/pkg/util/net.go
index d73e928c..5791b4f6 100644
--- a/pkg/util/net.go
+++ b/pkg/util/net.go
@@ -109,3 +109,15 @@ func InetAton(ip string) (ipnr uint32) {
        }
        return
 }
+
+func ParseRequestURL(r *http.Request) string {
+       if len(r.URL.Scheme) > 0 {
+               return r.URL.String()
+       }
+
+       scheme := "https://";
+       if r.TLS == nil {
+               scheme = "http://";
+       }
+       return scheme + r.Host + r.RequestURI
+}
diff --git a/server/infra/registry/registry.go 
b/server/infra/registry/registry.go
index 228b4e4a..b87aad18 100644
--- a/server/infra/registry/registry.go
+++ b/server/infra/registry/registry.go
@@ -17,8 +17,8 @@
 package registry
 
 import (
+       "bytes"
        "fmt"
-       "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        "github.com/astaxie/beego"
        "github.com/coreos/etcd/mvcc/mvccpb"
        "golang.org/x/net/context"
@@ -194,12 +194,54 @@ type PluginOp struct {
 }
 
 func (op PluginOp) String() string {
-       return fmt.Sprintf(
-               "{mode: %s, action: %s, key: %s, end: %s, val: %d, prefix: %t, 
prev: %t, lease: %d, keyOnly: %t, countOnly: %t, sort: %s, rev: %d, 
ignoreLease: %t, offset: %d, limit: %d}",
-               op.Mode, op.Action, op.Key, op.EndKey, 
len(util.BytesToStringWithNoCopy(op.Value)),
-               op.Prefix, op.PrevKV, op.Lease, op.KeyOnly, op.CountOnly,
-               op.SortOrder, op.Revision, op.IgnoreLease, op.Offset, op.Limit,
-       )
+       return op.FormatUrlParams()
+}
+
+func (op PluginOp) FormatUrlParams() string {
+       var buf bytes.Buffer
+       buf.WriteString("action=")
+       buf.WriteString(op.Action.String())
+       buf.WriteString("&mode=true")
+       buf.WriteString(op.Mode.String())
+       buf.WriteString("&key=")
+       buf.Write(op.Key)
+       buf.WriteString(fmt.Sprintf("&value=%d", len(op.Value)))
+       if len(op.EndKey) > 0 {
+               buf.WriteString("&end=")
+               buf.Write(op.EndKey)
+       }
+       if op.Prefix {
+               buf.WriteString("&prefix=true")
+       }
+       if op.PrevKV {
+               buf.WriteString("&prev=true")
+       }
+       if op.Lease > 0 {
+               buf.WriteString(fmt.Sprintf("&lease=%d", op.Lease))
+       }
+       if op.KeyOnly {
+               buf.WriteString("&keyOnly=true")
+       }
+       if op.CountOnly {
+               buf.WriteString("&countOnly=true")
+       }
+       if op.SortOrder != SORT_NONE {
+               buf.WriteString("&sort=")
+               buf.WriteString(op.SortOrder.String())
+       }
+       if op.Revision > 0 {
+               buf.WriteString(fmt.Sprintf("&rev=%d", op.Revision))
+       }
+       if op.IgnoreLease {
+               buf.WriteString("&ignoreLease=true")
+       }
+       if op.Offset > 0 {
+               buf.WriteString(fmt.Sprintf("&offset=%d", op.Offset))
+       }
+       if op.Limit > 0 {
+               buf.WriteString(fmt.Sprintf("&limit=%d", op.Limit))
+       }
+       return buf.String()
 }
 
 type Operation func(...PluginOpOption) (op PluginOp)
diff --git a/server/plugin/infra/registry/etcd/etcd.go 
b/server/plugin/infra/registry/etcd/etcd.go
index 7ffe5a6b..941aa7cd 100644
--- a/server/plugin/infra/registry/etcd/etcd.go
+++ b/server/plugin/infra/registry/etcd/etcd.go
@@ -39,7 +39,10 @@ const (
        CONNECT_MANAGER_SERVER_TIMEOUT = 10
 )
 
-var clientTLSConfig *tls.Config
+var (
+       clientTLSConfig *tls.Config
+       endpoint        string
+)
 
 func init() {
        mgr.RegisterPlugin(mgr.Plugin{mgr.REGISTRY, "etcd", NewRegistry})
@@ -602,6 +605,11 @@ func setResponseAndCallback(pResp 
*registry.PluginResponse, kvs []*mvccpb.KeyVal
        return cb("key information changed", pResp)
 }
 
+func sslEnabled() bool {
+       return core.ServerInfo.Config.SslEnabled &&
+               
strings.Index(strings.ToLower(registry.RegistryConfig().ClusterAddresses), 
"https://";) >= 0
+}
+
 func NewRegistry() mgr.PluginInstance {
        util.Logger().Warnf(nil, "starting service center in proxy mode")
 
@@ -611,18 +619,7 @@ func NewRegistry() mgr.PluginInstance {
        }
        addrs := strings.Split(registry.RegistryConfig().ClusterAddresses, ",")
 
-       if core.ServerInfo.Config.SslEnabled && 
strings.Index(registry.RegistryConfig().ClusterAddresses, "https://";) >= 0 {
-               var err error
-               // go client tls限制,提供身份证书、不认证服务端、不校验CN
-               clientTLSConfig, err = sctls.GetClientTLSConfig()
-               if err != nil {
-                       util.Logger().Error("get etcd client tls config 
failed", err)
-                       inst.err <- err
-                       return inst
-               }
-       }
-
-       endpoints := []string{}
+       endpoints := make([]string, 0, len(addrs))
        for _, addr := range addrs {
                if strings.Index(addr, "://") > 0 {
                        // 如果配置格式为"sr-0=http(s)://IP:Port",则需要分离IP:Port部分
@@ -630,8 +627,21 @@ func NewRegistry() mgr.PluginInstance {
                } else {
                        endpoints = append(endpoints, addr)
                }
+       }
 
+       scheme := "http://";
+       if sslEnabled() {
+               var err error
+               // go client tls限制,提供身份证书、不认证服务端、不校验CN
+               clientTLSConfig, err = sctls.GetClientTLSConfig()
+               if err != nil {
+                       util.Logger().Error("get etcd client tls config 
failed", err)
+                       inst.err <- err
+                       return inst
+               }
+               scheme = "https://";
        }
+       endpoint = scheme + endpoints[0]
 
        inv, err := time.ParseDuration(core.ServerInfo.Config.AutoSyncInterval)
        if err != nil {
diff --git a/server/plugin/infra/registry/etcd/tracing.go 
b/server/plugin/infra/registry/etcd/tracing.go
index 7e628fc8..72a38b08 100644
--- a/server/plugin/infra/registry/etcd/tracing.go
+++ b/server/plugin/infra/registry/etcd/tracing.go
@@ -25,7 +25,7 @@ import (
        "net/http"
 )
 
-func TracingBegin(ctx context.Context, operationName string, op 
registry.PluginOp) tracing.Span {
+func ToRequest(op registry.PluginOp) (*http.Request, error) {
        var action string
        switch op.Action {
        case registry.Get:
@@ -35,7 +35,11 @@ func TracingBegin(ctx context.Context, operationName string, 
op registry.PluginO
        case registry.Delete:
                action = http.MethodDelete
        }
-       r, err := http.NewRequest(action, util.BytesToStringWithNoCopy(op.Key), 
nil)
+       return http.NewRequest(action, endpoint+"/?"+op.FormatUrlParams(), nil)
+}
+
+func TracingBegin(ctx context.Context, operationName string, op 
registry.PluginOp) tracing.Span {
+       r, err := ToRequest(op)
        if err != nil {
                util.Logger().Errorf(err, "new backend request failed")
                return nil
diff --git a/server/plugin/infra/tracing/buildin/buildin.go 
b/server/plugin/infra/tracing/buildin/buildin.go
index bfae0863..b4616f21 100644
--- a/server/plugin/infra/tracing/buildin/buildin.go
+++ b/server/plugin/infra/tracing/buildin/buildin.go
@@ -63,7 +63,7 @@ func (zp *Zipkin) ServerBegin(operationName string, itf 
tracing.Request) tracing
                span = ZipkinTracer().StartSpan(operationName, 
ext.RPCServerOption(wireContext))
                ext.SpanKindRPCServer.Set(span)
                ext.HTTPMethod.Set(span, r.Method)
-               ext.HTTPUrl.Set(span, r.URL.String())
+               ext.HTTPUrl.Set(span, util.ParseRequestURL(r))
 
                span.SetTag("protocol", "HTTP")
                span.SetTag(zipkincore.HTTP_PATH, r.URL.Path)
@@ -104,7 +104,7 @@ func (zp *Zipkin) ClientBegin(operationName string, itf 
tracing.Request) tracing
                span = ZipkinTracer().StartSpan(operationName, 
opentracing.ChildOf(parentSpan.Context()))
                ext.SpanKindRPCClient.Set(span)
                ext.HTTPMethod.Set(span, r.Method)
-               ext.HTTPUrl.Set(span, r.URL.String())
+               ext.HTTPUrl.Set(span, util.ParseRequestURL(r))
 
                span.SetTag("protocol", "HTTP")
                span.SetTag(zipkincore.HTTP_PATH, r.URL.Path)
diff --git a/server/plugin/infra/tracing/buildin/span.go 
b/server/plugin/infra/tracing/buildin/span.go
index 32c09a78..5b8011d9 100644
--- a/server/plugin/infra/tracing/buildin/span.go
+++ b/server/plugin/infra/tracing/buildin/span.go
@@ -24,14 +24,14 @@ import (
 )
 
 type Span struct {
-       TraceID string `thrift:"trace_id,1" db:"trace_id" json:"traceId"`
+       TraceID string `thrift:"traceId,1" db:"traceId" json:"traceId"`
        // unused field # 2
        Name        string        `thrift:"name,3" db:"name" json:"name"`
        ID          string        `thrift:"id,4" db:"id" json:"id"`
-       ParentID    string        `thrift:"parent_id,5" db:"parent_id" 
json:"parentId,omitempty"`
+       ParentID    string        `thrift:"parentId,5" db:"parentId" 
json:"parentId,omitempty"`
        Annotations []*Annotation `thrift:"annotations,6" db:"annotations" 
json:"annotations"`
        // unused field # 7
-       BinaryAnnotations []*BinaryAnnotation `thrift:"binary_annotations,8" 
db:"binary_annotations" json:"binaryAnnotations"`
+       BinaryAnnotations []*BinaryAnnotation `thrift:"binaryAnnotations,8" 
db:"binaryAnnotations" json:"binaryAnnotations"`
        //Debug bool `thrift:"debug,9" db:"debug" json:"debug,omitempty"`
        Timestamp *int64 `thrift:"timestamp,10" db:"timestamp" 
json:"timestamp,omitempty"`
        Duration  *int64 `thrift:"duration,11" db:"duration" 
json:"duration,omitempty"`
@@ -41,20 +41,20 @@ type Span struct {
 type Annotation struct {
        Timestamp int64     `thrift:"timestamp,1" db:"timestamp" 
json:"timestamp"`
        Value     string    `thrift:"value,2" db:"value" json:"value"`
-       Host      *Endpoint `thrift:"host,3" db:"host" json:"host,omitempty"`
+       Host      *Endpoint `thrift:"endpoint,3" db:"endpoint" 
json:"endpoint,omitempty"`
 }
 
 type BinaryAnnotation struct {
        Key   string `thrift:"key,1" db:"key" json:"key"`
        Value string `thrift:"value,2" db:"value" json:"value"`
        //AnnotationType AnnotationType `thrift:"annotation_type,3" 
db:"annotation_type" json:"annotation_type"`
-       //Host *Endpoint `thrift:"host,4" db:"host" json:"host,omitempty"`
+       //Host *Endpoint `thrift:"endpoint,4" db:"endpoint" 
json:"endpoint,omitempty"`
 }
 
 type Endpoint struct {
        Ipv4        string `thrift:"ipv4,1" db:"ipv4" json:"ipv4"`
        Port        int16  `thrift:"port,2" db:"port" json:"port"`
-       ServiceName string `thrift:"service_name,3" db:"service_name" 
json:"serviceName"`
+       ServiceName string `thrift:"serviceName,3" db:"serviceName" 
json:"serviceName"`
        Ipv6        []byte `thrift:"ipv6,4" db:"ipv6" json:"ipv6,omitempty"`
 }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Wrong json output format in zipkin file collector
> -------------------------------------------------
>
>                 Key: SCB-332
>                 URL: https://issues.apache.org/jira/browse/SCB-332
>             Project: Apache ServiceComb
>          Issue Type: Bug
>          Components: Service-Center
>            Reporter: little-cui
>            Assignee: little-cui
>            Priority: Major
>             Fix For: service-center-1.0.0-m2
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to