diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index b694965d3d5..8303db9adfd 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -178,6 +178,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Use max in k8s overview dashboard aggregations. {pull}17015[17015] - Fix Disk Used and Disk Usage visualizations in the Metricbeat System dashboards. {issue}12435[12435] {pull}17272[17272] - Fix missing Accept header for Prometheus and OpenMetrics module. {issue}16870[16870] {pull}17291[17291] +- Further revise check for bad data in docker/memory. {pull}17400[17400] - Combine cloudwatch aggregated metrics into single event. {pull}17345[17345] *Packetbeat* diff --git a/metricbeat/module/docker/memory/helper.go b/metricbeat/module/docker/memory/helper.go index 459c26ccceb..03c93fafed9 100644 --- a/metricbeat/module/docker/memory/helper.go +++ b/metricbeat/module/docker/memory/helper.go @@ -51,7 +51,7 @@ func (s *MemoryService) getMemoryStatsList(containers []docker.Stat, dedot bool) //during this time, there doesn't appear to be any meaningful data, // and Limit will never be 0 unless the container is not running //and there's no cgroup data, and CPU usage should be greater than 0 for any running container. - if containerStats.Stats.MemoryStats.Limit == 0 && containerStats.Stats.PreCPUStats.CPUUsage.TotalUsage == 0 { + if containerStats.Stats.MemoryStats.Limit == 0 || containerStats.Stats.PreCPUStats.CPUUsage.TotalUsage == 0 { continue } formattedStats = append(formattedStats, s.getMemoryStats(containerStats, dedot)) diff --git a/metricbeat/module/docker/memory/memory.go b/metricbeat/module/docker/memory/memory.go index 3a56adba57a..697dc143eb9 100644 --- a/metricbeat/module/docker/memory/memory.go +++ b/metricbeat/module/docker/memory/memory.go @@ -20,6 +20,8 @@ package memory import ( + "fmt" + "github.com/docker/docker/client" "github.com/pkg/errors" @@ -70,6 +72,9 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { } memoryStats := m.memoryService.getMemoryStatsList(stats, m.dedot) + if len(memoryStats) == 0 { + return fmt.Errorf("No memory stats data available") + } eventsMapping(r, memoryStats) return nil diff --git a/metricbeat/module/docker/memory/memory_test.go b/metricbeat/module/docker/memory/memory_test.go index 695e6770de1..0fd15dc3483 100644 --- a/metricbeat/module/docker/memory/memory_test.go +++ b/metricbeat/module/docker/memory/memory_test.go @@ -109,6 +109,22 @@ func TestMemoryService_GetMemoryStats(t *testing.T) { assert.Equal(t, expectedFields, event.MetricSetFields) } +func TestMemoryServiceBadData(t *testing.T) { + + badMemStats := types.StatsJSON{ + Stats: types.Stats{ + Read: time.Now(), + MemoryStats: types.MemoryStats{}, //Test for cases where this is empty + }, + } + + memoryService := &MemoryService{} + memoryRawStats := []docker.Stat{docker.Stat{Stats: badMemStats}} + rawStats := memoryService.getMemoryStatsList(memoryRawStats, false) + assert.Len(t, rawStats, 0) + +} + func getMemoryStats(read time.Time, number uint64) types.StatsJSON { myMemoryStats := types.StatsJSON{