2013-01-15 16:06:17 +00:00
|
|
|
// Copyright 2013 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package retrieval
|
|
|
|
|
|
|
|
import (
|
2013-06-25 12:02:27 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2013-04-30 18:20:14 +00:00
|
|
|
"code.google.com/p/goprotobuf/proto"
|
2013-06-25 12:02:27 +00:00
|
|
|
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/extraction"
|
|
|
|
|
2013-04-30 18:20:14 +00:00
|
|
|
pb "github.com/prometheus/prometheus/config/generated"
|
2013-06-25 12:02:27 +00:00
|
|
|
|
|
|
|
"github.com/prometheus/prometheus/config"
|
2013-01-15 16:06:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type fakeTarget struct {
|
2014-07-29 18:31:11 +00:00
|
|
|
scrapeCount int
|
|
|
|
lastScrape time.Time
|
|
|
|
interval time.Duration
|
2013-01-15 16:06:17 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 13:31:27 +00:00
|
|
|
func (t fakeTarget) LastError() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-12-17 18:40:59 +00:00
|
|
|
func (t fakeTarget) URL() string {
|
2013-01-15 16:06:17 +00:00
|
|
|
return "fake"
|
|
|
|
}
|
|
|
|
|
2014-12-17 18:40:59 +00:00
|
|
|
func (t fakeTarget) GlobalURL() string {
|
|
|
|
return t.URL()
|
2013-04-10 12:26:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 12:02:27 +00:00
|
|
|
func (t fakeTarget) BaseLabels() clientmodel.LabelSet {
|
|
|
|
return clientmodel.LabelSet{}
|
2013-02-22 20:07:35 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 16:06:17 +00:00
|
|
|
func (t fakeTarget) Interval() time.Duration {
|
|
|
|
return t.interval
|
|
|
|
}
|
|
|
|
|
2014-07-29 18:31:11 +00:00
|
|
|
func (t fakeTarget) LastScrape() time.Time {
|
|
|
|
return t.lastScrape
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t fakeTarget) scrape(i extraction.Ingester) error {
|
2013-01-15 16:06:17 +00:00
|
|
|
t.scrapeCount++
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-07-29 18:31:11 +00:00
|
|
|
func (t fakeTarget) RunScraper(ingester extraction.Ingester, interval time.Duration) {
|
|
|
|
return
|
2013-01-15 16:06:17 +00:00
|
|
|
}
|
|
|
|
|
2014-07-29 18:31:11 +00:00
|
|
|
func (t fakeTarget) StopScraper() {
|
|
|
|
return
|
2014-07-29 16:28:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-29 18:31:11 +00:00
|
|
|
func (t fakeTarget) State() TargetState {
|
2014-12-10 15:16:49 +00:00
|
|
|
return Alive
|
2013-01-15 16:06:17 +00:00
|
|
|
}
|
|
|
|
|
2014-10-10 12:19:02 +00:00
|
|
|
func (t *fakeTarget) SetBaseLabelsFrom(newTarget Target) {}
|
2013-02-22 20:07:35 +00:00
|
|
|
|
2014-05-21 17:27:24 +00:00
|
|
|
func testTargetManager(t testing.TB) {
|
2014-07-29 18:31:11 +00:00
|
|
|
targetManager := NewTargetManager(nopIngester{})
|
2013-04-30 18:20:14 +00:00
|
|
|
testJob1 := config.JobConfig{
|
|
|
|
JobConfig: pb.JobConfig{
|
|
|
|
Name: proto.String("test_job1"),
|
|
|
|
ScrapeInterval: proto.String("1m"),
|
|
|
|
},
|
2013-02-22 20:07:35 +00:00
|
|
|
}
|
2013-04-30 18:20:14 +00:00
|
|
|
testJob2 := config.JobConfig{
|
|
|
|
JobConfig: pb.JobConfig{
|
|
|
|
Name: proto.String("test_job2"),
|
|
|
|
ScrapeInterval: proto.String("1m"),
|
|
|
|
},
|
2013-02-22 20:07:35 +00:00
|
|
|
}
|
2013-01-15 16:06:17 +00:00
|
|
|
|
|
|
|
target1GroupA := &fakeTarget{
|
2014-07-29 18:31:11 +00:00
|
|
|
interval: time.Minute,
|
2013-01-15 16:06:17 +00:00
|
|
|
}
|
|
|
|
target2GroupA := &fakeTarget{
|
2014-07-29 18:31:11 +00:00
|
|
|
interval: time.Minute,
|
2013-01-15 16:06:17 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 15:54:58 +00:00
|
|
|
targetManager.AddTarget(testJob1, target1GroupA)
|
|
|
|
targetManager.AddTarget(testJob1, target2GroupA)
|
2013-01-15 16:06:17 +00:00
|
|
|
|
|
|
|
target1GroupB := &fakeTarget{
|
2014-07-29 18:31:11 +00:00
|
|
|
interval: time.Minute * 2,
|
2013-01-15 16:06:17 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 15:54:58 +00:00
|
|
|
targetManager.AddTarget(testJob2, target1GroupB)
|
2013-01-15 16:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTargetManager(t *testing.T) {
|
|
|
|
testTargetManager(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTargetManager(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
testTargetManager(b)
|
|
|
|
}
|
|
|
|
}
|