pub struct DDSketch { /* private fields */ }Expand description
DDSketch implementation based on the Datadog Agent.
This implementation is subtly different from the open-source implementations of DDSketch, as Datadog made some
slight tweaks to configuration values and in-memory layout to optimize it for insertion performance within the
agent.
We’ve mimicked the agent version of DDSketch here in order to support a future where we can take sketches shipped
by the agent, handle them internally, merge them, and so on, without any loss of accuracy, eventually forwarding
them to Datadog ourselves.
As such, this implementation is constrained in the same ways: the configuration parameters can’t be changed, the collapsing strategy is fixed, and we support a limited number of methods for inserting into the sketch.
Importantly, we’ve a special function, again taken from the agent version, to allow us to interpolate histograms, specifically our own aggregated histograms, into a sketch so that we can emit useful default quantiles, rather than having to ship the buckets – upper bound and count – to a downstream system that might have no native way to do the same thing, basically providing no value as they have no way to render useful data from them.
§Features
This crate exposes a single feature, serde, which enables serialization and deserialization of DDSketch with
serde. This feature isn’t enabled by default, as it can be slightly risky to use. This is primarily due to the
fact that the format of DDSketch isn’t promised to be stable over time. If you enable this feature, you should
take care to avoid storing serialized DDSketch data for long periods of time, as deserializing it in the future
may work but could lead to incorrect/unexpected behavior or issues with correctness.
Implementations§
Source§impl DDSketch
impl DDSketch
Sourcepub fn remap_mapping() -> LogarithmicMapping
pub fn remap_mapping() -> LogarithmicMapping
Returns the canonical DDSketch mapping that aligns with the agent sketch’s key space.
Sourcepub fn value_for_key(key: i16) -> f64
pub fn value_for_key(key: i16) -> f64
Returns the representative value for the given agent sketch key.
Sourcepub fn min(&self) -> Option<f64>
pub fn min(&self) -> Option<f64>
Minimum value seen by this sketch.
Returns None if the sketch is empty.
Sourcepub fn max(&self) -> Option<f64>
pub fn max(&self) -> Option<f64>
Maximum value seen by this sketch.
Returns None if the sketch is empty.
Sourcepub fn sum(&self) -> Option<f64>
pub fn sum(&self) -> Option<f64>
Sum of all values seen by this sketch.
Returns None if the sketch is empty.
Sourcepub fn stored_sum(&self) -> f64
pub fn stored_sum(&self) -> f64
Returns the stored sum summary field without considering the sample count.
Sourcepub fn avg(&self) -> Option<f64>
pub fn avg(&self) -> Option<f64>
Average value seen by this sketch.
Returns None if the sketch is empty.
Sourcepub fn stored_avg(&self) -> f64
pub fn stored_avg(&self) -> f64
Returns the stored average summary field without considering the sample count.
Sourcepub fn stored_min(&self) -> f64
pub fn stored_min(&self) -> f64
Returns the stored minimum summary field without considering the sample count.
Sourcepub fn stored_max(&self) -> f64
pub fn stored_max(&self) -> f64
Returns the stored maximum summary field without considering the sample count.
Sourcepub fn insert_many(&mut self, vs: &[f64])
pub fn insert_many(&mut self, vs: &[f64])
Inserts many values into the sketch.
Sourcepub fn insert_interpolate_buckets(
&mut self,
buckets: Vec<Bucket>,
) -> Result<(), &'static str>
pub fn insert_interpolate_buckets( &mut self, buckets: Vec<Bucket>, ) -> Result<(), &'static str>
Inserts histogram buckets into the sketch via linear interpolation.
§Errors
Returns an error if a bucket size is greater that u32::MAX.
Sourcepub fn merge(&mut self, other: &DDSketch)
pub fn merge(&mut self, other: &DDSketch)
Merges another sketch into this sketch, without a loss of accuracy.
All samples present in the other sketch will be correctly represented in this sketch, and summary statistics such as the sum, average, count, min, and max, will represent the sum of samples from both sketches.
A zero-count sketch can retain bins after an upstream cumulative-to-delta conversion. Its summary fields do not describe samples in the current interval, so they do not contribute to the merged summary. Its bins are still merged.
Sourcepub fn merge_to_dogsketch(&self, dogsketch: &mut Dogsketch)
pub fn merge_to_dogsketch(&self, dogsketch: &mut Dogsketch)
Merges this sketch into the Dogsketch Protocol Buffers representation.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DDSketch
impl<'de> Deserialize<'de> for DDSketch
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for DDSketch
Auto Trait Implementations§
impl Freeze for DDSketch
impl RefUnwindSafe for DDSketch
impl Send for DDSketch
impl Sync for DDSketch
impl Unpin for DDSketch
impl UnwindSafe for DDSketch
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request