Skip to content
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(flags): Update errors processor to index feature flag data #6713

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions rust_snuba/src/processors/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ type GenericContext = BTreeMap<String, ContextStringify>;

#[derive(Debug, Default, Deserialize, JsonSchema)]
struct Contexts {
#[serde(default)]
features: Option<FeatureContextEnum>,
#[serde(default)]
replay: Option<ReplayContext>,
#[serde(default)]
Expand All @@ -181,6 +183,27 @@ struct TraceContext {
other: GenericContext,
}

#[derive(Debug, Deserialize, JsonSchema)]
#[serde(untagged)]
enum FeatureContextEnum {
Typed(FeatureContext),
Untyped(()),
}

#[derive(Debug, Default, Deserialize, JsonSchema)]
struct FeatureContext {
#[serde(default)]
values: Vec<FeatureContextItem>,
#[serde(default)]
version: u8,
}

#[derive(Debug, Default, Deserialize, JsonSchema)]
struct FeatureContextItem {
key: Unicodify,
value: Unicodify,
}

#[derive(Debug, Default, Deserialize, JsonSchema)]
struct ReplayContext {
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -382,6 +405,10 @@ struct ErrorRow {
tags_key: Vec<String>,
#[serde(rename = "tags.value")]
tags_value: Vec<String>,
#[serde(rename = "features.key")]
features_key: Vec<String>,
#[serde(rename = "features.value")]
features_value: Vec<String>,
timestamp: u32,
title: String,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -556,6 +583,20 @@ impl ErrorRow {
replay_id = Some(rid)
}

// Split feature keys and values into two vectors if the context could be parsed.
let mut features_key = Vec::new();
let mut features_value = Vec::new();

from_context.features.map(|v| match v {
FeatureContextEnum::Typed(ctx) => ctx.values.into_iter().for_each(|i| {
if let (Some(k), Some(v)) = (i.key.0, i.value.0) {
features_key.push(k);
features_value.push(v);
}
}),
FeatureContextEnum::Untyped(_) => {}
});

// Stacktrace.

let exceptions = from
Expand Down Expand Up @@ -661,6 +702,8 @@ impl ErrorRow {
exception_stacks_mechanism_type: stack_mechanism_types,
exception_stacks_type: stack_types,
exception_stacks_value: stack_values,
features_key,
features_value,
group_id: from.group_id,
http_method: from_request.method.0,
http_referer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ source: src/processors/mod.rs
expression: diff
---
[
Change {
path: ".<anyOf:0>.2.data.contexts.<anyOf:0>",
change: PropertyAdd {
lhs_additional_properties: true,
added: "features",
},
},
Change {
path: ".<anyOf:1>.0",
change: TypeRemove {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ expression: snapshot_payload
"exception_stacks.value": [
"Some exception."
],
"features.key": [],
"features.value": [],
"group_id": 124,
"http_method": null,
"http_referer": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ expression: snapshot_payload
"exception_stacks.value": [
"Some exception."
],
"features.key": [],
"features.value": [],
"group_id": 124,
"http_method": null,
"http_referer": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ expression: snapshot_payload
"exception_stacks.value": [
"Some exception."
],
"features.key": [],
"features.value": [],
"group_id": 124,
"http_method": null,
"http_referer": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ expression: snapshot_payload
"exception_stacks.mechanism_type": [],
"exception_stacks.type": [],
"exception_stacks.value": [],
"features.key": [],
"features.value": [],
"group_id": 124,
"http_method": null,
"http_referer": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ expression: snapshot_payload
"exception_stacks.mechanism_type": [],
"exception_stacks.type": [],
"exception_stacks.value": [],
"features.key": [],
"features.value": [],
"group_id": 123123123,
"http_method": null,
"http_referer": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ expression: snapshot_payload
"exception_stacks.mechanism_type": [],
"exception_stacks.type": [],
"exception_stacks.value": [],
"features.key": [],
"features.value": [],
"group_id": 124,
"http_method": null,
"http_referer": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ expression: snapshot_payload
"exception_stacks.mechanism_type": [],
"exception_stacks.type": [],
"exception_stacks.value": [],
"features.key": [],
"features.value": [],
"group_id": 123123,
"http_method": null,
"http_referer": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ expression: snapshot_payload
"exception_stacks.mechanism_type": [],
"exception_stacks.type": [],
"exception_stacks.value": [],
"features.key": [],
"features.value": [],
"group_id": 123,
"http_method": null,
"http_referer": null,
Expand Down
23 changes: 23 additions & 0 deletions snuba/datasets/processors/errors_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ def extract_promoted_contexts(
if trace_sampled:
output["trace_sampled"] = bool(trace_sampled)

extract_features_context(output, contexts)

def extract_common(
self,
output: MutableMapping[str, Any],
Expand Down Expand Up @@ -460,3 +462,24 @@ def extract_sdk(
if i:
sdk_integrations.append(i)
output["sdk_integrations"] = sdk_integrations


def extract_features_context(
output: MutableMapping[str, Any],
contexts: MutableMapping[str, Any],
) -> None:
features_keys = []
features_values = []
_flags = contexts.get("flags", {})
if isinstance(_flags, dict):
_features_inner = _flags.get("values", [])
if isinstance(_features_inner, list):
for flag in _features_inner:
if isinstance(flag, dict):
key = _unicodify(flag.get("key"))
if key is not None:
features_keys.append(key)
features_values.append(_unicodify(flag.get("value")))

output["features.key"] = features_keys
output["features.value"] = features_values
Loading
Loading