Merge pull request #182 from prometheus/julius-fix-up
Add instance label to health (up) timeseries.
This commit is contained in:
commit
584b93f92c
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue