MCPcopy
hub / github.com/grafana/tempo / PrepareDownscaleHandler

Method PrepareDownscaleHandler

modules/livestore/downscale.go:143–206  ·  view source on GitHub ↗

PrepareDownscaleHandler prepares the live-store for downscale by removing it from the ring on shutdown. Following methods are supported: - GET Returns set if the live-store is prepared for downscale, unset otherwise. - POST Enables prepare downscale mode (remove the live-store from the ring on sh

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

141// - DELETE
142// Disables prepare downscale mode (do not remove the live-store from the ring on shutdown).
143func (s *LiveStore) PrepareDownscaleHandler(w http.ResponseWriter, r *http.Request) {
144 // Don't allow callers to change the shutdown configuration while we're in the middle
145 // of starting or shutting down.
146 if s.State() != services.Running {
147 w.WriteHeader(http.StatusServiceUnavailable)
148 return
149 }
150 if s.ingestPartitionLifecycler == nil {
151 w.WriteHeader(http.StatusInternalServerError)
152 return
153 }
154
155 shutdownMarkerPath := shutdownmarker.GetPath(s.cfg.ShutdownMarkerDir)
156 switch r.Method {
157 case http.MethodGet:
158 exists, err := shutdownmarker.Exists(shutdownMarkerPath)
159 if err != nil {
160 level.Error(s.logger).Log("msg", "unable to check for prepare-shutdown marker file", "path", shutdownMarkerPath, "err", err)
161 w.WriteHeader(http.StatusInternalServerError)
162 return
163 }
164
165 if exists {
166 util.WriteTextResponse(w, "set\n")
167 } else {
168 util.WriteTextResponse(w, "unset\n")
169 }
170 case http.MethodPost:
171 if err := shutdownmarker.Create(shutdownMarkerPath); err != nil {
172 level.Error(s.logger).Log("msg", "unable to create prepare-shutdown marker file", "path", shutdownMarkerPath, "err", err)
173 w.WriteHeader(http.StatusInternalServerError)
174 return
175 }
176
177 state, _, err := s.ingestPartitionLifecycler.GetPartitionState(r.Context())
178 if err != nil {
179 level.Error(s.logger).Log("msg", "failed to get partition state", "err", err)
180 w.WriteHeader(http.StatusInternalServerError)
181 return
182 }
183 if state != ring.PartitionInactive {
184 level.Info(s.logger).Log("msg", "partition must be in INACTIVE state")
185 w.WriteHeader(http.StatusConflict)
186 return
187 }
188 s.setPrepareShutdown()
189 level.Info(s.logger).Log("msg", "live-store prepared for shutdown")
190
191 case http.MethodDelete:
192 if err := shutdownmarker.Remove(shutdownMarkerPath); err != nil {
193 level.Error(s.logger).Log("msg", "unable to remove prepare-shutdown marker file", "path", shutdownMarkerPath, "err", err)
194 w.WriteHeader(http.StatusInternalServerError)
195 return
196 }
197
198 s.unsetPrepareShutdown()
199 level.Info(s.logger).Log("msg", "live-store shutdown preparation cancelled")
200 default:

Callers

nothing calls this directly

Calls 11

setPrepareShutdownMethod · 0.95
unsetPrepareShutdownMethod · 0.95
GetPathFunction · 0.92
ExistsFunction · 0.92
WriteTextResponseFunction · 0.92
CreateFunction · 0.92
RemoveFunction · 0.92
LogMethod · 0.65
ErrorMethod · 0.65
ContextMethod · 0.65
WriteHeaderMethod · 0.45

Tested by

no test coverage detected