Skip to content

Commit 0a4632a

Browse files
[ddtelemetry] Support metric distributions with ddsketch (#268)
* Add a minimal ddsketch implementation with PB serialization * Add a distribution telemetry implementation * Adjust reaktive accuracy to match datadog's backend * fmt * Add docs and rename bucket to bin Rename bucket to bin in store function to be consistent with terminology in the protobuf definition. The name store_index is introduced to distinguish bins index from the index used in the store which have a different offset. * Reserve only required amount The reserve function takes as a parameter the additional space to reserve not the total size of the queue. * Format protobuf generated module * Deprecate telemetry distribution * Remove telemetry distributions Distributions should be replaced by sketches. * Update copyright header * Add owners for ddsketch * Apply suggestions * Rename sketches to distribution in public interfaces * Upgrade base64 * Disable rustfmt on automatically generated files Files with `@generated`tag in the header are ignored by rustfmt to avoid formatting conflicts. * Update DDSketch version * Update 3rd party LICENSE * Rename field in payload for serialization * Use Errors for add_point * Fix tests * Enable trace_api_bytes * Remove todo comments * Update doc * Disable formationg with skip instead of @generated * Add tests for distribution metrics --------- Co-authored-by: Vianney Ruhlmann <[email protected]>
1 parent 10054ce commit 0a4632a

File tree

19 files changed

+1122
-47
lines changed

19 files changed

+1122
-47
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ serverless @Datadog/serverless
2121
sidecar @Datadog/libdatadog-php @Datadog/libdatadog-apm
2222
sidecar-ffi @Datadog/libdatadog-php @Datadog/libdatadog-apm
2323
data-pipeline*/ @Datadog/libdatadog-apm
24+
ddsketch @Datadog/libdatadog-apm @Datadog/libdatadog-telemetry

Cargo.lock

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ members = [
2828
"serverless",
2929
"bin_tests",
3030
"data-pipeline",
31-
"data-pipeline-ffi"
31+
"data-pipeline-ffi",
32+
"ddsketch",
3233
]
3334
# https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2
3435
resolver = "2"

LICENSE-3rdparty.yml

Lines changed: 37 additions & 7 deletions
Large diffs are not rendered by default.

ddsketch/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "datadog-ddsketch"
3+
description = "Minimal implementation of Datadog's DDSketch"
4+
edition.workspace = true
5+
version.workspace = true
6+
rust-version.workspace = true
7+
license.workspace = true
8+
9+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
10+
11+
[dependencies]
12+
prost = "0.11.6"
13+
14+
[build-dependencies]
15+
prost-build = { version = "0.11.9", optional = true }
16+
protoc-bin-vendored = { version = "3.0.0", optional = true }
17+
18+
[features]
19+
generate-protobuf = ["dep:prost-build", "dep:protoc-bin-vendored"]

ddsketch/build.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use std::error::Error;
5+
6+
#[cfg(feature = "generate-protobuf")]
7+
use std::{
8+
env,
9+
fs::File,
10+
io::{Read, Write},
11+
path::Path,
12+
};
13+
14+
#[cfg(feature = "generate-protobuf")]
15+
const HEADER: &str = "// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
16+
// SPDX-License-Identifier: Apache-2.0
17+
18+
";
19+
20+
fn main() -> Result<(), Box<dyn Error>> {
21+
#[cfg(feature = "generate-protobuf")]
22+
{
23+
// protoc is required to compile proto files. This uses protobuf_src to compile protoc
24+
// from the source, setting the env var to tell prost_build where to find it.
25+
std::env::set_var("PROTOC", protoc_bin_vendored::protoc_bin_path().unwrap());
26+
27+
let mut config = prost_build::Config::new();
28+
29+
let cur_working_dir = env::var("CARGO_MANIFEST_DIR")?;
30+
let output_path = Path::new(&cur_working_dir).join("src");
31+
32+
config.out_dir(output_path.clone());
33+
34+
println!("cargo:rerun-if-changed=src/pb/DDSketch.proto");
35+
config.compile_protos(&["src/pb/DDSketch.proto"], &["src/"])?;
36+
37+
prepend_to_file(HEADER.as_bytes(), &output_path.join("pb.rs"))?;
38+
}
39+
40+
Ok(())
41+
}
42+
43+
#[cfg(feature = "generate-protobuf")]
44+
fn prepend_to_file(data: &[u8], file_path: &Path) -> Result<(), Box<dyn Error>> {
45+
let mut f = File::open(file_path)?;
46+
let mut content = data.to_owned();
47+
f.read_to_end(&mut content)?;
48+
49+
let mut f = File::create(file_path)?;
50+
f.write_all(content.as_slice())?;
51+
Ok(())
52+
}

0 commit comments

Comments
 (0)