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
|
package format
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/matttproud/prometheus/model"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,5 +23,5 @@ import (
|
||||||
// to the results channel.
|
// to the results channel.
|
||||||
type Processor interface {
|
type Processor interface {
|
||||||
// Process performs the work on the input and closes the incoming stream.
|
// 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"`
|
} `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.
|
// TODO(matt): Replace with plain-jane JSON unmarshalling.
|
||||||
defer stream.Close()
|
defer stream.Close()
|
||||||
|
|
||||||
|
@ -79,6 +79,10 @@ func (p *processor001) Process(stream io.ReadCloser, results chan Result) (err e
|
||||||
for _, entity := range entities {
|
for _, entity := range entities {
|
||||||
for _, value := range entity.Metric.Value {
|
for _, value := range entity.Metric.Value {
|
||||||
metric := model.Metric{}
|
metric := model.Metric{}
|
||||||
|
for label, labelValue := range baseLabels {
|
||||||
|
metric[label] = labelValue
|
||||||
|
}
|
||||||
|
|
||||||
for label, labelValue := range entity.BaseLabels {
|
for label, labelValue := range entity.BaseLabels {
|
||||||
metric[model.LabelName(label)] = model.LabelValue(labelValue)
|
metric[model.LabelName(label)] = model.LabelValue(labelValue)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ package format
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/matttproud/prometheus/model"
|
||||||
"github.com/matttproud/prometheus/utility/test"
|
"github.com/matttproud/prometheus/utility/test"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -42,7 +43,7 @@ func testProcessor001Process(t test.Tester) {
|
||||||
close(c)
|
close(c)
|
||||||
}(inputChannel)
|
}(inputChannel)
|
||||||
reader := strings.NewReader(scenario.in)
|
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 != nil && err != nil {
|
||||||
if scenario.err.Error() != err.Error() {
|
if scenario.err.Error() != err.Error() {
|
||||||
|
|
|
@ -21,6 +21,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
instance = "instance"
|
||||||
|
)
|
||||||
|
|
||||||
// The state of the given Target.
|
// The state of the given Target.
|
||||||
type TargetState int
|
type TargetState int
|
||||||
|
|
||||||
|
@ -142,7 +146,14 @@ func (t *target) Scrape(earliest time.Time, results chan format.Result) (err err
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue