Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zipkin tracing system support #7

Merged
merged 8 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type ContourConfigurationSpec struct {
// +optional
Metrics *MetricsConfig `json:"metrics,omitempty"`

// Tracing defines properties for exporting trace data to OpenTelemetry.
// Tracing defines properties for exporting trace data to the tracing system.
Tracing *TracingConfig `json:"tracing,omitempty"`

// FeatureFlags defines toggle to enable new contour features.
Expand Down Expand Up @@ -256,6 +256,12 @@ const (
HTTPVersion2 HTTPVersionType = "HTTP/2"
)

// TracingSystem is the tracing system used in Envoy
type TracingSystem string

const TracingSystemOpenTelemetry TracingSystem = "opentelemetry"
const TracingSystemZipkin TracingSystem = "zipkin"

// EnvoyConfig defines how Envoy is to be Configured from Contour.
type EnvoyConfig struct {
// Listener hold various configurable Envoy listener values.
Expand Down Expand Up @@ -797,7 +803,7 @@ type RateLimitServiceConfig struct {
DefaultGlobalRateLimitPolicy *contour_api_v1.GlobalRateLimitPolicy `json:"defaultGlobalRateLimitPolicy,omitempty"`
}

// TracingConfig defines properties for exporting trace data to OpenTelemetry.
// TracingConfig defines properties for exporting trace data to the tracing system.
type TracingConfig struct {
// IncludePodDetail defines a flag.
// If it is true, contour will add the pod name and namespace to the span of the trace.
Expand Down Expand Up @@ -827,6 +833,12 @@ type TracingConfig struct {

// ExtensionService identifies the extension service defining the otel-collector.
ExtensionService *NamespacedName `json:"extensionService"`

// System specifies the tracing system used in Evnoy.
// Supported systems are "opentelemetry" and "zipkin".
// Defaults to "opentelemetry".
// +optional
System *TracingSystem `json:"system"`
}

// CustomTag defines custom tags with unique tag name
Expand Down
8 changes: 8 additions & 0 deletions apis/projectcontour/v1alpha1/contourconfig_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ func (t *TracingConfig) Validate() error {
}
customTagNames = append(customTagNames, customTag.TagName)
}

if t.System != nil {
switch *t.System {
case TracingSystemOpenTelemetry, TracingSystemZipkin:
default:
return fmt.Errorf("invalid tracing system %q", *t.System)
}
}
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions apis/projectcontour/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ func (s *Server) setupTracingService(tracingConfig *contour_api_v1alpha1.Tracing
OverallSampling: overallSampling,
MaxPathTagLength: ref.Val(tracingConfig.MaxPathTagLength, 256),
CustomTags: customTags,
System: ref.Val(tracingConfig.System, contour_api_v1alpha1.TracingSystemOpenTelemetry),
}, nil

}
Expand Down
10 changes: 10 additions & 0 deletions cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,15 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_api_v1alpha
RequestHeaderName: customTag.RequestHeaderName,
})
}
var tracingSystem *contour_api_v1alpha1.TracingSystem
if ctx.Config.Tracing.System != nil {
switch *ctx.Config.Tracing.System {
case config.TracingSystemOpenTelemetry:
tracingSystem = ref.To(contour_api_v1alpha1.TracingSystemOpenTelemetry)
case config.TracingSystemZipkin:
tracingSystem = ref.To(contour_api_v1alpha1.TracingSystemZipkin)
}
}
tracingConfig = &contour_api_v1alpha1.TracingConfig{
IncludePodDetail: ctx.Config.Tracing.IncludePodDetail,
ServiceName: ctx.Config.Tracing.ServiceName,
Expand All @@ -402,6 +411,7 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_api_v1alpha
Name: namespacedName.Name,
Namespace: namespacedName.Namespace,
},
System: tracingSystem,
}
}

