@@ -49,7 +49,7 @@ type data struct {
4949}
5050
5151func newPodInfo (pod * corev1.Pod , scrapers map [Scraper ]* ScraperConfig , ds Datastore ) * podInfo {
52- scraper := & podInfo {
52+ info := & podInfo {
5353 scrapers : scrapers ,
5454 ds : ds ,
5555 once : sync.Once {},
@@ -60,10 +60,10 @@ func newPodInfo(pod *corev1.Pod, scrapers map[Scraper]*ScraperConfig, ds Datasto
6060 data .data [scraper .Name ()] = scraper .InitData ()
6161 }
6262
63- scraper .pod .Store (toInternalPod (pod ))
64- scraper .data .Store (data )
63+ info .pod .Store (toInternalPod (pod ))
64+ info .data .Store (data )
6565
66- return scraper
66+ return info
6767}
6868
6969type podInfo struct {
@@ -97,6 +97,11 @@ func (pi *podInfo) String() string {
9797 return fmt .Sprintf ("Pod: %v; Data: %v" , pi .GetPod (), pi .GetData ())
9898}
9999
100+ func (pi * podInfo ) Stop () {
101+ pi .logger .V (logutil .DEFAULT ).Info ("Stopping scrape loop" )
102+ pi .stopFunc ()
103+ }
104+
100105func (pi * podInfo ) startScrapers (ctx context.Context ) {
101106 // The returned context'pi Done channel is closed when the returned cancel function is called or when the parent context'pi Done channel is closed, whichever happens first.
102107 newCtx , cancel := context .WithCancel (ctx )
@@ -131,14 +136,19 @@ func (pi *podInfo) startScrapeLoop(ctx context.Context, scraper Scraper, interva
131136 }
132137 // allow processing partial results in case there was an error.
133138 // the scraper can return nil in case of an error and then do nothing in the ProcessResult function in case no partial update is required
134- scraper .ProcessResult (scrapedData )
139+ scraper .ProcessResult (ctx , scrapedData )
140+ // store updated data if its valid
141+ if scrapedData != nil {
142+ pi .storeScrapedData (scraper .Name (), scrapedData )
143+ }
135144 }
136145 }
137146}
138147
139- func (pi * podInfo ) Stop () {
140- pi .logger .V (logutil .DEFAULT ).Info ("Stopping scrape loop" )
141- pi .stopFunc ()
148+ func (pi * podInfo ) storeScrapedData (key string , data ScrapedData ) {
149+ updated := pi .data .Load ()
150+ updated .data [key ] = data
151+ pi .data .Store (updated )
142152}
143153
144154func toInternalPod (pod * corev1.Pod ) * backend.Pod {
0 commit comments