Skip to content

Commit

Permalink
Merge branch 'main' into feat/mongo-relationMode-prismaSkipIntegrity
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzSiL3Nce authored Dec 13, 2024
2 parents 85ae7c8 + 3872ce4 commit da66aba
Show file tree
Hide file tree
Showing 32 changed files with 660 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ concurrency:

jobs:
run:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
Expand All @@ -34,7 +34,7 @@ jobs:
run: cargo codspeed build -p request-handlers --features all

- name: Run the benchmarks
uses: CodSpeedHQ/action@v2
uses: CodSpeedHQ/action@v3
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test-driver-adapters-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: "Setup pnpm"
uses: pnpm/action-setup@v4.0.0
with:
version: 8
version: 9

- name: "Login to Docker Hub"
uses: docker/login-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wasm-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: "Setup pnpm"
uses: pnpm/action-setup@v4.0.0
with:
version: 8
version: 9

- name: "Login to Docker Hub"
uses: docker/login-action@v3
Expand Down
28 changes: 25 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ build-driver-adapters-kit: build-driver-adapters

build-driver-adapters: ensure-prisma-present
@echo "Building driver adapters..."
@cd ../prisma && pnpm --filter "*adapter*" i
@cd ../prisma && pnpm i
@echo "Driver adapters build completed.";

ensure-prisma-present:
Expand Down
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions libs/telemetry/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ impl TraceParent {
}
}

// TODO(aqrln): remove this method once the log capturing doesn't rely on trace IDs anymore
#[deprecated = "this must only be used to create an artificial traceparent for log capturing when tracing is disabled on the client"]
pub fn new_random() -> Self {
Self {
trace_id: TraceId::from_bytes(rand::random()),
Expand Down
2 changes: 1 addition & 1 deletion nix/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ in

nodejs_20
nodejs_20.pkgs.typescript-language-server
pnpm_8
pnpm_9

binaryen
cargo-insta
Expand Down
32 changes: 19 additions & 13 deletions psl/parser-database/src/attributes/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,16 @@ fn validate_uid_int_args<const N: usize>(
}

match args.first().map(|arg| &arg.value) {
Some(ast::Expression::NumericValue(val, _)) if !valid_values.contains(&val.parse::<u8>().unwrap()) => {
let valid_values_str = format_valid_values(valid_values);
ctx.push_attribute_validation_error(&format!(
"`{fn_name}()` takes either no argument, or a single integer argument which is either {valid_values_str}.",
));
}
None | Some(ast::Expression::NumericValue(_, _)) => accept(ctx),
Some(ast::Expression::NumericValue(val, _)) => match val.parse::<u8>().ok() {
Some(val) if valid_values.contains(&val) => accept(ctx),
_ => {
let valid_values_str = format_valid_values(valid_values);
ctx.push_attribute_validation_error(&format!(
"`{fn_name}()` takes either no argument, or a single integer argument which is either {valid_values_str}.",
));
}
},
None => accept(ctx),
_ => bail(),
}
}
Expand All @@ -430,12 +433,15 @@ fn validate_nanoid_args(args: &[ast::Argument], accept: AcceptFn<'_>, ctx: &mut
}

match args.first().map(|arg| &arg.value) {
Some(ast::Expression::NumericValue(val, _)) if val.parse::<u8>().unwrap() < 2 => {
ctx.push_attribute_validation_error(
"`nanoid()` takes either no argument, or a single integer argument >= 2.",
);
}
None | Some(ast::Expression::NumericValue(_, _)) => accept(ctx),
Some(ast::Expression::NumericValue(val, _)) => match val.parse::<u8>().ok() {
Some(val) if val >= 2 => accept(ctx),
_ => {
ctx.push_attribute_validation_error(
"`nanoid()` takes either no argument, or a single integer argument between 2 and 255.",
);
}
},
None => accept(ctx),
_ => bail(),
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
datasource db {
provider = "mysql"
url = "does_not_matter"
}

model Category {
id String @id @default(cuid(256))
}
// error: Error parsing attribute "@default": `cuid()` takes either no argument, or a single integer argument which is either 1 or 2.
// --> schema.prisma:7
//  | 
//  6 | model Category {
//  7 |  id String @id @default(cuid(256))
//  | 
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
datasource db {
provider = "mysql"
url = "does_not_matter"
}

model Category {
id String @id @default(nanoid(256))
}
// error: Error parsing attribute "@default": `nanoid()` takes either no argument, or a single integer argument between 2 and 255.
// --> schema.prisma:7
//  | 
//  6 | model Category {
//  7 |  id String @id @default(nanoid(256))
//  | 
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ datasource db {
model Category {
id String @id @default(nanoid(1))
}
// [1;91merror[0m: [1mError parsing attribute "@default": `nanoid()` takes either no argument, or a single integer argument >= 2.[0m
// [1;91merror[0m: [1mError parsing attribute "@default": `nanoid()` takes either no argument, or a single integer argument between 2 and 255.[0m
// --> schema.prisma:7
//  | 
//  6 | model Category {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
datasource db {
provider = "mysql"
url = "does_not_matter"
}

model Category {
id String @id @default(uuid(256))
}
// error: Error parsing attribute "@default": `uuid()` takes either no argument, or a single integer argument which is either 4 or 7.
// --> schema.prisma:7
//  | 
//  6 | model Category {
//  7 |  id String @id @default(uuid(256))
//  | 
1 change: 1 addition & 0 deletions quaint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ quaint-test-macros = { path = "quaint-test-macros" }
quaint-test-setup = { path = "quaint-test-setup" }
tokio = { version = "1", features = ["macros", "time"] }
expect-test = "1"
tracing-test = "0.2"

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { workspace = true, features = ["js"] }
Expand Down
32 changes: 29 additions & 3 deletions quaint/src/connector/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tracing::{info_span, Instrument};

use crate::ast::{Params, Value};
use crosstarget_utils::time::ElapsedTimeCounter;
use std::future::Future;
use std::{fmt, future::Future};

pub async fn query<'a, F, T, U>(
tag: &'static str,
Expand All @@ -16,8 +16,12 @@ where
F: FnOnce() -> U + 'a,
U: Future<Output = crate::Result<T>>,
{
let span =
info_span!("quaint:query", "db.system" = db_system_name, "db.statement" = %query, "otel.kind" = "client");
let span = info_span!(
"quaint:query",
"db.system" = db_system_name,
"db.statement" = %QueryForTracing(query),
"otel.kind" = "client"
);
do_query(tag, query, params, f).instrument(span).await
}

Expand Down Expand Up @@ -97,3 +101,25 @@ fn trace_query<'a>(query: &'a str, params: &'a [Value<'_>], result: &str, start:
duration_ms = start.elapsed_time().as_millis() as u64,
);
}

