From f2f192d342976d13f0defe88c496c60458f18139 Mon Sep 17 00:00:00 2001 From: Matt DeBoer Date: Thu, 6 Jul 2017 08:29:44 -0700 Subject: [PATCH] apply viability check --- pkg/selector/strategy/random/random.go | 21 +++++++------------ .../strategy/singlemostdata/singlemostdata.go | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/pkg/selector/strategy/random/random.go b/pkg/selector/strategy/random/random.go index 4937140..6d690a0 100644 --- a/pkg/selector/strategy/random/random.go +++ b/pkg/selector/strategy/random/random.go @@ -1,7 +1,6 @@ package random import ( - "context" "fmt" "math/rand" "net/url" @@ -10,7 +9,6 @@ import ( log "github.com/Sirupsen/logrus" "github.com/matt-deboer/mpp/pkg/locator" "github.com/matt-deboer/mpp/pkg/selector" - "github.com/prometheus/common/model" ) func init() { @@ -61,22 +59,17 @@ func (s *Selector) Select(endpoints []*locator.PrometheusEndpoint) (err error) { for _, endpoint := range endpoints { endpoint.Selected = false if endpoint.QueryAPI != nil { - value, err := endpoint.QueryAPI.Query(context.TODO(), "prometheus_build_info", time.Now()) + scraped, err := locator.ScrapeMetric(endpoint.Address, "prometheus_build_info") if err != nil { log.Errorf("Endpoint %v returned error: %v", endpoint, err) - } else { + endpoint.Error = err + } else if endpoint.Viable() { if log.GetLevel() >= log.DebugLevel { - log.Debugf("Endpoint %v returned value: %v", endpoint, value) - } - if value.Type() == model.ValVector { - if len(value.String()) > 0 { - endpoint.ComparisonMetricValue = value.String() - endpoint.Selected = true - selected++ - } - } else { - log.Errorf("Endpoint %v returned unexpected type: %v", endpoint, value.Type()) + log.Debugf("Endpoint %v returned value: %v", endpoint, scraped) } + endpoint.ComparisonMetricValue = scraped.String() + endpoint.Selected = true + selected++ } } } diff --git a/pkg/selector/strategy/singlemostdata/singlemostdata.go b/pkg/selector/strategy/singlemostdata/singlemostdata.go index 6df4dc2..f6f0860 100644 --- a/pkg/selector/strategy/singlemostdata/singlemostdata.go +++ b/pkg/selector/strategy/singlemostdata/singlemostdata.go @@ -67,7 +67,7 @@ func (s *Selector) Select(endpoints []*locator.PrometheusEndpoint) (err error) { } sampleValue := int64(scraped.Value) endpoint.ComparisonMetricValue = sampleValue - if sampleValue > mostData { + if sampleValue > mostData && endpoint.Viable() { mostData = sampleValue mostDataIndex = i }