Skip to content

Commit

Permalink
feat: add metrics for the number of resource & event watcher we have
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jun 5, 2024
1 parent 0c3fe16 commit d45e1a2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions scrapers/kubernetes/events_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func getUnstructuredFromInformedObj(resource v1.KubernetesResourceToWatch, obj a

// WatchResources watches Kubernetes resources
func WatchResources(ctx api.ScrapeContext, config v1.Kubernetes) error {

buffer := make(chan *unstructured.Unstructured, ctx.DutyContext().Properties().Int("kubernetes.watch.resources.bufferSize", WatchResourceBufferSize))
WatchResourceBuffer.Store(config.Hash(), buffer)

Expand Down Expand Up @@ -129,6 +130,7 @@ func WatchResources(ctx api.ScrapeContext, config v1.Kubernetes) error {
go informer.Run(stopper)
}

ctx.Counter("kubernetes_scraper_resource_watcher", lo.FromPtr(ctx.ScrapeConfig().GetPersistedID()).String()).Add(1)
ctx.Logger.V(1).Infof("waiting for informers")
wg.Wait()

Expand Down Expand Up @@ -193,6 +195,7 @@ func WatchEvents(ctx api.ScrapeContext, config v1.Kubernetes) error {
}
defer watcher.Stop()

ctx.Counter("kubernetes_scraper_event_watcher", lo.FromPtr(ctx.ScrapeConfig().GetPersistedID()).String()).Add(1)
for watchEvent := range watcher.ResultChan() {
var event v1.KubernetesEvent
if err := event.FromObj(watchEvent.Object); err != nil {
Expand Down

0 comments on commit d45e1a2

Please sign in to comment.