@@ -162,25 +162,28 @@ func (sr *SourceReaper) Run(ctx context.Context) {
162162 }
163163 case IsDirectlyFetchableMetric (sr .md , name ):
164164 err = sr .fetchOSMetric (ctx , name )
165+ sr .lastFetch [name ] = time .Now ()
165166 case name == specialMetricChangeEvents || name == specialMetricInstanceUp :
166167 err = sr .fetchSpecialMetric (ctx , name , metric .StorageName )
168+ sr .lastFetch [name ] = time .Now ()
167169 default :
168170 if cached := sr .reaper .GetMeasurementCache (sr .cacheKey (metric , name )); len (cached ) > 0 {
169171 l .WithField ("metric" , name ).Info ("instance level cache hit" )
170172 sr .sendEnvelope (ctx , name , metric .StorageName , cached )
173+ sr .lastFetch [name ] = time .Now ()
171174 break
172175 }
173176 sql := metric .GetSQL (sr .md .Version )
174177 if sql == "" {
175178 l .WithField ("source" , sr .md .Name ).WithField ("version" , sr .md .Version ).Warning ("no SQL found for metric version" )
179+ sr .lastFetch [name ] = time .Now ()
176180 break
177181 }
178182 batch = append (batch , batchEntry {name : name , metric : metric , sql : sql })
179183 }
180184 if err != nil {
181185 l .WithError (err ).WithField ("metric" , name ).Error ("failed to fetch metric" )
182186 }
183- sr .lastFetch [name ] = now
184187 }
185188
186189 if len (batch ) > 0 {
@@ -194,6 +197,11 @@ func (sr *SourceReaper) Run(ctx context.Context) {
194197 if err != nil {
195198 l .WithError (err ).Error ("failed to fetch metrics" )
196199 }
200+
201+ now := time .Now ()
202+ for _ , e := range batch {
203+ sr .lastFetch [e .name ] = now
204+ }
197205 }
198206 select {
199207 case <- ctx .Done ():
0 commit comments