From 8dbe26010e74263529fc83065761abd6017bed94 Mon Sep 17 00:00:00 2001 From: Paul Salaberria Date: Wed, 8 Jun 2022 19:45:25 +0200 Subject: [PATCH] Fix nits Simplification in listener v3 to be tested. Signed-off-by: Paul Salaberria --- manifests/emissary/emissary-crds.yaml.in | 4 ++++ .../v2/handwritten.conversion.go | 2 +- .../v3alpha1/crd_tracingservice.go | 4 ++++ python/ambassador/envoy/v3/v3listener.py | 17 ++--------------- python/ambassador/ir/irtracing.py | 1 + 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/manifests/emissary/emissary-crds.yaml.in b/manifests/emissary/emissary-crds.yaml.in index 2ed6a60103..38b7b371a1 100644 --- a/manifests/emissary/emissary-crds.yaml.in +++ b/manifests/emissary/emissary-crds.yaml.in @@ -3756,6 +3756,8 @@ spec: type: array v3CustomTags: items: + description: TracingCustomTag provides a data structure for capturing + envoy's `type.tracing.v3.CustomTag` properties: environment: description: Environment explicitly specifies the protocol stack @@ -3870,6 +3872,8 @@ spec: type: object custom_tags: items: + description: TracingCustomTag provides a data structure for capturing + envoy's `type.tracing.v3.CustomTag` properties: environment: description: Environment explicitly specifies the protocol stack diff --git a/pkg/api/getambassador.io/v2/handwritten.conversion.go b/pkg/api/getambassador.io/v2/handwritten.conversion.go index c432e2c195..a2c8130312 100644 --- a/pkg/api/getambassador.io/v2/handwritten.conversion.go +++ b/pkg/api/getambassador.io/v2/handwritten.conversion.go @@ -667,7 +667,7 @@ func Convert_v2_TracingServiceSpec_To_v3alpha1_TracingServiceSpec(in *TracingSer // WARNING: in.TagHeaders requires manual conversion: does not exist in peer-type // if only tag_headers are set, translate to custom_tags. // if both are set, ignore tag_headers. - if in.TagHeaders != nil && in.V3CustomTags == nil { + if in.TagHeaders != nil && in.V3CustomTags == nil { out.CustomTags = []v3alpha1.TracingCustomTag{} for _, tag := range in.TagHeaders { out.CustomTags = append(out.CustomTags, v3alpha1.TracingCustomTag{ diff --git a/pkg/api/getambassador.io/v3alpha1/crd_tracingservice.go b/pkg/api/getambassador.io/v3alpha1/crd_tracingservice.go index 2af003f250..93afbfa6f2 100644 --- a/pkg/api/getambassador.io/v3alpha1/crd_tracingservice.go +++ b/pkg/api/getambassador.io/v3alpha1/crd_tracingservice.go @@ -45,23 +45,27 @@ type TraceConfig struct { ServiceName string `json:"service_name,omitempty"` } +// TracingCustomTagTypeLiteral provides a data structure for capturing envoy's `type.tracing.v3.CustomTag.Literal` type TracingCustomTagTypeLiteral struct { // +kubebuilder:validation:Required Value string `json:"value"` } +// TracingCustomTagTypeEnvironment provides a data structure for capturing envoy's `type.tracing.v3.CustomTag.Environment` type TracingCustomTagTypeEnvironment struct { // +kubebuilder:validation:Required Name string `json:"name"` DefaultValue *string `json:"default_value,omitempty"` } +// TracingCustomTagTypeRequestHeader provides a data structure for capturing envoy's `type.tracing.v3.CustomTag.Header` type TracingCustomTagTypeRequestHeader struct { // +kubebuilder:validation:Required Name string `json:"name"` DefaultValue *string `json:"default_value,omitempty"` } +// TracingCustomTag provides a data structure for capturing envoy's `type.tracing.v3.CustomTag` type TracingCustomTag struct { // +kubebuilder:validation:Required Tag string `json:"tag"` diff --git a/python/ambassador/envoy/v3/v3listener.py b/python/ambassador/envoy/v3/v3listener.py index 6820799488..a35d142095 100644 --- a/python/ambassador/envoy/v3/v3listener.py +++ b/python/ambassador/envoy/v3/v3listener.py @@ -447,22 +447,9 @@ def base_http_config(self) -> Dict[str, Any]: base_http_config["tracing"] = {} self.traffic_direction = "OUTBOUND" - finalCustomTags = [] custom_tags = self.config.ir.tracing.get('custom_tags', []) - req_hdrs = self.config.ir.tracing.get('tag_headers', []) - if custom_tags or req_hdrs: - finalCustomTags += custom_tags - if req_hdrs: - for hdr in req_hdrs: - custom_tag = { - "request_header": { - "name": hdr, - }, - "tag": hdr, - } - finalCustomTags.append(custom_tag) - base_http_config["tracing"]["custom_tags"] = finalCustomTags - + if custom_tags: + base_http_config["tracing"]["custom_tags"] = custom_tags sampling = self.config.ir.tracing.get('sampling', {}) if sampling: diff --git a/python/ambassador/ir/irtracing.py b/python/ambassador/ir/irtracing.py index 7564cc3090..fec2be9833 100644 --- a/python/ambassador/ir/irtracing.py +++ b/python/ambassador/ir/irtracing.py @@ -14,6 +14,7 @@ class IRTracing(IRResource): service: str driver: str driver_config: dict + # TODO: tag_headers is deprecated and should be removed once migrated to CRD v3 tag_headers: list custom_tags: list host_rewrite: Optional[str]