From 501f514389cc41486b067cc7021f118430cbd098 Mon Sep 17 00:00:00 2001 From: Julien Levesy Date: Fri, 1 Dec 2023 23:00:26 +0100 Subject: [PATCH] feat(tsdb/agent): notify remote storage when commit happens (#13223) Signed-off-by: Julien Levesy Signed-off-by: Callum Styan Co-authored-by: Callum Styan --- CHANGELOG.md | 4 ++++ cmd/prometheus/main.go | 1 + tsdb/agent/db.go | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bab5107c..c541dd705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## unreleased + +* [BUGFIX] Agent: Participate in notify calls. #13223 + ## 2.48.0 / 2023-11-16 * [CHANGE] Remote-write: respect Retry-After header on 5xx errors. #12677 diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 4112cd842..dfafe66c6 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -1127,6 +1127,7 @@ func main() { ) localStorage.Set(db, 0) + db.SetWriteNotified(remoteStorage) close(dbOpen) <-cancel return nil diff --git a/tsdb/agent/db.go b/tsdb/agent/db.go index 66861a487..6afef1389 100644 --- a/tsdb/agent/db.go +++ b/tsdb/agent/db.go @@ -241,6 +241,8 @@ type DB struct { donec chan struct{} stopc chan struct{} + writeNotified wlog.WriteNotified + metrics *dbMetrics } @@ -311,6 +313,12 @@ func Open(l log.Logger, reg prometheus.Registerer, rs *remote.Storage, dir strin return db, nil } +// SetWriteNotified allows to set an instance to notify when a write happens. +// It must be used during initialization. It is not safe to use it during execution. +func (db *DB) SetWriteNotified(wn wlog.WriteNotified) { + db.writeNotified = wn +} + func validateOptions(opts *Options) *Options { if opts == nil { opts = DefaultOptions() @@ -962,6 +970,10 @@ func (a *appender) Commit() error { a.clearData() a.appenderPool.Put(a) + + if a.writeNotified != nil { + a.writeNotified.Notify() + } return nil }