-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(server): Send metrics via the global endpoint #2902
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4ac3a0e
feat(server): Send metrics via the global endpoint
jan-auer e94d6e7
ref: Doc comments
jan-auer 7dfdf87
meta: Changelog
jan-auer cc0f4bb
fix: Allow the batch endpoint without outcomes flag
jan-auer e0880e2
test: Add integration tests
jan-auer b11353e
fix: Sign payloads before encoding
jan-auer eb55fa4
fix: Introduce constant
jan-auer 350235d
fix: Comment on unwrap
jan-auer 36159cc
test: Test max_flush_bytes
jan-auer 5e2ac7d
ref: Move buckets into a field
jan-auer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,14 +276,10 @@ impl<'a> Iterator for BucketsViewBySizeIter<'a> { | |
} | ||
SplitDecision::MoveToNextBatch => break, | ||
SplitDecision::Split(at) => { | ||
// Only certain buckets can be split, if the bucket can't be split, | ||
// move it to the next batch. | ||
if bucket.can_split() { | ||
self.current = Index { | ||
slice: self.current.slice, | ||
bucket: self.current.bucket + at, | ||
}; | ||
} | ||
self.current = Index { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check for whether the bucket can split has been moved into |
||
slice: self.current.slice, | ||
bucket: self.current.bucket + at, | ||
}; | ||
break; | ||
} | ||
} | ||
|
@@ -332,6 +328,7 @@ impl<'a> Serialize for BucketsView<'a> { | |
/// ``` | ||
/// | ||
/// A view can be split again into multiple smaller views. | ||
#[derive(Clone)] | ||
pub struct BucketView<'a> { | ||
/// The source bucket. | ||
inner: &'a Bucket, | ||
|
@@ -427,6 +424,46 @@ impl<'a> BucketView<'a> { | |
Some(self) | ||
} | ||
|
||
/// Estimates the number of bytes needed to serialize the bucket without value. | ||
/// | ||
/// Note that this does not match the exact size of the serialized payload. Instead, the size is | ||
/// approximated through tags and a static overhead. | ||
fn estimated_base_size(&self) -> usize { | ||
50 + self.name().len() + aggregator::tags_cost(self.tags()) | ||
jan-auer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// Estimates the number of bytes needed to serialize the bucket. | ||
/// | ||
/// Note that this does not match the exact size of the serialized payload. Instead, the size is | ||
/// approximated through the number of contained values, assuming an average size of serialized | ||
/// values. | ||
pub fn estimated_size(&self) -> usize { | ||
self.estimated_base_size() + self.len() * AVG_VALUE_SIZE | ||
} | ||
|
||
/// Calculates a split for this bucket if its estimated serialization size exceeds a threshold. | ||
/// | ||
/// There are three possible return values: | ||
/// - `(Some, None)` if the bucket fits entirely into the size budget. There is no split. | ||
/// - `(None, Some)` if the size budget cannot even hold the bucket name and tags. There is no | ||
/// split, the entire bucket is moved. | ||
/// - `(Some, Some)` if the bucket fits partially. Remaining values are moved into a new bucket | ||
/// with all other information cloned. | ||
/// | ||
/// This is an approximate function. The bucket is not actually serialized, but rather its | ||
/// footprint is estimated through the number of data points contained. See | ||
/// [`estimated_size`](Self::estimated_size) for more information. | ||
pub fn split(self, size: usize, max_size: Option<usize>) -> (Option<Self>, Option<Self>) { | ||
match split_at(&self, size, max_size.unwrap_or(0) / BUCKET_SPLIT_FACTOR) { | ||
SplitDecision::BucketFits(_) => (Some(self), None), | ||
SplitDecision::MoveToNextBatch => (None, Some(self)), | ||
SplitDecision::Split(at) => { | ||
let Range { start, end } = self.range.clone(); | ||
(self.clone().select(start..at), self.select(at..end)) | ||
} | ||
} | ||
} | ||
|
||
/// Whether the bucket can be split into multiple. | ||
/// | ||
/// Only set and distribution buckets can be split. | ||
|
@@ -624,14 +661,18 @@ enum SplitDecision { | |
/// `estimate_size` for more information. | ||
fn split_at(bucket: &BucketView<'_>, max_size: usize, min_split_size: usize) -> SplitDecision { | ||
// If there's enough space for the entire bucket, do not perform a split. | ||
let bucket_size = estimate_size(bucket); | ||
let bucket_size = bucket.estimated_size(); | ||
if max_size >= bucket_size { | ||
return SplitDecision::BucketFits(bucket_size); | ||
} | ||
|
||
if !bucket.can_split() { | ||
return SplitDecision::MoveToNextBatch; | ||
} | ||
|
||
// If the bucket key can't even fit into the remaining length, move the entire bucket into | ||
// the right-hand side. | ||
let own_size = estimate_base_size(bucket); | ||
let own_size = bucket.estimated_base_size(); | ||
if max_size < (own_size + AVG_VALUE_SIZE) { | ||
// split_at must not be zero | ||
return SplitDecision::MoveToNextBatch; | ||
|
@@ -644,27 +685,9 @@ fn split_at(bucket: &BucketView<'_>, max_size: usize, min_split_size: usize) -> | |
// Perform a split with the remaining space after adding the key. We assume an average | ||
// length of 8 bytes per value and compute the number of items fitting into the left side. | ||
let split_at = (max_size - own_size) / AVG_VALUE_SIZE; | ||
|
||
SplitDecision::Split(split_at) | ||
} | ||
|
||
/// Estimates the number of bytes needed to serialize the bucket without value. | ||
/// | ||
/// Note that this does not match the exact size of the serialized payload. Instead, the size is | ||
/// approximated through tags and a static overhead. | ||
fn estimate_base_size(bucket: &BucketView<'_>) -> usize { | ||
50 + bucket.name().len() + aggregator::tags_cost(bucket.tags()) | ||
} | ||
|
||
/// Estimates the number of bytes needed to serialize the bucket. | ||
/// | ||
/// Note that this does not match the exact size of the serialized payload. Instead, the size is | ||
/// approximated through the number of contained values, assuming an average size of serialized | ||
/// values. | ||
fn estimate_size(bucket: &BucketView<'_>) -> usize { | ||
estimate_base_size(bucket) + bucket.len() * AVG_VALUE_SIZE | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use insta::assert_json_snapshot; | ||
|
@@ -919,7 +942,7 @@ b3:42:75|s"#; | |
.by_size(100) | ||
.map(|bv| { | ||
let len: usize = bv.iter().map(|b| b.len()).sum(); | ||
let size: usize = bv.iter().map(|b| estimate_size(&b)).sum(); | ||
let size: usize = bv.iter().map(|b| b.estimated_size()).sum(); | ||
(len, size) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
@@ -945,7 +968,7 @@ b3:42:75|s"#; | |
.by_size(250) | ||
.map(|bv| { | ||
let len: usize = bv.iter().map(|b| b.len()).sum(); | ||
let size: usize = bv.iter().map(|b| estimate_size(&b)).sum(); | ||
let size: usize = bv.iter().map(|b| b.estimated_size()).sum(); | ||
(len, size) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
@@ -971,7 +994,7 @@ b3:42:75|s"#; | |
.by_size(500) | ||
.map(|bv| { | ||
let len: usize = bv.iter().map(|b| b.len()).sum(); | ||
let size: usize = bv.iter().map(|b| estimate_size(&b)).sum(); | ||
let size: usize = bv.iter().map(|b| b.estimated_size()).sum(); | ||
(len, size) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BucketKeyRef
is no longer required. The hash created here and the hash used for partitioning do not have to be the same, which is why we can hash differently.