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

Store cloudfoundry.container.cpu.pct in decimal form #24219

Merged
merged 2 commits into from
Feb 25, 2021
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 @@ -131,6 +131,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Change types of numeric metrics from Kubelet summary api to double so as to cover big numbers. {pull}23335[23335]
- Add container.image.name and containe.name ECS fields for state_container. {pull}23802[23802]
- Add support for the MemoryPressure, DiskPressure, OutOfDisk and PIDPressure status conditions in state_node. {pull}[23905]
- Store `cloudfoundry.container.cpu.pct` in decimal form and as `scaled_float`. {pull}24219[24219]

*Packetbeat*

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7080,7 +7080,7 @@ type: long
CPU usage percentage.


type: float
type: scaled_float

--

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
description: >
Index of the instance the metric belongs to.
- name: cpu.pct
type: float
type: scaled_float
description: >
CPU usage percentage.
- name: memory.bytes
Expand Down
14 changes: 10 additions & 4 deletions x-pack/metricbeat/module/cloudfoundry/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package container

import (
"fmt"
"math"

"github.com/elastic/beats/v7/x-pack/metricbeat/module/cloudfoundry"

Expand Down Expand Up @@ -53,12 +54,17 @@ type containerReporter struct {

func (r *containerReporter) Event(event mb.Event) bool {
cpuPctKey := "cloudfoundry.container.cpu.pct"
found, err := cloudfoundry.HasNonNumericFloat(event.RootFields, cpuPctKey)
value, err := event.RootFields.GetValue(cpuPctKey)
if err != nil {
r.logger.Debugf("Unexpected failure while checking for non-numeric values: %v", err)
}
if found {
event.RootFields.Delete(cpuPctKey)
} else {
if value, ok := value.(float64); ok {
if math.IsNaN(value) || math.IsInf(value, 0) {
event.RootFields.Delete(cpuPctKey)
} else {
event.RootFields.Put(cpuPctKey, value/100)
}
}
}
return r.PushReporterV2.Event(event)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestMetricSet(t *testing.T) {

expectedFields := common.MapStr{
"cloudfoundry.app.id": "1234",
"cloudfoundry.container.cpu.pct": float64(12.34),
"cloudfoundry.container.cpu.pct": float64(0.1234),
"cloudfoundry.container.disk.bytes": uint64(0),
"cloudfoundry.container.disk.quota.bytes": uint64(0),
"cloudfoundry.container.instance_index": int32(0),
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestMetricValuesAreNumbers(t *testing.T) {
case "1234":
v, err := e.RootFields.GetValue(cpuPctKey)
if assert.NoError(t, err, "checking cpu pct") {
assert.Equal(t, 12.34, v.(float64))
assert.Equal(t, 0.1234, v.(float64))
}
default:
t.Errorf("unexpected app: %s", app)
Expand Down
2 changes: 1 addition & 1 deletion x-pack/metricbeat/module/cloudfoundry/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 0 additions & 27 deletions x-pack/metricbeat/module/cloudfoundry/util.go

This file was deleted.

70 changes: 0 additions & 70 deletions x-pack/metricbeat/module/cloudfoundry/util_test.go

This file was deleted.

5 changes: 3 additions & 2 deletions x-pack/metricbeat/module/cloudfoundry/value/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package value

import (
"fmt"
"math"

"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/metricbeat/mb"
Expand Down Expand Up @@ -51,11 +52,11 @@ type valueReporter struct {
}

func (r *valueReporter) Event(event mb.Event) bool {
found, err := cloudfoundry.HasNonNumericFloat(event.RootFields, "cloudfoundry.value.value")
value, err := event.RootFields.GetValue("cloudfoundry.value.value")
if err != nil {
r.logger.Debugf("Unexpected failure while checking for non-numeric values: %v", err)
}
if found {
if value, ok := value.(float64); ok && (math.IsNaN(value) || math.IsInf(value, 0)) {
r.logger.Debugf("Ignored event with float value that is not a number: %+v", event)
return true
}
Expand Down