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