This is an automated email from the ASF dual-hosted git repository.
littlecui pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new 268cba2 SCB-332 Wrong json output format in zipkin file collector
(#278)
268cba2 is described below
commit 268cba27f2ee6ff533ea94de12833c3052b1206d
Author: little-cui <[email protected]>
AuthorDate: Wed Feb 7 16:36:05 2018 +0800
SCB-332 Wrong json output format in zipkin file collector (#278)
* SCB-332 Wrong json output format in zipkin file collector
(cherry picked from commit 3f48ccb)
* SCB-332 Wrong json output format in zipkin file collector
---
pkg/util/net.go | 12 ++++++
server/infra/registry/registry.go | 56 ++++++++++++++++++++++----
server/plugin/infra/registry/etcd/etcd.go | 36 +++++++++++------
server/plugin/infra/registry/etcd/tracing.go | 8 +++-
server/plugin/infra/tracing/buildin/buildin.go | 4 +-
server/plugin/infra/tracing/buildin/span.go | 12 +++---
6 files changed, 98 insertions(+), 30 deletions(-)
diff --git a/pkg/util/net.go b/pkg/util/net.go
index d73e928..5791b4f 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 228b4e4..b87aad1 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 7ffe5a6..941aa7c 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 7e628fc..72a38b0 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 bfae086..b4616f2 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 32c09a7..5b8011d 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"`
}
--
To stop receiving notification emails like this one, please contact
[email protected].