@@ -118,12 +118,12 @@ func (c *Conditioner) Alert(ctx context.Context, req *iotv1proto.AlertRequest) (
118118 }
119119
120120 if active {
121- err = activateRemediation (ctx , rem , c .zonekeeperClient )
121+ err = c . sched . activateRemediation (ctx , rem , c .zonekeeperClient )
122122 if err != nil {
123123 c .logger .Error ("failed to activate condition alert" , "err" , err )
124124 }
125125 } else {
126- err = deactivateRemediation (ctx , rem , c .zonekeeperClient )
126+ err = c . sched . deactivateRemediation (ctx , rem , c .zonekeeperClient )
127127 if err != nil {
128128 c .logger .Error ("failed to deactivate condition alert" , "err" , err )
129129 }
@@ -199,7 +199,7 @@ func (c *Conditioner) Epoch(ctx context.Context, req *iotv1proto.EpochRequest) (
199199 ),
200200 )
201201
202- err = activateRemediation (ctx , rem , c .zonekeeperClient )
202+ err = c . sched . activateRemediation (ctx , rem , c .zonekeeperClient )
203203 if err != nil {
204204 c .logger .Error ("failed to run condition epoch" , "err" , err )
205205 }
@@ -218,7 +218,7 @@ func (c *Conditioner) Epoch(ctx context.Context, req *iotv1proto.EpochRequest) (
218218 // Schedule the zone activation
219219 if activate := activateRequest (ctx , rem ); activate != nil {
220220 err = c .sched .add (ctx , strings .Join ([]string {req .Location , req .Name , cond .Name , rem .Zone , "activate" }, "-" ), start , activate )
221- if err != nil {
221+ if err != nil && ! errors . Is ( err , ErrEmptyRequest ) {
222222 c .logger .Error ("failed to schedule activation" , "err" , err )
223223 errs = append (errs , fmt .Errorf ("condition %q: %w" , cond .Name , err ))
224224 }
@@ -227,14 +227,14 @@ func (c *Conditioner) Epoch(ctx context.Context, req *iotv1proto.EpochRequest) (
227227 // Schedule the zone deactivation
228228 if deactivate := deactivateRequest (ctx , rem ); deactivate == nil {
229229 err = c .sched .add (ctx , strings .Join ([]string {req .Location , req .Name , cond .Name , rem .Zone , "deactivate" }, "-" ), stop , deactivate )
230- if err != nil {
230+ if err != nil && ! errors . Is ( err , ErrEmptyRequest ) {
231231 c .logger .Error ("failed to schedule deactivation" , "err" , err )
232232 errs = append (errs , fmt .Errorf ("condition %q: %w" , cond .Name , err ))
233233 }
234234 }
235235 } else if now .After (stop ) {
236236 // If we are past the stop time, deactivate immediately.
237- err = deactivateRemediation (ctx , rem , c .zonekeeperClient )
237+ err = c . sched . deactivateRemediation (ctx , rem , c .zonekeeperClient )
238238 if err != nil {
239239 c .logger .Error ("failed to run condition epoch" , "err" , err )
240240 }
@@ -258,7 +258,7 @@ func (c *Conditioner) Status() []scheduleStatus {
258258func (c * Conditioner ) setSchedule (ctx context.Context , cond apiv1.Condition ) {
259259 var err error
260260
261- ctx , span := c .tracer .Start (ctx , "Conditioner.setSchedule" ) // trace.WithAttributes(attributes...),
261+ ctx , span := c .tracer .Start (ctx , "Conditioner.setSchedule" , trace .WithAttributes (attribute . String ( "name" , cond . Name )))
262262 defer tracing .ErrHandler (span , err , "set schedule failed" , c .logger )
263263
264264 if ! cond .Spec .Enabled {
@@ -292,7 +292,7 @@ func (c *Conditioner) setSchedule(ctx context.Context, cond apiv1.Condition) {
292292 req = activateRequest (ctx , rem )
293293
294294 err = c .sched .add (ctx , strings .Join ([]string {cond .Name , "schedule" , rem .Zone , "activate" }, "-" ), next , req )
295- if err != nil {
295+ if err != nil && ! errors . Is ( err , ErrEmptyRequest ) {
296296 span .AddEvent ("failed to set schedule" , trace .WithAttributes (attribute .String ("err" , err .Error ())))
297297 c .logger .Error ("failed to set schedule" , "err" , err )
298298 }
@@ -409,7 +409,7 @@ func (c *Conditioner) withinActiveWindow(ctx context.Context, rem apiv1.Remediat
409409 for _ , ti := range rem .TimeIntervals {
410410 tip , err := ti .AsPrometheus ()
411411 if err != nil {
412- c .logger .Error ("invalid time interval configuration" , "err" , err )
412+ c .logger .Error ("invalid time interval configuration" , "err" , err , "interval" , fmt . Sprintf ( "%+v" , ti ) )
413413 continue
414414 }
415415
@@ -457,7 +457,11 @@ func (c *Conditioner) runTimer(ctx context.Context) {
457457 names [cond .Name ] = struct {}{}
458458 }
459459
460- c .sched .removeExtraneous (names )
460+ // FIXME: this used to work because there was a 1:1 relationship between the
461+ // condition in the k8s API and the event. Now that we are scheduling epoch
462+ // events, we don't want to clean those up before they have fired. Do we
463+ // need this removal if they clean themselves up after execution?
464+ // c.sched.removeExtraneous(names)
461465}
462466
463467func (c * Conditioner ) starting (ctx context.Context ) error {
@@ -488,12 +492,12 @@ func (c *Conditioner) stopping(_ error) error {
488492 return nil
489493}
490494
491- func activateRemediation (ctx context.Context , rem apiv1.Remediation , zonekeeperClient iotv1proto.ZoneKeeperServiceClient ) error {
492- return execRequest (ctx , activateRequest (ctx , rem ), zonekeeperClient )
495+ func ( s * schedule ) activateRemediation (ctx context.Context , rem apiv1.Remediation , zonekeeperClient iotv1proto.ZoneKeeperServiceClient ) error {
496+ return s . execRequest (ctx , activateRequest (ctx , rem ), zonekeeperClient )
493497}
494498
495- func deactivateRemediation (ctx context.Context , rem apiv1.Remediation , zonekeeperClient iotv1proto.ZoneKeeperServiceClient ) error {
496- return execRequest (ctx , deactivateRequest (ctx , rem ), zonekeeperClient )
499+ func ( s * schedule ) deactivateRemediation (ctx context.Context , rem apiv1.Remediation , zonekeeperClient iotv1proto.ZoneKeeperServiceClient ) error {
500+ return s . execRequest (ctx , deactivateRequest (ctx , rem ), zonekeeperClient )
497501}
498502
499503func activateRequest (_ context.Context , rem apiv1.Remediation ) * request {
0 commit comments