diff --git a/CHANGELOG.md b/CHANGELOG.md index 61f7773ae3f..bb367bd267f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## main / unreleased +* [ENHANCEMENT] Extend `/flush` to support flushing a single tenant [#2260](https://github.com/grafana/tempo/pull/2260) (@kvrhdn) + ## v2.1.0-rc.0 / 2023-04-12 * [CHANGE] Capture and update search metrics for TraceQL [#2087](https://github.com/grafana/tempo/pull/2087) (@electron0zero) diff --git a/docs/sources/tempo/api_docs/_index.md b/docs/sources/tempo/api_docs/_index.md index c72322bebda..a1db767c074 100644 --- a/docs/sources/tempo/api_docs/_index.md +++ b/docs/sources/tempo/api_docs/_index.md @@ -374,6 +374,12 @@ GET,POST /flush Triggers a flush of all in-memory traces to the WAL. Useful at the time of rollout restarts and unexpected crashes. +Specify the `tenant` parameter to flush data of a single tenant only. + +``` +GET,POST /flush?tenant=dev +``` + ### Shutdown ``` diff --git a/modules/ingester/flush.go b/modules/ingester/flush.go index e9c702fc424..1ba73f3cb38 100644 --- a/modules/ingester/flush.go +++ b/modules/ingester/flush.go @@ -115,9 +115,23 @@ func (i *Ingester) ShutdownHandler(w http.ResponseWriter, _ *http.Request) { } // FlushHandler calls sweepAllInstances(true) which will force push all traces into the WAL and force -// mark all head blocks as ready to flush. -func (i *Ingester) FlushHandler(w http.ResponseWriter, _ *http.Request) { - i.sweepAllInstances(true) +// mark all head blocks as ready to flush. It will either flush all instances or if an instance is specified, +// just that one. +func (i *Ingester) FlushHandler(w http.ResponseWriter, r *http.Request) { + queryParamInstance := "tenant" + + if r.URL.Query().Has(queryParamInstance) { + instance, ok := i.getInstanceByID(r.URL.Query().Get(queryParamInstance)) + if !ok { + w.WriteHeader(http.StatusNotFound) + return + } + level.Info(log.Logger).Log("msg", "flushing instance", "instance", instance.instanceID) + i.sweepInstance(instance, true) + } else { + i.sweepAllInstances(true) + } + w.WriteHeader(http.StatusNoContent) }