From 43d80af2aea60b0c45711475d114e118d90c4581 Mon Sep 17 00:00:00 2001 From: Tom Myers <106530686+tommyers-elastic@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:59:41 +0100 Subject: [PATCH] fix concurrent map write error caused by reusing a mapstr.M (#40904) Co-authored-by: dparkerelastic --- x-pack/metricbeat/module/panw/interfaces/ha_interfaces.go | 6 ++---- .../metricbeat/module/panw/interfaces/ifnet_interfaces.go | 5 ++--- x-pack/metricbeat/module/panw/interfaces/tunnels.go | 3 +-- x-pack/metricbeat/module/panw/routing/bgp_peers.go | 3 +-- x-pack/metricbeat/module/panw/system/certificates.go | 3 +-- x-pack/metricbeat/module/panw/system/fans.go | 3 +-- x-pack/metricbeat/module/panw/system/filesystem.go | 3 +-- x-pack/metricbeat/module/panw/system/license.go | 3 +-- x-pack/metricbeat/module/panw/system/power.go | 3 +-- x-pack/metricbeat/module/panw/system/resources.go | 4 ++-- x-pack/metricbeat/module/panw/system/thermal.go | 3 +-- x-pack/metricbeat/module/panw/vpn/gp_sessions.go | 3 +-- x-pack/metricbeat/module/panw/vpn/gp_stats.go | 3 +-- 13 files changed, 16 insertions(+), 29 deletions(-) diff --git a/x-pack/metricbeat/module/panw/interfaces/ha_interfaces.go b/x-pack/metricbeat/module/panw/interfaces/ha_interfaces.go index 7228eca2955..657110e4f73 100644 --- a/x-pack/metricbeat/module/panw/interfaces/ha_interfaces.go +++ b/x-pack/metricbeat/module/panw/interfaces/ha_interfaces.go @@ -57,7 +57,6 @@ func makeGroupEvent(m *MetricSet, input HAResult) *mb.Event { group := input.Group timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) linkMonitoringEnabled, err := panw.StringToBool(group.LinkMonitoring.Enabled) if err != nil { @@ -130,7 +129,7 @@ func makeGroupEvent(m *MetricSet, input HAResult) *mb.Event { "ha.peer_info.conn_ha1_backup.description": group.PeerInfo.ConnHA1Backup.Desc, "ha.link_monitoring.enabled": linkMonitoringEnabled, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } return &event @@ -143,7 +142,6 @@ func makeLinkMonitoringEvents(m *MetricSet, links HALinkMonitoring) []mb.Event { events := make([]mb.Event, 0, len(links.Groups)) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) var event mb.Event for _, group := range links.Groups { @@ -172,7 +170,7 @@ func makeLinkMonitoringEvents(m *MetricSet, links HALinkMonitoring) []mb.Event { "ha.link_monitoring.group.interface.name": interface_entry.Name, "ha.link_monitoring.group.interface.status": interface_entry.Status, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } } diff --git a/x-pack/metricbeat/module/panw/interfaces/ifnet_interfaces.go b/x-pack/metricbeat/module/panw/interfaces/ifnet_interfaces.go index a94d1522b31..b14857f5905 100644 --- a/x-pack/metricbeat/module/panw/interfaces/ifnet_interfaces.go +++ b/x-pack/metricbeat/module/panw/interfaces/ifnet_interfaces.go @@ -51,7 +51,6 @@ func getIFNetInterfaceEvents(m *MetricSet) ([]mb.Event, error) { func formatIFInterfaceEvents(m *MetricSet, input InterfaceResult) []mb.Event { events := make([]mb.Event, 0, len(input.HW.Entries)+len(input.Ifnet.Entries)) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) // First process the phyiscal interfaces for _, entry := range input.HW.Entries { @@ -82,7 +81,7 @@ func formatIFInterfaceEvents(m *MetricSet, input InterfaceResult) []mb.Event { "physical.full_state": entry.ST, "physical.ae_member": members, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) @@ -104,7 +103,7 @@ func formatIFInterfaceEvents(m *MetricSet, input InterfaceResult) []mb.Event { "logical.dyn_addr": entry.DynAddr, "logical.addr6": entry.Addr6, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) diff --git a/x-pack/metricbeat/module/panw/interfaces/tunnels.go b/x-pack/metricbeat/module/panw/interfaces/tunnels.go index df01bec93dd..df4b371305f 100644 --- a/x-pack/metricbeat/module/panw/interfaces/tunnels.go +++ b/x-pack/metricbeat/module/panw/interfaces/tunnels.go @@ -45,7 +45,6 @@ func formatIPSecTunnelEvents(m *MetricSet, entries []TunnelsEntry) []mb.Event { events := make([]mb.Event, 0, len(entries)) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) for _, entry := range entries { event := mb.Event{ @@ -70,7 +69,7 @@ func formatIPSecTunnelEvents(m *MetricSet, entries []TunnelsEntry) []mb.Event { "ipsec_tunnel.life.sec": entry.Life, "ipsec_tunnel.kb": entry.KB, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) diff --git a/x-pack/metricbeat/module/panw/routing/bgp_peers.go b/x-pack/metricbeat/module/panw/routing/bgp_peers.go index a99ec08c6d7..92fb5a0ec52 100644 --- a/x-pack/metricbeat/module/panw/routing/bgp_peers.go +++ b/x-pack/metricbeat/module/panw/routing/bgp_peers.go @@ -73,7 +73,6 @@ func convertEntryBooleanFields(entry BGPEntry) map[string]bool { func formatBGPEvents(m *MetricSet, entries []BGPEntry) []mb.Event { events := make([]mb.Event, 0, len(entries)) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) for _, entry := range entries { booleanFields := convertEntryBooleanFields(entry) @@ -130,7 +129,7 @@ func formatBGPEvents(m *MetricSet, entries []BGPEntry) []mb.Event { "bgp.nexthop_thirdparty": booleanFields["bgp.nexthop_thirdparty"], "bgp.nexthop_peer": booleanFields["bgp.nexthop_peer"], }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) diff --git a/x-pack/metricbeat/module/panw/system/certificates.go b/x-pack/metricbeat/module/panw/system/certificates.go index 302225847b6..1909219d5dc 100644 --- a/x-pack/metricbeat/module/panw/system/certificates.go +++ b/x-pack/metricbeat/module/panw/system/certificates.go @@ -47,7 +47,6 @@ func getCertificateEvents(m *MetricSet) ([]mb.Event, error) { func formatCertificateEvents(m *MetricSet, input string) ([]mb.Event, error) { timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) certificates, err := parseCertificates(input) if err != nil { @@ -72,7 +71,7 @@ func formatCertificateEvents(m *MetricSet, input string) ([]mb.Event, error) { "certificate.db_name": certificate.DBName, "certificate.db_status": certificate.DBStatus, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) diff --git a/x-pack/metricbeat/module/panw/system/fans.go b/x-pack/metricbeat/module/panw/system/fans.go index e2c305c4524..7045d0a3f8e 100644 --- a/x-pack/metricbeat/module/panw/system/fans.go +++ b/x-pack/metricbeat/module/panw/system/fans.go @@ -40,7 +40,6 @@ func formatFanEvents(m *MetricSet, response *FanResponse) []mb.Event { events := make([]mb.Event, 0) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) for _, slot := range response.Result.Fan.Slots { for _, entry := range slot.Entries { @@ -58,7 +57,7 @@ func formatFanEvents(m *MetricSet, response *FanResponse) []mb.Event { "fan.rpm": entry.RPMs, "fan.min_rpm": entry.Min, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) } diff --git a/x-pack/metricbeat/module/panw/system/filesystem.go b/x-pack/metricbeat/module/panw/system/filesystem.go index 205fed3f6c0..64ae8881207 100644 --- a/x-pack/metricbeat/module/panw/system/filesystem.go +++ b/x-pack/metricbeat/module/panw/system/filesystem.go @@ -128,7 +128,6 @@ func formatFilesystemEvents(m *MetricSet, filesystems []Filesystem) []mb.Event { events := make([]mb.Event, 0, len(filesystems)) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) for _, filesystem := range filesystems { used, err := strconv.ParseInt(filesystem.UsePerc[:len(filesystem.UsePerc)-1], 10, 64) @@ -146,7 +145,7 @@ func formatFilesystemEvents(m *MetricSet, filesystems []Filesystem) []mb.Event { "filesystem.use_percent": used, "filesystem.mounted": filesystem.Mounted, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) diff --git a/x-pack/metricbeat/module/panw/system/license.go b/x-pack/metricbeat/module/panw/system/license.go index ee2df32c30d..752f3a8afa1 100644 --- a/x-pack/metricbeat/module/panw/system/license.go +++ b/x-pack/metricbeat/module/panw/system/license.go @@ -49,7 +49,6 @@ func getLicenseEvents(m *MetricSet) ([]mb.Event, error) { func formatLicenseEvents(m *MetricSet, licenses []License) []mb.Event { events := make([]mb.Event, 0, len(licenses)) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) for _, license := range licenses { expired, err := panw.StringToBool(license.Expired) @@ -87,7 +86,7 @@ func formatLicenseEvents(m *MetricSet, licenses []License) []mb.Event { "license.expired": expired, "license.auth_code": license.AuthCode, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } // only set the expires field if the license expires if !neverExpires { diff --git a/x-pack/metricbeat/module/panw/system/power.go b/x-pack/metricbeat/module/panw/system/power.go index 50b89cf6ff0..01006d949eb 100644 --- a/x-pack/metricbeat/module/panw/system/power.go +++ b/x-pack/metricbeat/module/panw/system/power.go @@ -44,7 +44,6 @@ func getPowerEvents(m *MetricSet) ([]mb.Event, error) { func formatPowerEvents(m *MetricSet, response *PowerResponse) []mb.Event { events := make([]mb.Event, 0) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) for _, slot := range response.Result.Power.Slots { for _, entry := range slot.Entries { @@ -59,7 +58,7 @@ func formatPowerEvents(m *MetricSet, response *PowerResponse) []mb.Event { "power.minimum_volts": entry.MinimumVolts, "power.maximum_volts": entry.MaximumVolts, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) } diff --git a/x-pack/metricbeat/module/panw/system/resources.go b/x-pack/metricbeat/module/panw/system/resources.go index 51c595b1fe0..54353fe2db6 100644 --- a/x-pack/metricbeat/module/panw/system/resources.go +++ b/x-pack/metricbeat/module/panw/system/resources.go @@ -69,7 +69,7 @@ MiB Swap: 5961.0 total, 4403.5 free, 1557.6 used. 1530.0 avail Mem */ func formatResourceEvents(m *MetricSet, input string) []mb.Event { timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) + events := make([]mb.Event, 0) // We only need the top 5 lines @@ -126,7 +126,7 @@ func formatResourceEvents(m *MetricSet, input string) []mb.Event { "available": swapInfo.Available, }, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) diff --git a/x-pack/metricbeat/module/panw/system/thermal.go b/x-pack/metricbeat/module/panw/system/thermal.go index 7f74372eb25..91f8454901d 100644 --- a/x-pack/metricbeat/module/panw/system/thermal.go +++ b/x-pack/metricbeat/module/panw/system/thermal.go @@ -43,7 +43,6 @@ func formatThermalEvents(m *MetricSet, response *ThermalResponse) []mb.Event { events := make([]mb.Event, 0, len(response.Result.Thermal.Slots)) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) var event mb.Event @@ -64,7 +63,7 @@ func formatThermalEvents(m *MetricSet, response *ThermalResponse) []mb.Event { "thermal.minimum_temp": entry.MinimumTemp, "thermal.maximum_temp": entry.MaximumTemp, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) diff --git a/x-pack/metricbeat/module/panw/vpn/gp_sessions.go b/x-pack/metricbeat/module/panw/vpn/gp_sessions.go index a82924f8a9c..ea8e3510e13 100644 --- a/x-pack/metricbeat/module/panw/vpn/gp_sessions.go +++ b/x-pack/metricbeat/module/panw/vpn/gp_sessions.go @@ -44,7 +44,6 @@ func formatGPSessionEvents(m *MetricSet, sessions []GPSession) []mb.Event { events := make([]mb.Event, 0, len(sessions)) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) for _, session := range sessions { isLocal, err := panw.StringToBool(session.IsLocal) @@ -79,7 +78,7 @@ func formatGPSessionEvents(m *MetricSet, sessions []GPSession) []mb.Event { "globalprotect.session.request_get_config": session.RequestGetConfig, "globalprotect.session.request_sslvpn_connect": session.RequestSSLVPNConnect, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event) diff --git a/x-pack/metricbeat/module/panw/vpn/gp_stats.go b/x-pack/metricbeat/module/panw/vpn/gp_stats.go index 10b6a0cd729..708b2be5b5c 100644 --- a/x-pack/metricbeat/module/panw/vpn/gp_stats.go +++ b/x-pack/metricbeat/module/panw/vpn/gp_stats.go @@ -46,7 +46,6 @@ func formatGPStatsEvents(m *MetricSet, response GPStatsResponse) []mb.Event { events := make([]mb.Event, 0, len(response.Result.Gateways)) timestamp := time.Now().UTC() - rootFields := panw.MakeRootFields(m.config.HostIp) totalCurrent := response.Result.TotalCurrentUsers totalPrevious := response.Result.TotalPreviousUsers @@ -61,7 +60,7 @@ func formatGPStatsEvents(m *MetricSet, response GPStatsResponse) []mb.Event { "globalprotect.total_current_users": totalCurrent, "globalprotect.total_previous_users": totalPrevious, }, - RootFields: rootFields, + RootFields: panw.MakeRootFields(m.config.HostIp), } events = append(events, event)