Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't collect empty ip addresses in docker container metricset #11247

Merged
merged 3 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Improve detection of file deletion on Windows. {pull}10747[10747]
- Fix errors in filebeat Zeek dashboard and README files. Add notice.log support. {pull}10916[10916]
- Fix a bug when converting NetFlow fields to snake_case. {pull}10950[10950]
- Add on_failure handler for Zeek ingest pipelines. Fix one field name error for notice and add an additional test
case. {issue}11004[11004] {pull}11105[11105]
- Add on_failure handler for Zeek ingest pipelines. Fix one field name error for notice and add an additional test case. {issue}11004[11004] {pull}11105[11105]
- Fix issue preventing docker container events to be stored if the container has a network interface without ip address {issue}11225[11225] {pull}[]

*Heartbeat*

Expand Down
4 changes: 3 additions & 1 deletion metricbeat/module/docker/container/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func eventMapping(r mb.ReporterV2, cont *types.Container, dedot bool) {
func extractIPAddresses(networks *types.SummaryNetworkSettings) []string {
ipAddresses := make([]string, 0, len(networks.Networks))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change ipAddresses is now not anymore len(networks.Networks). Is it mainly in testing that it might be empty or a common case? Thinking which use case we should optimise for.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though about this and I think that in most of the cases ipAddresses is still going to be len(networks.Networks).
The most common case where this is not going to be true is when the container is using the host network, in that case we would be creating an array of capacity one that we are not going to use.

for _, network := range networks.Networks {
ipAddresses = append(ipAddresses, network.IPAddress)
if len(network.IPAddress) > 0 {
ipAddresses = append(ipAddresses, network.IPAddress)
}
}
return ipAddresses
}