Fix opentracing configuration when multiple options are configured (#2075)
This commit is contained in:
parent
80462ecdad
commit
33475b7184
2 changed files with 55 additions and 22 deletions
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
package template
|
package template
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -145,6 +146,8 @@ var (
|
||||||
"isValidClientBodyBufferSize": isValidClientBodyBufferSize,
|
"isValidClientBodyBufferSize": isValidClientBodyBufferSize,
|
||||||
"buildForwardedFor": buildForwardedFor,
|
"buildForwardedFor": buildForwardedFor,
|
||||||
"buildAuthSignURL": buildAuthSignURL,
|
"buildAuthSignURL": buildAuthSignURL,
|
||||||
|
"buildOpentracingLoad": buildOpentracingLoad,
|
||||||
|
"buildOpentracing": buildOpentracing,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -714,3 +717,52 @@ func randomString() string {
|
||||||
|
|
||||||
return string(b)
|
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()
|
||||||
|
}
|
||||||
|
|
|
@ -11,17 +11,7 @@
|
||||||
load_module /etc/nginx/modules/ngx_http_modsecurity_module.so;
|
load_module /etc/nginx/modules/ngx_http_modsecurity_module.so;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ if $cfg.EnableOpentracing }}
|
{{ buildOpentracingLoad $cfg }}
|
||||||
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 }}
|
|
||||||
|
|
||||||
daemon off;
|
daemon off;
|
||||||
|
|
||||||
|
@ -107,17 +97,8 @@ http {
|
||||||
{{ if $cfg.EnableOpentracing }}
|
{{ if $cfg.EnableOpentracing }}
|
||||||
opentracing on;
|
opentracing on;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ if (and $cfg.EnableOpentracing (ne $cfg.ZipkinCollectorHost "")) }}
|
{{ buildOpentracing $cfg }}
|
||||||
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 }}
|
|
||||||
|
|
||||||
include /etc/nginx/mime.types;
|
include /etc/nginx/mime.types;
|
||||||
default_type text/html;
|
default_type text/html;
|
||||||
|
|
Loading…
Reference in a new issue