Skip to content

enhancement(context): add support for efficient mutable tag sets#1257

Merged
tobz merged 5 commits intomainfrom
tobz/efficient-mutable-tagsets
Mar 25, 2026
Merged

enhancement(context): add support for efficient mutable tag sets#1257
tobz merged 5 commits intomainfrom
tobz/efficient-mutable-tagsets

Conversation

@tobz
Copy link
Member

@tobz tobz commented Mar 24, 2026

Summary

This PR refactors TagSet to support efficient mutation of tag sets.

Today, TagSet and SharedTagSet form the basis for creating tag sets and cheaply sharing them. In components and helpers where we're building tag sets, we start by creating a TagSet, which supports mutability, and once these tagsets are "done", we can freeze them to create a SharedTagSet, which is then able to be cheaply cloned/shared. We use SharedTagSet as the tag storage for all event types: metrics, logs, and traces. However, this means that events cannot have their tags mutated. Adding support for mutation of tags can be done easily with a naive implementation, but we don't want to lose the things that make SharedTagSet so nice, namely being able to cheaply clone and share those chunks of tags that are constructed early in the pipeline, which are potentially interned, and so on.

This PR introduces changes to TagSet that effectively give it the ability to function like SharedTagSet -- the ability to cheaply extend it from another SharedTagSet -- while also efficiently allowing the "mutation" of the tag set by utilizing an "overlay" design: TagSet holds a "base" set of shared tag sets, a set of removals (which base tags to ignore), and a set of additions (new tags to add). These removals and additions are "overlaid" on the base tags during iteration, leading to the tags being emitted reflecting the intended state.

We've designed removal and addition to follow the existing semantics of TagSet but be as efficient as we can reasonably be. As tag removal is generally the more desired operation, we've tried to optimize this case a little more by making it efficient to do so: we use a bitset to store removal indexes so that determining which tags to remove during iteration is O(1).

In a sense, what we're really doing is preparing ourselves to be able to switch to using TagSet in events instead of SharedTagSet: TagSet today can already be mutated, but it has no support for structural sharing like SharedTagSet does.

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

How did you test this PR?

Added a bevy of new unit tests for our changes, as well as property tests to ensure the optimized removal/addition logic functions as intended.

References

AGTMETRICS-400

@tobz tobz requested a review from a team as a code owner March 24, 2026 14:56
@tobz tobz added the type/enhancement An enhancement in functionality or support. label Mar 24, 2026
@dd-octo-sts dd-octo-sts bot added the area/core Core functionality, event model, etc. label Mar 24, 2026
@pr-commenter
Copy link

pr-commenter bot commented Mar 24, 2026

Binary Size Analysis (Agent Data Plane)

Target: 36c9e85 (baseline) vs 02ed11d (comparison) diff
Analysis Type: Stripped binaries (debug symbols excluded)
Baseline Size: 26.17 MiB
Comparison Size: 26.18 MiB
Size Change: +10.70 KiB (+0.04%)
Pass/Fail Threshold: +5%
Result: PASSED ✅

Changes by Module

Module File Size Symbols
core +5.96 KiB 8724
smallvec +4.65 KiB 95
saluki_context::tags::tagset +3.16 KiB 14
saluki_context::resolver::TagsResolver -2.08 KiB 18
saluki_components::sources::otlp -1.82 KiB 164
[sections] -1.57 KiB 7
agent_data_plane::state::metrics -1.39 KiB 16
[Unmapped] +1.27 KiB 1
saluki_env::workload::metadata +1.26 KiB 2
saluki_core::observability::metrics +1.08 KiB 28
saluki_env::workload::aggregator -765 B 16
saluki_env::workload::collectors +665 B 216
saluki_components::transforms::host_tags +561 B 8
saluki_components::common::otlp -559 B 114
saluki_env::workload::stores +443 B 68
tokio -329 B 2275
alloc -280 B 770
saluki_components::common::datadog +241 B 326
agent_data_plane::cli::run +224 B 70
hyper_rustls -160 B 10

