Add instance label to health (up) timeseries.

This commit is contained in:
Julius Volz 2013-04-24 21:50:49 +02:00
parent 3ff916d209
commit d4ff85db5a
3 changed files with 48 additions and 0 deletions

View File

@ -23,6 +23,20 @@ type Sample struct {
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
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[model.MetricNameLabel] = model.ScrapeHealthMetricName
metric[model.InstanceLabel] = model.LabelValue(t.Address())
healthValue := model.SampleValue(0)
if healthy {

View File

@ -14,6 +14,7 @@
package retrieval
import (
"github.com/prometheus/prometheus/model"
"github.com/prometheus/prometheus/retrieval/format"
"testing"
"time"
@ -30,3 +31,35 @@ func TestTargetScrapeUpdatesState(t *testing.T) {
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)
}
}