diff --git a/docs/user-guide/nginx-configuration/configmap.md b/docs/user-guide/nginx-configuration/configmap.md index 0bead1c34c..0af29d574f 100755 --- a/docs/user-guide/nginx-configuration/configmap.md +++ b/docs/user-guide/nginx-configuration/configmap.md @@ -132,6 +132,7 @@ The following table shows a configuration option's name, type, and the default v |[zipkin-sample-rate](#zipkin-sample-rate)|float|1.0| |[jaeger-collector-host](#jaeger-collector-host)|string|""| |[jaeger-collector-port](#jaeger-collector-port)|int|6831| +|[jaeger-endpoint](#jaeger-endpoint)|string|""| |[jaeger-service-name](#jaeger-service-name)|string|"nginx"| |[jaeger-sampler-type](#jaeger-sampler-type)|string|"const"| |[jaeger-sampler-param](#jaeger-sampler-param)|string|"1"| @@ -845,6 +846,10 @@ Specifies the host to use when uploading traces. It must be a valid URL. Specifies the port to use when uploading traces. _**default:**_ 6831 +## jaeger-endpoint + +Specifies the endpoint to use when uploading traces to a collector. This takes priority over `jaeger-collector-host` if both are specified. + ## jaeger-service-name Specifies the service name to use for any traces created. _**default:**_ nginx diff --git a/docs/user-guide/third-party-addons/opentracing.md b/docs/user-guide/third-party-addons/opentracing.md index 5fb08f4321..1f4138250b 100644 --- a/docs/user-guide/third-party-addons/opentracing.md +++ b/docs/user-guide/third-party-addons/opentracing.md @@ -30,6 +30,7 @@ jaeger-collector-host: jaeger-agent.default.svc.cluster.local datadog-collector-host: datadog-agent.default.svc.cluster.local ``` NOTE: While the option is called `jaeger-collector-host`, you will need to point this to a `jaeger-agent`, and not the `jaeger-collector` component. +Alternatively, you can set `jaeger-endpoint` and specify the full endpoint for uploading traces. This will use TCP and should be used for a collector rather than an agent. Next you will need to deploy a distributed tracing system which uses OpenTracing. [Zipkin](https://github.com/openzipkin/zipkin) and @@ -57,6 +58,9 @@ zipkin-sample-rate # specifies the port to use when uploading traces, Default: 6831 jaeger-collector-port +# specifies the endpoint to use when uploading traces to a collector instead of an agent +jaeger-endpoint + # specifies the service name to use for any traces created, Default: nginx jaeger-service-name diff --git a/internal/ingress/controller/config/config.go b/internal/ingress/controller/config/config.go index 63bd65aac6..35691cb55c 100644 --- a/internal/ingress/controller/config/config.go +++ b/internal/ingress/controller/config/config.go @@ -555,6 +555,9 @@ type Configuration struct { // Default: 6831 JaegerCollectorPort int `json:"jaeger-collector-port"` + // JaegerEndpoint specifies the enpoint to use when uploading traces to a collector over TCP + JaegerEndpoint string `json:"jaeger-endpoint"` + // JaegerServiceName specifies the service name to use for any traces created // Default: nginx JaegerServiceName string `json:"jaeger-service-name"` diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index baf0ff45ea..cef2853505 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -1039,6 +1039,7 @@ const jaegerTmpl = `{ "samplingServerURL": "{{ .JaegerSamplerHost }}:{{ .JaegerSamplerPort }}/sampling" }, "reporter": { + "endpoint": "{{ .JaegerEndpoint }}", "localAgentHostPort": "{{ .JaegerCollectorHost }}:{{ .JaegerCollectorPort }}" }, "headers": { @@ -1068,7 +1069,7 @@ func createOpentracingCfg(cfg ngx_config.Configuration) error { if err != nil { return err } - } else if cfg.JaegerCollectorHost != "" { + } else if cfg.JaegerCollectorHost != "" || cfg.JaegerEndpoint != "" { tmpl, err = template.New("jaeger").Parse(jaegerTmpl) if err != nil { return err diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 014bdfdb94..6cdc1d7b2a 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -1018,7 +1018,7 @@ func buildOpentracing(c interface{}, s interface{}) string { buf.WriteString("opentracing_load_tracer /usr/local/lib64/libdd_opentracing.so /etc/nginx/opentracing.json;") } else if cfg.ZipkinCollectorHost != "" { buf.WriteString("opentracing_load_tracer /usr/local/lib/libzipkin_opentracing_plugin.so /etc/nginx/opentracing.json;") - } else if cfg.JaegerCollectorHost != "" { + } else if cfg.JaegerCollectorHost != "" || cfg.JaegerEndpoint != "" { buf.WriteString("opentracing_load_tracer /usr/local/lib/libjaegertracing_plugin.so /etc/nginx/opentracing.json;") } diff --git a/internal/ingress/controller/template/template_test.go b/internal/ingress/controller/template/template_test.go index abccb0d9c4..1af9881970 100644 --- a/internal/ingress/controller/template/template_test.go +++ b/internal/ingress/controller/template/template_test.go @@ -1163,6 +1163,16 @@ func TestBuildOpenTracing(t *testing.T) { t.Errorf("Expected '%v' but returned '%v'", expected, actual) } + cfgNoHost := config.Configuration{ + EnableOpentracing: true, + } + expected = "\r\n" + actual = buildOpentracing(cfgNoHost, []*ingress.Server{}) + + if expected != actual { + t.Errorf("Expected '%v' but returned '%v'", expected, actual) + } + cfgJaeger := config.Configuration{ EnableOpentracing: true, JaegerCollectorHost: "jaeger-host.com", @@ -1196,6 +1206,17 @@ func TestBuildOpenTracing(t *testing.T) { t.Errorf("Expected '%v' but returned '%v'", expected, actual) } + cfgJaegerEndpoint := config.Configuration{ + EnableOpentracing: true, + JaegerEndpoint: "http://jaeger-collector.com:14268/api/traces", + } + expected = "opentracing_load_tracer /usr/local/lib/libjaegertracing_plugin.so /etc/nginx/opentracing.json;\r\n" + actual = buildOpentracing(cfgJaegerEndpoint, []*ingress.Server{}) + + if expected != actual { + t.Errorf("Expected '%v' but returned '%v'", expected, actual) + } + cfgOpenTracing := config.Configuration{ EnableOpentracing: true, DatadogCollectorHost: "datadog-host.com", diff --git a/test/e2e/settings/opentracing.go b/test/e2e/settings/opentracing.go index 9230102949..498bc7a401 100644 --- a/test/e2e/settings/opentracing.go +++ b/test/e2e/settings/opentracing.go @@ -33,6 +33,7 @@ const ( jaegerCollectorHost = "jaeger-collector-host" jaegerSamplerHost = "jaeger-sampler-host" + // jaegerEndpoint = "jaeger-endpoint" datadogCollectorHost = "datadog-collector-host" @@ -174,6 +175,20 @@ var _ = framework.IngressNginxDescribe("Configure OpenTracing", func() { assert.NotContains(ginkgo.GinkgoT(), log, "Unexpected failure reloading the backend", "reloading nginx after a configmap change") }) + /* + ginkgo.It("should enable opentracing using jaeger with an HTTP endpoint", func() { + config := map[string]string{} + config[enableOpentracing] = "true" + config[jaegerEndpoint] = "http://127.0.0.1/api/traces" + f.SetNginxConfigMapData(config) + + framework.Sleep(10 * time.Second) + log, err := f.NginxLogs() + assert.Nil(ginkgo.GinkgoT(), err, "obtaining nginx logs") + assert.NotContains(ginkgo.GinkgoT(), log, "Unexpected failure reloading the backend", "reloading nginx after a configmap change") + }) + */ + ginkgo.It("should enable opentracing using datadog", func() { config := map[string]string{} config[enableOpentracing] = "true"