From 0e88aa03281567bd30f896e3bc621dbd8937f7c0 Mon Sep 17 00:00:00 2001 From: Alex K <8418476+fearful-symmetry@users.noreply.github.com> Date: Thu, 2 Apr 2020 08:14:41 -0700 Subject: [PATCH 1/2] [Metricbeat] Further revise check for bad data in docker/memory (#17400) * use OR to check for missing data and report lack of memory data * add changelog entry * remove space (cherry picked from commit b80066c3fac7628d65f44c9809781e36715d3fdb) --- CHANGELOG.next.asciidoc | 2 ++ metricbeat/module/docker/memory/helper.go | 2 +- metricbeat/module/docker/memory/memory.go | 5 +++++ metricbeat/module/docker/memory/memory_test.go | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index b694965d3d5..3221aef971b 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -178,6 +178,8 @@ 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] +- Fix issue in Jolokia module when mbean contains multiple quoted properties. {issue}17375[17375] {pull}17374[17374] - 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{ From 75bfe75d11e5dc0b9147e8bc5eaddb88b92d7769 Mon Sep 17 00:00:00 2001 From: Alex Kristiansen Date: Thu, 2 Apr 2020 09:16:40 -0700 Subject: [PATCH 2/2] fix changelog --- CHANGELOG.next.asciidoc | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 3221aef971b..8303db9adfd 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -179,7 +179,6 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - 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] -- Fix issue in Jolokia module when mbean contains multiple quoted properties. {issue}17375[17375] {pull}17374[17374] - Combine cloudwatch aggregated metrics into single event. {pull}17345[17345] *Packetbeat*