@@ -49,7 +49,7 @@ type data struct {
49
49
}
50
50
51
51
func newPodInfo (pod * corev1.Pod , scrapers map [Scraper ]* ScraperConfig , ds Datastore ) * podInfo {
52
- scraper := & podInfo {
52
+ info := & podInfo {
53
53
scrapers : scrapers ,
54
54
ds : ds ,
55
55
once : sync.Once {},
@@ -60,10 +60,10 @@ func newPodInfo(pod *corev1.Pod, scrapers map[Scraper]*ScraperConfig, ds Datasto
60
60
data .data [scraper .Name ()] = scraper .InitData ()
61
61
}
62
62
63
- scraper .pod .Store (toInternalPod (pod ))
64
- scraper .data .Store (data )
63
+ info .pod .Store (toInternalPod (pod ))
64
+ info .data .Store (data )
65
65
66
- return scraper
66
+ return info
67
67
}
68
68
69
69
type podInfo struct {
@@ -97,6 +97,11 @@ func (pi *podInfo) String() string {
97
97
return fmt .Sprintf ("Pod: %v; Data: %v" , pi .GetPod (), pi .GetData ())
98
98
}
99
99
100
+ func (pi * podInfo ) Stop () {
101
+ pi .logger .V (logutil .DEFAULT ).Info ("Stopping scrape loop" )
102
+ pi .stopFunc ()
103
+ }
104
+
100
105
func (pi * podInfo ) startScrapers (ctx context.Context ) {
101
106
// 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.
102
107
newCtx , cancel := context .WithCancel (ctx )
@@ -131,14 +136,19 @@ func (pi *podInfo) startScrapeLoop(ctx context.Context, scraper Scraper, interva
131
136
}
132
137
// allow processing partial results in case there was an error.
133
138
// 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
+ }
135
144
}
136
145
}
137
146
}
138
147
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 )
142
152
}
143
153
144
154
func toInternalPod (pod * corev1.Pod ) * backend.Pod {
0 commit comments