mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-03 16:59:22 +02:00
envoy: Tracing config improvements (#754)
This commit is contained in:
parent
2d02f2dfa0
commit
727d4bed9d
4 changed files with 94 additions and 47 deletions
1
go.mod
1
go.mod
|
@ -25,6 +25,7 @@ require (
|
|||
github.com/lithammer/shortuuid/v3 v3.0.4
|
||||
github.com/mitchellh/hashstructure v1.0.0
|
||||
github.com/natefinch/atomic v0.0.0-20150920032501-a62ce929ffcc
|
||||
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce
|
||||
github.com/onsi/ginkgo v1.11.0 // indirect
|
||||
github.com/onsi/gocleanup v0.0.0-20140331211545-c1a5478700b5
|
||||
github.com/onsi/gomega v1.8.1 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -358,6 +358,8 @@ github.com/nrdcg/auroradns v1.0.1/go.mod h1:y4pc0i9QXYlFCWrhWrUSIETnZgrf4KuwjDIW
|
|||
github.com/nrdcg/dnspod-go v0.4.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgPTGKr6KQ=
|
||||
github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ=
|
||||
github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw=
|
||||
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
|
||||
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
|
||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
|
|
|
@ -242,68 +242,43 @@ func (srv *Server) addTraceConfig(traceOpts *config.TracingOptions, bootCfg *env
|
|||
return nil
|
||||
}
|
||||
|
||||
zipkinPort, err := strconv.Atoi(traceOpts.ZipkinEndpoint.Port())
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid port number: %w", err)
|
||||
}
|
||||
zipkinAddress := traceOpts.ZipkinEndpoint.Hostname()
|
||||
const zipkinClusterName = "zipkin"
|
||||
|
||||
zipkinEndpoint := &envoy_config_endpoint_v3.LbEndpoint_Endpoint{
|
||||
Endpoint: &envoy_config_endpoint_v3.Endpoint{
|
||||
Address: &envoy_config_core_v3.Address{
|
||||
Address: &envoy_config_core_v3.Address_SocketAddress{
|
||||
SocketAddress: &envoy_config_core_v3.SocketAddress{
|
||||
Address: zipkinAddress,
|
||||
PortSpecifier: &envoy_config_core_v3.SocketAddress_PortValue{
|
||||
PortValue: uint32(zipkinPort),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// We only support zipkin in envoy currently
|
||||
if traceOpts.Provider != config.ZipkinTracingProviderName {
|
||||
return nil
|
||||
}
|
||||
|
||||
zipkinCluster := &envoy_config_cluster_v3.Cluster{
|
||||
Name: zipkinClusterName,
|
||||
ConnectTimeout: &durationpb.Duration{
|
||||
Seconds: 10,
|
||||
},
|
||||
ClusterDiscoveryType: &envoy_config_cluster_v3.Cluster_Type{
|
||||
Type: envoy_config_cluster_v3.Cluster_STATIC,
|
||||
},
|
||||
LbPolicy: envoy_config_cluster_v3.Cluster_ROUND_ROBIN,
|
||||
LoadAssignment: &envoy_config_endpoint_v3.ClusterLoadAssignment{
|
||||
ClusterName: zipkinClusterName,
|
||||
Endpoints: []*envoy_config_endpoint_v3.LocalityLbEndpoints{
|
||||
{
|
||||
LbEndpoints: []*envoy_config_endpoint_v3.LbEndpoint{
|
||||
{
|
||||
HostIdentifier: zipkinEndpoint,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
if traceOpts.ZipkinEndpoint.String() == "" {
|
||||
return fmt.Errorf("missing zipkin url")
|
||||
}
|
||||
|
||||
// TODO the outbound header list should be configurable when this moves to
|
||||
// HTTPConnectionManager filters
|
||||
tracingTC, _ := ptypes.MarshalAny(
|
||||
&envoy_config_trace_v3.ZipkinConfig{
|
||||
CollectorCluster: zipkinClusterName,
|
||||
CollectorEndpoint: traceOpts.ZipkinEndpoint.Path,
|
||||
CollectorEndpointVersion: envoy_config_trace_v3.ZipkinConfig_HTTP_JSON,
|
||||
&envoy_config_trace_v3.OpenCensusConfig{
|
||||
ZipkinExporterEnabled: true,
|
||||
ZipkinUrl: traceOpts.ZipkinEndpoint.String(),
|
||||
IncomingTraceContext: []envoy_config_trace_v3.OpenCensusConfig_TraceContext{
|
||||
envoy_config_trace_v3.OpenCensusConfig_B3,
|
||||
envoy_config_trace_v3.OpenCensusConfig_TRACE_CONTEXT,
|
||||
envoy_config_trace_v3.OpenCensusConfig_CLOUD_TRACE_CONTEXT,
|
||||
envoy_config_trace_v3.OpenCensusConfig_GRPC_TRACE_BIN,
|
||||
},
|
||||
OutgoingTraceContext: []envoy_config_trace_v3.OpenCensusConfig_TraceContext{
|
||||
envoy_config_trace_v3.OpenCensusConfig_B3,
|
||||
envoy_config_trace_v3.OpenCensusConfig_TRACE_CONTEXT,
|
||||
envoy_config_trace_v3.OpenCensusConfig_GRPC_TRACE_BIN,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
tracingCfg := &envoy_config_trace_v3.Tracing{
|
||||
Http: &envoy_config_trace_v3.Tracing_Http{
|
||||
Name: "envoy.tracers.zipkin",
|
||||
Name: "envoy.tracers.opencensus",
|
||||
ConfigType: &envoy_config_trace_v3.Tracing_Http_TypedConfig{
|
||||
TypedConfig: tracingTC,
|
||||
},
|
||||
},
|
||||
}
|
||||
bootCfg.StaticResources.Clusters = append(bootCfg.StaticResources.Clusters, zipkinCluster)
|
||||
bootCfg.Tracing = tracingCfg
|
||||
|
||||
return nil
|
||||
|
|
69
internal/envoy/envoy_test.go
Normal file
69
internal/envoy/envoy_test.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
package envoy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
envoy_config_bootstrap_v3 "github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/nsf/jsondiff"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
|
||||
"github.com/pomerium/pomerium/config"
|
||||
)
|
||||
|
||||
func jsonDump(t *testing.T, m proto.GeneratedMessage) []byte {
|
||||
t.Helper()
|
||||
|
||||
jsonBytes, err := protojson.Marshal(proto.MessageV2(m))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal json: %s", err)
|
||||
}
|
||||
return jsonBytes
|
||||
}
|
||||
|
||||
func Test_addTraceConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
opts *config.TracingOptions
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"good zipkin",
|
||||
&config.TracingOptions{Provider: config.ZipkinTracingProviderName, ZipkinEndpoint: &url.URL{Host: "localhost:9411"}},
|
||||
`{"tracing":{"http":{"name":"envoy.tracers.opencensus","typedConfig":{"@type":"type.googleapis.com/envoy.config.trace.v3.OpenCensusConfig","zipkinExporterEnabled":true,"zipkinUrl":"//localhost:9411","incomingTraceContext":["B3","TRACE_CONTEXT","CLOUD_TRACE_CONTEXT","GRPC_TRACE_BIN"],"outgoingTraceContext":["B3","TRACE_CONTEXT","GRPC_TRACE_BIN"]}}}}`,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"good jaeger",
|
||||
&config.TracingOptions{Provider: config.JaegerTracingProviderName},
|
||||
`{}`,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"bad zipkin",
|
||||
&config.TracingOptions{Provider: config.ZipkinTracingProviderName, ZipkinEndpoint: &url.URL{}},
|
||||
`{}`,
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
srv := &Server{}
|
||||
baseCfg := &envoy_config_bootstrap_v3.Bootstrap{}
|
||||
|
||||
err := srv.addTraceConfig(tt.opts, baseCfg)
|
||||
|
||||
assert.Equal(t, tt.wantErr, err != nil, "unexpected error state")
|
||||
|
||||
diff, diffStr := jsondiff.Compare([]byte(tt.want), jsonDump(t, baseCfg), &jsondiff.Options{})
|
||||
assert.Equal(t, jsondiff.FullMatch, diff, fmt.Sprintf("%s: differences: %s", diff.String(), diffStr))
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue