-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
86 additions
and
52 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[env] | ||
# Force SQLX to run in offline mode for CI. Devs can change this if they want, to live code against the DB, | ||
# but we use it at the workspace level here to allow use of sqlx macros across all crates | ||
SQLX_OFFLINE = "true" | ||
SQLX_OFFLINE = "false" |
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 |
---|---|---|
@@ -1,37 +1,84 @@ | ||
use sqlx::{types::Uuid, Executor, Postgres}; | ||
use std::hash::Hash; | ||
use uuid::Uuid; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct ErrorTrackingGroup { | ||
pub struct ErrorTrackingIssueFingerprint { | ||
pub id: Uuid, | ||
pub team_id: i32, | ||
pub fingerprint: String, | ||
pub issue_id: Uuid, | ||
pub version: i64, | ||
} | ||
|
||
pub struct ErrorTrackingGroup { | ||
pub id: Uuid, | ||
pub team_id: i32, | ||
pub fingerprint: String, | ||
} | ||
|
||
impl Hash for ErrorTrackingGroup { | ||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
self.team_id.hash(state); | ||
self.fingerprint.hash(state); | ||
pub async fn error_tracking_issue_for_fingerprint<'c, E>( | ||
executor: E, | ||
team_id: i32, | ||
fingerprint: String, | ||
) -> Uuid | ||
where | ||
E: sqlx::Executor<'c, Database = sqlx::Postgres>, | ||
{ | ||
let res = sqlx::query_as!( | ||
ErrorTrackingIssueFingerprint, | ||
r#" | ||
SELECT * | ||
FROM posthog_errortrackingissuefingerprint | ||
WHERE team_id = $1 AND fingerprint = $2 | ||
ORDER BY version DESC | ||
"#, | ||
team_id, | ||
fingerprint | ||
) | ||
.fetch_one(executor) | ||
.await; | ||
|
||
match res { | ||
Ok(issue_fingerprint) => issue_fingerprint.issue_id, | ||
Err(_) => { | ||
return create_error_tracking_issue(executor, team_id, fingerprint).await; | ||
} | ||
} | ||
} | ||
|
||
impl ErrorTrackingGroup { | ||
pub async fn issue<'c, E>(&self, executor: E) -> Result<(), sqlx::Error> | ||
where | ||
E: Executor<'c, Database = Postgres>, | ||
{ | ||
sqlx::query!( | ||
r#" | ||
INSERT INTO posthog_errortrackinggroup (id, fingerprint, team_id, created_at) | ||
VALUES ($1, $2, $3, NOW()) ON CONFLICT | ||
ON CONSTRAINT posthog_eventdefinition_team_id_name_80fa0b87_uniq | ||
DO UPDATE SET created_at = $4 | ||
pub async fn create_error_tracking_issue<'c, E>( | ||
executor: E, | ||
team_id: i32, | ||
fingerprint: String, | ||
) -> Uuid | ||
where | ||
E: sqlx::Executor<'c, Database = sqlx::Postgres>, | ||
{ | ||
let issue_id = Uuid::now_v7(); | ||
|
||
sqlx::query!( | ||
r#" | ||
INSERT INTO posthog_errortrackinggroup (id, team_id, fingerprint) | ||
VALUES ($1, $2, $3) | ||
"#, | ||
Uuid::now_v7(), | ||
self.fingerprint, | ||
self.team_id, | ||
) | ||
.execute(executor) | ||
.await | ||
.map(|_| ()) | ||
} | ||
issue_id, | ||
team_id, | ||
fingerprint | ||
) | ||
.execute(executor) | ||
.await; | ||
|
||
sqlx::query!( | ||
r#" | ||
INSERT INTO posthog_errortrackingissuefingerprint (team_id, fingerprint, issue_id) | ||
VALUES ($1, $2, $3) | ||
"#, | ||
team_id, | ||
fingerprint, | ||
issue_id | ||
) | ||
.execute(executor) | ||
.await; | ||
|
||
// TODO: write to Kafka | ||
|
||
issue_id | ||
} |