Skip to content

Commit 2ff3fa2

Browse files
codesomegouthamve
authored andcommitted
HTTP handler for ingester shutdown (#1746)
* HTTP handler for ingester shutdown Signed-off-by: Ganesh Vernekar <[email protected]> * Add /shutdown endpoint Signed-off-by: Ganesh Vernekar <[email protected]> * Avoid panic on multiple shutdown calls to ingester Signed-off-by: Ganesh Vernekar <[email protected]> * Add entry in CHANGELOG and docs/apis.md Signed-off-by: Ganesh Vernekar <[email protected]> * Fix review comments Signed-off-by: Ganesh Vernekar <[email protected]>
1 parent 97af4bb commit 2ff3fa2

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This release adds support for Redis as an alternative to Memcached, and also inc
3131
* [CHANGE] In table-manager, default DynamoDB capacity was reduced from 3,000 units to 1,000 units. We recommend you do not run with the defaults: find out what figures are needed for your environment and set that via `-dynamodb.periodic-table.write-throughput` and `-dynamodb.chunk-table.write-throughput`.
3232
* [FEATURE] Add Redis support for caching #1612
3333
* [FEATURE] Allow spreading chunk writes across multiple S3 buckets #1625
34+
* [FEATURE] Added `/shutdown` endpoint for ingester to shutdown all operations of the ingester. #1746
3435
* [ENHANCEMENT] Upgraded Prometheus to 2.12.0 and Alertmanager to 0.19.0. #1597
3536
* [ENHANCEMENT] Cortex is now built with Go 1.13 #1675, #1676, #1679
3637
* [ENHANCEMENT] Many optimisations, mostly impacting ingester and querier: #1574, #1624, #1638, #1644, #1649, #1654, #1702
@@ -67,4 +68,4 @@ This release has several exciting features, the most notable of them being setti
6768
* `ha-tracker.cluster` is now `distributor.ha-tracker.cluster`
6869
* [FEATURE] You can specify "heap ballast" to reduce Go GC Churn #1489
6970
* [BUGFIX] HA Tracker no longer always makes a request to Consul/Etcd when a request is not from the active replica #1516
70-
* [BUGFIX] Queries are now correctly cancelled by the query-frontend #1508
71+
* [BUGFIX] Queries are now correctly cancelled by the query-frontend #1508

docs/apis.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,10 @@ Error Response: BadRequest(400)
127127
These API endpoints will disable/enable the current Rule and Alertmanager configuration for a tenant.
128128

129129
Note that setting a new config will effectively "re-enable" the Rules and Alertmanager configuration for a tenant.
130+
131+
#### Ingester Shutdown
132+
133+
`POST /shutdown` - Shutdown all operations of an ingester. Shutdown operations performed are similar to when an ingester is gracefully shutting down, including flushing of chunks if no other ingester is in `PENDING` state. Ingester does not terminate after calling this endpoint.
134+
135+
- Normal Response Codes: NoContent(204)
136+
- Error Response Codes: Unauthorized(401)

pkg/cortex/modules.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ func (t *Cortex) initIngester(cfg *Config) (err error) {
253253
grpc_health_v1.RegisterHealthServer(t.server.GRPC, t.ingester)
254254
t.server.HTTP.Path("/ready").Handler(http.HandlerFunc(t.ingester.ReadinessHandler))
255255
t.server.HTTP.Path("/flush").Handler(http.HandlerFunc(t.ingester.FlushHandler))
256+
t.server.HTTP.Path("/shutdown").Handler(http.HandlerFunc(t.ingester.ShutdownHandler))
256257
return
257258
}
258259

pkg/ingester/ingester.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,26 @@ func (i *Ingester) loop() {
254254

255255
// Shutdown beings the process to stop this ingester.
256256
func (i *Ingester) Shutdown() {
257-
// First wait for our flush loop to stop.
258-
close(i.quit)
259-
i.done.Wait()
257+
select {
258+
case <-i.quit:
259+
// Ingester was already shutdown.
260+
return
261+
default:
262+
// First wait for our flush loop to stop.
263+
close(i.quit)
264+
i.done.Wait()
265+
266+
// Next initiate our graceful exit from the ring.
267+
i.lifecycler.Shutdown()
268+
}
269+
}
260270

261-
// Next initiate our graceful exit from the ring.
262-
i.lifecycler.Shutdown()
271+
// ShutdownHandler triggers the following set of operations in order:
272+
// * Change the state of ring to stop accepting writes.
273+
// * Flush all the chunks.
274+
func (i *Ingester) ShutdownHandler(w http.ResponseWriter, r *http.Request) {
275+
i.Shutdown()
276+
w.WriteHeader(http.StatusNoContent)
263277
}
264278

265279
// StopIncomingRequests is called during the shutdown process.

0 commit comments

Comments
 (0)