-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Changes from 1 commit
8d1a552
7cdc0e7
3dff47f
d7eb1b1
43eaf99
0a1358e
b1f933c
09bf31a
7c666fd
1bb20b2
c4203e2
79c60a3
372e47d
c5f952f
f6d05ed
cdd47df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ func loadClient(kubeconfigPath string) (*k8s.Client, error) { | |
return k8s.NewClient(&config) | ||
} | ||
|
||
func start(p *Prometheus) error { | ||
func (p *Prometheus) start(ctx context.Context) error { | ||
client, err := k8s.NewInClusterClient() | ||
if err != nil { | ||
u, err := user.Current() | ||
|
@@ -55,7 +55,6 @@ func start(p *Prometheus) error { | |
} | ||
} | ||
|
||
p.ctx, p.cancel = context.WithCancel(context.Background()) | ||
p.wg = sync.WaitGroup{} | ||
in := make(chan payload) | ||
|
||
|
@@ -64,24 +63,23 @@ func start(p *Prometheus) error { | |
defer p.wg.Done() | ||
for { | ||
select { | ||
case <-p.ctx.Done(): | ||
case <-ctx.Done(): | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to use a return or we won't exit the for loop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we remove the err checking logic on the p.watch as well, since it doesn't effectively do anything for us? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would probably move the logging from line 84 up to this function, and just |
||
case <-time.After(time.Second): | ||
err := watch(p, client, in) | ||
err := p.watch(ctx, client, in) | ||
if err == nil { | ||
break | ||
} | ||
} | ||
} | ||
log.Printf("D! [inputs.prometheus] shutting down") | ||
}() | ||
|
||
return nil | ||
} | ||
|
||
func watch(p *Prometheus, client *k8s.Client, in chan payload) error { | ||
func (p *Prometheus) watch(ctx context.Context, client *k8s.Client, in chan payload) error { | ||
pod := &corev1.Pod{} | ||
watcher, err := client.Watch(p.ctx, "", &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 | ||
|
@@ -90,7 +88,7 @@ func watch(p *Prometheus, client *k8s.Client, in chan payload) error { | |
|
||
for { | ||
select { | ||
case <-p.ctx.Done(): | ||
case <-ctx.Done(): | ||
return nil | ||
default: | ||
pod = &corev1.Pod{} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove, unused.