@@ -122,11 +122,11 @@ func getScrapeConfigHealth(obj *unstructured.Unstructured) (*HealthStatus, error
122
122
return nil , fmt .Errorf ("failed to parse lastRun timestamp: %w" , err )
123
123
}
124
124
125
- var schedule time.Duration
125
+ var nextRuntime time.Time
126
126
if scheduleRaw , _ , err := unstructured .NestedString (obj .Object , "spec" , "schedule" ); err != nil {
127
127
return nil , fmt .Errorf ("failed to parse scraper schedule: %w" , err )
128
128
} else if scheduleRaw == "" {
129
- schedule = time .Hour // The default schedule
129
+ nextRuntime = parsedLastRuntime . Add ( time .Hour ) // The default schedule
130
130
} else {
131
131
parsedSchedule , err := cron .ParseStandard (scheduleRaw )
132
132
if err != nil {
@@ -137,18 +137,18 @@ func getScrapeConfigHealth(obj *unstructured.Unstructured) (*HealthStatus, error
137
137
}, nil
138
138
}
139
139
140
- schedule = time . Until ( parsedSchedule .Next (time . Now ()) )
140
+ nextRuntime = parsedSchedule .Next (parsedLastRuntime )
141
141
}
142
142
143
- elapsed := time .Since (parsedLastRuntime )
144
- if elapsed > schedule * 2 {
145
- status .Health = HealthUnhealthy
143
+ // If the ScrapeConfig is few minutes behind the schedule, it's not healthy
144
+ if time .Since (nextRuntime ) > time .Minute * 10 {
146
145
status .Status = "Stale"
147
- status .Message = fmt .Sprintf ("scraper hasn't run for %s" , duration .HumanDuration (elapsed ))
148
- } else if elapsed > schedule && status .Health != HealthUnhealthy {
149
146
status .Health = HealthWarning
150
- status .Status = "Stale"
151
- status .Message = fmt .Sprintf ("scraper hasn't run for %s" , duration .HumanDuration (elapsed ))
147
+ status .Message = fmt .Sprintf ("scraper hasn't run for %s" , duration .HumanDuration (time .Since (parsedLastRuntime )))
148
+
149
+ if time .Since (nextRuntime ) > time .Hour {
150
+ status .Health = HealthUnhealthy
151
+ }
152
152
}
153
153
}
154
154
0 commit comments