Merge pull request #5931 from bvandewalle/add-opentracing-operation-name-settings
Add opentracing operation name settings
This commit is contained in:
commit
835c40f6c5
6 changed files with 163 additions and 0 deletions
|
@ -121,6 +121,8 @@ The following table shows a configuration option's name, type, and the default v
|
|||
|[proxy-add-original-uri-header](#proxy-add-original-uri-header)|bool|"false"|
|
||||
|[generate-request-id](#generate-request-id)|bool|"true"|
|
||||
|[enable-opentracing](#enable-opentracing)|bool|"false"|
|
||||
|[opentracing-operation-name](#opentracing-operation-name)|string|""|
|
||||
|[opentracing-location-operation-name](#opentracing-location-operation-name)|string|""|
|
||||
|[zipkin-collector-host](#zipkin-collector-host)|string|""|
|
||||
|[zipkin-collector-port](#zipkin-collector-port)|int|9411|
|
||||
|[zipkin-service-name](#zipkin-service-name)|string|"nginx"|
|
||||
|
@ -773,6 +775,18 @@ Enables the nginx Opentracing extension. _**default:**_ is disabled
|
|||
_References:_
|
||||
[https://github.com/opentracing-contrib/nginx-opentracing](https://github.com/opentracing-contrib/nginx-opentracing)
|
||||
|
||||
## opentracing-operation-name
|
||||
|
||||
Specifies a custom name for the server span. _**default:**_ is empty
|
||||
|
||||
For example, set to "HTTP $request_method $uri".
|
||||
|
||||
## opentracing-location-operation-name
|
||||
|
||||
Specifies a custom name for the location span. _**default:**_ is empty
|
||||
|
||||
For example, set to "HTTP $request_method $uri".
|
||||
|
||||
## zipkin-collector-host
|
||||
|
||||
Specifies the host to use when uploading traces. It must be a valid URL.
|
||||
|
|
|
@ -39,6 +39,12 @@ have been tested.
|
|||
|
||||
Other optional configuration options:
|
||||
```
|
||||
# specifies the name to use for the server span
|
||||
opentracing-operation-name
|
||||
|
||||
# specifies specifies the name to use for the location span
|
||||
opentracing-location-operation-name
|
||||
|
||||
# specifies the port to use when uploading traces, Default: 9411
|
||||
zipkin-collector-port
|
||||
|
||||
|
|
|
@ -503,6 +503,12 @@ type Configuration struct {
|
|||
// By default this is disabled
|
||||
EnableOpentracing bool `json:"enable-opentracing"`
|
||||
|
||||
// OpentracingOperationName specifies a custom name for the server span
|
||||
OpentracingOperationName string `json:"opentracing-operation-name"`
|
||||
|
||||
// OpentracingOperationName specifies a custom name for the location span
|
||||
OpentracingLocationOperationName string `json:"opentracing-location-operation-name"`
|
||||
|
||||
// ZipkinCollectorHost specifies the host to use when uploading traces
|
||||
ZipkinCollectorHost string `json:"zipkin-collector-host"`
|
||||
|
||||
|
|
|
@ -970,6 +970,13 @@ func buildOpentracing(c interface{}, s interface{}) string {
|
|||
|
||||
buf.WriteString("\r\n")
|
||||
|
||||
if cfg.OpentracingOperationName != "" {
|
||||
buf.WriteString(fmt.Sprintf("opentracing_operation_name \"%s\";\n", cfg.OpentracingOperationName))
|
||||
}
|
||||
if cfg.OpentracingLocationOperationName != "" {
|
||||
buf.WriteString(fmt.Sprintf("opentracing_location_operation_name \"%s\";\n", cfg.OpentracingLocationOperationName))
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
|
|
@ -1193,6 +1193,21 @@ func TestBuildOpenTracing(t *testing.T) {
|
|||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
cfgOpenTracing := config.Configuration{
|
||||
EnableOpentracing: true,
|
||||
DatadogCollectorHost: "datadog-host.com",
|
||||
OpentracingOperationName: "my-operation-name",
|
||||
OpentracingLocationOperationName: "my-location-operation-name",
|
||||
}
|
||||
expected = "opentracing_load_tracer /usr/local/lib64/libdd_opentracing.so /etc/nginx/opentracing.json;\r\n"
|
||||
expected += "opentracing_operation_name \"my-operation-name\";\n"
|
||||
expected += "opentracing_location_operation_name \"my-location-operation-name\";\n"
|
||||
actual = buildOpentracing(cfgOpenTracing, []*ingress.Server{})
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestEnforceRegexModifier(t *testing.T) {
|
||||
|
|
115
test/e2e/settings/opentracing.go
Normal file
115
test/e2e/settings/opentracing.go
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/onsi/ginkgo"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
||||
var _ = framework.IngressNginxDescribe("Configure OpenTracing", func() {
|
||||
f := framework.NewDefaultFramework("enable-opentracing")
|
||||
enableOpentracing := "enable-opentracing"
|
||||
zipkinCollectorHost := "zipkin-collector-host"
|
||||
opentracingOperationName := "opentracing-operation-name"
|
||||
opentracingLocationOperationName := "opentracing-location-operation-name"
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeployment()
|
||||
})
|
||||
|
||||
ginkgo.AfterEach(func() {
|
||||
})
|
||||
|
||||
ginkgo.It("should not exists opentracing directive", func() {
|
||||
f.UpdateNginxConfigMapData(enableOpentracing, "false")
|
||||
|
||||
f.EnsureIngress(framework.NewSingleIngress(enableOpentracing, "/", enableOpentracing, f.Namespace, "http-svc", 80, nil))
|
||||
|
||||
f.WaitForNginxConfiguration(
|
||||
func(cfg string) bool {
|
||||
return !strings.Contains(cfg, "opentracing on")
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.It("should exists opentracing directive when is enabled", func() {
|
||||
f.UpdateNginxConfigMapData(enableOpentracing, "true")
|
||||
f.UpdateNginxConfigMapData(zipkinCollectorHost, "127.0.0.1")
|
||||
|
||||
f.EnsureIngress(framework.NewSingleIngress(enableOpentracing, "/", enableOpentracing, f.Namespace, "http-svc", 80, nil))
|
||||
|
||||
f.WaitForNginxConfiguration(
|
||||
func(cfg string) bool {
|
||||
return strings.Contains(cfg, "opentracing on")
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.It("should not exists opentracing_operation_name directive when is empty", func() {
|
||||
f.UpdateNginxConfigMapData(enableOpentracing, "true")
|
||||
f.UpdateNginxConfigMapData(zipkinCollectorHost, "127.0.0.1")
|
||||
f.UpdateNginxConfigMapData(opentracingOperationName, "")
|
||||
|
||||
f.EnsureIngress(framework.NewSingleIngress(enableOpentracing, "/", enableOpentracing, f.Namespace, "http-svc", 80, nil))
|
||||
|
||||
f.WaitForNginxConfiguration(
|
||||
func(cfg string) bool {
|
||||
return !strings.Contains(cfg, "opentracing_operation_name")
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.It("should exists opentracing_operation_name directive when is configured", func() {
|
||||
f.UpdateNginxConfigMapData(enableOpentracing, "true")
|
||||
f.UpdateNginxConfigMapData(zipkinCollectorHost, "127.0.0.1")
|
||||
f.UpdateNginxConfigMapData(opentracingOperationName, "HTTP $request_method $uri")
|
||||
|
||||
f.EnsureIngress(framework.NewSingleIngress(enableOpentracing, "/", enableOpentracing, f.Namespace, "http-svc", 80, nil))
|
||||
|
||||
f.WaitForNginxConfiguration(
|
||||
func(cfg string) bool {
|
||||
return strings.Contains(cfg, "opentracing_operation_name \"HTTP $request_method $uri\"")
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.It("should not exists opentracing_location_operation_name directive when is empty", func() {
|
||||
f.UpdateNginxConfigMapData(enableOpentracing, "true")
|
||||
f.UpdateNginxConfigMapData(zipkinCollectorHost, "127.0.0.1")
|
||||
f.UpdateNginxConfigMapData(opentracingLocationOperationName, "")
|
||||
|
||||
f.EnsureIngress(framework.NewSingleIngress(enableOpentracing, "/", enableOpentracing, f.Namespace, "http-svc", 80, nil))
|
||||
|
||||
f.WaitForNginxConfiguration(
|
||||
func(cfg string) bool {
|
||||
return !strings.Contains(cfg, "opentracing_location_operation_name")
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.It("should exists opentracing_location_operation_name directive when is configured", func() {
|
||||
f.UpdateNginxConfigMapData(enableOpentracing, "true")
|
||||
f.UpdateNginxConfigMapData(zipkinCollectorHost, "127.0.0.1")
|
||||
f.UpdateNginxConfigMapData(opentracingLocationOperationName, "HTTP $request_method $uri")
|
||||
|
||||
f.EnsureIngress(framework.NewSingleIngress(enableOpentracing, "/", enableOpentracing, f.Namespace, "http-svc", 80, nil))
|
||||
|
||||
f.WaitForNginxConfiguration(
|
||||
func(cfg string) bool {
|
||||
return strings.Contains(cfg, "opentracing_location_operation_name \"HTTP $request_method $uri\"")
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue