Skip to content

Commit

Permalink
promplay: append all the decoded metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
thypon committed Oct 30, 2017
1 parent 46ce6ec commit 137fba9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
8 changes: 1 addition & 7 deletions Gopkg.lock

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

17 changes: 11 additions & 6 deletions bin/promplay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}()

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 137fba9

Please sign in to comment.