(runningError error)
| 269 | } |
| 270 | |
| 271 | func (l *BasicLifecycler) stopping(runningError error) error { |
| 272 | if runningError != nil { |
| 273 | return nil |
| 274 | } |
| 275 | |
| 276 | // Let the delegate change the instance state (ie. to LEAVING) and handling any |
| 277 | // state transferring / flushing while we continue to heartbeat. |
| 278 | done := make(chan struct{}) |
| 279 | go func() { |
| 280 | defer close(done) |
| 281 | l.delegate.OnRingInstanceStopping(l) |
| 282 | }() |
| 283 | |
| 284 | // Heartbeat while the stopping delegate function is running. |
| 285 | heartbeatTickerStop, heartbeatTickerChan := newDisableableTicker(l.cfg.HeartbeatPeriod) |
| 286 | defer heartbeatTickerStop() |
| 287 | |
| 288 | heartbeatLoop: |
| 289 | for { |
| 290 | select { |
| 291 | case <-heartbeatTickerChan: |
| 292 | l.heartbeat(context.Background()) |
| 293 | case <-done: |
| 294 | break heartbeatLoop |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | if l.ShouldKeepInstanceInTheRingOnShutdown() { |
| 299 | level.Info(l.logger).Log("msg", "keeping instance the ring", "ring", l.ringName) |
| 300 | } else { |
| 301 | // Remove the instance from the ring. |
| 302 | if err := l.unregisterInstance(context.Background()); err != nil { |
| 303 | return errors.Wrapf(err, "failed to unregister instance from the ring (ring: %s)", l.ringName) |
| 304 | } |
| 305 | level.Info(l.logger).Log("msg", "instance removed from the ring", "ring", l.ringName) |
| 306 | } |
| 307 | |
| 308 | return nil |
| 309 | } |
| 310 | |
| 311 | // registerInstance registers the instance in the ring. The initial state and set of tokens |
| 312 | // depends on the OnRingInstanceRegister() delegate function. |
nothing calls this directly
no test coverage detected