rm kindJaegerUdp
This commit is contained in:
@@ -3,6 +3,7 @@ package trace
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/lang"
|
"github.com/zeromicro/go-zero/core/lang"
|
||||||
@@ -18,11 +19,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
kindJaeger = "jaeger"
|
kindJaeger = "jaeger"
|
||||||
kindJaegerUdp = "jaegerudp"
|
kindZipkin = "zipkin"
|
||||||
kindZipkin = "zipkin"
|
kindOtlpGrpc = "otlpgrpc"
|
||||||
kindOtlpGrpc = "otlpgrpc"
|
kindOtlpHttp = "otlphttp"
|
||||||
kindOtlpHttp = "otlphttp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -58,10 +58,14 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
|||||||
// Just support jaeger and zipkin now, more for later
|
// Just support jaeger and zipkin now, more for later
|
||||||
switch c.Batcher {
|
switch c.Batcher {
|
||||||
case kindJaeger:
|
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)))
|
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:
|
case kindZipkin:
|
||||||
return zipkin.New(c.Endpoint)
|
return zipkin.New(c.Endpoint)
|
||||||
case kindOtlpGrpc:
|
case kindOtlpGrpc:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func TestStartAgent(t *testing.T) {
|
|||||||
endpoint2 = "remotehost:1234"
|
endpoint2 = "remotehost:1234"
|
||||||
endpoint3 = "localhost:1235"
|
endpoint3 = "localhost:1235"
|
||||||
endpoint4 = "localhost:1236"
|
endpoint4 = "localhost:1236"
|
||||||
endpoint5 = "localhost:6831"
|
endpoint5 = "udp://localhost:6831"
|
||||||
)
|
)
|
||||||
c1 := Config{
|
c1 := Config{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
@@ -48,7 +48,7 @@ func TestStartAgent(t *testing.T) {
|
|||||||
c7 := Config{
|
c7 := Config{
|
||||||
Name: "UDP",
|
Name: "UDP",
|
||||||
Endpoint: endpoint5,
|
Endpoint: endpoint5,
|
||||||
Batcher: kindJaegerUdp,
|
Batcher: kindJaeger,
|
||||||
}
|
}
|
||||||
|
|
||||||
StartAgent(c1)
|
StartAgent(c1)
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
package trace
|
package trace
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TraceName represents the tracing name.
|
// TraceName represents the tracing name.
|
||||||
const TraceName = "go-zero"
|
const TraceName = "go-zero"
|
||||||
|
|
||||||
@@ -12,17 +8,5 @@ type Config struct {
|
|||||||
Name string `json:",optional"`
|
Name string `json:",optional"`
|
||||||
Endpoint string `json:",optional"`
|
Endpoint string `json:",optional"`
|
||||||
Sampler float64 `json:",default=1.0"`
|
Sampler float64 `json:",default=1.0"`
|
||||||
Batcher string `json:",default=jaeger,options=jaeger|jaegerudp|zipkin|otlpgrpc|otlphttp"`
|
Batcher string `json:",default=jaeger,options=jaeger|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
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user