Skip to content

Commit

Permalink
apply viability check
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-deboer committed Jul 6, 2017
1 parent 346ca35 commit f2f192d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
21 changes: 7 additions & 14 deletions pkg/selector/strategy/random/random.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package random

import (
"context"
"fmt"
"math/rand"
"net/url"
Expand All @@ -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() {
Expand Down Expand Up @@ -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++
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/selector/strategy/singlemostdata/singlemostdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f2f192d

Please sign in to comment.