Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scraping for Prometheus endpoint in Kubernetes #4920

Merged
merged 16 commits into from
Nov 5, 2018
Prev Previous commit
Next Next commit
Move error logging up
  • Loading branch information
glinton committed Nov 5, 2018
commit f6d05ed85775a6946f10bcc9f1437386ecff4720
13 changes: 5 additions & 8 deletions plugins/inputs/prometheus/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,18 @@ func (p *Prometheus) start(ctx context.Context) error {
}

p.wg = sync.WaitGroup{}
in := make(chan payload)

p.wg.Add(1)
go func() {
defer p.wg.Done()
for {
select {
case <-ctx.Done():
break
return
case <-time.After(time.Second):
err := p.watch(ctx, client, in)
if err == nil {
break
err := p.watch(ctx, client)
if err != nil {
log.Printf("E! [inputs.prometheus] unable to watch resources: %v", err)
}
}
}
Expand All @@ -77,11 +76,10 @@ func (p *Prometheus) start(ctx context.Context) error {
return nil
}

func (p *Prometheus) watch(ctx context.Context, client *k8s.Client, in chan payload) error {
func (p *Prometheus) watch(ctx context.Context, client *k8s.Client) error {
pod := &corev1.Pod{}
watcher, err := client.Watch(ctx, "", &corev1.Pod{})
if err != nil {
log.Printf("E! [inputs.prometheus] unable to watch resources: %v", err)
return err
}
defer watcher.Close()
Expand All @@ -95,7 +93,6 @@ func (p *Prometheus) watch(ctx context.Context, client *k8s.Client, in chan payl
// An error here means we need to reconnect the watcher.
eventType, err := watcher.Next(pod)
if err != nil {
log.Printf("D! [inputs.prometheus] unable to watch next: %v", err)
return err
}

Expand Down