From ea1e6471dec5ad1dc08bc81b34e0ce0088a1e77a Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Fri, 25 Jan 2013 13:38:20 +0100 Subject: [PATCH] Add base labels back. --- retrieval/format/processor.go | 3 ++- retrieval/format/processor0_0_1.go | 6 +++++- retrieval/format/processor0_0_1_test.go | 3 ++- retrieval/target.go | 13 ++++++++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/retrieval/format/processor.go b/retrieval/format/processor.go index 9912c11071..16719218d2 100644 --- a/retrieval/format/processor.go +++ b/retrieval/format/processor.go @@ -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) } diff --git a/retrieval/format/processor0_0_1.go b/retrieval/format/processor0_0_1.go index 42d243d680..b4727c56dd 100644 --- a/retrieval/format/processor0_0_1.go +++ b/retrieval/format/processor0_0_1.go @@ -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) } diff --git a/retrieval/format/processor0_0_1_test.go b/retrieval/format/processor0_0_1_test.go index 2797ba00be..0349add2e6 100644 --- a/retrieval/format/processor0_0_1_test.go +++ b/retrieval/format/processor0_0_1_test.go @@ -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() { diff --git a/retrieval/target.go b/retrieval/target.go index 435b73854c..660e06506a 100644 --- a/retrieval/target.go +++ b/retrieval/target.go @@ -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 }