From 819959c87e868bcc1bb659ca0e5503ebfa82860d Mon Sep 17 00:00:00 2001 From: Vijay Samuel Date: Sun, 18 Feb 2018 15:58:54 -0800 Subject: [PATCH] Refactor prometheus endpoint parsing to look similar to upstream prometheus (#6332) --- CHANGELOG.asciidoc | 1 + metricbeat/helper/prometheus.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index d6e15a372496..403924b4927d 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -224,6 +224,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] - Update prometheus dependencies to latest {pull}6333[6333] *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) } }