From b80b19902a400a7e5f63de5400b9c15e371e46e7 Mon Sep 17 00:00:00 2001 From: Andre Marianiello Date: Tue, 27 Nov 2018 08:35:29 -0500 Subject: [PATCH] Use opentracing_grpc_propagate_context when necessary --- Makefile | 2 +- .../ingress/controller/template/template.go | 15 +++++++++++++++ .../controller/template/template_test.go | 18 ++++++++++++++++++ rootfs/etc/nginx/template/nginx.tmpl | 2 +- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 12f30a7981..b1bb7735f7 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ IMAGE = $(REGISTRY)/$(IMGNAME) MULTI_ARCH_IMG = $(IMAGE)-$(ARCH) # Set default base image dynamically for each arch -BASEIMAGE?=quay.io/kubernetes-ingress-controller/nginx-$(ARCH):0.70 +BASEIMAGE?=quay.io/kubernetes-ingress-controller/nginx-$(ARCH):0.71 ifeq ($(ARCH),arm) QEMUARCH=arm diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 6aaf43e2e1..993978d2c4 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -159,6 +159,7 @@ var ( "stripLocationModifer": stripLocationModifer, "buildCustomErrorDeps": buildCustomErrorDeps, "collectCustomErrorsPerServer": collectCustomErrorsPerServer, + "opentracingPropagateContext": opentracingPropagateContext, } ) @@ -954,3 +955,17 @@ func collectCustomErrorsPerServer(input interface{}) []int { return uniqueCodes } + +func opentracingPropagateContext(loc interface{}) string { + location, ok := loc.(*ingress.Location) + if !ok { + glog.Errorf("expected a '*ingress.Location' type but %T was returned", loc) + return "opentracing_propagate_context" + } + + if location.BackendProtocol == "GRPC" || location.BackendProtocol == "GRPCS" { + return "opentracing_grpc_propagate_context" + } + + return "opentracing_propagate_context" +} diff --git a/internal/ingress/controller/template/template_test.go b/internal/ingress/controller/template/template_test.go index 385ed7359f..d08baccb63 100644 --- a/internal/ingress/controller/template/template_test.go +++ b/internal/ingress/controller/template/template_test.go @@ -834,3 +834,21 @@ func TestEscapeLiteralDollar(t *testing.T) { t.Errorf("Expected %v but returned %v", expected, escapedPath) } } + +func Test_opentracingPropagateContext(t *testing.T) { + tests := map[interface{}]string{ + &ingress.Location{BackendProtocol: "HTTP"}: "opentracing_propagate_context", + &ingress.Location{BackendProtocol: "HTTPS"}: "opentracing_propagate_context", + &ingress.Location{BackendProtocol: "GRPC"}: "opentracing_grpc_propagate_context", + &ingress.Location{BackendProtocol: "GRPCS"}: "opentracing_grpc_propagate_context", + &ingress.Location{BackendProtocol: "AJP"}: "opentracing_propagate_context", + "not a location": "opentracing_propagate_context", + } + + for loc, expectedDirective := range tests { + actualDirective := opentracingPropagateContext(loc) + if actualDirective != expectedDirective { + t.Errorf("Expected %v but returned %v", expectedDirective, actualDirective) + } + } +} diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index dcaae86383..4572e801c6 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -1015,7 +1015,7 @@ stream { set $location_path "{{ $location.Path | escapeLiteralDollar }}"; {{ if $all.Cfg.EnableOpentracing }} - opentracing_propagate_context; + {{ opentracingPropagateContext $location }}; {{ end }} rewrite_by_lua_block {