Skip to content

Commit 8ee7685

Browse files
authored
Fix TCP & UDP input metricsets for ports > 32767 (#46486)
When parsing the port to collect metrics, the TCP & UDP inputs were parsing the port as a int16, which limited the maximum port to 32767. This commit fixes it by parsing the port as uint16.
1 parent 46ae121 commit 8ee7685

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ otherwise no tag is added. {issue}42208[42208] {pull}42403[42403]
280280
- The Unix input now fails on errors listening to the socket and its status is set to failed when running under Elastic Agent. {pull}46302[46302]
281281
- Fix race condition that could cause Filebeat to hang during shutdown after failing to startup {issue}45034[45034] {pull}46331[46331]
282282
- Fixed hints autodiscover for Docker when the configuration is only `hints.enabled: true`. {issue}45156[45156] {pull}45864[45864]
283+
- Fix metrics from TCP & UDP inputs when the port number is > 32767 {pull}46486[46486]
283284

284285
*Heartbeat*
285286

filebeat/input/netmetrics/netmetrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func addrs(addr string, log *logp.Logger) (addr4, addr6 []string, err error) {
4848
if err != nil {
4949
return nil, nil, fmt.Errorf("failed to get address for %s: %w", addr, err)
5050
}
51-
pn, err := strconv.ParseInt(port, 10, 16)
51+
pn, err := strconv.ParseUint(port, 10, 16)
5252
if err != nil {
5353
return nil, nil, fmt.Errorf("failed to get port for %s: %w", addr, err)
5454
}

filebeat/input/netmetrics/netmetrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
func TestAddrs(t *testing.T) {
3232
t.Run("ipv4", func(t *testing.T) {
33-
addr4, addr6, err := addrs("0.0.0.0:9001", logptest.NewTestingLogger(t, ""))
33+
addr4, addr6, err := addrs("0.0.0.0:65535", logptest.NewTestingLogger(t, ""))
3434
if err != nil {
3535
t.Errorf("unexpected error: %v", err)
3636
}

0 commit comments

Comments
 (0)