diff --git a/CHANGELOG.md b/CHANGELOG.md index 141213cd70..a0468295b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Changes by Version ================== +0.16.0 (2020-12-03) +------------------- +* Bumped OpenTelemetry Collector to v0.16.0 ([#135](https://github.com/open-telemetry/opentelemetry-operator/pull/135), [@jpkrohling](https://github.com/jpkrohling)) +* Fix image prefix for release image ([#133](https://github.com/open-telemetry/opentelemetry-operator/pull/133), [@jpkrohling](https://github.com/jpkrohling)) +* Explicitly set Service Port Protocol for Jaeger Receivers ([#117](https://github.com/open-telemetry/opentelemetry-operator/pull/117), [@KingJ](https://github.com/KingJ)) + +_Note: The default port for the OTLP receiver has been changed from 55680 to 4317. To keep compatibility with your existing workload, the operator is now generating a service with the two port numbers by default. Both have 4317 as the target port._ + 0.15.0 (2020-11-27) ------------------- * Bumped OpenTelemetry Collector to v0.15.0 ([#131](https://github.com/open-telemetry/opentelemetry-operator/pull/131), [@jpkrohling](https://github.com/jpkrohling)) diff --git a/pkg/collector/parser/receiver_generic_test.go b/pkg/collector/parser/receiver_generic_test.go index dba6b7961a..bf05cc342f 100644 --- a/pkg/collector/parser/receiver_generic_test.go +++ b/pkg/collector/parser/receiver_generic_test.go @@ -52,7 +52,6 @@ func TestDownstreamParsers(t *testing.T) { }{ {"zipkin", "zipkin", "__zipkin", 9411, parser.NewZipkinReceiverParser}, {"opencensus", "opencensus", "__opencensus", 55678, parser.NewOpenCensusReceiverParser}, - {"otlp", "otlp", "__otlp", 55680, parser.NewOTLPReceiverParser}, // contrib receivers {"carbon", "carbon", "__carbon", 2003, parser.NewCarbonReceiverParser}, diff --git a/pkg/collector/parser/receiver_otlp.go b/pkg/collector/parser/receiver_otlp.go index acf19b6fa1..57bd2706c2 100644 --- a/pkg/collector/parser/receiver_otlp.go +++ b/pkg/collector/parser/receiver_otlp.go @@ -1,18 +1,106 @@ package parser -import "github.com/go-logr/logr" +import ( + "fmt" -const parserNameOTLP = "__otlp" + "github.com/go-logr/logr" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var _ ReceiverParser = &OTLPReceiverParser{} + +const ( + parserNameOTLP = "__otlp" + + defaultOTLPGRPCPort int32 = 4317 + defaultOTLPGRPCLegacyPort int32 = 55680 + defaultOTLPHTTPPort int32 = 55681 +) + +// OTLPReceiverParser parses the configuration for OTLP receivers +type OTLPReceiverParser struct { + logger logr.Logger + name string + config map[interface{}]interface{} +} // NewOTLPReceiverParser builds a new parser for OTLP receivers func NewOTLPReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 55680, - parserName: parserNameOTLP, + if protocols, ok := config["protocols"].(map[interface{}]interface{}); ok { + return &OTLPReceiverParser{ + logger: logger, + name: name, + config: protocols, + } + } + + return &OTLPReceiverParser{ + name: name, + config: map[interface{}]interface{}{}, + } +} + +// Ports returns all the service ports for all protocols in this parser +func (o *OTLPReceiverParser) Ports() ([]corev1.ServicePort, error) { + ports := []corev1.ServicePort{} + + for _, protocol := range []struct { + name string + defaultPorts []corev1.ServicePort + }{ + { + name: "grpc", + defaultPorts: []corev1.ServicePort{ + { + Name: portName(fmt.Sprintf("%s-grpc", o.name), defaultOTLPGRPCPort), + Port: defaultOTLPGRPCPort, + TargetPort: intstr.FromInt(int(defaultOTLPGRPCPort)), + }, + { + Name: portName(fmt.Sprintf("%s-grpc-legacy", o.name), defaultOTLPGRPCLegacyPort), + Port: defaultOTLPGRPCLegacyPort, + TargetPort: intstr.FromInt(int(defaultOTLPGRPCPort)), // we target the official port, not the legacy + }, + }, + }, + { + name: "http", + defaultPorts: []corev1.ServicePort{{ + Name: portName(fmt.Sprintf("%s-http", o.name), defaultOTLPHTTPPort), + Port: defaultOTLPHTTPPort, + TargetPort: intstr.FromInt(int(defaultOTLPHTTPPort)), + }}, + }, + } { + // do we have the protocol specified at all? + if receiverProtocol, ok := o.config[protocol.name]; ok { + // we have the specified protocol, we definitely need a service port + nameWithProtocol := fmt.Sprintf("%s-%s", o.name, protocol.name) + var protocolPort *corev1.ServicePort + + // do we have a configuration block for the protocol? + settings, ok := receiverProtocol.(map[interface{}]interface{}) + if ok { + protocolPort = singlePortFromConfigEndpoint(o.logger, nameWithProtocol, settings) + } + + // have we parsed a port based on the configuration block? + // if not, we use the default port + if protocolPort == nil { + ports = append(ports, protocol.defaultPorts...) + } else { + ports = append(ports, *protocolPort) + } + } } + + return ports, nil +} + +// ParserName returns the name of this parser +func (o *OTLPReceiverParser) ParserName() string { + return parserNameOTLP } func init() { diff --git a/pkg/collector/parser/receiver_otlp_test.go b/pkg/collector/parser/receiver_otlp_test.go index 5f45a86403..6d2154a8e2 100644 --- a/pkg/collector/parser/receiver_otlp_test.go +++ b/pkg/collector/parser/receiver_otlp_test.go @@ -1,3 +1,73 @@ package parser -// all tests for the OTLP parser are currently part of the test TestDownstreamParsers +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestOTLPSelfRegisters(t *testing.T) { + // verify + assert.True(t, IsRegistered("otlp")) +} + +func TestOTLPIsFoundByName(t *testing.T) { + // test + p := For(logger, "otlp", map[interface{}]interface{}{}) + + // verify + assert.Equal(t, "__otlp", p.ParserName()) +} + +func TestOTLPPortsOverridden(t *testing.T) { + // prepare + builder := NewOTLPReceiverParser(logger, "otlp", map[interface{}]interface{}{ + "protocols": map[interface{}]interface{}{ + "grpc": map[interface{}]interface{}{ + "endpoint": "0.0.0.0:1234", + }, + }, + }) + + // test + ports, err := builder.Ports() + + // verify + assert.NoError(t, err) + assert.Len(t, ports, 1) + assert.EqualValues(t, 1234, ports[0].Port) +} + +func TestOTLPExposeDefaultPorts(t *testing.T) { + // prepare + builder := NewOTLPReceiverParser(logger, "otlp", map[interface{}]interface{}{ + "protocols": map[interface{}]interface{}{ + "grpc": map[interface{}]interface{}{}, + }, + }) + + expectedResults := map[string]struct { + portNumber int32 + seen bool + }{ + "otlp-grpc": {portNumber: 4317}, + "otlp-grpc-legacy": {portNumber: 55680}, + } + + // test + ports, err := builder.Ports() + + // verify + assert.NoError(t, err) + assert.Len(t, ports, 2) + + 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) + } +} diff --git a/versions.txt b/versions.txt index eb4d9a3956..345e870537 100644 --- a/versions.txt +++ b/versions.txt @@ -2,7 +2,7 @@ # by default with the OpenTelemetry Operator. This would usually be the latest # stable OpenTelemetry version. When you update this file, make sure to update the # the docs as well. -opentelemetry-collector=0.15.0 +opentelemetry-collector=0.16.0 # Represents the next release of the OpenTelemetry Operator. -operator=0.15.0 +operator=0.16.0