Detailed Symbol Changes

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [NEW] +1.79Mi  [NEW] +1.79Mi    std::thread::local::LocalKey<T>::with::h9509cd908892b298
  [NEW]  +114Ki  [NEW]  +114Ki    agent_data_plane::cli::run::create_topology::_{{closure}}::h43eb8ea3ec192ff9
  [NEW] +84.6Ki  [NEW] +84.5Ki    agent_data_plane::internal::control_plane::spawn_control_plane::_{{closure}}::he4363c74261e6d41
  [NEW] +64.2Ki  [NEW] +64.0Ki    saluki_components::common::datadog::io::run_endpoint_io_loop::_{{closure}}::hbdbf0366c968b3f9
  [NEW] +59.9Ki  [NEW] +59.8Ki    agent_data_plane::cli::run::handle_run_command::_{{closure}}::h38e8632c512f6b8f
  [NEW] +49.5Ki  [NEW] +49.3Ki    saluki_app::bootstrap::AppBootstrapper::bootstrap::_{{closure}}::h9dab5cec760ff990
  [NEW] +46.4Ki  [NEW] +46.3Ki    h2::proto::connection::Connection<T,P,B>::poll::h2bd60749b0dad36f
  [NEW] +46.2Ki  [NEW] +46.0Ki    _<saluki_components::forwarders::otlp::OtlpForwarder as saluki_core::components::forwarders::Forwarder>::run::_{{closure}}::h585350274ac713a7
  [NEW] +45.7Ki  [NEW] +45.5Ki    _<saluki_components::destinations::prometheus::Prometheus as saluki_core::components::destinations::Destination>::run::_{{closure}}::haccb9cdb776372dc
  [NEW] +44.3Ki  [NEW] +44.1Ki    _<saluki_components::transforms::aggregate::Aggregate as saluki_core::components::transforms::Transform>::run::_{{closure}}::h2e710c2c1ea3a770
  +0.1% +10.4Ki  +0.1% +6.48Ki    [21860 Others]
  [DEL] -44.4Ki  [DEL] -44.2Ki    _<saluki_components::transforms::aggregate::Aggregate as saluki_core::components::transforms::Transform>::run::_{{closure}}::h4183d8718b35855c
  [DEL] -45.7Ki  [DEL] -45.5Ki    _<saluki_components::destinations::prometheus::Prometheus as saluki_core::components::destinations::Destination>::run::_{{closure}}::he34c6c99f535251c
  [DEL] -46.1Ki  [DEL] -45.9Ki    _<saluki_components::forwarders::otlp::OtlpForwarder as saluki_core::components::forwarders::Forwarder>::run::_{{closure}}::h3fc056b8c3b1ef5a
  [DEL] -46.4Ki  [DEL] -46.3Ki    h2::proto::connection::Connection<T,P,B>::poll::h882eac246abc63c7
  [DEL] -49.5Ki  [DEL] -49.3Ki    saluki_app::bootstrap::AppBootstrapper::bootstrap::_{{closure}}::he5d18b68ad8674e3
  [DEL] -59.9Ki  [DEL] -59.7Ki    agent_data_plane::cli::run::handle_run_command::_{{closure}}::h18a09eec15b3cc76
  [DEL] -64.2Ki  [DEL] -64.0Ki    saluki_components::common::datadog::io::run_endpoint_io_loop::_{{closure}}::hbbac7c9eda9e917d
  [DEL] -84.6Ki  [DEL] -84.5Ki    agent_data_plane::internal::control_plane::spawn_control_plane::_{{closure}}::h10ad1a803e89e510
  [DEL]  -114Ki  [DEL]  -114Ki    agent_data_plane::cli::run::create_topology::_{{closure}}::hd2940cf47ffc187f
  [DEL] -1.79Mi  [DEL] -1.79Mi    std::thread::local::LocalKey<T>::with::h9949df9476fbdca7
  +0.0% +10.7Ki  +0.0% +6.73Ki    TOTAL

@pr-commenter
Copy link

pr-commenter bot commented Mar 24, 2026

Regression Detector (Agent Data Plane)

Regression Detector Results

Run ID: af78ff00-e8d2-4f0d-88f6-06c78fc5ded1

Baseline: 36c9e85
Comparison: 02ed11d
Diff

Optimization Goals: ✅ No significant changes detected

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI trials links
otlp_ingest_logs_5mb_throughput ingress throughput +0.05 [-0.08, +0.18] 1 (metrics) (profiles) (logs)
otlp_ingest_logs_5mb_cpu % cpu utilization -1.03 [-6.07, +4.02] 1 (metrics) (profiles) (logs)
otlp_ingest_logs_5mb_memory memory utilization -1.39 [-1.83, -0.96] 1 (metrics) (profiles) (logs)

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
dsd_uds_10mb_3k_contexts_cpu % cpu utilization +7.58 [-22.62, +37.78] 1 (metrics) (profiles) (logs)
dsd_uds_1mb_3k_contexts_cpu % cpu utilization +4.83 [-50.98, +60.63] 1 (metrics) (profiles) (logs)
dsd_uds_500mb_3k_contexts_throughput ingress throughput +1.97 [+1.84, +2.09] 1 (metrics) (profiles) (logs)
otlp_ingest_traces_ottl_filtering_5mb_memory memory utilization +1.51 [+1.17, +1.85] 1 (metrics) (profiles) (logs)
otlp_ingest_traces_5mb_memory memory utilization +0.85 [+0.60, +1.10] 1 (metrics) (profiles) (logs)
dsd_uds_500mb_3k_contexts_cpu % cpu utilization +0.80 [-0.58, +2.19] 1 (metrics) (profiles) (logs)
otlp_ingest_traces_ottl_transform_5mb_memory memory utilization +0.77 [+0.51, +1.03] 1 (metrics) (profiles) (logs)
otlp_ingest_traces_ottl_transform_5mb_cpu % cpu utilization +0.24 [-1.81, +2.29] 1 (metrics) (profiles) (logs)
dsd_uds_100mb_3k_contexts_cpu % cpu utilization +0.19 [-6.02, +6.40] 1 (metrics) (profiles) (logs)
dsd_uds_1mb_3k_contexts_memory memory utilization +0.07 [-0.11, +0.24] 1 (metrics) (profiles) (logs)
otlp_ingest_logs_5mb_throughput ingress throughput +0.05 [-0.08, +0.18] 1 (metrics) (profiles) (logs)
otlp_ingest_metrics_5mb_throughput ingress throughput +0.03 [-0.10, +0.15] 1 (metrics) (profiles) (logs)
dsd_uds_100mb_3k_contexts_throughput ingress throughput +0.01 [-0.04, +0.05] 1 (metrics) (profiles) (logs)
otlp_ingest_traces_ottl_transform_5mb_throughput ingress throughput +0.00 [-0.02, +0.02] 1 (metrics) (profiles) (logs)
dsd_uds_10mb_3k_contexts_throughput ingress throughput -0.00 [-0.14, +0.14] 1 (metrics) (profiles) (logs)
otlp_ingest_traces_ottl_filtering_5mb_throughput ingress throughput -0.00 [-0.02, +0.02] 1 (metrics) (profiles) (logs)
dsd_uds_512kb_3k_contexts_throughput ingress throughput -0.00 [-0.06, +0.05] 1 (metrics) (profiles) (logs)
otlp_ingest_traces_5mb_throughput ingress throughput -0.00 [-0.02, +0.02] 1 (metrics) (profiles) (logs)
dsd_uds_1mb_3k_contexts_throughput ingress throughput -0.00 [-0.06, +0.05] 1 (metrics) (profiles) (logs)
quality_gates_rss_dsd_medium memory utilization -0.05 [-0.24, +0.14] 1 (metrics) (profiles) (logs)
dsd_uds_512kb_3k_contexts_memory memory utilization -0.09 [-0.26, +0.08] 1 (metrics) (profiles) (logs)
quality_gates_rss_dsd_ultraheavy memory utilization -0.20 [-0.33, -0.07] 1 (metrics) (profiles) (logs)
quality_gates_rss_dsd_low memory utilization -0.23 [-0.43, -0.04] 1 (metrics) (profiles) (logs)
dsd_uds_10mb_3k_contexts_memory memory utilization -0.33 [-0.52, -0.14] 1 (metrics) (profiles) (logs)
dsd_uds_100mb_3k_contexts_memory memory utilization -0.43 [-0.61, -0.25] 1 (metrics) (profiles) (logs)
dsd_uds_500mb_3k_contexts_memory memory utilization -0.44 [-0.61, -0.27] 1 (metrics) (profiles) (logs)
quality_gates_rss_dsd_heavy memory utilization -0.46 [-0.59, -0.32] 1 (metrics) (profiles) (logs)
otlp_ingest_traces_ottl_filtering_5mb_cpu % cpu utilization -0.58 [-3.19, +2.03] 1 (metrics) (profiles) (logs)
otlp_ingest_metrics_5mb_cpu % cpu utilization -0.83 [-10.32, +8.66] 1 (metrics) (profiles) (logs)
quality_gates_rss_idle memory utilization -1.01 [-1.04, -0.97] 1 (metrics) (profiles) (logs)
otlp_ingest_logs_5mb_cpu % cpu utilization -1.03 [-6.07, +4.02] 1 (metrics) (profiles) (logs)
otlp_ingest_logs_5mb_memory memory utilization -1.39 [-1.83, -0.96] 1 (metrics) (profiles) (logs)
otlp_ingest_metrics_5mb_memory memory utilization -2.29 [-2.52, -2.06] 1 (metrics) (profiles) (logs)
dsd_uds_512kb_3k_contexts_cpu % cpu utilization -2.51 [-59.53, +54.50] 1 (metrics) (profiles) (logs)
otlp_ingest_traces_5mb_cpu % cpu utilization -3.77 [-5.76, -1.79] 1 (metrics) (profiles) (logs)

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed observed_value links
quality_gates_rss_dsd_heavy memory_usage 10/10 113.00MiB ≤ 140MiB (metrics) (profiles) (logs)
quality_gates_rss_dsd_low memory_usage 10/10 33.62MiB ≤ 50MiB (metrics) (profiles) (logs)
quality_gates_rss_dsd_medium memory_usage 10/10 52.74MiB ≤ 75MiB (metrics) (profiles) (logs)
quality_gates_rss_dsd_ultraheavy memory_usage 10/10 167.23MiB ≤ 200MiB (metrics) (profiles) (logs)
quality_gates_rss_idle memory_usage 10/10 20.93MiB ≤ 40MiB (metrics) (profiles) (logs)

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

@tobz
Copy link
Member Author

tobz commented Mar 25, 2026

As a general note: it doesn't seem like the change to TagSet has materially impacted memory or CPU usage in the construction phase that we still undertake to get from borrowed DogStatsD metric packets to TagSet to SharedTagSet... so that's good.

@tobz
Copy link
Member Author

tobz commented Mar 25, 2026

/merge

@gh-worker-devflow-routing-ef8351
Copy link

gh-worker-devflow-routing-ef8351 bot commented Mar 25, 2026

View all feedbacks in Devflow UI.

2026-03-25 12:34:20 UTC ℹ️ Start processing command /merge


2026-03-25 12:34:24 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 12m (p90).


2026-03-25 12:57:37 UTC 🚨 MergeQueue: This merge request is in error

mergequeue build completed successfully, but the github api returned an error while merging the pr.
It's probably because:

  • some status checks are failing:
    • dd-gitlab/build-adp-image-fips-internal
  • target branch of PR is restricted to only allow up-to-date branches, but the pr is now outdated
Details

Error: PUT https://api.github.com/repos/DataDog/saluki/pulls/1257/merge: 405 14 of 14 required status checks are expected. [] (Request ID: AB08:242F5E:8E2DF9:25F4927:69C3DBB9)

FullStacktrace:
activity error (type: github.GithubService_MergePullRequest, scheduledEventID: 50, startedEventID: 51, identity: 1@github-worker-867588667-czfbz@): PUT https://api.github.com/repos/DataDog/saluki/pulls/1257/merge: 405 14 of 14 required status checks are expected. [] (Request ID: AB08:242F5E:8E2DF9:25F4927:69C3DBB9) (type: GitFailure, retryable: false): PUT https://api.github.com/repos/DataDog/saluki/pulls/1257/merge: 405 14 of 14 required status checks are expected. [] (type: ErrorResponse, retryable: true)

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

Labels

area/core Core functionality, event model, etc. mergequeue-status: done type/enhancement An enhancement in functionality or support.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants