Skip to content
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
1 change: 1 addition & 0 deletions receiver/jaegerreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
1 change: 1 addition & 0 deletions receiver/jaegerreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func TestLoadConfig(t *testing.T) {
},
},
RemoteSampling: &RemoteSamplingConfig{
HostEndpoint: "0.0.0.0:5778",
FetchEndpoint: "jaeger-collector:1234",
},
})
Expand Down
15 changes: 13 additions & 2 deletions receiver/jaegerreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) ||
Expand Down
21 changes: 21 additions & 0 deletions receiver/jaegerreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package jaegerreceiver

import (
"context"
"fmt"
"testing"

"github.com/spf13/viper"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions receiver/jaegerreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down