-
Notifications
You must be signed in to change notification settings - Fork 2
[CRE-1299] - support white listed requests #113
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,7 @@ pub struct Submission { | |
| pub chunks_done: ChunkCount, | ||
| pub chunk_size: ChunkSize, | ||
| pub metadata: Option<Metadata>, | ||
| pub strategic_metadata: Option<StrategicMetadataMap>, | ||
| pub otel_trace_carrier: String, | ||
| } | ||
|
|
||
|
|
@@ -224,6 +225,7 @@ impl Submission { | |
| chunks_done: ChunkCount::zero(), | ||
| chunk_size: ChunkSize::default(), | ||
| metadata: None, | ||
| strategic_metadata: None, | ||
| otel_trace_carrier, | ||
| } | ||
| } | ||
|
|
@@ -243,6 +245,7 @@ impl Submission { | |
| chunks_done: ChunkCount::zero(), | ||
| chunk_size, | ||
| metadata, | ||
| strategic_metadata: None, | ||
| otel_trace_carrier, | ||
| }; | ||
| let chunks = chunks | ||
|
|
@@ -268,7 +271,7 @@ pub mod db { | |
| db::{Connection, True, WriterConnection, WriterPool}, | ||
| }; | ||
| use chunk::ChunkSize; | ||
| use sqlx::{query, query_as, Sqlite}; | ||
| use sqlx::{query, Sqlite}; | ||
|
|
||
| use axum_prometheus::metrics::{counter, histogram}; | ||
|
|
||
|
|
@@ -421,6 +424,7 @@ pub mod db { | |
| chunks_done: ChunkCount::zero(), | ||
| chunk_size, | ||
| metadata, | ||
| strategic_metadata: None, | ||
| otel_trace_carrier, | ||
| }; | ||
| let iter = chunks_contents | ||
|
|
@@ -461,25 +465,37 @@ pub mod db { | |
| id: SubmissionId, | ||
| mut conn: impl Connection, | ||
| ) -> Result<Submission, E<DatabaseError, SubmissionNotFound>> { | ||
| let submission = query_as!( | ||
| Submission, | ||
| let submission_row = query!( | ||
| r#" | ||
| SELECT id AS "id: SubmissionId" | ||
| , prefix | ||
| , chunks_total AS "chunks_total: ChunkCount" | ||
| , chunks_done AS "chunks_done: ChunkCount" | ||
| , chunk_size AS "chunk_size: ChunkSize" | ||
| , chunk_size AS "chunk_size!: ChunkSize" | ||
| , metadata | ||
| , ( SELECT json_group_object(metadata_key, metadata_value) | ||
| FROM submissions_metadata | ||
| WHERE submission_id = submissions.id | ||
| ) AS "strategic_metadata: sqlx::types::Json<StrategicMetadataMap>" | ||
| , otel_trace_carrier | ||
| FROM submissions WHERE id = $1 | ||
| "#, | ||
| id | ||
| ) | ||
| .fetch_optional(conn.get_inner()) | ||
| .await?; | ||
| match submission { | ||
| match submission_row { | ||
| None => Err(E::R(SubmissionNotFound(id))), | ||
| Some(submission) => Ok(submission), | ||
| Some(row) => Ok(Submission { | ||
| id: row.id, | ||
| prefix: row.prefix, | ||
| chunks_total: row.chunks_total, | ||
| chunks_done: row.chunks_done, | ||
| chunk_size: row.chunk_size, | ||
| metadata: row.metadata, | ||
| strategic_metadata: row.strategic_metadata.map(|json| json.0), | ||
| otel_trace_carrier: row.otel_trace_carrier, | ||
| }), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -535,24 +551,37 @@ pub mod db { | |
| // NOTE: The order is important here; a concurrent writer could move a submission | ||
| // from InProgress to Completed/Failed in-between the queries. | ||
|
|
||
| let submission = query_as!( | ||
| Submission, | ||
| let submission_row = query!( | ||
| r#" | ||
| SELECT | ||
| id AS "id: SubmissionId" | ||
| , prefix | ||
| , chunks_total AS "chunks_total: ChunkCount" | ||
| , chunks_done AS "chunks_done: ChunkCount" | ||
| , chunk_size AS "chunk_size: ChunkSize" | ||
| , chunk_size AS "chunk_size!: ChunkSize" | ||
| , metadata | ||
| , ( SELECT json_group_object(metadata_key, metadata_value) | ||
| FROM submissions_metadata | ||
| WHERE submission_id = submissions.id | ||
| ) AS "strategic_metadata: sqlx::types::Json<StrategicMetadataMap>" | ||
| , otel_trace_carrier | ||
| FROM submissions WHERE id = $1 | ||
| "#, | ||
| id | ||
| ) | ||
| .fetch_optional(conn.get_inner()) | ||
| .await?; | ||
| if let Some(submission) = submission { | ||
| if let Some(row) = submission_row { | ||
| let submission = Submission { | ||
| id: row.id, | ||
| prefix: row.prefix, | ||
| chunks_total: row.chunks_total, | ||
| chunks_done: row.chunks_done, | ||
| chunk_size: row.chunk_size, | ||
| metadata: row.metadata, | ||
| strategic_metadata: row.strategic_metadata.map(|json| json.0), | ||
| otel_trace_carrier: row.otel_trace_carrier, | ||
| }; | ||
| return Ok(Some(SubmissionStatus::InProgress(submission))); | ||
| } | ||
|
|
||
|
|
@@ -1046,6 +1075,11 @@ pub mod test { | |
| .expect("insertion failed"); | ||
|
|
||
| let fetched_submission = get_submission(submission.id, &mut conn).await.unwrap(); | ||
| // When fetched from DB with no metadata rows, json_group_object returns '{}'. | ||
|
Contributor
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. Ah so there is no distinction between Reading a bit further indeed shows to me that we can also remove the |
||
| let submission = Submission { | ||
| strategic_metadata: Some(Default::default()), | ||
| ..submission | ||
| }; | ||
| assert_eq!(fetched_submission, submission); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to point out that for the other queries we also assert the query plan. This allows us to spot potentially very bad execution behaviour. Could you add that for these queries?