From 0a4779da7ef3787341d74bcc07fbdaff8dc0bdb9 Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Fri, 14 Dec 2018 09:03:18 +0800 Subject: [PATCH] Don't scale CPU metrics The CPU% metrics should be in the range [0,1], so stop scaling by 100. Fixes https://github.com/elastic/apm-agent-go/issues/392 --- .travis.yml | 7 +++++-- CHANGELOG.md | 6 +++++- builtin_metrics.go | 6 +++--- metrics_test.go | 8 ++++++++ version.go | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 533be26a2..e6b2d7e2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,11 @@ matrix: - go: "1.x" before_install: - - go get -v golang.org/x/tools/cmd/goimports - - if (go run scripts/mingoversion.go 1.10 &>/dev/null); then go get -v golang.org/x/lint/golint; fi + - | + if (go run scripts/mingoversion.go 1.10 &>/dev/null); then + go get -v golang.org/x/lint/golint; + go get -v golang.org/x/tools/cmd/goimports; + fi script: - make install check diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c4873d8a..f119bdf6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog -## [Unreleased](https://github.com/elastic/apm-agent-go/compare/v1.1.0...master) +## [Unreleased](https://github.com/elastic/apm-agent-go/compare/v1.1.1...master) + +## [v1.1.1](https://github.com/elastic/apm-agent-go/releases/tag/v1.1.1) + + - CPU% metrics are now correctly in the range [0,1] ## [v1.1.0](https://github.com/elastic/apm-agent-go/releases/tag/v1.1.0) diff --git a/builtin_metrics.go b/builtin_metrics.go index 272e95623..b34a3f4ac 100644 --- a/builtin_metrics.go +++ b/builtin_metrics.go @@ -97,11 +97,11 @@ func calculateCPUUsage(current, last cpuMetrics) (systemUsage, processUsage floa return 0, 0 } - idlePercent := 100 * float64(idleDelta) / float64(systemTotalDelta) - systemUsage = 100 - idlePercent + idlePercent := float64(idleDelta) / float64(systemTotalDelta) + systemUsage = 1 - idlePercent processTotalDelta := current.process.Total() - last.process.Total() - processUsage = 100 * float64(processTotalDelta) / float64(systemTotalDelta) + processUsage = float64(processTotalDelta) / float64(systemTotalDelta) return systemUsage, processUsage } diff --git a/metrics_test.go b/metrics_test.go index 466e81d04..b37e1cec0 100644 --- a/metrics_test.go +++ b/metrics_test.go @@ -46,6 +46,14 @@ func TestTracerMetricsBuiltin(t *testing.T) { }, "value: %v", gcPct.Value) } + // CPU% should be in the range [0,1], not [0,100]. + cpuTotalNormPct := builtinMetrics.Samples["system.cpu.total.norm.pct"] + if assert.NotNil(t, gcPct.Value) { + assert.Condition(t, func() bool { + return cpuTotalNormPct.Value >= 0 && cpuTotalNormPct.Value <= 1 + }, "value: %v", cpuTotalNormPct.Value) + } + expected := []string{ "golang.goroutines", "golang.heap.allocations.mallocs", diff --git a/version.go b/version.go index 216862005..0328dc9cd 100644 --- a/version.go +++ b/version.go @@ -2,5 +2,5 @@ package apm const ( // AgentVersion is the Elastic APM Go Agent version. - AgentVersion = "1.1.0" + AgentVersion = "1.1.1" )