Skip to content

Commit

Permalink
fix concurrent map write error caused by reusing a mapstr.M (#40904)
Browse files Browse the repository at this point in the history
Co-authored-by: dparkerelastic <david.parker@elastic.co>
  • Loading branch information
tommyers-elastic and dparkerelastic authored Sep 19, 2024
1 parent 029e056 commit 43d80af
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 29 deletions.
6 changes: 2 additions & 4 deletions x-pack/metricbeat/module/panw/interfaces/ha_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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),
}
}

Expand Down
5 changes: 2 additions & 3 deletions x-pack/metricbeat/module/panw/interfaces/ifnet_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions x-pack/metricbeat/module/panw/interfaces/tunnels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions x-pack/metricbeat/module/panw/routing/bgp_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions x-pack/metricbeat/module/panw/system/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions x-pack/metricbeat/module/panw/system/fans.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions x-pack/metricbeat/module/panw/system/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions x-pack/metricbeat/module/panw/system/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions x-pack/metricbeat/module/panw/system/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/metricbeat/module/panw/system/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions x-pack/metricbeat/module/panw/system/thermal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions x-pack/metricbeat/module/panw/vpn/gp_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions x-pack/metricbeat/module/panw/vpn/gp_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 43d80af

Please sign in to comment.