2013-01-15 08:06:17 -08: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 05:02:27 -07:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2013-04-30 11:20:14 -07:00
|
|
|
"code.google.com/p/goprotobuf/proto"
|
2013-06-25 05:02:27 -07:00
|
|
|
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/extraction"
|
|
|
|
|
2013-04-30 11:20:14 -07:00
|
|
|
pb "github.com/prometheus/prometheus/config/generated"
|
2013-06-25 05:02:27 -07:00
|
|
|
|
|
|
|
"github.com/prometheus/prometheus/config"
|
2013-01-15 08:06:17 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
type fakeTarget struct {
|
2014-07-29 11:31:11 -07:00
|
|
|
scrapeCount int
|
|
|
|
lastScrape time.Time
|
|
|
|
interval time.Duration
|
2013-01-15 08:06:17 -08:00
|
|
|
}
|
|
|
|
|
2013-05-21 06:31:27 -07:00
|
|
|
func (t fakeTarget) LastError() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-01-15 08:06:17 -08:00
|
|
|
func (t fakeTarget) Address() string {
|
|
|
|
return "fake"
|
|
|
|
}
|
|
|
|
|
2013-04-10 05:26:07 -07:00
|
|
|
func (t fakeTarget) GlobalAddress() string {
|
|
|
|
return t.Address()
|
|
|
|
}
|
|
|
|
|
2013-06-25 05:02:27 -07:00
|
|
|
func (t fakeTarget) BaseLabels() clientmodel.LabelSet {
|
|
|
|
return clientmodel.LabelSet{}
|
2013-02-22 12:07:35 -08:00
|
|
|
}
|
|
|
|
|
2013-01-15 08:06:17 -08:00
|
|
|
func (t fakeTarget) Interval() time.Duration {
|
|
|
|
return t.interval
|
|
|
|
}
|
|
|
|
|
2014-07-29 11:31:11 -07:00
|
|
|
func (t fakeTarget) LastScrape() time.Time {
|
|
|
|
return t.lastScrape
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t fakeTarget) scrape(i extraction.Ingester) error {
|
2013-01-15 08:06:17 -08:00
|
|
|
t.scrapeCount++
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-07-29 11:31:11 -07:00
|
|
|
func (t fakeTarget) RunScraper(ingester extraction.Ingester, interval time.Duration) {
|
|
|
|
return
|
2013-01-15 08:06:17 -08:00
|
|
|
}
|
|
|
|
|
2014-07-29 11:31:11 -07:00
|
|
|
func (t fakeTarget) StopScraper() {
|
|
|
|
return
|
2014-07-29 09:28:48 -07:00
|
|
|
}
|
|
|
|
|
2014-07-29 11:31:11 -07:00
|
|
|
func (t fakeTarget) State() TargetState {
|
2014-12-10 07:16:49 -08:00
|
|
|
return Alive
|
2013-01-15 08:06:17 -08:00
|
|
|
}
|
|
|
|
|
2014-10-10 05:19:02 -07:00
|
|
|
func (t *fakeTarget) SetBaseLabelsFrom(newTarget Target) {}
|
2013-02-22 12:07:35 -08:00
|
|
|
|
2014-05-21 10:27:24 -07:00
|
|
|
func testTargetManager(t testing.TB) {
|
2014-07-29 11:31:11 -07:00
|
|
|
targetManager := NewTargetManager(nopIngester{})
|
2013-04-30 11:20:14 -07:00
|
|
|
testJob1 := config.JobConfig{
|
|
|
|
JobConfig: pb.JobConfig{
|
|
|
|
Name: proto.String("test_job1"),
|
|
|
|
ScrapeInterval: proto.String("1m"),
|
|
|
|
},
|
2013-02-22 12:07:35 -08:00
|
|
|
}
|
2013-04-30 11:20:14 -07:00
|
|
|
testJob2 := config.JobConfig{
|
|
|
|
JobConfig: pb.JobConfig{
|
|
|
|
Name: proto.String("test_job2"),
|
|
|
|
ScrapeInterval: proto.String("1m"),
|
|
|
|
},
|
2013-02-22 12:07:35 -08:00
|
|
|
}
|
2013-01-15 08:06:17 -08:00
|
|
|
|
|
|
|
target1GroupA := &fakeTarget{
|
2014-07-29 11:31:11 -07:00
|
|
|
interval: time.Minute,
|
2013-01-15 08:06:17 -08:00
|
|
|
}
|
|
|
|
target2GroupA := &fakeTarget{
|
2014-07-29 11:31:11 -07:00
|
|
|
interval: time.Minute,
|
2013-01-15 08:06:17 -08:00
|
|
|
}
|
|
|
|
|
2013-06-11 08:54:58 -07:00
|
|
|
targetManager.AddTarget(testJob1, target1GroupA)
|
|
|
|
targetManager.AddTarget(testJob1, target2GroupA)
|
2013-01-15 08:06:17 -08:00
|
|
|
|
|
|
|
target1GroupB := &fakeTarget{
|
2014-07-29 11:31:11 -07:00
|
|
|
interval: time.Minute * 2,
|
2013-01-15 08:06:17 -08:00
|
|
|
}
|
|
|
|
|
2013-06-11 08:54:58 -07:00
|
|
|
targetManager.AddTarget(testJob2, target1GroupB)
|
2013-01-15 08:06:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTargetManager(t *testing.T) {
|
|
|
|
testTargetManager(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTargetManager(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
testTargetManager(b)
|
|
|
|
}
|
|
|
|
}
|