diff --git a/receiver/jaegerreceiver/config.go b/receiver/jaegerreceiver/config.go index 30de0fe0b7c..c5efcfe7066 100644 --- a/receiver/jaegerreceiver/config.go +++ b/receiver/jaegerreceiver/config.go @@ -23,6 +23,7 @@ const protocolsFieldName = "protocols" // RemoteSamplingConfig defines config key for remote sampling fetch endpoint type RemoteSamplingConfig struct { + HostEndpoint string `mapstructure:"host_endpoint"` FetchEndpoint string `mapstructure:"fetch_endpoint"` } diff --git a/receiver/jaegerreceiver/config_test.go b/receiver/jaegerreceiver/config_test.go index 362d700df38..9e09fdf5d46 100644 --- a/receiver/jaegerreceiver/config_test.go +++ b/receiver/jaegerreceiver/config_test.go @@ -74,6 +74,7 @@ func TestLoadConfig(t *testing.T) { }, }, RemoteSampling: &RemoteSamplingConfig{ + HostEndpoint: "0.0.0.0:5778", FetchEndpoint: "jaeger-collector:1234", }, }) diff --git a/receiver/jaegerreceiver/factory.go b/receiver/jaegerreceiver/factory.go index 3c50c39779e..17e26e33639 100644 --- a/receiver/jaegerreceiver/factory.go +++ b/receiver/jaegerreceiver/factory.go @@ -50,8 +50,9 @@ const ( defaultHTTPBindEndpoint = "localhost:14268" defaultTChannelBindEndpoint = "localhost:14267" - defaultThriftCompactBindEndpoint = "localhost:6831" - defaultThriftBinaryBindEndpoint = "localhost:6832" + defaultThriftCompactBindEndpoint = "localhost:6831" + defaultThriftBinaryBindEndpoint = "localhost:6832" + defaultAgentRemoteSamplingHTTPPort = 5778 ) // Factory is the factory for Jaeger receiver. @@ -183,6 +184,16 @@ func (f *Factory) CreateTraceReceiver( if remoteSamplingConfig != nil { config.RemoteSamplingEndpoint = remoteSamplingConfig.FetchEndpoint + + if len(remoteSamplingConfig.HostEndpoint) == 0 { + config.AgentHTTPPort = defaultAgentRemoteSamplingHTTPPort + } else { + var err error + config.AgentHTTPPort, err = extractPortFromEndpoint(remoteSamplingConfig.HostEndpoint) + if err != nil { + return nil, err + } + } } if (protoGRPC == nil && protoHTTP == nil && protoTChannel == nil && protoThriftBinary == nil && protoThriftCompact == nil) || diff --git a/receiver/jaegerreceiver/factory_test.go b/receiver/jaegerreceiver/factory_test.go index 58bbf58b571..dc49587833d 100644 --- a/receiver/jaegerreceiver/factory_test.go +++ b/receiver/jaegerreceiver/factory_test.go @@ -16,6 +16,7 @@ package jaegerreceiver import ( "context" + "fmt" "testing" "github.com/spf13/viper" @@ -117,6 +118,23 @@ func TestCreateInvalidThriftCompactEndpoint(t *testing.T) { assert.Equal(t, 6831, r.(*jReceiver).config.AgentCompactThriftPort, "thrift port should be default") } +func TestDefaultAgentRemoteSamplingHTTPPort(t *testing.T) { + factory := Factory{} + cfg := factory.CreateDefaultConfig() + rCfg := cfg.(*Config) + + endpoint := "localhost:1234" + rCfg.Protocols[protoThriftCompact], _ = defaultsForProtocol(protoThriftCompact) + rCfg.RemoteSampling = &RemoteSamplingConfig{ + FetchEndpoint: endpoint, + } + r, err := factory.CreateTraceReceiver(context.Background(), zap.NewNop(), cfg, nil) + + assert.NoError(t, err, "create trace receiver should not error") + assert.Equal(t, endpoint, r.(*jReceiver).config.RemoteSamplingEndpoint) + assert.Equal(t, defaultAgentRemoteSamplingHTTPPort, r.(*jReceiver).config.AgentHTTPPort, "agent http port should be default") +} + func TestCreateNoPort(t *testing.T) { factory := Factory{} cfg := factory.CreateDefaultConfig() @@ -205,15 +223,18 @@ func TestRemoteSamplingConfigPropagation(t *testing.T) { cfg := factory.CreateDefaultConfig() rCfg := cfg.(*Config) + hostPort := 5778 endpoint := "localhost:1234" rCfg.Protocols[protoThriftCompact], _ = defaultsForProtocol(protoThriftCompact) rCfg.RemoteSampling = &RemoteSamplingConfig{ FetchEndpoint: endpoint, + HostEndpoint: fmt.Sprintf("localhost:%d", hostPort), } r, err := factory.CreateTraceReceiver(context.Background(), zap.NewNop(), cfg, nil) assert.NoError(t, err, "create trace receiver should not error") assert.Equal(t, endpoint, r.(*jReceiver).config.RemoteSamplingEndpoint) + assert.Equal(t, hostPort, r.(*jReceiver).config.AgentHTTPPort, "agent http port should be configured value") } func TestCustomUnmarshalErrors(t *testing.T) { diff --git a/receiver/jaegerreceiver/testdata/config.yaml b/receiver/jaegerreceiver/testdata/config.yaml index 47065bc8bfb..8ef10b9a260 100644 --- a/receiver/jaegerreceiver/testdata/config.yaml +++ b/receiver/jaegerreceiver/testdata/config.yaml @@ -16,6 +16,7 @@ receivers: thrift-binary: endpoint: "0.0.0.0:789" remote_sampling: + host_endpoint: "0.0.0.0:5778" fetch_endpoint: "jaeger-collector:1234" # The following demonstrates how to enable protocols with defaults. jaeger/defaults: