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

[Metricbeat] Further revise check for bad data in docker/memory #17400

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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