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

Change the default port for OTLP HTTP #373

Merged
merged 3 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 15 additions & 7 deletions pkg/collector/parser/receiver_otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ var _ ReceiverParser = &OTLPReceiverParser{}
const (
parserNameOTLP = "__otlp"

defaultOTLPGRPCPort int32 = 4317
defaultOTLPHTTPPort int32 = 55681
defaultOTLPGRPCPort int32 = 4317
defaultOTLPHTTPLegacyPort int32 = 55681
defaultOTLPHTTPPort int32 = 4318
)

// OTLPReceiverParser parses the configuration for OTLP receivers.
Expand Down Expand Up @@ -74,11 +75,18 @@ func (o *OTLPReceiverParser) Ports() ([]corev1.ServicePort, error) {
},
{
name: "http",
defaultPorts: []corev1.ServicePort{{
Name: portName(fmt.Sprintf("%s-http", o.name), defaultOTLPHTTPPort),
Port: defaultOTLPHTTPPort,
TargetPort: intstr.FromInt(int(defaultOTLPHTTPPort)),
}},
defaultPorts: []corev1.ServicePort{
{
Name: portName(fmt.Sprintf("%s-http", o.name), defaultOTLPHTTPPort),
Port: defaultOTLPHTTPPort,
TargetPort: intstr.FromInt(int(defaultOTLPHTTPPort)),
},
{
Name: portName(fmt.Sprintf("%s-http-legacy", o.name), defaultOTLPHTTPLegacyPort),
Port: defaultOTLPHTTPLegacyPort,
TargetPort: intstr.FromInt(int(defaultOTLPHTTPPort)), // we target the official port, not the legacy
},
},
},
} {
// do we have the protocol specified at all?
Expand Down
28 changes: 25 additions & 3 deletions pkg/collector/parser/receiver_otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,53 @@ func TestOTLPPortsOverridden(t *testing.T) {
"grpc": map[interface{}]interface{}{
"endpoint": "0.0.0.0:1234",
},
"http": map[interface{}]interface{}{
"endpoint": "0.0.0.0:1235",
},
},
})

expectedResults := map[string]struct {
portNumber int32
seen bool
}{
"otlp-grpc": {portNumber: 1234},
"otlp-http": {portNumber: 1235},
}

// test
ports, err := builder.Ports()

// verify
assert.NoError(t, err)
assert.Len(t, ports, 1)
assert.EqualValues(t, 1234, ports[0].Port)
assert.Len(t, ports, len(expectedResults))

for _, port := range ports {
r := expectedResults[port.Name]
r.seen = true
expectedResults[port.Name] = r
assert.EqualValues(t, r.portNumber, port.Port)
}
for k, v := range expectedResults {
assert.True(t, v.seen, "the port %s wasn't included in the service ports", k)
}
}

func TestOTLPExposeDefaultPorts(t *testing.T) {
// prepare
builder := NewOTLPReceiverParser(logger, "otlp", map[interface{}]interface{}{
"protocols": map[interface{}]interface{}{
"grpc": map[interface{}]interface{}{},
"http": map[interface{}]interface{}{},
},
})

expectedResults := map[string]struct {
portNumber int32
seen bool
}{
"otlp-grpc": {portNumber: 4317},
"otlp-grpc": {portNumber: 4317},
"otlp-http-legacy": {portNumber: 55681},
}

// test
Expand Down