mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add base labels back.
This commit is contained in:
parent
9c98df2b37
commit
ea1e6471de
|
@ -14,6 +14,7 @@
|
|||
package format
|
||||
|
||||
import (
|
||||
"github.com/matttproud/prometheus/model"
|
||||
"io"
|
||||
)
|
||||
|
||||
|
@ -22,5 +23,5 @@ import (
|
|||
// to the results channel.
|
||||
type Processor interface {
|
||||
// Process performs the work on the input and closes the incoming stream.
|
||||
Process(stream io.ReadCloser, results chan Result) (err error)
|
||||
Process(stream io.ReadCloser, baseLabels model.LabelSet, results chan Result) (err error)
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ type entity001 []struct {
|
|||
} `json:"metric"`
|
||||
}
|
||||
|
||||
func (p *processor001) Process(stream io.ReadCloser, results chan Result) (err error) {
|
||||
func (p *processor001) Process(stream io.ReadCloser, baseLabels model.LabelSet, results chan Result) (err error) {
|
||||
// TODO(matt): Replace with plain-jane JSON unmarshalling.
|
||||
defer stream.Close()
|
||||
|
||||
|
@ -79,6 +79,10 @@ func (p *processor001) Process(stream io.ReadCloser, results chan Result) (err e
|
|||
for _, entity := range entities {
|
||||
for _, value := range entity.Metric.Value {
|
||||
metric := model.Metric{}
|
||||
for label, labelValue := range baseLabels {
|
||||
metric[label] = labelValue
|
||||
}
|
||||
|
||||
for label, labelValue := range entity.BaseLabels {
|
||||
metric[model.LabelName(label)] = model.LabelValue(labelValue)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package format
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/matttproud/prometheus/model"
|
||||
"github.com/matttproud/prometheus/utility/test"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
@ -42,7 +43,7 @@ func testProcessor001Process(t test.Tester) {
|
|||
close(c)
|
||||
}(inputChannel)
|
||||
reader := strings.NewReader(scenario.in)
|
||||
err := Processor001.Process(ioutil.NopCloser(reader), inputChannel)
|
||||
err := Processor001.Process(ioutil.NopCloser(reader), model.LabelSet{}, inputChannel)
|
||||
|
||||
if scenario.err != nil && err != nil {
|
||||
if scenario.err.Error() != err.Error() {
|
||||
|
|
|
@ -21,6 +21,10 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
instance = "instance"
|
||||
)
|
||||
|
||||
// The state of the given Target.
|
||||
type TargetState int
|
||||
|
||||
|
@ -142,7 +146,14 @@ func (t *target) Scrape(earliest time.Time, results chan format.Result) (err err
|
|||
return
|
||||
}
|
||||
|
||||
err = processor.Process(resp.Body, results)
|
||||
// XXX: This is a wart; we need to handle this more gracefully down the
|
||||
// road, especially once we have service discovery support.
|
||||
baseLabels := model.LabelSet{instance: model.LabelValue(t.Address())}
|
||||
for baseLabel, baseValue := range t.BaseLabels {
|
||||
baseLabels[baseLabel] = baseValue
|
||||
}
|
||||
|
||||
err = processor.Process(resp.Body, baseLabels, results)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue