Repository navigation
fix(telemetry): let every replica write the minute's rollup row - #914
Merged
Merged
Conversation
Each API process writes the telemetry rollup for the current minute. The write was UPSERT ... CONTENT, which replaces the whole row, and created_at only defaults on create. The second process to write a minute (another replica, or a daemon restarted inside the minute) was refused with "Couldn't coerce value for field created_at: Expected datetime but found NONE". With two API replicas that is one warning a minute, and the stored row belongs to whichever replica wrote first. The upsert now sets the fields it owns and leaves created_at alone, so a later writer updates the row. The live test file used its own copy of the statement; it now runs the product's. Co-Authored-By: Nova (Claude Fable 5.2) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
💡 What changes
Every API process writes the runtime telemetry rollup for the current minute into one shared row. The second process to write a given minute was refused, so a deployment with two API replicas logged this once a minute:
It was found in the logs of a two-replica deployment on 1.5.0, where the two API pods logged 54 of these in an hour between them, one per minute. A single daemon hits the same failure when it restarts inside a minute it has already written.
After this change the later writer updates the row, and the warning stops.
🛠️ How it works
The write was
UPSERT telemetry_rollups CONTENT $record WHERE bucket_key = $bucket_key.CONTENTreplaces the whole row, the record carries nocreated_at, and the field isTYPE datetime DEFAULT time::now(), which fills in only on create. On an existing row the replacement leftcreated_atempty and the schema refused the write.The upsert now uses
SETfor the ten fields the rollup owns, socreated_atkeeps the value it got when the row was created. Each listed field is still replaced whole (summariesincluded), so nothing from an earlier writer's snapshot leaks into the row the wayMERGEwould allow.test_surreal_live_nested_fields.pycarried its own copy of the statement. It now imports the service's, so the live suite exercises what the product runs.🧪 Validation
test_rollup_for_a_minute_that_already_has_a_row_updates_itwrites the same minute twice as two fresh processes and checks one row, the second writer's data, and the originalcreated_at. With the oldCONTENTstatement put back, it fails on "the second write was refused".test_live_runtime_rollup_accepts_every_replica_in_the_same_minutedoes the same over two connections, then has both write a fresh minute at once.tests/test_surreal_live_nested_fields.pyandtests/test_telemetry_routes.pytogether: 17 passed.WHERE bucket_keyform stays and no record-id scheme is added.🚦 Rollout
No schema change and nothing to migrate. During a rolling deploy an old pod can still be refused for a minute it writes second; that ends when the last old pod is gone. A revert brings the warning back and loses nothing.
📌 Not in this PR
With several replicas, the row for a minute holds the snapshot of whichever replica wrote last, since each process only sees its own counters. That was already true of the first writer before this fix. Combining replicas is a separate piece of work.
Summary by CodeRabbit