Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Zipkin server if port/address is not configured #2554

Merged
merged 5 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ install-tools:
install-ci: install-tools

.PHONY: test-ci
test-ci: build-examples lint cover
# TODO (ys) added test-otel to at least ensure tests run in CI,
# but this needs to be changed in the lint and cover targets instead
test-ci: build-examples lint cover test-otel

.PHONY: thrift
thrift: idl/thrift/jaeger.thrift thrift-image
Expand Down
2 changes: 1 addition & 1 deletion cmd/collector/app/builder_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func AddOTELJaegerFlags(flags *flag.FlagSet) {

// AddOTELZipkinFlags adds flag that are exposed by OTEL Zipkin receiver
func AddOTELZipkinFlags(flags *flag.FlagSet) {
flags.String(CollectorZipkinHTTPHostPort, ports.PortToHostPort(0), "The host:port (e.g. 127.0.0.1:9411 or :9411) of the collector's Zipkin server")
flags.String(CollectorZipkinHTTPHostPort, "", "The host:port (e.g. 127.0.0.1:9411 or :9411) of the collector's Zipkin server (disabled by default)")
}

// InitFromViper initializes CollectorOptions with properties from viper
Expand Down
1 change: 1 addition & 0 deletions cmd/collector/app/server/zipkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ZipkinServerParams struct {
// StartZipkinServer based on the given parameters
func StartZipkinServer(params *ZipkinServerParams) (*http.Server, error) {
if params.HostPort == "" {
params.Logger.Info("Not listening for Zipkin HTTP traffic, port not configured")
return nil, nil
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/opentelemetry/app/defaultconfig/default_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/exporter/memoryexporter"
jaegerresource "github.com/jaegertracing/jaeger/cmd/opentelemetry/app/processor/resourceprocessor"
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/receiver/kafkareceiver"
"github.com/jaegertracing/jaeger/ports"
)

const (
Expand Down Expand Up @@ -164,7 +163,7 @@ func createReceivers(component ComponentType, factories component.Factories) con
"otlp": factories.Receivers["otlp"].CreateDefaultConfig(),
}
zipkin := factories.Receivers["zipkin"].CreateDefaultConfig().(*zipkinreceiver.Config)
if zipkin.Endpoint != "" && zipkin.Endpoint != ports.PortToHostPort(0) {
if zipkin.Endpoint != "" {
recvs["zipkin"] = zipkin
}
return recvs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"go.opentelemetry.io/collector/receiver/zipkinreceiver"

jConfig "github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/ports"
)

func TestDefaultValues(t *testing.T) {
Expand All @@ -39,7 +38,7 @@ func TestDefaultValues(t *testing.T) {

factory := &Factory{Viper: v, Wrapped: zipkinreceiver.NewFactory()}
cfg := factory.CreateDefaultConfig().(*zipkinreceiver.Config)
assert.Equal(t, ports.PortToHostPort(0), cfg.Endpoint)
assert.Equal(t, "", cfg.Endpoint)
}

func TestLoadConfigAndFlags(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions ports/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func GetAddressFromCLIOptions(port int, hostPort string) string {
return PortToHostPort(port)
}

if hostPort == "" {
return ""
}

if strings.Contains(hostPort, ":") {
return hostPort
}
Expand Down
31 changes: 18 additions & 13 deletions ports/ports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package ports

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -25,17 +26,21 @@ func TestPortToHostPort(t *testing.T) {
}

func TestGetAddressFromCLIOptionsLegacy(t *testing.T) {
assert.Equal(t, ":123", GetAddressFromCLIOptions(123, ""))
}

func TestGetAddressFromCLIOptionHostPort(t *testing.T) {
assert.Equal(t, "127.0.0.1:123", GetAddressFromCLIOptions(0, "127.0.0.1:123"))
}

func TestGetAddressFromCLIOptionOnlyPort(t *testing.T) {
assert.Equal(t, ":123", GetAddressFromCLIOptions(0, ":123"))
}

func TestGetAddressFromCLIOptionOnlyPortWithoutColon(t *testing.T) {
assert.Equal(t, ":123", GetAddressFromCLIOptions(0, "123"))
tests := []struct {
port int
hostPort string
out string
}{
{port: 123, hostPort: "", out: ":123"},
{port: 0, hostPort: "127.0.0.1:123", out: "127.0.0.1:123"},
{port: 0, hostPort: ":123", out: ":123"},
{port: 123, hostPort: "567", out: ":123"},
{port: 0, hostPort: "123", out: ":123"},
{port: 0, hostPort: "", out: ""},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%+v", test), func(t *testing.T) {
assert.Equal(t, test.out, GetAddressFromCLIOptions(test.port, test.hostPort))
})
}
}