From f777f5ba0b63aa91df58d9181491114506e1511a Mon Sep 17 00:00:00 2001 From: Vijay Samuel Date: Thu, 8 Feb 2018 16:46:02 -0800 Subject: [PATCH] Refactor prometheus endpoint parsing to look similar to upstream prometheus --- CHANGELOG.asciidoc | 1 + metricbeat/helper/prometheus.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 1009a7e0e736..d653907e26ff 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -223,6 +223,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di - Docker and Kubernetes modules are now GA, instead of Beta. {pull}6105[6105] - Add pct calculated fields for Pod and container CPU and memory usages. {pull}6158[6158] - Add statefulset support to Kubernetes module. {pull}6236[6236] +- Refactor prometheus endpoint parsing to look similar to upstream prometheus {pull}6332[6332] *Packetbeat* diff --git a/metricbeat/helper/prometheus.go b/metricbeat/helper/prometheus.go index 9843cd2d8a5c..3338cfbeeb04 100644 --- a/metricbeat/helper/prometheus.go +++ b/metricbeat/helper/prometheus.go @@ -2,11 +2,12 @@ package helper import ( "fmt" - - "github.com/elastic/beats/metricbeat/mb" + "io" dto "github.com/prometheus/client_model/go" "github.com/prometheus/common/expfmt" + + "github.com/elastic/beats/metricbeat/mb" ) // Prometheus helper retrieves prometheus formatted metrics @@ -42,10 +43,14 @@ func (p *Prometheus) GetFamilies() ([]*dto.MetricFamily, error) { } families := []*dto.MetricFamily{} - for err == nil { + for { mf := &dto.MetricFamily{} err = decoder.Decode(mf) - if err == nil { + if err != nil { + if err == io.EOF { + break + } + } else { families = append(families, mf) } }