Deprecate opentracing (#10615)
This commit is contained in:
parent
9ed0d7f7af
commit
30820a5acc
14 changed files with 4 additions and 1089 deletions
|
|
@ -268,7 +268,6 @@ var funcMap = text_template.FuncMap{
|
|||
"buildForwardedFor": buildForwardedFor,
|
||||
"buildAuthSignURL": buildAuthSignURL,
|
||||
"buildAuthSignURLLocation": buildAuthSignURLLocation,
|
||||
"buildOpentracing": buildOpentracing,
|
||||
"buildOpentelemetry": buildOpentelemetry,
|
||||
"proxySetHeader": proxySetHeader,
|
||||
"enforceRegexModifier": enforceRegexModifier,
|
||||
|
|
@ -277,9 +276,7 @@ var funcMap = text_template.FuncMap{
|
|||
"shouldLoadModSecurityModule": shouldLoadModSecurityModule,
|
||||
"buildHTTPListener": buildHTTPListener,
|
||||
"buildHTTPSListener": buildHTTPSListener,
|
||||
"buildOpentracingForLocation": buildOpentracingForLocation,
|
||||
"buildOpentelemetryForLocation": buildOpentelemetryForLocation,
|
||||
"shouldLoadOpentracingModule": shouldLoadOpentracingModule,
|
||||
"shouldLoadOpentelemetryModule": shouldLoadOpentelemetryModule,
|
||||
"buildModSecurityForLocation": buildModSecurityForLocation,
|
||||
"buildMirrorLocations": buildMirrorLocations,
|
||||
|
|
@ -1209,46 +1206,6 @@ func randomString() string {
|
|||
return string(b)
|
||||
}
|
||||
|
||||
func buildOpentracing(c, s interface{}) string {
|
||||
cfg, ok := c.(config.Configuration)
|
||||
if !ok {
|
||||
klog.Errorf("expected a 'config.Configuration' type but %T was returned", c)
|
||||
return ""
|
||||
}
|
||||
|
||||
servers, ok := s.([]*ingress.Server)
|
||||
if !ok {
|
||||
klog.Errorf("expected an '[]*ingress.Server' type but %T was returned", s)
|
||||
return ""
|
||||
}
|
||||
|
||||
if !shouldLoadOpentracingModule(cfg, servers) {
|
||||
return ""
|
||||
}
|
||||
|
||||
buf := bytes.NewBufferString("")
|
||||
|
||||
//nolint:gocritic // rewriting if-else to switch statement is not more readable
|
||||
if cfg.DatadogCollectorHost != "" {
|
||||
buf.WriteString("opentracing_load_tracer /usr/local/lib/libdd_opentracing.so /etc/ingress-controller/telemetry/opentracing.json;")
|
||||
} else if cfg.ZipkinCollectorHost != "" {
|
||||
buf.WriteString("opentracing_load_tracer /usr/local/lib/libzipkin_opentracing_plugin.so /etc/ingress-controller/telemetry/opentracing.json;")
|
||||
} else if cfg.JaegerCollectorHost != "" || cfg.JaegerEndpoint != "" {
|
||||
buf.WriteString("opentracing_load_tracer /usr/local/lib/libjaegertracing_plugin.so /etc/ingress-controller/telemetry/opentracing.json;")
|
||||
}
|
||||
|
||||
buf.WriteString("\r\n")
|
||||
|
||||
if cfg.OpentracingOperationName != "" {
|
||||
fmt.Fprintf(buf, "opentracing_operation_name \"%s\";\n", cfg.OpentracingOperationName)
|
||||
}
|
||||
if cfg.OpentracingLocationOperationName != "" {
|
||||
fmt.Fprintf(buf, "opentracing_location_operation_name \"%s\";\n", cfg.OpentracingLocationOperationName)
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func buildOpentelemetry(c, s interface{}) string {
|
||||
cfg, ok := c.(config.Configuration)
|
||||
if !ok {
|
||||
|
|
@ -1362,18 +1319,6 @@ func buildCustomErrorLocationsPerServer(input interface{}) []errorLocation {
|
|||
return errorLocations
|
||||
}
|
||||
|
||||
func opentracingPropagateContext(location *ingress.Location) string {
|
||||
if location == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if location.BackendProtocol == grpcProtocol || location.BackendProtocol == grpcsProtocol {
|
||||
return "opentracing_grpc_propagate_context;"
|
||||
}
|
||||
|
||||
return "opentracing_propagate_context;"
|
||||
}
|
||||
|
||||
func opentelemetryPropagateContext(location *ingress.Location) string {
|
||||
if location == nil {
|
||||
return ""
|
||||
|
|
@ -1569,31 +1514,6 @@ func httpsListener(addresses []string, co string, tc *config.TemplateConfig) []s
|
|||
return out
|
||||
}
|
||||
|
||||
func buildOpentracingForLocation(isOTEnabled, isOTTrustSet bool, location *ingress.Location) string {
|
||||
isOTEnabledInLoc := location.Opentracing.Enabled
|
||||
isOTSetInLoc := location.Opentracing.Set
|
||||
|
||||
if isOTEnabled {
|
||||
if isOTSetInLoc && !isOTEnabledInLoc {
|
||||
return "opentracing off;"
|
||||
}
|
||||
} else if !isOTSetInLoc || !isOTEnabledInLoc {
|
||||
return ""
|
||||
}
|
||||
|
||||
opc := opentracingPropagateContext(location)
|
||||
if opc != "" {
|
||||
opc = fmt.Sprintf("opentracing on;\n%v", opc)
|
||||
}
|
||||
|
||||
if (!isOTTrustSet && !location.Opentracing.TrustSet) ||
|
||||
(location.Opentracing.TrustSet && !location.Opentracing.TrustEnabled) {
|
||||
opc += "\nopentracing_trust_incoming_span off;"
|
||||
}
|
||||
|
||||
return opc
|
||||
}
|
||||
|
||||
func buildOpentelemetryForLocation(isOTEnabled, isOTTrustSet bool, location *ingress.Location) string {
|
||||
isOTEnabledInLoc := location.Opentelemetry.Enabled
|
||||
isOTSetInLoc := location.Opentelemetry.Set
|
||||
|
|
@ -1624,37 +1544,6 @@ func buildOpentelemetryForLocation(isOTEnabled, isOTTrustSet bool, location *ing
|
|||
return opc
|
||||
}
|
||||
|
||||
// shouldLoadOpentracingModule determines whether or not the Opentracing module needs to be loaded.
|
||||
// First, it checks if `enable-opentracing` is set in the ConfigMap. If it is not, it iterates over all locations to
|
||||
// check if Opentracing is enabled by the annotation `nginx.ingress.kubernetes.io/enable-opentracing`.
|
||||
func shouldLoadOpentracingModule(c, s interface{}) bool {
|
||||
cfg, ok := c.(config.Configuration)
|
||||
if !ok {
|
||||
klog.Errorf("expected a 'config.Configuration' type but %T was returned", c)
|
||||
return false
|
||||
}
|
||||
|
||||
servers, ok := s.([]*ingress.Server)
|
||||
if !ok {
|
||||
klog.Errorf("expected an '[]*ingress.Server' type but %T was returned", s)
|
||||
return false
|
||||
}
|
||||
|
||||
if cfg.EnableOpentracing {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, server := range servers {
|
||||
for _, location := range server.Locations {
|
||||
if location.Opentracing.Enabled {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// shouldLoadOpentelemetryModule determines whether or not the Opentelemetry module needs to be loaded.
|
||||
// It checks if `enable-opentelemetry` is set in the ConfigMap.
|
||||
func shouldLoadOpentelemetryModule(c, s interface{}) bool {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ import (
|
|||
"k8s.io/ingress-nginx/internal/ingress/annotations/authreq"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/modsecurity"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/opentelemetry"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/opentracing"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/ratelimit"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/rewrite"
|
||||
"k8s.io/ingress-nginx/internal/ingress/controller/config"
|
||||
|
|
@ -1134,25 +1133,6 @@ func TestEscapeLiteralDollar(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestOpentracingPropagateContext(t *testing.T) {
|
||||
tests := map[*ingress.Location]string{
|
||||
{BackendProtocol: httpProtocol}: "opentracing_propagate_context;",
|
||||
{BackendProtocol: httpsProtocol}: "opentracing_propagate_context;",
|
||||
{BackendProtocol: autoHTTPProtocol}: "opentracing_propagate_context;",
|
||||
{BackendProtocol: grpcProtocol}: "opentracing_grpc_propagate_context;",
|
||||
{BackendProtocol: grpcsProtocol}: "opentracing_grpc_propagate_context;",
|
||||
{BackendProtocol: fcgiProtocol}: "opentracing_propagate_context;",
|
||||
nil: "",
|
||||
}
|
||||
|
||||
for loc, expectedDirective := range tests {
|
||||
actualDirective := opentracingPropagateContext(loc)
|
||||
if actualDirective != expectedDirective {
|
||||
t.Errorf("Expected %v but returned %v", expectedDirective, actualDirective)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpentelemetryPropagateContext(t *testing.T) {
|
||||
tests := map[*ingress.Location]string{
|
||||
{BackendProtocol: httpProtocol}: "opentelemetry_propagate;",
|
||||
|
|
@ -1640,85 +1620,6 @@ func TestProxySetHeader(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuildOpenTracing(t *testing.T) {
|
||||
invalidType := &ingress.Ingress{}
|
||||
expected := ""
|
||||
actual := buildOpentracing(invalidType, []*ingress.Server{})
|
||||
|
||||
if expected != actual {
|
||||
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",
|
||||
}
|
||||
expected = "opentracing_load_tracer /usr/local/lib/libjaegertracing_plugin.so /etc/ingress-controller/telemetry/opentracing.json;\r\n"
|
||||
actual = buildOpentracing(cfgJaeger, []*ingress.Server{})
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
cfgZipkin := config.Configuration{
|
||||
EnableOpentracing: true,
|
||||
ZipkinCollectorHost: "zipkin-host.com",
|
||||
}
|
||||
expected = "opentracing_load_tracer /usr/local/lib/libzipkin_opentracing_plugin.so /etc/ingress-controller/telemetry/opentracing.json;\r\n"
|
||||
actual = buildOpentracing(cfgZipkin, []*ingress.Server{})
|
||||
|
||||
if expected != actual {
|
||||
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/ingress-controller/telemetry/opentracing.json;\r\n"
|
||||
actual = buildOpentracing(cfgDatadog, []*ingress.Server{})
|
||||
|
||||
if expected != actual {
|
||||
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/ingress-controller/telemetry/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",
|
||||
OpentracingOperationName: "my-operation-name",
|
||||
OpentracingLocationOperationName: "my-location-operation-name",
|
||||
}
|
||||
expected = "opentracing_load_tracer /usr/local/lib/libdd_opentracing.so /etc/ingress-controller/telemetry/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 TestBuildOpenTelemetry(t *testing.T) {
|
||||
invalidType := &ingress.Ingress{}
|
||||
expected := ""
|
||||
|
|
@ -1831,107 +1732,6 @@ func TestShouldLoadModSecurityModule(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestOpentracingForLocation(t *testing.T) {
|
||||
trueVal := true
|
||||
falseVal := false
|
||||
|
||||
loadOT := `opentracing on;
|
||||
opentracing_propagate_context;`
|
||||
loadOTUntrustedSpan := `opentracing on;
|
||||
opentracing_propagate_context;
|
||||
opentracing_trust_incoming_span off;`
|
||||
testCases := []struct {
|
||||
description string
|
||||
globalOT bool
|
||||
isSetInLoc bool
|
||||
isOTInLoc *bool
|
||||
globalTrust bool
|
||||
isTrustSetInLoc bool
|
||||
isTrustInLoc *bool
|
||||
expected string
|
||||
}{
|
||||
{"globally enabled, without annotation", true, false, nil, true, false, nil, loadOT},
|
||||
{"globally enabled and enabled in location", true, true, &trueVal, true, false, nil, loadOT},
|
||||
{"globally disabled and not enabled in location", false, false, nil, true, false, nil, ""},
|
||||
{"globally disabled but enabled in location", false, true, &trueVal, true, false, nil, loadOT},
|
||||
{"globally trusted, not trusted in location", true, false, nil, true, true, &falseVal, loadOTUntrustedSpan},
|
||||
{"not globally trusted, trust set in location", true, false, nil, false, true, &trueVal, loadOT},
|
||||
{"not globally trusted, trust not set in location", true, false, nil, false, false, nil, loadOTUntrustedSpan},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
il := &ingress.Location{
|
||||
Opentracing: opentracing.Config{Set: testCase.isSetInLoc, TrustSet: testCase.isTrustSetInLoc},
|
||||
}
|
||||
if il.Opentracing.Set {
|
||||
il.Opentracing.Enabled = *testCase.isOTInLoc
|
||||
}
|
||||
if il.Opentracing.TrustSet {
|
||||
il.Opentracing.TrustEnabled = *testCase.isTrustInLoc
|
||||
}
|
||||
|
||||
actual := buildOpentracingForLocation(testCase.globalOT, testCase.globalTrust, il)
|
||||
|
||||
if testCase.expected != actual {
|
||||
t.Errorf("%v: expected '%v' but returned '%v'", testCase.description, testCase.expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:dupl // Ignore dupl errors for similar test case
|
||||
func TestShouldLoadOpentracingModule(t *testing.T) {
|
||||
// ### Invalid argument type tests ###
|
||||
// The first tests should return false.
|
||||
expected := false
|
||||
|
||||
invalidType := &ingress.Ingress{}
|
||||
actual := shouldLoadOpentracingModule(config.Configuration{}, invalidType)
|
||||
if expected != actual {
|
||||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
actual = shouldLoadOpentracingModule(invalidType, []*ingress.Server{})
|
||||
if expected != actual {
|
||||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
// ### Functional tests ###
|
||||
actual = shouldLoadOpentracingModule(config.Configuration{}, []*ingress.Server{})
|
||||
if expected != actual {
|
||||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
// All further tests should return true.
|
||||
expected = true
|
||||
|
||||
configuration := config.Configuration{EnableOpentracing: true}
|
||||
actual = shouldLoadOpentracingModule(configuration, []*ingress.Server{})
|
||||
if expected != actual {
|
||||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
servers := []*ingress.Server{
|
||||
{
|
||||
Locations: []*ingress.Location{
|
||||
{
|
||||
Opentracing: opentracing.Config{
|
||||
Enabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
actual = shouldLoadOpentracingModule(config.Configuration{}, servers)
|
||||
if expected != actual {
|
||||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
actual = shouldLoadOpentracingModule(configuration, servers)
|
||||
if expected != actual {
|
||||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpentelemetryForLocation(t *testing.T) {
|
||||
trueVal := true
|
||||
falseVal := false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue