fix: avoid flushing empty tenant settings (quick win) #4458
+2
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have a design problem in pkg/settings/bucket.go
It holds a kind of in in-memory cache of the tenant settings stored in the bucket file
tenant_settings.json
. BUT that struct is reload before every read or write operation (hence, it doesn't act as a cache), and gets flushed after every write operation (hence we could completely discard after flush).Problem comes for the logic on Flush. tenant-settings flushes the in-memory version on graceful shutdowns and every 24h. When tenant-settings has not received a single CRUD operation during a release or 24h cycle, the in-memory store is empty then an empty store is flushed.
This causes this very prominent bug, where settings are completely wiped out.

(note the 2B files, corresponding to empty json
{}
).I could fix this by loading data on start, but still, fail to see any pros of doing such a load and flush. This PR is just a quick win, where we remove the flush from the service lifecycle. I'm not removing the unneeded in-memory cache yet. I think that the extended solution should be through directly using a proper object definition over pkg/settings/store/store.go