Skip to content

Commit 56242b0

Browse files
committed
PR feedback
1 parent 2300301 commit 56242b0

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

internal/collector/otel_collector_plugin.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ func (oc *Collector) updateResourceAttributes(
706706
}
707707

708708
func (oc *Collector) findAvailableSyslogServer(ctx context.Context, napSyslogServer string) string {
709-
if oc.previousNAPSysLogServer != "" && oc.previousNAPSysLogServer == napSyslogServer {
710-
return oc.previousNAPSysLogServer
709+
if oc.previousNAPSysLogServer != "" && normaliseAddress(oc.previousNAPSysLogServer) == normaliseAddress(napSyslogServer) {
710+
return napSyslogServer
711711
}
712712

713713
listenConfig := &net.ListenConfig{}
@@ -812,3 +812,16 @@ func setProxyWithBasicAuth(ctx context.Context, proxy *config.Proxy, parsedProxy
812812
proxyURL := parsedProxyURL.String()
813813
setProxyEnvs(ctx, proxyURL, "Setting Proxy with basic auth")
814814
}
815+
816+
func normaliseAddress(address string) string {
817+
host, port, err := net.SplitHostPort(address)
818+
if err != nil {
819+
return address
820+
}
821+
822+
if host == "localhost" {
823+
host = "127.0.0.1"
824+
}
825+
826+
return net.JoinHostPort(host, port)
827+
}

internal/collector/otel_collector_plugin_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -959,16 +959,16 @@ func TestCollector_findAvailableSyslogServers(t *testing.T) {
959959
portInUse: false,
960960
},
961961
{
962-
name: "Test 5: port in use find next server",
962+
name: "Test 6: port hasn't changed",
963963
expectedSyslogServer: "localhost:1122",
964-
previousNAPSysLogServer: "",
964+
previousNAPSysLogServer: "localhost:1122",
965965
syslogServers: "localhost:1122",
966966
portInUse: true,
967967
},
968968
{
969-
name: "Test 6: port hasn't changed",
969+
name: "Test 7: port hasn't changed, but is now localhost",
970970
expectedSyslogServer: "localhost:1122",
971-
previousNAPSysLogServer: "localhost:1122",
971+
previousNAPSysLogServer: "127.0.0.1:1122",
972972
syslogServers: "localhost:1122",
973973
portInUse: true,
974974
},
@@ -983,7 +983,7 @@ func TestCollector_findAvailableSyslogServers(t *testing.T) {
983983

984984
if test.portInUse {
985985
listenConfig := &net.ListenConfig{}
986-
ln, listenError := listenConfig.Listen(ctx, "tcp", "localhost:15632")
986+
ln, listenError := listenConfig.Listen(ctx, "tcp", test.syslogServers)
987987
require.NoError(t, listenError)
988988
defer ln.Close()
989989
}

0 commit comments

Comments
 (0)