Support concurrent KVP telemetry with configurable event prefix#286
Open
peytonr18 wants to merge 1 commit intoAzure:mainfrom
Open
Support concurrent KVP telemetry with configurable event prefix#286peytonr18 wants to merge 1 commit intoAzure:mainfrom
peytonr18 wants to merge 1 commit intoAzure:mainfrom
Conversation
cadejacobson
approved these changes
Feb 20, 2026
Contributor
cadejacobson
left a comment
There was a problem hiding this comment.
This looks awesome to me! Good work
cjp256
reviewed
Feb 20, 2026
| let path = temp_path.clone(); | ||
| std::thread::spawn(move || { | ||
| // Each thread opens its own file descriptor. | ||
| let mut file = OpenOptions::new() |
Contributor
There was a problem hiding this comment.
I wonder if kvp::new() should be responsible for opening the file as we're already opening it there?
Seems like having the interface dictate initialization avoids allowing the caller to do unexpected things when opening the file.
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.
Summary
Bolsters the KVP telemetry infrastructure to support concurrent KVP emissions from multiple processes/libraries and allows external callers to configure their own event prefix.
Changes
Configurable event prefix (
kvp.rs)event_prefix: Stringfield toEmitKVPLayerso each subscriber instance carries its own prefix.generate_event_keyto acceptevent_prefixas a parameter instead of using the module-level constant.Kvp::newto acceptevent_prefix: &str.EVENT_PREFIXfromconsttopub constso it can be re-exported.Public API (
logging.rs)Kvp::new(vm_id, event_prefix)now takesOption<&str>for the prefix —Nonefalls back toEVENT_PREFIX,Some("my-lib-1.0")allows a custom prefix.EVENT_PREFIXaspub use crate::kvp::EVENT_PREFIXfor external consumers.setup_layerspassesEVENT_PREFIXto the internalKvp::new.Safe concurrent truncation (
kvp.rs)truncate_guest_pool_filenow acquires an exclusiveflockbefore checking file metadata and truncating, eliminating a TOCTOU race where concurrent processes could both decide the file is stale and truncate each other's data.Kvp::write_kvpsmadepub(crate)(kvp.rs)write_kvpsfromprivatetopub(crate)so concurrent tests (and future internal callers) can use it directly without the full tracing infrastructure.encode_kvp_itemvisibility fromprivatetopub(crate).Concurrent write tests (
kvp.rs)test_multi_thread_kvp_concurrent_writes: 4 threads × 5,000 iterations each, each with its own file descriptor, writing to the same temp file. Verifies all 20,000 records are intact and decodable.test_multi_process_kvp_concurrent_writes: 4 child processes × 5,000 iterations each writing to the same temp file. Verifies all 20,000 records are intact and decodable.Resolves #239