From 0b16ffa9bfab8451a04b77ef2e2a8cabeeea9d31 Mon Sep 17 00:00:00 2001 From: Andrew Stucki Date: Wed, 9 Dec 2020 12:06:13 -0500 Subject: [PATCH] [Metricbeat] Use egress/ingress instead of inbound/outbound for system/socket metricset (#22992) * [Metricbeat] Use egress/ingress instead of inbound/outbound for system/socket metricset * Add changelog * Fix stray deletion (cherry picked from commit 65e5908f28dca9ad0ad0c628d4b28980ee368d69) --- CHANGELOG.next.asciidoc | 1 + metricbeat/helper/socket/listeners.go | 30 +++++++++---------- metricbeat/helper/socket/listeners_test.go | 16 +++++----- .../{data_outbound.json => data_egress.json} | 4 +-- .../{data_inbound.json => data_ingress.json} | 4 +-- metricbeat/module/system/socket/socket.go | 8 ++--- .../module/system/socket/socket_test.go | 4 +-- 7 files changed, 34 insertions(+), 33 deletions(-) rename metricbeat/module/system/socket/_meta/{data_outbound.json => data_egress.json} (96%) rename metricbeat/module/system/socket/_meta/{data_inbound.json => data_ingress.json} (96%) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 21b1521e4c6..42d42a1071d 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -76,6 +76,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Change cloud.provider from googlecloud to gcp. {pull}21775[21775] - API address and shard ID are required settings in the Cloud Foundry module. {pull}21759[21759] - Rename googlecloud module to gcp module. {pull}22246[22246] +- Use ingress/egress instead of inbound/outbound for system/socket metricset. {pull}22992[22992] *Packetbeat* diff --git a/metricbeat/helper/socket/listeners.go b/metricbeat/helper/socket/listeners.go index 4a6d7913f0c..2f29e2f67d6 100644 --- a/metricbeat/helper/socket/listeners.go +++ b/metricbeat/helper/socket/listeners.go @@ -27,26 +27,26 @@ type Direction uint8 const ( _ Direction = iota - // Inbound indicates a connection was established from the outside to + // Ingress indicates a connection was established from the outside to // listening socket on this host. - Inbound - // Outbound indicates a connection was established from this socket to an + Ingress + // Egress indicates a connection was established from this socket to an // external listening socket. - Outbound + Egress // Listening indicates a socket that is listening. Listening ) // Names for the direction of a connection const ( - InboundName = "inbound" - OutboundName = "outbound" + IngressName = "ingress" + EgressName = "egress" ListeningName = "listening" ) var directionNames = map[Direction]string{ - Inbound: InboundName, - Outbound: OutboundName, + Ingress: IngressName, + Egress: EgressName, Listening: ListeningName, } @@ -111,7 +111,7 @@ func (t *ListenerTable) Put(proto uint8, ip net.IP, port int) { // Direction returns whether the connection was incoming or outgoing based on // the protocol and local address. It compares the given local address to the -// listeners in the table for the protocol and returns Inbound if there is a +// listeners in the table for the protocol and returns Ingress if there is a // match. If remotePort is 0 then Listening is returned. func (t *ListenerTable) Direction( family uint8, proto uint8, @@ -125,13 +125,13 @@ func (t *ListenerTable) Direction( // Are there any listeners on the given protocol? ports, exists := t.data[proto] if !exists { - return Outbound + return Egress } // Is there any listener on the port? interfaces, exists := ports[localPort] if !exists { - return Outbound + return Egress } // Is there a listener that specific interface? OR @@ -139,13 +139,13 @@ func (t *ListenerTable) Direction( for _, ip := range interfaces.ips { switch { case ip.Equal(localIP): - return Inbound + return Ingress case family == syscall.AF_INET && ip.Equal(net.IPv4zero): - return Inbound + return Ingress case family == syscall.AF_INET6 && ip.Equal(net.IPv6zero): - return Inbound + return Ingress } } - return Outbound + return Egress } diff --git a/metricbeat/helper/socket/listeners_test.go b/metricbeat/helper/socket/listeners_test.go index 8faad666aca..60386b13c80 100644 --- a/metricbeat/helper/socket/listeners_test.go +++ b/metricbeat/helper/socket/listeners_test.go @@ -42,22 +42,22 @@ func TestListenerTable(t *testing.T) { // Listener on 192.0.2.1:80 l.Put(proto, lAddr, httpPort) - assert.Equal(t, Inbound, l.Direction(syscall.AF_INET, proto, lAddr, httpPort, rAddr, ephemeralPort)) - assert.Equal(t, Outbound, l.Direction(syscall.AF_INET, 0, lAddr, httpPort, rAddr, ephemeralPort)) - assert.Equal(t, Outbound, l.Direction(syscall.AF_INET, proto, lAddr, ephemeralPort, rAddr, ephemeralPort)) + assert.Equal(t, Ingress, l.Direction(syscall.AF_INET, proto, lAddr, httpPort, rAddr, ephemeralPort)) + assert.Equal(t, Egress, l.Direction(syscall.AF_INET, 0, lAddr, httpPort, rAddr, ephemeralPort)) + assert.Equal(t, Egress, l.Direction(syscall.AF_INET, proto, lAddr, ephemeralPort, rAddr, ephemeralPort)) // Listener on 0.0.0.0:80 l.Reset() l.Put(proto, net.IPv4zero, httpPort) - assert.Equal(t, Inbound, l.Direction(syscall.AF_INET, proto, lAddr, httpPort, rAddr, ephemeralPort)) - assert.Equal(t, Outbound, l.Direction(syscall.AF_INET6, proto, ipv6Addr, httpPort, rAddr, ephemeralPort)) + assert.Equal(t, Ingress, l.Direction(syscall.AF_INET, proto, lAddr, httpPort, rAddr, ephemeralPort)) + assert.Equal(t, Egress, l.Direction(syscall.AF_INET6, proto, ipv6Addr, httpPort, rAddr, ephemeralPort)) // Listener on :::80 l.Reset() l.Put(proto, net.IPv6zero, httpPort) - assert.Equal(t, Inbound, l.Direction(syscall.AF_INET6, proto, ipv6Addr, httpPort, rAddr, ephemeralPort)) - assert.Equal(t, Inbound, l.Direction(syscall.AF_INET6, proto, ipv4InIpv6, httpPort, rAddr, ephemeralPort)) - assert.Equal(t, Outbound, l.Direction(syscall.AF_INET, proto, lAddr, httpPort, rAddr, ephemeralPort)) + assert.Equal(t, Ingress, l.Direction(syscall.AF_INET6, proto, ipv6Addr, httpPort, rAddr, ephemeralPort)) + assert.Equal(t, Ingress, l.Direction(syscall.AF_INET6, proto, ipv4InIpv6, httpPort, rAddr, ephemeralPort)) + assert.Equal(t, Egress, l.Direction(syscall.AF_INET, proto, lAddr, httpPort, rAddr, ephemeralPort)) } diff --git a/metricbeat/module/system/socket/_meta/data_outbound.json b/metricbeat/module/system/socket/_meta/data_egress.json similarity index 96% rename from metricbeat/module/system/socket/_meta/data_outbound.json rename to metricbeat/module/system/socket/_meta/data_egress.json index 0013574ab44..917c906813d 100644 --- a/metricbeat/module/system/socket/_meta/data_outbound.json +++ b/metricbeat/module/system/socket/_meta/data_egress.json @@ -17,7 +17,7 @@ "name": "socket" }, "network": { - "direction": "outbound", + "direction": "egress", "iana_number": "41", "type": "ipv6" }, @@ -45,4 +45,4 @@ "id": "0", "name": "root" } -} \ No newline at end of file +} diff --git a/metricbeat/module/system/socket/_meta/data_inbound.json b/metricbeat/module/system/socket/_meta/data_ingress.json similarity index 96% rename from metricbeat/module/system/socket/_meta/data_inbound.json rename to metricbeat/module/system/socket/_meta/data_ingress.json index 59ef52bcb22..5ccc8040c01 100644 --- a/metricbeat/module/system/socket/_meta/data_inbound.json +++ b/metricbeat/module/system/socket/_meta/data_ingress.json @@ -17,7 +17,7 @@ "name": "socket" }, "network": { - "direction": "inbound", + "direction": "ingress", "iana_number": "41", "type": "ipv6" }, @@ -45,4 +45,4 @@ "id": "0", "name": "root" } -} \ No newline at end of file +} diff --git a/metricbeat/module/system/socket/socket.go b/metricbeat/module/system/socket/socket.go index bca2b795af1..4d2eb0707f9 100644 --- a/metricbeat/module/system/socket/socket.go +++ b/metricbeat/module/system/socket/socket.go @@ -277,14 +277,14 @@ var ( } localHostInfoGroup = map[string]string{ - sock.InboundName: "destination", - sock.OutboundName: "source", + sock.IngressName: "destination", + sock.EgressName: "source", sock.ListeningName: "server", } remoteHostInfoGroup = map[string]string{ - sock.InboundName: "source", - sock.OutboundName: "destination", + sock.IngressName: "source", + sock.EgressName: "destination", } ) diff --git a/metricbeat/module/system/socket/socket_test.go b/metricbeat/module/system/socket/socket_test.go index ccf23d99d7a..6c92125646d 100644 --- a/metricbeat/module/system/socket/socket_test.go +++ b/metricbeat/module/system/socket/socket_test.go @@ -49,8 +49,8 @@ func TestData(t *testing.T) { path string }{ {sock.ListeningName, "."}, - {sock.InboundName, "./_meta/data_inbound.json"}, - {sock.OutboundName, "./_meta/data_outbound.json"}, + {sock.IngressName, "./_meta/data_ingress.json"}, + {sock.EgressName, "./_meta/data_egress.json"}, } f := mbtest.NewReportingMetricSetV2Error(t, getConfig())