Rename UNREACHABLE to UNHEALTHY.

The current wording suggests that a target is not reachable at all,
although it might also get set when the target was reachable, but there
was some other error during the scrape (invalid headers or invalid
scrape content). UNHEALTHY is a more general wording that includes all
these cases.

For consistency, ALIVE is also renamed to HEALTHY.
This commit is contained in:
Julius Volz 2015-03-07 21:50:02 +01:00
parent 38ab8cc39b
commit 140eede5e0
4 changed files with 20 additions and 24 deletions

View file

@ -72,26 +72,22 @@ func (t TargetState) String() string {
switch t { switch t {
case Unknown: case Unknown:
return "UNKNOWN" return "UNKNOWN"
case Alive: case Healthy:
return "ALIVE" return "HEALTHY"
case Unreachable: case Unhealthy:
return "UNREACHABLE" return "UNHEALTHY"
} }
panic("unknown state") panic("unknown state")
} }
const ( const (
// Unknown is the state of a Target that has not been seen; we know // Unknown is the state of a Target before it is first scraped.
// nothing about it, except that it is on our docket for examination.
Unknown TargetState = iota Unknown TargetState = iota
// Alive is the state of a Target that has been found and successfully // Healthy is the state of a Target that has been successfully scraped.
// queried. Healthy
Alive // Unhealthy is the state of a Target that was scraped unsuccessfully.
// Unreachable is the state of a Target that was either historically Unhealthy
// found or not found and then determined to be unhealthy by either not
// responding or disappearing.
Unreachable
) )
// A Target represents an endpoint that should be interrogated for metrics. // A Target represents an endpoint that should be interrogated for metrics.
@ -294,9 +290,9 @@ func (t *target) scrape(ingester extraction.Ingester) (err error) {
defer func(start time.Time) { defer func(start time.Time) {
t.Lock() // Writing t.state and t.lastError requires the lock. t.Lock() // Writing t.state and t.lastError requires the lock.
if err == nil { if err == nil {
t.state = Alive t.state = Healthy
} else { } else {
t.state = Unreachable t.state = Unhealthy
} }
t.lastError = err t.lastError = err
t.Unlock() t.Unlock()

View file

@ -61,8 +61,8 @@ func TestTargetScrapeUpdatesState(t *testing.T) {
httpClient: utility.NewDeadlineClient(0), httpClient: utility.NewDeadlineClient(0),
} }
testTarget.scrape(nopIngester{}) testTarget.scrape(nopIngester{})
if testTarget.state != Unreachable { if testTarget.state != Unhealthy {
t.Errorf("Expected target state %v, actual: %v", Unreachable, testTarget.state) t.Errorf("Expected target state %v, actual: %v", Unhealthy, testTarget.state)
} }
} }
@ -84,8 +84,8 @@ func TestTargetScrapeWithFullChannel(t *testing.T) {
).(*target) ).(*target)
testTarget.scrape(ChannelIngester(make(chan clientmodel.Samples))) // Capacity 0. testTarget.scrape(ChannelIngester(make(chan clientmodel.Samples))) // Capacity 0.
if testTarget.state != Unreachable { if testTarget.state != Unhealthy {
t.Errorf("Expected target state %v, actual: %v", Unreachable, testTarget.state) t.Errorf("Expected target state %v, actual: %v", Unhealthy, testTarget.state)
} }
if testTarget.lastError != errIngestChannelFull { if testTarget.lastError != errIngestChannelFull {
t.Errorf("Expected target error %q, actual: %q", errIngestChannelFull, testTarget.lastError) t.Errorf("Expected target error %q, actual: %q", errIngestChannelFull, testTarget.lastError)

View file

@ -77,7 +77,7 @@ func (t fakeTarget) StopScraper() {
} }
func (t fakeTarget) State() TargetState { func (t fakeTarget) State() TargetState {
return Alive return Healthy
} }
func (t *fakeTarget) SetBaseLabelsFrom(newTarget Target) {} func (t *fakeTarget) SetBaseLabelsFrom(newTarget Target) {}

View file

@ -115,7 +115,7 @@ func TestTargetPoolReplaceTargets(t *testing.T) {
pool := NewTargetPool(nil, nil, nopIngester{}, time.Duration(1)) pool := NewTargetPool(nil, nil, nopIngester{}, time.Duration(1))
oldTarget1 := &target{ oldTarget1 := &target{
url: "example1", url: "example1",
state: Unreachable, state: Unhealthy,
scraperStopping: make(chan struct{}), scraperStopping: make(chan struct{}),
scraperStopped: make(chan struct{}), scraperStopped: make(chan struct{}),
newBaseLabels: make(chan clientmodel.LabelSet, 1), newBaseLabels: make(chan clientmodel.LabelSet, 1),
@ -123,7 +123,7 @@ func TestTargetPoolReplaceTargets(t *testing.T) {
} }
oldTarget2 := &target{ oldTarget2 := &target{
url: "example2", url: "example2",
state: Unreachable, state: Unhealthy,
scraperStopping: make(chan struct{}), scraperStopping: make(chan struct{}),
scraperStopped: make(chan struct{}), scraperStopped: make(chan struct{}),
newBaseLabels: make(chan clientmodel.LabelSet, 1), newBaseLabels: make(chan clientmodel.LabelSet, 1),
@ -131,7 +131,7 @@ func TestTargetPoolReplaceTargets(t *testing.T) {
} }
newTarget1 := &target{ newTarget1 := &target{
url: "example1", url: "example1",
state: Alive, state: Healthy,
scraperStopping: make(chan struct{}), scraperStopping: make(chan struct{}),
scraperStopped: make(chan struct{}), scraperStopped: make(chan struct{}),
newBaseLabels: make(chan clientmodel.LabelSet, 1), newBaseLabels: make(chan clientmodel.LabelSet, 1),
@ -139,7 +139,7 @@ func TestTargetPoolReplaceTargets(t *testing.T) {
} }
newTarget2 := &target{ newTarget2 := &target{
url: "example3", url: "example3",
state: Alive, state: Healthy,
scraperStopping: make(chan struct{}), scraperStopping: make(chan struct{}),
scraperStopped: make(chan struct{}), scraperStopped: make(chan struct{}),
newBaseLabels: make(chan clientmodel.LabelSet, 1), newBaseLabels: make(chan clientmodel.LabelSet, 1),