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 cannot be changed, the collapsing strategy is fixed, and we support a limited number of methods for inserting into the sketch.
Importantly, we have 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 is not enabled by default, as it can be slightly risky to use. This is primarily due to the
fact that the format of DDSketch
is not 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 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 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 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>
§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.
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