2015-01-21 11:07:45 -08:00
|
|
|
// Copyright 2013 The Prometheus Authors
|
2013-02-24 17:52:52 -08:00
|
|
|
// 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 (
|
2015-03-14 19:36:15 -07:00
|
|
|
"time"
|
|
|
|
|
2015-08-20 08:18:46 -07:00
|
|
|
"github.com/prometheus/common/model"
|
2015-04-20 03:24:25 -07:00
|
|
|
|
|
|
|
"github.com/prometheus/prometheus/config"
|
2013-02-24 17:52:52 -08:00
|
|
|
)
|
|
|
|
|
2015-03-14 19:36:15 -07:00
|
|
|
type nopAppender struct{}
|
|
|
|
|
2015-08-20 08:18:46 -07:00
|
|
|
func (a nopAppender) Append(*model.Sample) {
|
2015-03-14 19:36:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type slowAppender struct{}
|
|
|
|
|
2015-08-20 08:18:46 -07:00
|
|
|
func (a slowAppender) Append(*model.Sample) {
|
2015-03-14 19:36:15 -07:00
|
|
|
time.Sleep(time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
type collectResultAppender struct {
|
2015-08-20 08:18:46 -07:00
|
|
|
result model.Samples
|
2015-03-14 19:36:15 -07:00
|
|
|
}
|
2013-08-13 07:14:18 -07:00
|
|
|
|
2015-08-20 08:18:46 -07:00
|
|
|
func (a *collectResultAppender) Append(s *model.Sample) {
|
2015-06-22 13:35:19 -07:00
|
|
|
for ln, lv := range s.Metric {
|
|
|
|
if len(lv) == 0 {
|
|
|
|
delete(s.Metric, ln)
|
|
|
|
}
|
|
|
|
}
|
2015-03-14 19:36:15 -07:00
|
|
|
a.result = append(a.result, s)
|
2013-08-13 07:14:18 -07:00
|
|
|
}
|
2015-04-20 03:24:25 -07:00
|
|
|
|
|
|
|
// fakeTargetProvider implements a TargetProvider and allows manual injection
|
|
|
|
// of TargetGroups through the update channel.
|
|
|
|
type fakeTargetProvider struct {
|
|
|
|
sources []string
|
|
|
|
update chan *config.TargetGroup
|
|
|
|
}
|
|
|
|
|
2015-08-10 07:44:32 -07:00
|
|
|
func (tp *fakeTargetProvider) Run(ch chan<- *config.TargetGroup, done <-chan struct{}) {
|
2015-04-20 03:24:25 -07:00
|
|
|
defer close(ch)
|
2015-08-10 07:44:32 -07:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case tg := <-tp.update:
|
|
|
|
ch <- tg
|
|
|
|
case <-done:
|
|
|
|
return
|
|
|
|
}
|
2015-04-20 03:24:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tp *fakeTargetProvider) Sources() []string {
|
|
|
|
return tp.sources
|
|
|
|
}
|