From 137fba9125989890582e67ee461e417c5197cca3 Mon Sep 17 00:00:00 2001 From: Andrea Brancaleoni Date: Mon, 30 Oct 2017 16:08:23 +0100 Subject: [PATCH] promplay: append all the decoded metrics --- Gopkg.lock | 8 +------- bin/promplay/main.go | 17 +++++++++++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index e5a2361..02eb13b 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -85,12 +85,6 @@ revision = "1edf99ce5dc52e8e680176c22864e5acc67b9243" version = "v1.5.3" -[[projects]] - branch = "master" - name = "github.com/ropes/go-linker-vars-example" - packages = ["src/version"] - revision = "4d2722ea9b879f2bbcb2c7012b1694fb878a068e" - [[projects]] name = "github.com/sirupsen/logrus" packages = ["."] @@ -142,6 +136,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "2f89ccf22d9569212d4d2e566b6e6f05d1d5566589f92308670ae94801caac77" + inputs-digest = "f6ea5c1f6b23c7b511ffeb67f68aaafb3d6a615ba58a778911e601f004db41c5" solver-name = "gps-cdcl" solver-version = 1 diff --git a/bin/promplay/main.go b/bin/promplay/main.go index 8b01c04..9ad710a 100644 --- a/bin/promplay/main.go +++ b/bin/promplay/main.go @@ -102,9 +102,12 @@ func generateFramereader() { func updateURLTimestamp(timestamp int64, name string, url string, body io.Reader) io.Reader { dec := expfmt.NewDecoder(body, expfmt.FmtText) pr, pw := io.Pipe() + enc := expfmt.NewEncoder(pw, expfmt.FmtText) //ts := timestamp * 1000 go func() { + count := 0 + for { var metrics dto.MetricFamily err := dec.Decode(&metrics) @@ -132,10 +135,12 @@ func updateURLTimestamp(timestamp int64, name string, url string, body io.Reader metric.Label = append(metric.Label, &urlp) } - enc := expfmt.NewEncoder(pw, expfmt.FmtText) - enc.Encode(&metrics) + + count += 1 } + + logrus.Printf("%d metrics unmarshalled for %s", count, url) pw.Close() }() @@ -200,13 +205,13 @@ func main() { } decSamples := make(model.Vector, 0, 1) + tempSamples := make(model.Vector, 0, 1) - if err := sdec.Decode(&decSamples); err != nil { - logrus.Errorln("Could not decode metric:", err) - continue + for err := sdec.Decode(&tempSamples); err == nil; err = sdec.Decode(&tempSamples) { + decSamples = append(decSamples, tempSamples...) } - logrus.Debugln("Ingested", len(decSamples), "metrics") + logrus.Infoln("Ingested", len(decSamples), "metrics") for sampleAppender.NeedsThrottling() { logrus.Debugln("Waiting 100ms for appender to be ready for more data")