diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index b280be4ec15..afd3f58cc73 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -54,6 +54,8 @@ https://github.com/elastic/beats/compare/v6.7.0...6.x[Check the HEAD diff] *Metricbeat* +- Prevent the docker/memory metricset from processing invalid events before container start {pull}11676[11676] + *Packetbeat* *Winlogbeat* diff --git a/metricbeat/module/docker/memory/helper.go b/metricbeat/module/docker/memory/helper.go index b7c63b91881..69f26c370ac 100644 --- a/metricbeat/module/docker/memory/helper.go +++ b/metricbeat/module/docker/memory/helper.go @@ -22,6 +22,7 @@ import ( "github.com/elastic/beats/metricbeat/module/docker" ) +// MemoryData contains parsed container memory info type MemoryData struct { Time common.Time Container *docker.Container @@ -34,12 +35,19 @@ type MemoryData struct { UsageP float64 } +// MemoryService is placeholder for the the memory stat parsers type MemoryService struct{} -func (s *MemoryService) getMemoryStatsList(rawStats []docker.Stat, dedot bool) []MemoryData { +func (s *MemoryService) getMemoryStatsList(containers []docker.Stat, dedot bool) []MemoryData { formattedStats := []MemoryData{} - for _, myRawStats := range rawStats { - formattedStats = append(formattedStats, s.getMemoryStats(myRawStats, dedot)) + for _, containerStats := range containers { + //There appears to be a race where a container will report with a stat object before it actually starts + //during this time, there doesn't appear to be any meaningful data, + // and Limit will never be 0 unless the container is not running & there's no cgroup data + if containerStats.Stats.MemoryStats.Limit == 0 { + continue + } + formattedStats = append(formattedStats, s.getMemoryStats(containerStats, dedot)) } return formattedStats diff --git a/metricbeat/module/docker/memory/memory.go b/metricbeat/module/docker/memory/memory.go index 466b6ca38d0..a4273dcf42b 100644 --- a/metricbeat/module/docker/memory/memory.go +++ b/metricbeat/module/docker/memory/memory.go @@ -32,6 +32,7 @@ func init() { ) } +// MetricSet type defines all fields of the MetricSet type MetricSet struct { mb.BaseMetricSet memoryService *MemoryService