-
Notifications
You must be signed in to change notification settings - Fork 121
feat(client-reports): Protocol support for client reports #1074
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ae3bbc5
feat(client-reports): Added initial support for client reports
mitsuhiko 441fd4d
test: added tests for basic client reports
mitsuhiko b2df16b
test: added test for removal of client report from envelopes
mitsuhiko 42e2432
fix: clippy
mitsuhiko 00be1af
fix: tests
mitsuhiko 956e0b3
test: added integration test for sdk outcomes
mitsuhiko e7cfdf7
meta: changelog
mitsuhiko 7cc0c68
ref: change queue_full to queue_overflow
mitsuhiko c69a351
ref: change protocol to be object based like the last revision documents
mitsuhiko 093117f
ref: make an early return even earlier
mitsuhiko 2bb083a
Merge branch 'master' into feature/client-reports
mitsuhiko 0843775
feat: create an explicit internal data category
mitsuhiko 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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -501,6 +501,8 @@ struct Limits { | |
| max_attachment_size: ByteSize, | ||
| /// The maximum combined size for all attachments in an envelope or request. | ||
| max_attachments_size: ByteSize, | ||
| /// The maximum combined size for all client reports in an envelope or request. | ||
| max_client_reports_size: ByteSize, | ||
| /// The maximum payload size for an entire envelopes. Individual limits still apply. | ||
| max_envelope_size: ByteSize, | ||
| /// The maximum number of session items per envelope. | ||
|
|
@@ -539,6 +541,7 @@ impl Default for Limits { | |
| max_event_size: ByteSize::mebibytes(1), | ||
| max_attachment_size: ByteSize::mebibytes(100), | ||
| max_attachments_size: ByteSize::mebibytes(100), | ||
| max_client_reports_size: ByteSize::kibibytes(4), | ||
| max_envelope_size: ByteSize::mebibytes(100), | ||
| max_session_count: 100, | ||
| max_api_payload_size: ByteSize::mebibytes(20), | ||
|
|
@@ -1451,6 +1454,11 @@ impl Config { | |
| self.values.limits.max_attachments_size.as_bytes() | ||
| } | ||
|
|
||
| /// Returns the maxmium combined size of client reports in bytes. | ||
|
Contributor
Author
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. Not sure if we want this config flag, but if we do, we probably need to document it. |
||
| pub fn max_client_reports_size(&self) -> usize { | ||
| self.values.limits.max_client_reports_size.as_bytes() | ||
| } | ||
|
|
||
| /// Returns the maximum size of an envelope payload in bytes. | ||
| /// | ||
| /// Individual item size limits still apply. | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| use relay_common::{DataCategory, UnixTimestamp}; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
| pub struct DiscardedEvent { | ||
| pub reason: String, | ||
| pub category: DataCategory, | ||
| pub quantity: u32, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
| pub struct ClientReport { | ||
| /// The timestamp of when the report was created. | ||
| pub timestamp: Option<UnixTimestamp>, | ||
| /// Discard reason counters. | ||
| pub discarded_events: Vec<DiscardedEvent>, | ||
| } | ||
|
|
||
| impl ClientReport { | ||
| /// Parses a client report update from JSON. | ||
| pub fn parse(payload: &[u8]) -> Result<Self, serde_json::Error> { | ||
| serde_json::from_slice(payload) | ||
| } | ||
|
|
||
| /// Serializes a client report update back into JSON. | ||
| pub fn serialize(&self) -> Result<Vec<u8>, serde_json::Error> { | ||
| serde_json::to_vec(self) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_client_report_roundtrip() { | ||
| let json = r#"{ | ||
| "timestamp": "2020-02-07T15:17:00Z", | ||
| "discarded_events": [ | ||
| {"reason": "foo_reason", "category": "error", "quantity": 42}, | ||
| {"reason": "foo_reason", "category": "transaction", "quantity": 23} | ||
| ] | ||
| }"#; | ||
|
|
||
| let output = r#"{ | ||
| "timestamp": 1581088620, | ||
| "discarded_events": [ | ||
| { | ||
| "reason": "foo_reason", | ||
| "category": "error", | ||
| "quantity": 42 | ||
| }, | ||
| { | ||
| "reason": "foo_reason", | ||
| "category": "transaction", | ||
| "quantity": 23 | ||
| } | ||
| ] | ||
| }"#; | ||
|
|
||
| let update = ClientReport { | ||
| timestamp: Some("2020-02-07T15:17:00Z".parse().unwrap()), | ||
| discarded_events: vec![ | ||
| DiscardedEvent { | ||
| reason: "foo_reason".into(), | ||
| category: DataCategory::Error, | ||
| quantity: 42, | ||
| }, | ||
| DiscardedEvent { | ||
| reason: "foo_reason".into(), | ||
| category: DataCategory::Transaction, | ||
| quantity: 23, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| let parsed = ClientReport::parse(json.as_bytes()).unwrap(); | ||
| assert_eq_dbg!(update, parsed); | ||
| assert_eq_str!(output, serde_json::to_string_pretty(&update).unwrap()); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.