mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -08:00
Remove extraction.Result type, simplify code.
This commit is contained in:
parent
9a4ca68a61
commit
d6b9e97655
13
main.go
13
main.go
|
@ -23,7 +23,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/prometheus/client_golang/extraction"
|
|
||||||
|
|
||||||
clientmodel "github.com/prometheus/client_golang/model"
|
clientmodel "github.com/prometheus/client_golang/model"
|
||||||
registry "github.com/prometheus/client_golang/prometheus"
|
registry "github.com/prometheus/client_golang/prometheus"
|
||||||
|
@ -81,7 +80,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type prometheus struct {
|
type prometheus struct {
|
||||||
unwrittenSamples chan *extraction.Result
|
unwrittenSamples chan clientmodel.Samples
|
||||||
|
|
||||||
ruleManager manager.RuleManager
|
ruleManager manager.RuleManager
|
||||||
targetManager retrieval.TargetManager
|
targetManager retrieval.TargetManager
|
||||||
|
@ -102,7 +101,7 @@ func NewPrometheus() *prometheus {
|
||||||
glog.Fatalf("Error loading configuration from %s: %v", *configFile, err)
|
glog.Fatalf("Error loading configuration from %s: %v", *configFile, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
unwrittenSamples := make(chan *extraction.Result, *samplesQueueCapacity)
|
unwrittenSamples := make(chan clientmodel.Samples, *samplesQueueCapacity)
|
||||||
|
|
||||||
ingester := &retrieval.MergeLabelsIngester{
|
ingester := &retrieval.MergeLabelsIngester{
|
||||||
Labels: conf.GlobalLabels(),
|
Labels: conf.GlobalLabels(),
|
||||||
|
@ -214,11 +213,11 @@ func (p *prometheus) Serve() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for block := range p.unwrittenSamples {
|
for samples := range p.unwrittenSamples {
|
||||||
if block.Err == nil && len(block.Samples) > 0 {
|
if len(samples) > 0 {
|
||||||
p.storage.AppendSamples(block.Samples)
|
p.storage.AppendSamples(samples)
|
||||||
if p.remoteTSDBQueue != nil {
|
if p.remoteTSDBQueue != nil {
|
||||||
p.remoteTSDBQueue.Queue(block.Samples)
|
p.remoteTSDBQueue.Queue(samples)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,11 @@
|
||||||
package retrieval
|
package retrieval
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/prometheus/client_golang/extraction"
|
clientmodel "github.com/prometheus/client_golang/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type nopIngester struct{}
|
type nopIngester struct{}
|
||||||
|
|
||||||
func (i nopIngester) Ingest(*extraction.Result) error {
|
func (i nopIngester) Ingest(clientmodel.Samples) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,19 +31,19 @@ type MergeLabelsIngester struct {
|
||||||
|
|
||||||
// Ingest ingests the provided extraction result by merging in i.Labels and then
|
// Ingest ingests the provided extraction result by merging in i.Labels and then
|
||||||
// handing it over to i.Ingester.
|
// handing it over to i.Ingester.
|
||||||
func (i *MergeLabelsIngester) Ingest(r *extraction.Result) error {
|
func (i *MergeLabelsIngester) Ingest(samples clientmodel.Samples) error {
|
||||||
for _, s := range r.Samples {
|
for _, s := range samples {
|
||||||
s.Metric.MergeFromLabelSet(i.Labels, i.CollisionPrefix)
|
s.Metric.MergeFromLabelSet(i.Labels, i.CollisionPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
return i.Ingester.Ingest(r)
|
return i.Ingester.Ingest(samples)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelIngester feeds results into a channel without modifying them.
|
// ChannelIngester feeds results into a channel without modifying them.
|
||||||
type ChannelIngester chan<- *extraction.Result
|
type ChannelIngester chan<- clientmodel.Samples
|
||||||
|
|
||||||
// Ingest ingests the provided extraction result by sending it to i.
|
// Ingest ingests the provided extraction result by sending it to i.
|
||||||
func (i ChannelIngester) Ingest(r *extraction.Result) error {
|
func (i ChannelIngester) Ingest(s clientmodel.Samples) error {
|
||||||
i <- r
|
i <- s
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,10 +205,7 @@ func (t *target) recordScrapeHealth(ingester extraction.Ingester, timestamp clie
|
||||||
Value: clientmodel.SampleValue(float64(scrapeDuration) / float64(time.Second)),
|
Value: clientmodel.SampleValue(float64(scrapeDuration) / float64(time.Second)),
|
||||||
}
|
}
|
||||||
|
|
||||||
ingester.Ingest(&extraction.Result{
|
ingester.Ingest(clientmodel.Samples{healthSample, durationSample})
|
||||||
Err: nil,
|
|
||||||
Samples: clientmodel.Samples{healthSample, durationSample},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunScraper implements Target.
|
// RunScraper implements Target.
|
||||||
|
|
|
@ -22,17 +22,15 @@ import (
|
||||||
|
|
||||||
clientmodel "github.com/prometheus/client_golang/model"
|
clientmodel "github.com/prometheus/client_golang/model"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/extraction"
|
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/utility"
|
"github.com/prometheus/prometheus/utility"
|
||||||
)
|
)
|
||||||
|
|
||||||
type collectResultIngester struct {
|
type collectResultIngester struct {
|
||||||
result *extraction.Result
|
result clientmodel.Samples
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *collectResultIngester) Ingest(r *extraction.Result) error {
|
func (i *collectResultIngester) Ingest(s clientmodel.Samples) error {
|
||||||
i.result = r
|
i.result = s
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,11 +59,11 @@ func TestTargetRecordScrapeHealth(t *testing.T) {
|
||||||
|
|
||||||
result := ingester.result
|
result := ingester.result
|
||||||
|
|
||||||
if len(result.Samples) != 2 {
|
if len(result) != 2 {
|
||||||
t.Fatalf("Expected two samples, got %d", len(result.Samples))
|
t.Fatalf("Expected two samples, got %d", len(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
actual := result.Samples[0]
|
actual := result[0]
|
||||||
expected := &clientmodel.Sample{
|
expected := &clientmodel.Sample{
|
||||||
Metric: clientmodel.Metric{
|
Metric: clientmodel.Metric{
|
||||||
clientmodel.MetricNameLabel: scrapeHealthMetricName,
|
clientmodel.MetricNameLabel: scrapeHealthMetricName,
|
||||||
|
@ -76,15 +74,11 @@ func TestTargetRecordScrapeHealth(t *testing.T) {
|
||||||
Value: 1,
|
Value: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.Err != nil {
|
|
||||||
t.Fatalf("Got unexpected error: %v", result.Err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !actual.Equal(expected) {
|
if !actual.Equal(expected) {
|
||||||
t.Fatalf("Expected and actual samples not equal. Expected: %v, actual: %v", expected, actual)
|
t.Fatalf("Expected and actual samples not equal. Expected: %v, actual: %v", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual = result.Samples[1]
|
actual = result[1]
|
||||||
expected = &clientmodel.Sample{
|
expected = &clientmodel.Sample{
|
||||||
Metric: clientmodel.Metric{
|
Metric: clientmodel.Metric{
|
||||||
clientmodel.MetricNameLabel: scrapeDurationMetricName,
|
clientmodel.MetricNameLabel: scrapeDurationMetricName,
|
||||||
|
@ -95,10 +89,6 @@ func TestTargetRecordScrapeHealth(t *testing.T) {
|
||||||
Value: 2.0,
|
Value: 2.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.Err != nil {
|
|
||||||
t.Fatalf("Got unexpected error: %v", result.Err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !actual.Equal(expected) {
|
if !actual.Equal(expected) {
|
||||||
t.Fatalf("Expected and actual samples not equal. Expected: %v, actual: %v", expected, actual)
|
t.Fatalf("Expected and actual samples not equal. Expected: %v, actual: %v", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/prometheus/client_golang/extraction"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
clientmodel "github.com/prometheus/client_golang/model"
|
clientmodel "github.com/prometheus/client_golang/model"
|
||||||
|
@ -95,7 +94,7 @@ type ruleManager struct {
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
storage local.Storage
|
storage local.Storage
|
||||||
|
|
||||||
results chan<- *extraction.Result
|
results chan<- clientmodel.Samples
|
||||||
notificationHandler *notification.NotificationHandler
|
notificationHandler *notification.NotificationHandler
|
||||||
|
|
||||||
prometheusURL string
|
prometheusURL string
|
||||||
|
@ -107,7 +106,7 @@ type RuleManagerOptions struct {
|
||||||
Storage local.Storage
|
Storage local.Storage
|
||||||
|
|
||||||
NotificationHandler *notification.NotificationHandler
|
NotificationHandler *notification.NotificationHandler
|
||||||
Results chan<- *extraction.Result
|
Results chan<- clientmodel.Samples
|
||||||
|
|
||||||
PrometheusURL string
|
PrometheusURL string
|
||||||
}
|
}
|
||||||
|
@ -210,7 +209,7 @@ func (m *ruleManager) queueAlertNotifications(rule *rules.AlertingRule, timestam
|
||||||
m.notificationHandler.SubmitReqs(notifications)
|
m.notificationHandler.SubmitReqs(notifications)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ruleManager) runIteration(results chan<- *extraction.Result) {
|
func (m *ruleManager) runIteration(results chan<- clientmodel.Samples) {
|
||||||
now := clientmodel.Now()
|
now := clientmodel.Now()
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
|
|
||||||
|
@ -240,11 +239,8 @@ func (m *ruleManager) runIteration(results chan<- *extraction.Result) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
evalFailures.Inc()
|
evalFailures.Inc()
|
||||||
}
|
} else {
|
||||||
|
m.results <- samples
|
||||||
m.results <- &extraction.Result{
|
|
||||||
Samples: samples,
|
|
||||||
Err: err,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch r := rule.(type) {
|
switch r := rule.(type) {
|
||||||
|
|
Loading…
Reference in a new issue