Skip to content

Commit

Permalink
Change the default port for OLTP HTTP (#373)
Browse files Browse the repository at this point in the history
* Change the default port for OLTP http
And marking the existing as legacy.

* Fix tests
  • Loading branch information
joaopgrassi authored Aug 6, 2021
1 parent 90b4e81 commit 3eae0e5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
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
31 changes: 27 additions & 4 deletions pkg/collector/parser/receiver_otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,62 @@ 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": {portNumber: 4318},
"otlp-http-legacy": {portNumber: 55681},
}

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

// verify
assert.NoError(t, err)
assert.Len(t, ports, 1)
assert.Len(t, ports, len(expectedResults))

for _, port := range ports {
r := expectedResults[port.Name]
Expand Down

0 comments on commit 3eae0e5

Please sign in to comment.