From d7be5db7de2fa5ae46aece4ecbba9117738dbaa4 Mon Sep 17 00:00:00 2001 From: Sungmin Lee Date: Tue, 7 Jan 2020 16:59:59 -0800 Subject: [PATCH] Support sample rate and global sampling configuration for Datadog in ConfigMap --- .../nginx-configuration/configmap.md | 32 +++++++++++++++++++ .../third-party-addons/opentracing.md | 6 ++++ internal/ingress/controller/config/config.go | 13 ++++++++ internal/ingress/controller/nginx.go | 4 ++- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/docs/user-guide/nginx-configuration/configmap.md b/docs/user-guide/nginx-configuration/configmap.md index 6b2c3a76d6..200a09c00b 100755 --- a/docs/user-guide/nginx-configuration/configmap.md +++ b/docs/user-guide/nginx-configuration/configmap.md @@ -131,6 +131,12 @@ The following table shows a configuration option's name, type, and the default v |[jaeger-debug-header](#jaeger-debug-header)|string|uber-debug-id| |[jaeger-baggage-header](#jaeger-baggage-header)|string|jaeger-baggage| |[jaeger-trace-baggage-header-prefix](#jaeger-trace-baggage-header-prefix)|string|uberctx-| +|[datadog-collector-host](#datadog-collector-host)|string|""| +|[datadog-collector-port](#datadog-collector-port)|int|8126| +|[datadog-service-name](#datadog-service-name)|service|"nginx"| +|[datadog-operation-name-override](#datadog-operation-name-override)|service|"nginx.handle"| +|[datadog-priority-sampling](#datadog-priority-sampling)|bool|"true"| +|[datadog-sample-rate](#datadog-sample-rate)|float|1.0| |[main-snippet](#main-snippet)|string|""| |[http-snippet](#http-snippet)|string|""| |[server-snippet](#server-snippet)|string|""| @@ -780,6 +786,32 @@ Specifies the header name used to submit baggage if there is no root span. _**de Specifies the header prefix used to propagate baggage. _**default:**_ uberctx- +## datadog-collector-host + +Specifies the datadog agent host to use when uploading traces. It must be a valid URL. + +## datadog-collector-port + +Specifies the port to use when uploading traces. _**default:**_ 8126 + +## datadog-service-name + +Specifies the service name to use for any traces created. _**default:**_ nginx + +## datadog-operation-name-override + +Overrides the operation naem to use for any traces crated. _**default:**_ nginx.handle + +## datadog-priority-sampling + +Specifies to use client-side sampling. +If true disables client-side sampling (thus ignoring `sample_rate`) and enables distributed priority sampling, where traces are sampled based on a combination of user-assigned priorities and configuration from the agent. _**default:**_ true + +## datadog-sample-rate + +Specifies sample rate for any traces created. +This is effective only when `datadog-priority-sampling` is `false` _**default:**_ 1.0 + ## main-snippet Adds custom configuration to the main section of the nginx configuration. diff --git a/docs/user-guide/third-party-addons/opentracing.md b/docs/user-guide/third-party-addons/opentracing.md index df8568e240..ca7dc98906 100644 --- a/docs/user-guide/third-party-addons/opentracing.md +++ b/docs/user-guide/third-party-addons/opentracing.md @@ -88,6 +88,12 @@ datadog-service-name # specifies the operation name to use for any traces collected, Default: nginx.handle datadog-operation-name-override + +# Specifies to use client-side sampling for distributed priority sampling and ignore sample rate, Default: true +datadog-priority-sampling + +# specifies sample rate for any traces created, Default: 1.0 +datadog-sample-rate ``` 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. diff --git a/internal/ingress/controller/config/config.go b/internal/ingress/controller/config/config.go index 717a916243..6ef7cda28d 100644 --- a/internal/ingress/controller/config/config.go +++ b/internal/ingress/controller/config/config.go @@ -552,6 +552,17 @@ type Configuration struct { // Default: nginx.handle DatadogOperationNameOverride string `json:"datadog-operation-name-override"` + // DatadogPrioritySampling specifies to use client-side sampling + // If true disables client-side sampling (thus ignoring sample_rate) and enables distributed + // priority sampling, where traces are sampled based on a combination of user-assigned + // Default: true + DatadogPrioritySampling bool `json:"datadog-priority-sampling"` + + // DatadogSampleRate specifies sample rate for any traces created. + // This is effective only when datadog-priority-sampling is false + // Default: 1.0 + DatadogSampleRate float32 `json:"datadog-sample-rate"` + // MainSnippet adds custom configuration to the main section of the nginx configuration MainSnippet string `json:"main-snippet"` @@ -767,6 +778,8 @@ func NewDefault() Configuration { DatadogServiceName: "nginx", DatadogCollectorPort: 8126, DatadogOperationNameOverride: "nginx.handle", + DatadogSampleRate: 1.0, + DatadogPrioritySampling: true, LimitReqStatusCode: 503, LimitConnStatusCode: 503, SyslogPort: 514, diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index faf4316747..4809837dce 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -1075,7 +1075,9 @@ const datadogTmpl = `{ "service": "{{ .DatadogServiceName }}", "agent_host": "{{ .DatadogCollectorHost }}", "agent_port": {{ .DatadogCollectorPort }}, - "operation_name_override": "{{ .DatadogOperationNameOverride }}" + "operation_name_override": "{{ .DatadogOperationNameOverride }}", + "sample_rate": {{ .DatadogSampleRate }}, + "dd.priority.sampling": {{ .DatadogPrioritySampling }} }` func createOpentracingCfg(cfg ngx_config.Configuration) error {