Expand Down
14 changes: 12 additions & 2 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ spec:
type: object
tracing:
description: Tracing defines properties for exporting trace data to
OpenTelemetry.
the tracing system.
properties:
customTags:
description: CustomTags defines a list of custom tags with unique
Expand Down Expand Up @@ -1145,6 +1145,11 @@ spec:
description: ServiceName defines the name for the service. contour's
default is contour.
type: string
system:
description: System specifies the tracing system used in Evnoy.
Supported systems are "opentelemetry" and "zipkin". Defaults
to "opentelemetry".
type: string
required:
- extensionService
type: object
Expand Down Expand Up @@ -4856,7 +4861,7 @@ spec:
type: object
tracing:
description: Tracing defines properties for exporting trace data
to OpenTelemetry.
to the tracing system.
properties:
customTags:
description: CustomTags defines a list of custom tags with
Expand Down Expand Up @@ -4915,6 +4920,11 @@ spec:
description: ServiceName defines the name for the service.
contour's default is contour.
type: string
system:
description: System specifies the tracing system used in Evnoy.
Supported systems are "opentelemetry" and "zipkin". Defaults
to "opentelemetry".
type: string
required:
- extensionService
type: object
Expand Down
14 changes: 12 additions & 2 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ spec:
type: object
tracing:
description: Tracing defines properties for exporting trace data to
OpenTelemetry.
the tracing system.
properties:
customTags:
description: CustomTags defines a list of custom tags with unique
Expand Down Expand Up @@ -1364,6 +1364,11 @@ spec:
description: ServiceName defines the name for the service. contour's
default is contour.
type: string
system:
description: System specifies the tracing system used in Evnoy.
Supported systems are "opentelemetry" and "zipkin". Defaults
to "opentelemetry".
type: string
required:
- extensionService
type: object
Expand Down Expand Up @@ -5075,7 +5080,7 @@ spec:
type: object
tracing:
description: Tracing defines properties for exporting trace data
to OpenTelemetry.
to the tracing system.
properties:
customTags:
description: CustomTags defines a list of custom tags with
Expand Down Expand Up @@ -5134,6 +5139,11 @@ spec:
description: ServiceName defines the name for the service.
contour's default is contour.
type: string
system:
description: System specifies the tracing system used in Evnoy.
Supported systems are "opentelemetry" and "zipkin". Defaults
to "opentelemetry".
type: string
required:
- extensionService
type: object
Expand Down
14 changes: 12 additions & 2 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ spec:
type: object
tracing:
description: Tracing defines properties for exporting trace data to
OpenTelemetry.
the tracing system.
properties:
customTags:
description: CustomTags defines a list of custom tags with unique
Expand Down Expand Up @@ -1156,6 +1156,11 @@ spec:
description: ServiceName defines the name for the service. contour's
default is contour.
type: string
system:
description: System specifies the tracing system used in Evnoy.
Supported systems are "opentelemetry" and "zipkin". Defaults
to "opentelemetry".
type: string
required:
- extensionService
type: object
Expand Down Expand Up @@ -4867,7 +4872,7 @@ spec:
type: object
tracing:
description: Tracing defines properties for exporting trace data
to OpenTelemetry.
to the tracing system.
properties:
customTags:
description: CustomTags defines a list of custom tags with
Expand Down Expand Up @@ -4926,6 +4931,11 @@ spec:
description: ServiceName defines the name for the service.
contour's default is contour.
type: string
system:
description: System specifies the tracing system used in Evnoy.
Supported systems are "opentelemetry" and "zipkin". Defaults
to "opentelemetry".
type: string
required:
- extensionService
type: object
Expand Down
14 changes: 12 additions & 2 deletions examples/render/contour-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ spec:
type: object
tracing:
description: Tracing defines properties for exporting trace data to
OpenTelemetry.
the tracing system.
properties:
customTags:
description: CustomTags defines a list of custom tags with unique
Expand Down Expand Up @@ -1367,6 +1367,11 @@ spec:
description: ServiceName defines the name for the service. contour's
default is contour.
type: string
system:
description: System specifies the tracing system used in Evnoy.
Supported systems are "opentelemetry" and "zipkin". Defaults
to "opentelemetry".
type: string
required:
- extensionService
type: object
Expand Down Expand Up @@ -5078,7 +5083,7 @@ spec:
type: object
tracing:
description: Tracing defines properties for exporting trace data
to OpenTelemetry.
to the tracing system.
properties:
customTags:
description: CustomTags defines a list of custom tags with
Expand Down Expand Up @@ -5137,6 +5142,11 @@ spec:
description: ServiceName defines the name for the service.
contour's default is contour.
type: string
system:
description: System specifies the tracing system used in Evnoy.
Supported systems are "opentelemetry" and "zipkin". Defaults
to "opentelemetry".
type: string
required:
- extensionService
type: object
Expand Down
14 changes: 12 additions & 2 deletions examples/render/contour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ spec:
type: object
tracing:
description: Tracing defines properties for exporting trace data to
OpenTelemetry.
the tracing system.
properties:
customTags:
description: CustomTags defines a list of custom tags with unique
Expand Down Expand Up @@ -1364,6 +1364,11 @@ spec:
description: ServiceName defines the name for the service. contour's
default is contour.
type: string
system:
description: System specifies the tracing system used in Evnoy.
Supported systems are "opentelemetry" and "zipkin". Defaults
to "opentelemetry".
type: string
required:
- extensionService
type: object
Expand Down Expand Up @@ -5075,7 +5080,7 @@ spec:
type: object
tracing:
description: Tracing defines properties for exporting trace data
to OpenTelemetry.
to the tracing system.
properties:
customTags:
description: CustomTags defines a list of custom tags with
Expand Down Expand Up @@ -5134,6 +5139,11 @@ spec:
description: ServiceName defines the name for the service.
contour's default is contour.
type: string
system:
description: System specifies the tracing system used in Evnoy.
Supported systems are "opentelemetry" and "zipkin". Defaults
to "opentelemetry".
type: string
required:
- extensionService
type: object
Expand Down
5 changes: 5 additions & 0 deletions internal/envoy/v3/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func buildRoute(dagRoute *dag.Route, vhostName string, secure bool) *envoy_route
Match: RouteMatch(dagRoute),
Metadata: getRouteMetadata(dagRoute),
}
if dagRoute.Name != "" {
route.Decorator = &envoy_route_v3.Decorator{
Operation: dagRoute.Name,
}
}

