diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 1204f5c3ccb..2c0ff743f0a 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -37,6 +37,10 @@ https://github.com/elastic/beats/compare/v5.6.4...5.6[Check the HEAD diff] *Metricbeat* - Clarify meaning of percentages reported by system core metricset. {pull}5565[5565] +- Change field type of http header from nested to object {pull}5258[5258] +- Fix the fetching of process information when some data is missing under MacOS X. {issue}5337[5337] +- Change `MySQL active connections` visualization title to `MySQL total connections`. {issue}4812[4812] +- Fix map overwrite in docker diskio module. {issue}5582[5582] *Packetbeat* diff --git a/metricbeat/module/docker/diskio/diskio_test.go b/metricbeat/module/docker/diskio/diskio_test.go index 461a1fdfdae..dca777994e1 100644 --- a/metricbeat/module/docker/diskio/diskio_test.go +++ b/metricbeat/module/docker/diskio/diskio_test.go @@ -1,14 +1,129 @@ package diskio import ( + "encoding/json" "testing" "time" + + "github.com/elastic/beats/metricbeat/module/docker" + + dc "github.com/fsouza/go-dockerclient" ) var blkioService BLkioService var oldBlkioRaw = make([]BlkioRaw, 3) var newBlkioRaw = make([]BlkioRaw, 3) +func TestDeltaMultipleContainers(t *testing.T) { + var apiContainer1 docker.Stat + var apiContainer2 docker.Stat + metrics := dc.BlkioStatsEntry{ + Major: 123, + Minor: 123, + Op: "Total", + Value: 123, + } + jsonContainers := `[ + { + "Id": "8dfafdbc3a40", + "Names": ["container"] + },{ + "Id": "8dfafdbc3a41", + "Names": ["container1"] + }]` + var containers []dc.APIContainers + err := json.Unmarshal([]byte(jsonContainers), &containers) + if err != nil { + t.Fatal(err) + } + + apiContainer1.Stats.Read = time.Now() + apiContainer1.Container = containers[0] + apiContainer1.Stats.BlkioStats.IOServicedRecursive = append(apiContainer1.Stats.BlkioStats.IOServicedRecursive, metrics) + apiContainer2.Stats.Read = time.Now() + apiContainer2.Container = containers[1] + apiContainer2.Stats.BlkioStats.IOServicedRecursive = append(apiContainer2.Stats.BlkioStats.IOServicedRecursive, metrics) + dockerStats := []docker.Stat{apiContainer1, apiContainer2} + stats := blkioService.getBlkioStatsList(dockerStats) + totals := make([]float64, 2) + for _, stat := range stats { + totals[0] = stat.totals + } + + dockerStats[0].Stats.BlkioStats.IOServicedRecursive[0].Value = 1000 + dockerStats[0].Stats.Read = dockerStats[0].Stats.Read.Add(time.Second * 10) + dockerStats[1].Stats.BlkioStats.IOServicedRecursive[0].Value = 1000 + dockerStats[1].Stats.Read = dockerStats[0].Stats.Read.Add(time.Second * 10) + stats = blkioService.getBlkioStatsList(dockerStats) + for _, stat := range stats { + totals[1] = stat.totals + if stat.totals < totals[0] { + t.Errorf("getBlkioStatsList(%v) => %v, want value bigger than %v", dockerStats, stat.totals, totals[0]) + } + } + + dockerStats[0].Stats.Read = dockerStats[0].Stats.Read.Add(time.Second * 15) + dockerStats[0].Stats.BlkioStats.IOServicedRecursive[0].Value = 2000 + dockerStats[1].Stats.BlkioStats.IOServicedRecursive[0].Value = 2000 + dockerStats[1].Stats.Read = dockerStats[0].Stats.Read.Add(time.Second * 15) + stats = blkioService.getBlkioStatsList(dockerStats) + for _, stat := range stats { + if stat.totals < totals[1] || stat.totals < totals[0] { + t.Errorf("getBlkioStatsList(%v) => %v, want value bigger than %v", dockerStats, stat.totals, totals[1]) + } + } + +} + +func TestDeltaOneContainer(t *testing.T) { + var apiContainer docker.Stat + metrics := dc.BlkioStatsEntry{ + Major: 123, + Minor: 123, + Op: "Total", + Value: 123, + } + jsonContainers := ` + { + "Id": "8dfafdbc3a40", + "Names": ["container"] + }` + var containers dc.APIContainers + err := json.Unmarshal([]byte(jsonContainers), &containers) + if err != nil { + t.Fatal(err) + } + + apiContainer.Stats.Read = time.Now() + apiContainer.Container = containers + apiContainer.Stats.BlkioStats.IOServicedRecursive = append(apiContainer.Stats.BlkioStats.IOServicedRecursive, metrics) + dockerStats := []docker.Stat{apiContainer} + stats := blkioService.getBlkioStatsList(dockerStats) + totals := make([]float64, 2) + for _, stat := range stats { + totals[0] = stat.totals + } + + dockerStats[0].Stats.BlkioStats.IOServicedRecursive[0].Value = 1000 + dockerStats[0].Stats.Read = dockerStats[0].Stats.Read.Add(time.Second * 10) + stats = blkioService.getBlkioStatsList(dockerStats) + for _, stat := range stats { + if stat.totals < totals[0] { + t.Errorf("getBlkioStatsList(%v) => %v, want value bigger than %v", dockerStats, stat.totals, totals[0]) + } + } + + dockerStats[0].Stats.BlkioStats.IOServicedRecursive[0].Value = 2000 + dockerStats[0].Stats.Read = dockerStats[0].Stats.Read.Add(time.Second * 15) + stats = blkioService.getBlkioStatsList(dockerStats) + for _, stat := range stats { + if stat.totals < totals[1] || stat.totals < totals[0] { + t.Errorf("getBlkioStatsList(%v) => %v, want value bigger than %v", dockerStats, stat.totals, totals[1]) + } + } + +} + func TestWritePs(t *testing.T) { oldWritePs := []uint64{220, 951, 0} newWritePs := []uint64{120, 2951, 0} diff --git a/metricbeat/module/docker/diskio/helper.go b/metricbeat/module/docker/diskio/helper.go index ff1831e2d7c..6f71c6fdb54 100644 --- a/metricbeat/module/docker/diskio/helper.go +++ b/metricbeat/module/docker/diskio/helper.go @@ -35,7 +35,9 @@ type BLkioService struct { func (io *BLkioService) getBlkioStatsList(rawStats []docker.Stat) []BlkioStats { formattedStats := []BlkioStats{} - + if io.BlkioSTatsPerContainer == nil { + io.BlkioSTatsPerContainer = make(map[string]BlkioRaw) + } for _, myRawStats := range rawStats { formattedStats = append(formattedStats, io.getBlkioStats(&myRawStats)) } @@ -55,9 +57,7 @@ func (io *BLkioService) getBlkioStats(myRawStat *docker.Stat) BlkioStats { if exist { myBlkioStats.reads = io.getReadPs(&oldBlkioStats, &newBlkioStats) myBlkioStats.writes = io.getWritePs(&oldBlkioStats, &newBlkioStats) - myBlkioStats.totals = io.getReadPs(&oldBlkioStats, &newBlkioStats) - } else { - io.BlkioSTatsPerContainer = make(map[string]BlkioRaw) + myBlkioStats.totals = io.getTotalPs(&oldBlkioStats, &newBlkioStats) } io.BlkioSTatsPerContainer[myRawStat.Container.ID] = newBlkioStats