From 06b4a406617fe8399babb55959e7f5e534772ceb Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Sun, 14 Jul 2013 18:48:03 +0200 Subject: [PATCH 1/2] Represent targets in a tabular interface. This commit represents a target group's endpoints in a tabular fashion for better differentiation of their state in a concise manner. --- retrieval/scheduler.go | 2 +- retrieval/target.go | 22 +++++++-------- retrieval/targetmanager_test.go | 2 +- retrieval/targetpool.go | 2 +- web/templates/status.html | 49 ++++++++++++++++++++++++--------- 5 files changed, 50 insertions(+), 27 deletions(-) diff --git a/retrieval/scheduler.go b/retrieval/scheduler.go index 062baf259d..7b9a17c013 100644 --- a/retrieval/scheduler.go +++ b/retrieval/scheduler.go @@ -25,7 +25,7 @@ const ( // The base units for the exponential backoff. DEFAULT_BACKOFF_VALUE_UNIT = time.Second // The maximum allowed backoff time. - MAXIMUM_BACKOFF_VALUE = 30 * time.Minute + MAXIMUM_BACKOFF_VALUE = 2 * time.Minute ) // scheduler is an interface that various scheduling strategies must fulfill diff --git a/retrieval/target.go b/retrieval/target.go index c3354b2a6a..abd767136c 100644 --- a/retrieval/target.go +++ b/retrieval/target.go @@ -97,7 +97,7 @@ type Target interface { // time, but it should occur no sooner than it. // // Right now, this is used as the sorting key in TargetPool. - scheduledFor() time.Time + ScheduledFor() time.Time // Return the last encountered scrape error, if any. LastError() error // The address to which the Target corresponds. Out of all of the available @@ -176,11 +176,11 @@ func (t *target) recordScrapeHealth(results chan<- *extraction.Result, timestamp } } -func (t *target) Scrape(earliest time.Time, results chan<- *extraction.Result) (err error) { +func (t *target) Scrape(earliest time.Time, results chan<- *extraction.Result) error { now := time.Now() futureState := t.state - - if err = t.scrape(now, results); err != nil { + err := t.scrape(now, results) + if err != nil { t.recordScrapeHealth(results, now, false) futureState = UNREACHABLE } else { @@ -249,23 +249,23 @@ func (t *target) scrape(timestamp time.Time, results chan<- *extraction.Result) return processor.ProcessSingle(buf, results, processOptions) } -func (t target) State() TargetState { +func (t *target) State() TargetState { return t.state } -func (t target) scheduledFor() time.Time { +func (t *target) ScheduledFor() time.Time { return t.scheduler.ScheduledFor() } -func (t target) LastError() error { +func (t *target) LastError() error { return t.lastError } -func (t target) Address() string { +func (t *target) Address() string { return t.address } -func (t target) GlobalAddress() string { +func (t *target) GlobalAddress() string { address := t.address hostname, err := os.Hostname() if err != nil { @@ -278,7 +278,7 @@ func (t target) GlobalAddress() string { return address } -func (t target) BaseLabels() clientmodel.LabelSet { +func (t *target) BaseLabels() clientmodel.LabelSet { return t.baseLabels } @@ -299,7 +299,7 @@ func (t targets) Len() int { } func (t targets) Less(i, j int) bool { - return t[i].scheduledFor().Before(t[j].scheduledFor()) + return t[i].ScheduledFor().Before(t[j].ScheduledFor()) } func (t targets) Swap(i, j int) { diff --git a/retrieval/targetmanager_test.go b/retrieval/targetmanager_test.go index e02a121403..cee692eee6 100644 --- a/retrieval/targetmanager_test.go +++ b/retrieval/targetmanager_test.go @@ -66,7 +66,7 @@ func (t fakeTarget) State() TargetState { return ALIVE } -func (t *fakeTarget) scheduledFor() (time time.Time) { +func (t *fakeTarget) ScheduledFor() (time time.Time) { time = t.schedules[t.scheduleIndex] t.scheduleIndex++ diff --git a/retrieval/targetpool.go b/retrieval/targetpool.go index 0dfbc00e80..abe376a61c 100644 --- a/retrieval/targetpool.go +++ b/retrieval/targetpool.go @@ -146,7 +146,7 @@ func (p *TargetPool) runIteration(results chan<- *extraction.Result, interval ti for _, target := range p.targets { now := time.Now() - if target.scheduledFor().After(now) { + if target.ScheduledFor().After(now) { // None of the remaining targets are ready to be scheduled. Signal that // we're done processing them in this scrape iteration. continue diff --git a/web/templates/status.html b/web/templates/status.html index 9ec4eaee59..7a408db0df 100644 --- a/web/templates/status.html +++ b/web/templates/status.html @@ -42,19 +42,42 @@
From f7704af4f828c4fea83255bf212939f17ec2b5d7 Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Mon, 15 Jul 2013 15:11:41 +0200 Subject: [PATCH 2/2] Code Review: Formatting comments. --- retrieval/target.go | 7 +++ storage/metric/operation_test.go | 18 ++++---- web/templates/status.html | 77 +++++++++++++++----------------- 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/retrieval/target.go b/retrieval/target.go index abd767136c..b2875f4e02 100644 --- a/retrieval/target.go +++ b/retrieval/target.go @@ -98,6 +98,9 @@ type Target interface { // // Right now, this is used as the sorting key in TargetPool. ScheduledFor() time.Time + // EstimatedTimeToExecute emits the amount of time until the next prospective + // scheduling opportunity for this target. + EstimatedTimeToExecute() time.Duration // Return the last encountered scrape error, if any. LastError() error // The address to which the Target corresponds. Out of all of the available @@ -257,6 +260,10 @@ func (t *target) ScheduledFor() time.Time { return t.scheduler.ScheduledFor() } +func (t *target) EstimatedTimeToExecute() time.Duration { + return t.scheduler.ScheduledFor().Sub(time.Now()) +} + func (t *target) LastError() error { return t.lastError } diff --git a/storage/metric/operation_test.go b/storage/metric/operation_test.go index e39cbdeb09..6a44fd4eeb 100644 --- a/storage/metric/operation_test.go +++ b/storage/metric/operation_test.go @@ -1838,13 +1838,13 @@ func TestGetValueRangeAtIntervalOp(t *testing.T) { var scenarios = []struct { op getValueRangeAtIntervalOp - in model.Values - out model.Values + in Values + out Values }{ // All values before the first range. { op: testOp, - in: model.Values{ + in: Values{ { Timestamp: testInstant.Add(-4 * time.Minute), Value: 1, @@ -1854,12 +1854,12 @@ func TestGetValueRangeAtIntervalOp(t *testing.T) { Value: 2, }, }, - out: model.Values{}, + out: Values{}, }, // Values starting before first range, ending after last. { op: testOp, - in: model.Values{ + in: Values{ { Timestamp: testInstant.Add(-4 * time.Minute), Value: 1, @@ -1917,7 +1917,7 @@ func TestGetValueRangeAtIntervalOp(t *testing.T) { Value: 14, }, }, - out: model.Values{ + out: Values{ { Timestamp: testInstant.Add(-2 * time.Minute), Value: 3, @@ -1959,17 +1959,17 @@ func TestGetValueRangeAtIntervalOp(t *testing.T) { // Values starting after last range. { op: testOp, - in: model.Values{ + in: Values{ { Timestamp: testInstant.Add(21 * time.Minute), Value: 14, }, }, - out: model.Values{}, + out: Values{}, }, } for i, scenario := range scenarios { - actual := model.Values{} + actual := Values{} for !scenario.op.Consumed() { actual = append(actual, scenario.op.ExtractSamples(scenario.in)...) } diff --git a/web/templates/status.html b/web/templates/status.html index 7a408db0df..25656923f3 100644 --- a/web/templates/status.html +++ b/web/templates/status.html @@ -40,46 +40,43 @@

Targets

-
    - {{range $job, $pool := .TargetPools}} -
  • {{$job}} - - - - - - - - - - - - {{range $pool.Targets}} - - - - - - - - {{end}} - -
    EndpointStateBase LabelsEarliest RetrievalError
    - {{.Address}} - - {{.State}} - - {{.BaseLabels}} - - {{.ScheduledFor}} - - {{if .LastError}} - {{.LastError}} - {{end}} -
    -
  • - {{end}} -
+ {{range $job, $pool := .TargetPools}} +

{{$job}}

+ + + + + + + + + + + + {{range $pool.Targets}} + + + + + + + + {{end}} + +
EndpointStateBase LabelsNext RetrievalError
+ {{.Address}} + + {{.State}} + + {{.BaseLabels}} + + {{.EstimatedTimeToExecute}} + + {{if .LastError}} + {{.LastError}} + {{end}} +
+ {{end}}

Curation