Use opentracing_grpc_propagate_context when necessary

This commit is contained in:
Andre Marianiello 2018-11-27 08:35:29 -05:00
parent fdeeac3606
commit b80b19902a
4 changed files with 35 additions and 2 deletions

View file

@ -61,7 +61,7 @@ IMAGE = $(REGISTRY)/$(IMGNAME)
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH) MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
# Set default base image dynamically for each 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) ifeq ($(ARCH),arm)
QEMUARCH=arm QEMUARCH=arm

View file

@ -159,6 +159,7 @@ var (
"stripLocationModifer": stripLocationModifer, "stripLocationModifer": stripLocationModifer,
"buildCustomErrorDeps": buildCustomErrorDeps, "buildCustomErrorDeps": buildCustomErrorDeps,
"collectCustomErrorsPerServer": collectCustomErrorsPerServer, "collectCustomErrorsPerServer": collectCustomErrorsPerServer,
"opentracingPropagateContext": opentracingPropagateContext,
} }
) )
@ -954,3 +955,17 @@ func collectCustomErrorsPerServer(input interface{}) []int {
return uniqueCodes 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"
}

View file

@ -834,3 +834,21 @@ func TestEscapeLiteralDollar(t *testing.T) {
t.Errorf("Expected %v but returned %v", expected, escapedPath) 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)
}
}
}

View file

@ -1015,7 +1015,7 @@ stream {
set $location_path "{{ $location.Path | escapeLiteralDollar }}"; set $location_path "{{ $location.Path | escapeLiteralDollar }}";
{{ if $all.Cfg.EnableOpentracing }} {{ if $all.Cfg.EnableOpentracing }}
opentracing_propagate_context; {{ opentracingPropagateContext $location }};
{{ end }} {{ end }}
rewrite_by_lua_block { rewrite_by_lua_block {