Skip to content

Commit

Permalink
feat(protocol): Improve the grouping protocol config (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Mar 28, 2019
1 parent e23d3ec commit 5bac740
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
4 changes: 3 additions & 1 deletion general/src/protocol/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ pub struct GroupingConfig {
/// The id of the grouping config.
#[metastructure(max_chars = "enumlike")]
pub id: Annotated<String>,
/// The enhancements configuration.
pub enhancements: Annotated<String>,
}

/// The sentry v7 event structure.
Expand Down Expand Up @@ -337,7 +339,7 @@ pub struct Event {
pub project: Annotated<u64>,

/// The grouping configuration for this event.
pub grouping_config: Annotated<GroupingConfig>,
pub grouping_config: Annotated<Object<Value>>,

/// Legacy checksum used for grouping before fingerprint hashes.
#[metastructure(max_chars = "hash")]
Expand Down
24 changes: 4 additions & 20 deletions general/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use std::collections::BTreeSet;
use std::sync::Arc;

use serde::{Deserialize, Serialize};
use serde_json::Value;

use crate::processor::{ProcessingState, Processor};
use crate::protocol::{Event, GroupingConfig, IpAddr};
use crate::types::{Annotated, Meta, ValueAction};
use crate::protocol::{Event, IpAddr};
use crate::types::{Meta, ValueAction};

mod event_error;
mod geo;
Expand All @@ -18,23 +19,6 @@ mod trimming;

pub use crate::store::geo::GeoIpLookup;

/// The config for the grouping config in store
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(default)]
pub struct StoreGroupingConfig {
/// The id of the grouping algorithm that should be used.
pub id: String,
}

impl StoreGroupingConfig {
/// Converts this config into one the event structure supports.
pub fn as_grouping_config(&self) -> GroupingConfig {
GroupingConfig {
id: Annotated::from(self.id.clone()),
}
}
}

/// The config for store.
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(default)]
Expand All @@ -44,7 +28,7 @@ pub struct StoreConfig {
pub client: Option<String>,
pub key_id: Option<String>,
pub protocol_version: Option<String>,
pub grouping_config: Option<StoreGroupingConfig>,
pub grouping_config: Option<Value>,

/// Hard limit for stacktrace frames
/// Corresponds to SENTRY_STACKTRACE_FRAMES_HARD_LIMIT
Expand Down
26 changes: 14 additions & 12 deletions general/src/store/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use crate::protocol::{
Frame, IpAddr, Level, LogEntry, Request, Stacktrace, Tags, User,
};
use crate::store::{GeoIpLookup, StoreConfig};
use crate::types::{Annotated, Empty, Error, ErrorKind, Meta, Object, ValueAction};
use crate::types::{
Annotated, Empty, Error, ErrorKind, FromValue, Meta, Object, Value, ValueAction,
};

mod contexts;
mod logentry;
Expand Down Expand Up @@ -293,12 +295,13 @@ impl<'a> Processor for NormalizeProcessor<'a> {
event.key_id = Annotated::from(self.config.key_id.clone());
event.ty = Annotated::from(self.infer_event_type(event));
event.version = Annotated::from(self.config.protocol_version.clone());
event.grouping_config = Annotated::from(
self.config
.grouping_config
.as_ref()
.map(|x| x.as_grouping_config()),
);
event.grouping_config = self
.config
.grouping_config
.clone()
.map_or(Annotated::empty(), |x| {
FromValue::from_value(Annotated::<Value>::from(x))
});

// Validate basic attributes
event.platform.apply(|platform, _| {
Expand Down Expand Up @@ -542,7 +545,6 @@ impl<'a> Processor for NormalizeProcessor<'a> {
use crate::{
processor::process_value,
protocol::{PairList, TagEntry},
types::Value,
};

#[cfg(test)]
Expand Down Expand Up @@ -1179,9 +1181,9 @@ fn test_discards_received() {
#[test]
fn test_grouping_config() {
use crate::protocol::LogEntry;
use crate::store::StoreGroupingConfig;
use crate::types::SerializableAnnotated;
use insta::assert_ron_snapshot_matches;
use serde_json::json;

let mut event = Annotated::new(Event {
logentry: Annotated::from(LogEntry {
Expand All @@ -1193,9 +1195,9 @@ fn test_grouping_config() {

let mut processor = NormalizeProcessor::new(
Arc::new(StoreConfig {
grouping_config: Some(StoreGroupingConfig {
id: "legacy:1234-12-12".into(),
}),
grouping_config: Some(json!({
"id": "legacy:1234-12-12".to_string(),
})),
..Default::default()
}),
None,
Expand Down

0 comments on commit 5bac740

Please sign in to comment.