Skip to content

Commit

Permalink
componentParser: set correct target port (#3141)
Browse files Browse the repository at this point in the history
* componentParser: set correct target port

Signed-off-by: Benedikt Bongartz <[email protected]>

* componentParser: Only set targetport for parsers with config

Signed-off-by: Benedikt Bongartz <[email protected]>

---------

Signed-off-by: Benedikt Bongartz <[email protected]>
  • Loading branch information
frzifus committed Jul 16, 2024
1 parent d2a9337 commit a515234
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 28 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fix_invalid_port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: set correct target port in services created based on the given otel config.

# One or more tracking issues related to the change
issues: [3139]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
8 changes: 6 additions & 2 deletions internal/components/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,18 @@ type ComponentPortParser interface {
}

func ConstructServicePort(current *corev1.ServicePort, port int32) corev1.ServicePort {
return corev1.ServicePort{
svc := corev1.ServicePort{
Name: current.Name,
Port: port,
TargetPort: current.TargetPort,
NodePort: current.NodePort,
AppProtocol: current.AppProtocol,
Protocol: current.Protocol,
}

if port > 0 && current.TargetPort.IntValue() > 0 {
svc.TargetPort = intstr.FromInt32(port)
}
return svc
}

func GetPortsForConfig(logger logr.Logger, config map[string]interface{}, retriever ParserRetriever) ([]corev1.ServicePort, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/components/multi_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func TestMultiPortReceiver_Ports(t *testing.T) {
{
Name: "receiver3-http",
Port: 80,
TargetPort: intstr.FromInt32(8080),
TargetPort: intstr.FromInt(80),
},
},
wantErr: assert.NoError,
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestMultiPortReceiver_Ports(t *testing.T) {
{
Name: "receiver6-grpc",
Port: 4317,
TargetPort: intstr.FromInt32(4317),
TargetPort: intstr.FromInt(4317),
Protocol: corev1.ProtocolTCP,
AppProtocol: &components.GrpcProtocol,
},
Expand Down
28 changes: 16 additions & 12 deletions internal/components/receivers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,21 @@ var (
)),
components.NewMultiPortReceiver("jaeger",
components.WithPortMapping(components.GrpcProtocol, 14250,
components.WithTargetPort(14250),
components.WithProtocol(corev1.ProtocolTCP),
components.WithAppProtocol(&components.GrpcProtocol),
),
components.WithPortMapping("thrift_http", 14268,
components.WithTargetPort(14268),
components.WithProtocol(corev1.ProtocolTCP),
components.WithAppProtocol(&components.HttpProtocol),
),
components.WithPortMapping("thrift_compact", 6831,
components.WithTargetPort(6831),
components.WithProtocol(corev1.ProtocolUDP),
),
components.WithPortMapping("thrift_binary", 6832,
components.WithTargetPort(6832),
components.WithProtocol(corev1.ProtocolUDP),
),
),
Expand All @@ -92,20 +96,20 @@ var (
components.WithAppProtocol(&components.HttpProtocol),
),
),
components.NewSinglePortParser("awsxray", 2000),
components.NewSinglePortParser("carbon", 2003),
components.NewSinglePortParser("collectd", 8081),
components.NewSinglePortParser("fluentforward", 8006),
components.NewSinglePortParser("influxdb", 8086),
components.NewSinglePortParser("opencensus", 55678, components.WithAppProtocol(nil)),
components.NewSinglePortParser("sapm", 7276),
components.NewSinglePortParser("signalfx", 9943),
components.NewSinglePortParser("splunk_hec", 8088),
components.NewSinglePortParser("statsd", 8125, components.WithProtocol(corev1.ProtocolUDP)),
components.NewSinglePortParser("awsxray", 2000, components.WithTargetPort(2000)),
components.NewSinglePortParser("carbon", 2003, components.WithTargetPort(2003)),
components.NewSinglePortParser("collectd", 8081, components.WithTargetPort(8081)),
components.NewSinglePortParser("fluentforward", 8006, components.WithTargetPort(8006)),
components.NewSinglePortParser("influxdb", 8086, components.WithTargetPort(8086)),
components.NewSinglePortParser("opencensus", 55678, components.WithAppProtocol(nil), components.WithTargetPort(55678)),
components.NewSinglePortParser("sapm", 7276, components.WithTargetPort(7276)),
components.NewSinglePortParser("signalfx", 9943, components.WithTargetPort(9943)),
components.NewSinglePortParser("splunk_hec", 8088, components.WithTargetPort(8088)),
components.NewSinglePortParser("statsd", 8125, components.WithProtocol(corev1.ProtocolUDP), components.WithTargetPort(8125)),
components.NewSinglePortParser("tcplog", components.UnsetPort, components.WithProtocol(corev1.ProtocolTCP)),
components.NewSinglePortParser("udplog", components.UnsetPort, components.WithProtocol(corev1.ProtocolUDP)),
components.NewSinglePortParser("wavefront", 2003),
components.NewSinglePortParser("zipkin", 9411, components.WithAppProtocol(&components.HttpProtocol), components.WithProtocol(corev1.ProtocolTCP)),
components.NewSinglePortParser("wavefront", 2003, components.WithTargetPort(2003)),
components.NewSinglePortParser("zipkin", 9411, components.WithAppProtocol(&components.HttpProtocol), components.WithProtocol(corev1.ProtocolTCP), components.WithTargetPort(3100)),
NewScraperParser("prometheus"),
NewScraperParser("kubeletstats"),
NewScraperParser("sshcheck"),
Expand Down
26 changes: 16 additions & 10 deletions internal/components/receivers/multi_endpoint_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestMultiEndpointReceiverParsers(t *testing.T) {
{
Name: "jaeger-grpc",
Port: 14250,
TargetPort: intstr.FromInt(14250),
Protocol: corev1.ProtocolTCP,
AppProtocol: &grpc,
},
Expand All @@ -77,6 +78,7 @@ func TestMultiEndpointReceiverParsers(t *testing.T) {
{
Name: "jaeger-grpc",
Port: 1234,
TargetPort: intstr.FromInt(1234),
Protocol: corev1.ProtocolTCP,
AppProtocol: &grpc,
},
Expand All @@ -97,24 +99,28 @@ func TestMultiEndpointReceiverParsers(t *testing.T) {
{
Name: "jaeger-grpc",
Port: 14250,
TargetPort: intstr.FromInt(14250),
Protocol: corev1.ProtocolTCP,
AppProtocol: &grpc,
},
{
Name: "port-14268",
Port: 14268,
TargetPort: intstr.FromInt(14268),
Protocol: corev1.ProtocolTCP,
AppProtocol: &http,
},
{
Name: "port-6831",
Port: 6831,
Protocol: corev1.ProtocolUDP,
Name: "port-6831",
Port: 6831,
TargetPort: intstr.FromInt(6831),
Protocol: corev1.ProtocolUDP,
},
{
Name: "port-6832",
Port: 6832,
Protocol: corev1.ProtocolUDP,
Name: "port-6832",
Port: 6832,
TargetPort: intstr.FromInt(6832),
Protocol: corev1.ProtocolUDP,
},
},
},
Expand Down Expand Up @@ -155,7 +161,7 @@ func TestMultiEndpointReceiverParsers(t *testing.T) {
{
Name: "otlp-grpc",
Port: 1234,
TargetPort: intstr.FromInt32(4317),
TargetPort: intstr.FromInt(1234),
AppProtocol: &grpc,
},
},
Expand Down Expand Up @@ -221,7 +227,7 @@ func TestMultiEndpointReceiverParsers(t *testing.T) {
{
Name: "otlp-test-grpc",
Port: 1234,
TargetPort: intstr.FromInt32(4317),
TargetPort: intstr.FromInt32(1234),
AppProtocol: &grpc,
},
},
Expand Down Expand Up @@ -287,7 +293,7 @@ func TestMultiEndpointReceiverParsers(t *testing.T) {
{
Name: "loki-grpc",
Port: 1234,
TargetPort: intstr.FromInt32(9095),
TargetPort: intstr.FromInt(1234),
AppProtocol: &grpc,
},
},
Expand Down Expand Up @@ -353,7 +359,7 @@ func TestMultiEndpointReceiverParsers(t *testing.T) {
{
Name: "skywalking-grpc",
Port: 1234,
TargetPort: intstr.FromInt32(11800),
TargetPort: intstr.FromInt(1234),
AppProtocol: &grpc,
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/components/single_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func TestSingleEndpointParser_Ports(t *testing.T) {
{
Name: "testparser",
Port: 8080,
TargetPort: intstr.FromInt32(4317),
TargetPort: intstr.FromInt32(8080),
Protocol: corev1.ProtocolTCP,
AppProtocol: &components.GrpcProtocol,
},
Expand Down Expand Up @@ -357,7 +357,7 @@ func TestNewSilentSinglePortParser_Ports(t *testing.T) {
{
Name: "testparser",
Port: 8080,
TargetPort: intstr.FromInt32(4317),
TargetPort: intstr.FromInt32(8080),
Protocol: corev1.ProtocolTCP,
AppProtocol: &components.GrpcProtocol,
},
Expand Down
2 changes: 2 additions & 0 deletions internal/manifests/collector/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
"github.com/open-telemetry/opentelemetry-operator/internal/config"
Expand Down Expand Up @@ -331,6 +332,7 @@ func serviceWithInternalTrafficPolicy(name string, ports []v1beta1.PortsSpec, in

svcPorts := []v1.ServicePort{}
for _, p := range ports {
p.ServicePort.TargetPort = intstr.FromInt32(p.Port)
svcPorts = append(svcPorts, p.ServicePort)
}

Expand Down

0 comments on commit a515234

Please sign in to comment.