Merge pull request #182 from prometheus/julius-fix-up

Add instance label to health (up) timeseries.
This commit is contained in:
juliusv 2013-04-26 03:50:36 -07:00
commit 584b93f92c
3 changed files with 48 additions and 0 deletions

View File

@ -23,6 +23,20 @@ type Sample struct {
Timestamp time.Time Timestamp time.Time
} }
func (s Sample) Equal(sample Sample) bool {
if !NewFingerprintFromMetric(s.Metric).Equal(NewFingerprintFromMetric(sample.Metric)) {
return false
}
if !s.Timestamp.Equal(sample.Timestamp) {
return false
}
if !s.Value.Equal(sample.Value) {
return false
}
return true
}
type Samples []Sample type Samples []Sample
func (s Samples) Len() int { func (s Samples) Len() int {

View File

@ -142,6 +142,7 @@ func (t *target) recordScrapeHealth(results chan format.Result, timestamp time.T
metric[label] = value metric[label] = value
} }
metric[model.MetricNameLabel] = model.ScrapeHealthMetricName metric[model.MetricNameLabel] = model.ScrapeHealthMetricName
metric[model.InstanceLabel] = model.LabelValue(t.Address())
healthValue := model.SampleValue(0) healthValue := model.SampleValue(0)
if healthy { if healthy {

View File

@ -14,6 +14,7 @@
package retrieval package retrieval
import ( import (
"github.com/prometheus/prometheus/model"
"github.com/prometheus/prometheus/retrieval/format" "github.com/prometheus/prometheus/retrieval/format"
"testing" "testing"
"time" "time"
@ -30,3 +31,35 @@ func TestTargetScrapeUpdatesState(t *testing.T) {
t.Errorf("Expected target state %v, actual: %v", UNREACHABLE, testTarget.state) t.Errorf("Expected target state %v, actual: %v", UNREACHABLE, testTarget.state)
} }
} }
func TestTargetRecordScrapeHealth(t *testing.T) {
testTarget := target{
scheduler: literalScheduler{},
address: "http://example.url",
baseLabels: model.LabelSet{model.JobLabel: "testjob"},
}
now := time.Now()
results := make(chan format.Result)
go testTarget.recordScrapeHealth(results, now, true)
result := <-results
actual := result.Sample
expected := model.Sample{
Metric: model.Metric{
model.MetricNameLabel: model.ScrapeHealthMetricName,
model.InstanceLabel: "http://example.url",
model.JobLabel: "testjob",
},
Timestamp: now,
Value: 1,
}
if result.Err != nil {
t.Fatalf("Got unexpected error: %v", result.Err)
}
if !actual.Equal(expected) {
t.Fatalf("Expected and actual samples not equal. Expected: %v, actual: %v", expected, actual)
}
}