Skip to content

fix(activitylog): ttl for kv buckets - #4115

Open
maki5 wants to merge 1 commit into
opencloud-eu:mainfrom
maki5:fix/activitylog_nats_ttl
Open

maki5 wants to merge 1 commit into
opencloud-eu:mainfrom
maki5:fix/activitylog_nats_ttl

Conversation

@maki5

@maki5 maki5 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

refs: #3814

@codacy-production

codacy-production Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 17 complexity

Metric Results
Complexity 17

View in Codacy

🟢 Coverage 0.00% diff coverage · +0.00% coverage variation

Metric Results
Coverage variation ✅ +0.00% coverage variation (-1.00%)
Diff coverage ✅ 0.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (5b9c898) 94500 28670 30.34%
Head commit (a901bd3) 94535 (+35) 28682 (+12) 30.34% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4115) 38 0 0.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@maki5
maki5 requested review from aduffeck and butonic November 24, 2026 14:45
@aduffeck

Copy link
Copy Markdown
Member

Thanks for picking this up. Using the stream's max age for the TTL makes sense to me. Each KV entry is a debounce batch of at most ACTIVITYLOG_WRITE_BUFFER_DURATION (10s by default) for one resource, so expiring a key only drops activities that are a few seconds apart. With realistic TTLs that's close enough to per-entry expiry. It's also the only thing that cleans up resources that never get new activity, since MAX_ACTIVITIES is only enforced when a resource gets new activity.

One problem before this can go in: MaxAge applies to every message in the stream, including the activitylog.version key. That key is only written by the migration. Once it expires, the next startup runs migrateToV1 again over the whole bucket. That means a kv.Get per key, a failed keyValueEnvelope unmarshal for each msgpack batch and one error log line per key, and then the version key gets written again. Nothing gets corrupted, but on a large bucket it's a slow startup and a wall of errors, and it comes back after every TTL period.

I don't have a good proposal for how to fix that right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants