Skip to content

feat(metrics-v3): add Datadog V3 payload encoder#2223

Open
atanzu wants to merge 1 commit into
mainfrom
mark.kirichenko/AGTMETRICS-536/add-metrics-v3-encoder
Open

feat(metrics-v3): add Datadog V3 payload encoder#2223
atanzu wants to merge 1 commit into
mainfrom
mark.kirichenko/AGTMETRICS-536/add-metrics-v3-encoder

Conversation

@atanzu

@atanzu atanzu commented Jul 10, 2026

Copy link
Copy Markdown

What does this PR do?

Add a new library which allows to encode metric payloads using V3 columnar format.

Motivation

This library enables users to encode their metric payloads using an efficient column-based protocol. For performance and compatibility reasons (we also want to keep this crate no_std so we could use it in very resource-constrained environments) this crate does manual protobuf serialization.

Additional Notes

How to test the change?

We do correctness test by comparing the resulting encoded payload with the one produced from protobuf-generated code.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

📚 Documentation Check Results

⚠️ 1 documentation warning(s) found

📦 libdd-metrics-v3 - 1 warning(s)


Updated: 2026-07-10 14:29:51 UTC | Commit: 04af58b | missing-docs job results

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jul 10, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 98.54%
Overall Coverage: 74.58% (+0.26%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: a743570 | Docs | Datadog PR Page | Give us feedback!

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

🔒 Cargo Deny Results

No issues found!

📦 libdd-metrics-v3 - ✅ No issues


Updated: 2026-07-10 14:31:38 UTC | Commit: 04af58b | dependency-check job results

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Clippy Allow Annotation Report

Comparing clippy allow annotations between branches:

  • Base Branch: origin/main
  • PR Branch: origin/mark.kirichenko/AGTMETRICS-536/add-metrics-v3-encoder

Summary by Rule

Rule Base Branch PR Branch Change

Annotation Counts by File

File Base Branch PR Branch Change

Annotation Stats by Crate

Crate Base Branch PR Branch Change
clippy-annotation-reporter 5 5 No change (0%)
datadog-ffe-ffi 1 1 No change (0%)
datadog-ipc 22 22 No change (0%)
datadog-live-debugger 4 4 No change (0%)
datadog-live-debugger-ffi 10 10 No change (0%)
datadog-profiling-replayer 4 4 No change (0%)
datadog-sidecar 45 45 No change (0%)
libdd-common 13 13 No change (0%)
libdd-common-ffi 12 12 No change (0%)
libdd-data-pipeline 6 6 No change (0%)
libdd-ddsketch 2 2 No change (0%)
libdd-dogstatsd-client 1 1 No change (0%)
libdd-profiling 13 13 No change (0%)
libdd-remote-config 3 3 No change (0%)
libdd-telemetry 20 20 No change (0%)
libdd-tinybytes 4 4 No change (0%)
libdd-trace-normalization 2 2 No change (0%)
libdd-trace-obfuscation 3 3 No change (0%)
libdd-trace-stats 1 1 No change (0%)
libdd-trace-utils 11 11 No change (0%)
Total 182 182 No change (0%)

About This Report

This report tracks Clippy allow annotations for specific rules, showing how they've changed in this PR. Decreasing the number of these annotations generally improves code quality.

@atanzu atanzu force-pushed the mark.kirichenko/AGTMETRICS-536/add-metrics-v3-encoder branch from db0bdea to f0b893c Compare July 10, 2026 12:42
@pr-commenter

pr-commenter Bot commented Jul 10, 2026

Copy link
Copy Markdown

Benchmarks

Comparison

Benchmark execution time: 2026-07-10 15:15:23

Comparing candidate commit a743570 in PR branch mark.kirichenko/AGTMETRICS-536/add-metrics-v3-encoder with baseline commit a41a0f4 in branch main.

Found 3 performance improvements and 4 performance regressions! Performance is the same for 170 metrics, 10 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:alloc_free/system/4096

  • 🟩 execution_time [-12.822ns; -12.699ns] or [-13.672%; -13.540%]

scenario:glob_matcher/ascii_wildcard_backtrack_match/wall_time

  • 🟥 execution_time [+4.384ns; +4.403ns] or [+11.774%; +11.826%]

scenario:glob_matcher/ascii_wildcard_heavy_backtrack/wall_time

  • 🟥 execution_time [+4.297ns; +4.330ns] or [+10.447%; +10.525%]

scenario:glob_matcher/ascii_wildcard_question_match/wall_time

  • 🟩 execution_time [-16.259ns; -16.240ns] or [-28.233%; -28.200%]

scenario:glob_matcher/ascii_wildcard_star_match/wall_time

  • 🟩 execution_time [-16.655ns; -16.632ns] or [-28.722%; -28.682%]

scenario:glob_matcher/unicode_pattern_wildcard_match/wall_time

  • 🟥 execution_time [+10.083ns; +10.171ns] or [+8.182%; +8.254%]

scenario:receiver_entry_point/report/2644

  • 🟥 execution_time [+175.738µs; +188.940µs] or [+4.857%; +5.222%]

Candidate

Omitted due to size.

Baseline

Omitted due to size.

@dd-octo-sts

dd-octo-sts Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Artifact Size Benchmark Report

aarch64-alpine-linux-musl
Artifact Baseline Commit Change
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 85.88 MB 85.88 MB 0% (0 B) 👌
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 7.88 MB 7.88 MB 0% (0 B) 👌
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 97.10 MB 97.10 MB 0% (0 B) 👌
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.61 MB 10.61 MB 0% (0 B) 👌
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 25.45 MB 25.45 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 88.44 KB 88.44 KB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 184.54 MB 184.54 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 946.77 MB 946.77 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 8.32 MB 8.32 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 88.44 KB 88.44 KB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 24.62 MB 24.62 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 49.03 MB 49.03 MB 0% (0 B) 👌
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 22.05 MB 22.05 MB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 89.82 KB 89.82 KB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 188.76 MB 188.76 MB +0% (+8.00 KB) 👌
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 935.45 MB 935.45 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 6.43 MB 6.43 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 89.82 KB 89.82 KB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 26.43 MB 26.43 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 46.66 MB 46.66 MB 0% (0 B) 👌
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 76.58 MB 76.58 MB 0% (0 B) 👌
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 8.78 MB 8.78 MB 0% (0 B) 👌
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 92.10 MB 92.10 MB 0% (0 B) 👌
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.69 MB 10.69 MB 0% (0 B) 👌

@atanzu atanzu force-pushed the mark.kirichenko/AGTMETRICS-536/add-metrics-v3-encoder branch from f0b893c to f6a9fc0 Compare July 10, 2026 13:52
Allows to encode metric payloads using V3 columnar format.

This library enables users to encode their metric payloads using an
efficient column-based protocol. For performance and compatibility
reasons (we also want to keep this crate `no_std` so we could use it in
very resource-constrained environments) this crate does manual protobuf
serialization.

Signed-off-by: Mark Kirichenko <mark.kirichenko@datadoghq.com>
@atanzu atanzu force-pushed the mark.kirichenko/AGTMETRICS-536/add-metrics-v3-encoder branch from f6a9fc0 to a743570 Compare July 10, 2026 14:28
@atanzu atanzu marked this pull request as ready for review July 10, 2026 15:19
@atanzu atanzu requested review from a team as code owners July 10, 2026 15:19

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a743570c4b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +691 to +693
if no_index {
self.writer.types[self.metric_idx] |= FLAG_NO_INDEX;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear flagNoIndex when origin is reset

If set_origin is called more than once for the same metric, a later call with no_index == false does not undo an earlier no_index == true; the bit is only ever ORed into types. In that scenario the finalized payload still marks the series as flagNoIndex, so the metric can be hidden/non-indexed even though the latest setter value requested indexing.

Useful? React with 👍 / 👎.

Comment on lines +747 to +751
self.writer.sketch_num_bins.push(bin_keys.len() as u64);

let key_start = self.writer.sketch_bin_keys.len();
self.writer.sketch_bin_keys.extend_from_slice(bin_keys);
self.writer.sketch_bin_cnts.extend_from_slice(bin_counts);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate sketch bin counts before recording bins

When bin_keys.len() != bin_counts.len(), this records sketch_num_bins from the key count but writes a different number of count entries. A decoder will consume that advertised number of counts for the sketch, so short count slices steal counts from the next sketch and long slices leave extras that shift later sketches, corrupting distribution payloads instead of rejecting the invalid input.

Useful? React with 👍 / 👎.

///
/// Use the setter methods to configure the metric, add points with [`add_point`](Self::add_point),
/// then call [`close`](Self::close) to finalize.
pub struct V3MetricBuilder<'a> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Finalize metrics when the builder is dropped

If a caller lets V3MetricBuilder fall out of scope without calling close, the metric keeps its default zero value type while its point values remain in vals_float64; finalizing the writer then encodes those non-zero points as zeros and leaves stray value-column entries. Because close has no return value and the builder is not enforced by the type system, this is an easy way for normal API use to silently corrupt a payload.

Useful? React with 👍 / 👎.

Comment on lines +717 to +720
pub fn add_point(&mut self, timestamp: i64, value: f64) {
self.writer.timestamps.push(timestamp);
self.writer.vals_float64.push(value);
self.writer.num_points[self.metric_idx] += 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject plain points for sketch metrics

When the builder was created with V3MetricType::Sketch, calling the generic add_point path records only one timestamp/value and no sketch count/bin metadata, but the encoded type still tells decoders to read three summary values plus a count and sketch bins for each point. That malformed sketch consumes subsequent value columns incorrectly (or fails to decode), so this method should reject sketch metrics rather than accepting them silently.

Useful? React with 👍 / 👎.

Comment on lines +738 to +744
self.writer.timestamps.push(timestamp);

// Count goes in sint64, sum/min/max go in float64
self.writer.vals_sint64.push(count);
self.writer.vals_float64.push(sum);
self.writer.vals_float64.push(min);
self.writer.vals_float64.push(max);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject sketches for non-sketch metrics

When the builder was created for a Count/Rate/Gauge, add_sketch still appends sketch summaries, counts, and bin columns, but the metric type remains non-sketch so decoders will read only one normal value for the point. The extra values and sketch columns then shift the cursors used for following metrics, corrupting the rest of the payload rather than rejecting the mismatched API call.

Useful? React with 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant