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

Explicitly set Service Port Protocol for Jaeger Receivers #117

Merged
merged 4 commits into from
Dec 1, 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
28 changes: 18 additions & 10 deletions pkg/collector/parser/receiver_jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,29 @@ func (j *JaegerReceiverParser) Ports() ([]corev1.ServicePort, error) {
ports := []corev1.ServicePort{}

for _, protocol := range []struct {
name string
defaultPort int32
name string
defaultPort int32
transportProtocol corev1.Protocol
}{
{
name: "grpc",
defaultPort: defaultGRPCPort,
name: "grpc",
defaultPort: defaultGRPCPort,
transportProtocol: corev1.ProtocolTCP,
},
{
name: "thrift_http",
defaultPort: defaultThriftHTTPPort,
name: "thrift_http",
defaultPort: defaultThriftHTTPPort,
transportProtocol: corev1.ProtocolTCP,
},
{
name: "thrift_compact",
defaultPort: defaultThriftCompactPort,
name: "thrift_compact",
defaultPort: defaultThriftCompactPort,
transportProtocol: corev1.ProtocolUDP,
},
{
name: "thrift_binary",
defaultPort: defaultThriftBinaryPort,
name: "thrift_binary",
defaultPort: defaultThriftBinaryPort,
transportProtocol: corev1.ProtocolUDP,
},
} {
// do we have the protocol specified at all?
Expand All @@ -87,6 +92,9 @@ func (j *JaegerReceiverParser) Ports() ([]corev1.ServicePort, error) {
}
}

// set the appropriate transport protocol (i.e. TCP/UDP) for this kind of receiver protocol
protocolPort.Protocol = protocol.transportProtocol

// at this point, we *have* a port specified, add it to the list of ports
ports = append(ports, *protocolPort)
}
Expand Down
17 changes: 11 additions & 6 deletions pkg/collector/parser/receiver_jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
)

func TestJaegerSelfRegisters(t *testing.T) {
Expand Down Expand Up @@ -34,6 +35,7 @@ func TestJaegerMinimalConfiguration(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, ports, 1)
assert.EqualValues(t, 14250, ports[0].Port)
assert.EqualValues(t, corev1.ProtocolTCP, ports[0].Protocol)
}

func TestJaegerPortsOverridden(t *testing.T) {
Expand All @@ -53,6 +55,7 @@ func TestJaegerPortsOverridden(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, ports, 1)
assert.EqualValues(t, 1234, ports[0].Port)
assert.EqualValues(t, corev1.ProtocolTCP, ports[0].Protocol)
}

func TestJaegerExposeDefaultPorts(t *testing.T) {
Expand All @@ -67,13 +70,14 @@ func TestJaegerExposeDefaultPorts(t *testing.T) {
})

expectedResults := map[string]struct {
portNumber int32
seen bool
portNumber int32
seen bool
transportProtocol corev1.Protocol
}{
"jaeger-grpc": {portNumber: 14250},
"jaeger-thrift-http": {portNumber: 14268},
"jaeger-thrift-compact": {portNumber: 6831},
"jaeger-thrift-binary": {portNumber: 6832},
"jaeger-grpc": {portNumber: 14250, transportProtocol: corev1.ProtocolTCP},
"jaeger-thrift-http": {portNumber: 14268, transportProtocol: corev1.ProtocolTCP},
"jaeger-thrift-compact": {portNumber: 6831, transportProtocol: corev1.ProtocolUDP},
"jaeger-thrift-binary": {portNumber: 6832, transportProtocol: corev1.ProtocolUDP},
}

// test
Expand All @@ -88,6 +92,7 @@ func TestJaegerExposeDefaultPorts(t *testing.T) {
r.seen = true
expectedResults[port.Name] = r
assert.EqualValues(t, r.portNumber, port.Port)
assert.EqualValues(t, r.transportProtocol, port.Protocol)
}
for k, v := range expectedResults {
assert.True(t, v.seen, "the port %s wasn't included in the service ports", k)
Expand Down