瀏覽代碼

rm kindJaegerUdp

xiandong 2 年之前
父節點
當前提交
6dbcfb5e5d
共有 4 個文件被更改,包括 15 次插入54 次删除
  1. 12 8
      core/trace/agent.go
  2. 2 2
      core/trace/agent_test.go
  3. 1 16
      core/trace/config.go
  4. 0 28
      core/trace/config_test.go

+ 12 - 8
core/trace/agent.go

@@ -3,6 +3,7 @@ package trace
 import (
 	"context"
 	"fmt"
+	"net/url"
 	"sync"
 
 	"github.com/zeromicro/go-zero/core/lang"
@@ -18,11 +19,10 @@ import (
 )
 
 const (
-	kindJaeger    = "jaeger"
-	kindJaegerUdp = "jaegerudp"
-	kindZipkin    = "zipkin"
-	kindOtlpGrpc  = "otlpgrpc"
-	kindOtlpHttp  = "otlphttp"
+	kindJaeger   = "jaeger"
+	kindZipkin   = "zipkin"
+	kindOtlpGrpc = "otlpgrpc"
+	kindOtlpHttp = "otlphttp"
 )
 
 var (
@@ -58,10 +58,14 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
 	// Just support jaeger and zipkin now, more for later
 	switch c.Batcher {
 	case kindJaeger:
+		u, parseErr := url.Parse(c.Endpoint)
+		if parseErr != nil {
+			return nil, fmt.Errorf("invalid jaeger endpoint: %s", c.Endpoint)
+		}
+		if u.Scheme == "udp" {
+			return jaeger.New(jaeger.WithAgentEndpoint(jaeger.WithAgentHost(u.Hostname()), jaeger.WithAgentPort(u.Port())))
+		}
 		return jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(c.Endpoint)))
-	case kindJaegerUdp:
-		host, port := c.parseEndpoint()
-		return jaeger.New(jaeger.WithAgentEndpoint(jaeger.WithAgentHost(host), jaeger.WithAgentPort(port)))
 	case kindZipkin:
 		return zipkin.New(c.Endpoint)
 	case kindOtlpGrpc:

+ 2 - 2
core/trace/agent_test.go

@@ -15,7 +15,7 @@ func TestStartAgent(t *testing.T) {
 		endpoint2 = "remotehost:1234"
 		endpoint3 = "localhost:1235"
 		endpoint4 = "localhost:1236"
-		endpoint5 = "localhost:6831"
+		endpoint5 = "udp://localhost:6831"
 	)
 	c1 := Config{
 		Name: "foo",
@@ -48,7 +48,7 @@ func TestStartAgent(t *testing.T) {
 	c7 := Config{
 		Name:     "UDP",
 		Endpoint: endpoint5,
-		Batcher:  kindJaegerUdp,
+		Batcher:  kindJaeger,
 	}
 
 	StartAgent(c1)

+ 1 - 16
core/trace/config.go

@@ -1,9 +1,5 @@
 package trace
 
-import (
-	"strings"
-)
-
 // TraceName represents the tracing name.
 const TraceName = "go-zero"
 
@@ -12,16 +8,5 @@ type Config struct {
 	Name     string  `json:",optional"`
 	Endpoint string  `json:",optional"`
 	Sampler  float64 `json:",default=1.0"`
-	Batcher  string  `json:",default=jaeger,options=jaeger|jaegerudp|zipkin|otlpgrpc|otlphttp"`
-}
-
-func (c *Config) parseEndpoint() (host string, port string) {
-	EndpointSlice := strings.Split(c.Endpoint, ":")
-	if len(EndpointSlice) > 0 {
-		host = strings.TrimSpace(EndpointSlice[0])
-	}
-	if len(EndpointSlice) > 1 {
-		port = strings.TrimSpace(EndpointSlice[1])
-	}
-	return host, port
+	Batcher  string  `json:",default=jaeger,options=jaeger|zipkin|otlpgrpc|otlphttp"`
 }

+ 0 - 28
core/trace/config_test.go

@@ -1,28 +0,0 @@
-package trace
-
-import (
-	"github.com/stretchr/testify/assert"
-	"github.com/zeromicro/go-zero/core/logx"
-	"testing"
-)
-
-func TestConfig_parseEndpoint(t *testing.T) {
-	logx.Disable()
-
-	c1 := Config{
-		Name:     "not UDP",
-		Endpoint: "http://localhost:14268/api/traces",
-		Batcher:  kindJaegerUdp,
-	}
-	c2 := Config{
-		Name:     "UDP",
-		Endpoint: "localhost:6831",
-		Batcher:  kindJaegerUdp,
-	}
-	host1, port1 := c1.parseEndpoint()
-	assert.NotEqual(t, "localhost", host1)
-	assert.NotEqual(t, "14268", port1)
-	host2, port2 := c2.parseEndpoint()
-	assert.Equal(t, "localhost", host2)
-	assert.Equal(t, "6831", port2)
-}