Skip to content

Commit

Permalink
Fix opentracing configuration when multiple options are configured (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored Feb 13, 2018
1 parent 80462ec commit 33475b7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
52 changes: 52 additions & 0 deletions internal/ingress/controller/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package template

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -145,6 +146,8 @@ var (
"isValidClientBodyBufferSize": isValidClientBodyBufferSize,
"buildForwardedFor": buildForwardedFor,
"buildAuthSignURL": buildAuthSignURL,
"buildOpentracingLoad": buildOpentracingLoad,
"buildOpentracing": buildOpentracing,
}
)

Expand Down Expand Up @@ -714,3 +717,52 @@ func randomString() string {

return string(b)
}

func buildOpentracingLoad(input interface{}) string {
cfg, ok := input.(config.Configuration)
if !ok {
glog.Errorf("expected a 'config.Configuration' type but %T was returned", input)
return ""
}

if !cfg.EnableOpentracing {
return ""
}

buf := bytes.NewBufferString("load_module/etc/nginx/modules/ngx_http_opentracing_module.so;")

if cfg.ZipkinCollectorHost != "" {
buf.WriteString("load_module/etc/nginx/modules/ngx_http_zipkin_module.so;")
} else if cfg.JaegerCollectorHost != "" {
buf.WriteString("load_module/etc/nginx/modules/ngx_http_jaeger_module.so;")
}

return buf.String()
}

func buildOpentracing(input interface{}) string {
cfg, ok := input.(config.Configuration)
if !ok {
glog.Errorf("expected a 'config.Configuration' type but %T was returned", input)
return ""
}

if !cfg.EnableOpentracing {
return ""
}

buf := bytes.NewBufferString("")

if cfg.ZipkinCollectorHost != "" {
buf.WriteString(fmt.Sprintf("zipkin_collector_host %v;", cfg.ZipkinCollectorHost))
buf.WriteString(fmt.Sprintf("zipkin_collector_port %v;", cfg.ZipkinCollectorPort))
buf.WriteString(fmt.Sprintf("zipkin_service_name %v;", cfg.ZipkinServiceName))
} else if cfg.JaegerCollectorHost != "" {
buf.WriteString(fmt.Sprintf("jaeger_reporter_local_agent_host_port %v:%v;", cfg.JaegerCollectorHost, cfg.JaegerCollectorPort))
buf.WriteString(fmt.Sprintf("jaeger_service_name %v;", cfg.JaegerServiceName))
buf.WriteString(fmt.Sprintf("jaeger_sampler_type %v;", cfg.JaegerSamplerType))
buf.WriteString(fmt.Sprintf("jaeger_sampler_param %v;", cfg.JaegerSamplerParam))
}

return buf.String()
}
25 changes: 3 additions & 22 deletions rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@
load_module /etc/nginx/modules/ngx_http_modsecurity_module.so;
{{ end }}

{{ if $cfg.EnableOpentracing }}
load_module /etc/nginx/modules/ngx_http_opentracing_module.so;
{{ end }}

{{ if (and $cfg.EnableOpentracing (ne $cfg.ZipkinCollectorHost "")) }}
load_module /etc/nginx/modules/ngx_http_zipkin_module.so;
{{ end }}

{{ if (and $cfg.EnableOpentracing (ne $cfg.JaegerCollectorHost "")) }}
load_module /etc/nginx/modules/ngx_http_jaeger_module.so;
{{ end }}
{{ buildOpentracingLoad $cfg }}

daemon off;

Expand Down Expand Up @@ -107,17 +97,8 @@ http {
{{ if $cfg.EnableOpentracing }}
opentracing on;
{{ end }}

{{ if (and $cfg.EnableOpentracing (ne $cfg.ZipkinCollectorHost "")) }}
zipkin_collector_host {{ $cfg.ZipkinCollectorHost }};
zipkin_collector_port {{ $cfg.ZipkinCollectorPort }};
zipkin_service_name {{ $cfg.ZipkinServiceName }};
{{ else if (and $cfg.EnableOpentracing (ne $cfg.JaegerCollectorHost "")) }}
jaeger_reporter_local_agent_host_port {{ $cfg.JaegerCollectorHost }}:{{ $cfg.JaegerCollectorPort }};
jaeger_service_name {{ $cfg.JaegerServiceName }};
jaeger_sampler_type {{ $cfg.JaegerSamplerType }};
jaeger_sampler_param {{ $cfg.JaegerSamplerParam }};
{{ end }}

{{ buildOpentracing $cfg }}

include /etc/nginx/mime.types;
default_type text/html;
Expand Down

0 comments on commit 33475b7

Please sign in to comment.