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: decrypted notifications analytics #286

Merged
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
1 change: 1 addition & 0 deletions src/analytics/client_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ pub struct ClientInfo {
pub project_id: Arc<str>,
pub client_id: Arc<str>,
pub push_provider: Arc<str>,
pub always_raw: bool,
pub registered_at: chrono::NaiveDateTime,
}
7 changes: 4 additions & 3 deletions src/analytics/message_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ pub struct MessageInfo {
pub client_id: Arc<str>,
pub topic: Arc<str>,
pub push_provider: Arc<str>,
pub always_encrypted: bool,
pub encrypted: bool,
pub flags: u32,
pub always_raw: Option<bool>,
pub tag: Option<u32>,
pub encrypted: Option<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking. It's a bit confusing to have always_raw and encrypted. The value from encrypted comes from body.legacy maybe we should use legacy_encrypted? So it will not confuse the data team as well.

Copy link
Member Author

@chris13524 chris13524 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't change the scheme since there is already data that's been exported using it. We'd have to wipe the data or adjust queries to exclude the old schema, which can be done but in this case doesn't seem necessary

pub flags: Option<u32>,
pub status: u16,
pub response_message: Option<Arc<str>>,
pub received_at: chrono::NaiveDateTime,
Expand Down
30 changes: 11 additions & 19 deletions src/handlers/push_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,10 @@ pub async fn handler_internal(
.unwrap_or("error: no topic".to_owned().into()),
),
push_provider: "unknown".into(),
always_encrypted: body.raw.is_some(),
encrypted: body
.legacy
.as_ref()
.map(|m| m.payload.is_encrypted())
.unwrap_or(false),
flags: body.legacy.as_ref().map(|m| m.payload.flags).unwrap_or(0),
always_raw: None,
tag: body.raw.as_ref().map(|m| m.tag),
encrypted: body.legacy.as_ref().map(|m| m.payload.is_encrypted()),
flags: body.legacy.as_ref().map(|m| m.payload.flags),
status: 0,
response_message: None,
received_at: wc::analytics::time::now(),
Expand Down Expand Up @@ -212,18 +209,13 @@ pub async fn handler_internal(
client_id: client_id.clone().into(),
topic: push_message.topic(),
push_provider: client.push_type.as_str().into(),
always_encrypted: match push_message {
PushMessage::RawPushMessage(_) => true,
PushMessage::LegacyPushMessage(_) => false,
},
encrypted: match push_message {
PushMessage::RawPushMessage(_) => false,
PushMessage::LegacyPushMessage(ref msg) => msg.payload.is_encrypted(),
},
flags: match push_message {
PushMessage::RawPushMessage(_) => 0,
PushMessage::LegacyPushMessage(ref msg) => msg.payload.flags,
},
always_raw: Some(client.always_raw),
tag: cloned_body.raw.as_ref().map(|m| m.tag),
encrypted: cloned_body
.legacy
.as_ref()
.map(|m| m.payload.is_encrypted()),
flags: cloned_body.legacy.as_ref().map(|m| m.payload.flags),
status: 0,
response_message: None,
received_at: wc::analytics::time::now(),
Expand Down
4 changes: 3 additions & 1 deletion src/handlers/register_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ pub async fn handler(
.trim_start_matches(DECENTRALIZED_IDENTIFIER_PREFIX)
.to_owned();

let always_raw = body.always_raw.unwrap_or(false);
state
.client_store
.create_client(&tenant_id, &client_id, Client {
tenant_id: tenant_id.clone(),
push_type,
token: body.token,
always_raw: body.always_raw.unwrap_or(false),
always_raw,
})
.await?;

Expand Down Expand Up @@ -130,6 +131,7 @@ pub async fn handler(
project_id: tenant_id.into(),
client_id: client_id.into(),
push_provider: body.push_type.as_str().into(),
always_raw,
registered_at: wc::analytics::time::now(),
};

Expand Down
Loading