Skip to content

Commit

Permalink
Merge pull request #3766 from alanjcastonguay/feature/datadog-opentra…
Browse files Browse the repository at this point in the history
…cing

Support Opentracing with Datadog - part 2
  • Loading branch information
k8s-ci-robot authored Feb 16, 2019
2 parents b72dfa9 + a29c27e commit 39906c9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.76
BASEIMAGE?=quay.io/kubernetes-ingress-controller/nginx-$(ARCH):0.77

ifeq ($(ARCH),arm64)
QEMUARCH=aarch64
Expand Down
17 changes: 15 additions & 2 deletions docs/user-guide/third-party-addons/opentracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ We must also set the host to use when uploading traces:
```
zipkin-collector-host: zipkin.default.svc.cluster.local
jaeger-collector-host: jaeger-collector.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.

Next you will need to deploy a distributed tracing system which uses OpenTracing. Both [Zipkin](https://github.com/openzipkin/zipkin) and
[Jaeger](https://github.com/jaegertracing/jaeger) have been tested.
Next you will need to deploy a distributed tracing system which uses OpenTracing.
[Zipkin](https://github.com/openzipkin/zipkin) and
[Jaeger](https://github.com/jaegertracing/jaeger) and
[Datadog](https://github.com/DataDog/dd-opentracing-cpp)
have been tested.

Other optional configuration options:
```
Expand All @@ -47,6 +51,15 @@ jaeger-sampler-type
# specifies the argument to be passed to the sampler constructor, Default: 1
jaeger-sampler-param
# specifies the port to use when uploading traces, Default 8126
datadog-collector-port
# specifies the service name to use for any traces created, Default: nginx
datadog-service-name
# specifies the operation name to use for any traces collected, Default: nginx.handle
datadog-operation-name-override
```

All these options (including host) allow environment variables, such as `$HOSTNAME` or `$HOST_IP`. In the case of Jaeger, if you have a Jaeger agent running on each machine in your cluster, you can use something like `$HOST_IP` (which can be 'mounted' with the `status.hostIP` fieldpath, as described [here](https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#capabilities-of-the-downward-api)) to make sure traces will be sent to the local agent.
Expand Down
18 changes: 18 additions & 0 deletions internal/ingress/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,21 @@ type Configuration struct {
// Default: 1
JaegerSamplerParam string `json:"jaeger-sampler-param"`

// DatadogCollectorHost specifies the datadog agent host to use when uploading traces
DatadogCollectorHost string `json:"datadog-collector-host"`

// DatadogCollectorPort specifies the port to use when uploading traces
// Default: 8126
DatadogCollectorPort int `json:"datadog-collector-port"`

// DatadogServiceName specifies the service name to use for any traces created
// Default: nginx
DatadogServiceName string `json:"datadog-service-name"`

// DatadogOperationNameOverride overrides the operation naem to use for any traces crated
// Default: nginx.handle
DatadogOperationNameOverride string `json:"datadog-operation-name-override"`

// MainSnippet adds custom configuration to the main section of the nginx configuration
MainSnippet string `json:"main-snippet"`

Expand Down Expand Up @@ -685,6 +700,9 @@ func NewDefault() Configuration {
JaegerServiceName: "nginx",
JaegerSamplerType: "const",
JaegerSamplerParam: "1",
DatadogServiceName: "nginx",
DatadogCollectorPort: 8126,
DatadogOperationNameOverride: "nginx.handle",
LimitReqStatusCode: 503,
LimitConnStatusCode: 503,
SyslogPort: 514,
Expand Down
12 changes: 12 additions & 0 deletions internal/ingress/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,13 @@ const jaegerTmpl = `{
}
}`

const datadogTmpl = `{
"service": "{{ .DatadogServiceName }}",
"agent_host": "{{ .DatadogCollectorHost }}",
"agent_port": {{ .DatadogCollectorPort }},
"operation_name_override": "{{ .DatadogOperationNameOverride }}"
}`

func createOpentracingCfg(cfg ngx_config.Configuration) error {
var tmpl *template.Template
var err error
Expand All @@ -957,6 +964,11 @@ func createOpentracingCfg(cfg ngx_config.Configuration) error {
if err != nil {
return err
}
} else if cfg.DatadogCollectorHost != "" {
tmpl, err = template.New("datadog").Parse(datadogTmpl)
if err != nil {
return err
}
} else {
tmpl, _ = template.New("empty").Parse("{}")
}
Expand Down
2 changes: 2 additions & 0 deletions internal/ingress/controller/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,8 @@ func buildOpentracing(input interface{}) string {
buf.WriteString("opentracing_load_tracer /usr/local/lib/libzipkin_opentracing.so /etc/nginx/opentracing.json;")
} else if cfg.JaegerCollectorHost != "" {
buf.WriteString("opentracing_load_tracer /usr/local/lib/libjaegertracing_plugin.so /etc/nginx/opentracing.json;")
} else if cfg.DatadogCollectorHost != "" {
buf.WriteString("opentracing_load_tracer /usr/local/lib/libdd_opentracing.so /etc/nginx/opentracing.json;")
}

buf.WriteString("\r\n")
Expand Down
11 changes: 11 additions & 0 deletions internal/ingress/controller/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,17 @@ func TestBuildOpenTracing(t *testing.T) {
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
}

cfgDatadog := config.Configuration{
EnableOpentracing: true,
DatadogCollectorHost: "datadog-host.com",
}
expected = "opentracing_load_tracer /usr/local/lib/libdd_opentracing.so /etc/nginx/opentracing.json;\r\n"
actual = buildOpentracing(cfgDatadog)

if expected != actual {
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
}

}

func TestEnforceRegexModifier(t *testing.T) {
Expand Down

0 comments on commit 39906c9

Please sign in to comment.