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

Fleet apache: convert status.total_kbytes to status.total_bytes #23022

Merged
merged 2 commits into from
Dec 10, 2020
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 @@ -863,6 +863,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- `kibana` module: `stats` metricset no-longer collects usage-related data. {pull}22732[22732]
- Adjust the Apache status fields in the fleet mode. {pull}22821[22821]
- Add process.state, process.cpu.pct, process.cpu.start_time and process.memory.pct. {pull}22845[22845]
- Apache: convert status.total_kbytes to status.total_bytes in fleet mode. {pull}23022[23022]

*Packetbeat*

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/apache/status/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func eventMapping(scanner *bufio.Scanner, hostname string) (common.MapStr, error
for scanner.Scan() {
if match := matchNumber.FindStringSubmatch(scanner.Text()); len(match) == 3 {
// Total Accesses: 16147
//Total kBytes: 12988
// Total kBytes: 12988
// Uptime: 3229728
// CPULoad: .000408393
// CPUUser: 0
Expand Down
7 changes: 7 additions & 0 deletions metricbeat/module/apache/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ func adjustFleetEvent(event mb.Event) mb.Event {
var adjusted mb.Event
adjusted.MetricSetFields = event.MetricSetFields.Clone()

// Convert apache.status.total_kbytes to apache.status.total_bytes
totalKBytes, err := adjusted.MetricSetFields.GetValue("total_kbytes")
if err == nil {
adjusted.MetricSetFields.Put("total_bytes", totalKBytes.(int64)*1024)
adjusted.MetricSetFields.Delete("total_kbytes")
}

// Remove apache.hostname
adjusted.MetricSetFields.Delete("hostname")
return adjusted
Expand Down
11 changes: 9 additions & 2 deletions metricbeat/module/apache/status/status_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ func TestFetchFleetMode(t *testing.T) {
t.Fatal("Too few top-level elements in the event")
}

_, err := event.MetricSetFields.GetValue("hostname")
assert.Equal(t, common.ErrKeyNotFound, err, "apache.hostname shouldn't be present in the fleet mode")
_, err := event.MetricSetFields.GetValue("total_kbytes")
assert.Equal(t, common.ErrKeyNotFound, err, "apache.status.total_kbytes shouldn't be present in the fleet mode")

totalBytes, err := event.MetricSetFields.GetValue("total_bytes")
assert.NoError(t, err, "apache.status.total_bytes should be present in the fleet mode")
assert.GreaterOrEqual(t, totalBytes.(int64), int64(0), "apache.status.total_bytes should be non-negative")

_, err = event.MetricSetFields.GetValue("hostname")
assert.Equal(t, common.ErrKeyNotFound, err, "apache.status.hostname shouldn't be present in the fleet mode")
}

func getConfig(host string) map[string]interface{} {
Expand Down