struct QueryForTracing<'a>(&'a str);

impl fmt::Display for QueryForTracing<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let query = self
.0
.split_once("/* traceparent=")
.map_or(self.0, |(str, remainder)| {
if remainder
.split_once("*/")
.is_some_and(|(_, suffix)| suffix.trim_end().is_empty())
{
str
} else {
self.0
}
})
.trim();
write!(f, "{query}")
}
}
27 changes: 27 additions & 0 deletions quaint/src/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
};
use quaint_test_macros::test_each_connector;
use quaint_test_setup::Tags;
use tracing_test::traced_test;

#[test_each_connector]
async fn single_value(api: &mut dyn TestApi) -> crate::Result<()> {
Expand Down Expand Up @@ -3636,3 +3637,29 @@ async fn overflowing_int_errors_out(api: &mut dyn TestApi) -> crate::Result<()>

Ok(())
}

#[test_each_connector]
#[traced_test]
async fn traceparent_is_stripped_from_the_log(api: &mut dyn TestApi) -> crate::Result<()> {
api.conn()
.query_raw("SELECT 1 /* traceparent=1 */", &[])
.await?
.into_single()?;
let expected = r#"db.statement=SELECT 1 otel.kind="client""#.to_owned();
assert!(logs_contain(&expected), "expected logs to contain '{expected}'");

Ok(())
}

#[test_each_connector]
#[traced_test]
async fn traceparent_inside_of_query_isnt_stripped_from_log(api: &mut dyn TestApi) -> crate::Result<()> {
api.conn()
.query_raw("SELECT /* traceparent=1 */ 1", &[])
.await?
.into_single()?;
let expected = r#"db.statement=SELECT /* traceparent=1 */ 1 otel.kind="client""#.to_owned();
assert!(logs_contain(&expected), "expected logs to contain '{expected}'");

Ok(())
}
Loading

0 comments on commit da66aba

Please sign in to comment.