Skip to content

Commit

Permalink
[Metricbeat] Further revise check for bad data in docker/memory (#17400)
Browse files Browse the repository at this point in the history
* use OR to check for missing data and report lack of memory data

* add changelog entry

* remove space
  • Loading branch information
fearful-symmetry committed Apr 2, 2020
1 parent 543a5f4 commit b80066c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,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]
- 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]

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/docker/memory/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/module/docker/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package memory

import (
"fmt"

"github.com/docker/docker/client"
"github.com/pkg/errors"

Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions metricbeat/module/docker/memory/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit b80066c

Please sign in to comment.