if dagRoute.StatPrefix != nil {
route.StatPrefix = *dagRoute.StatPrefix
Expand Down
28 changes: 25 additions & 3 deletions internal/envoy/v3/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
package v3

import (
"strings"

envoy_config_trace_v3 "github.com/envoyproxy/go-control-plane/envoy/config/trace/v3"
http "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
envoy_trace_v3 "github.com/envoyproxy/go-control-plane/envoy/type/tracing/v3"
envoy_type "github.com/envoyproxy/go-control-plane/envoy/type/v3"
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/protobuf"
"github.com/projectcontour/contour/internal/timeout"
Expand All @@ -39,22 +42,40 @@ func TracingConfig(tracing *EnvoyTracingConfig) *http.HttpConnectionManager_Trac
}
}

return &http.HttpConnectionManager_Tracing{
connManagerTracing := &http.HttpConnectionManager_Tracing{
OverallSampling: &envoy_type.Percent{
Value: tracing.OverallSampling,
},
MaxPathTagLength: wrapperspb.UInt32(tracing.MaxPathTagLength),
CustomTags: customTags,
Provider: &envoy_config_trace_v3.Tracing_Http{
}
switch tracing.System {
case contour_api_v1alpha1.TracingSystemOpenTelemetry:
connManagerTracing.Provider = &envoy_config_trace_v3.Tracing_Http{
Name: "envoy.tracers.opentelemetry",
ConfigType: &envoy_config_trace_v3.Tracing_Http_TypedConfig{
TypedConfig: protobuf.MustMarshalAny(&envoy_config_trace_v3.OpenTelemetryConfig{
GrpcService: GrpcService(dag.ExtensionClusterName(tracing.ExtensionService), tracing.SNI, tracing.Timeout),
ServiceName: tracing.ServiceName,
}),
},
},
}
case contour_api_v1alpha1.TracingSystemZipkin:
connManagerTracing.Provider = &envoy_config_trace_v3.Tracing_Http{
Name: "envoy.tracers.zipkin",
ConfigType: &envoy_config_trace_v3.Tracing_Http_TypedConfig{
TypedConfig: protobuf.MustMarshalAny(&envoy_config_trace_v3.ZipkinConfig{
CollectorCluster: dag.ExtensionClusterName(tracing.ExtensionService),
CollectorHostname: strings.ReplaceAll(dag.ExtensionClusterName(tracing.ExtensionService), "/", "."),
CollectorEndpoint: "/api/v2/spans",
SharedSpanContext: wrapperspb.Bool(false),
CollectorEndpointVersion: envoy_config_trace_v3.ZipkinConfig_HTTP_JSON,
}),
},
}
}

return connManagerTracing
}

func customTag(tag *CustomTag) *envoy_trace_v3.CustomTag {
Expand Down Expand Up @@ -102,6 +123,7 @@ type EnvoyTracingConfig struct {
OverallSampling float64
MaxPathTagLength uint32
CustomTags []*CustomTag
System contour_api_v1alpha1.TracingSystem
}

type CustomTag struct {
Expand Down
Loading
Loading