Skip to content

Commit c65a490

Browse files
Sujay JayakarConvex, Inc.
authored andcommitted
Port scheduler tests to isolate2 (#24851)
GitOrigin-RevId: 6c433fa30b997b6018a3f511f75c2c7de84fbc4d
1 parent f0898cc commit c65a490

File tree

10 files changed

+443
-416
lines changed

10 files changed

+443
-416
lines changed

crates/isolate/src/environment/action/mod.rs

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ use self::{
111111
task_executor::TaskExecutor,
112112
};
113113
use super::warnings::{
114-
add_warning_if_approaching_duration_limit,
115-
add_warning_if_approaching_limit,
114+
approaching_duration_limit_warning,
115+
approaching_limit_warning,
116+
SystemWarning,
116117
};
117118
use crate::{
118119
client::{
@@ -942,29 +943,31 @@ impl<RT: Runtime> ActionEnvironment<RT> {
942943
arguments: &ConvexArray,
943944
result: Option<&ConvexValue>,
944945
) -> anyhow::Result<()> {
945-
add_warning_if_approaching_limit(
946-
self,
946+
if let Some(warning) = approaching_limit_warning(
947947
arguments.size(),
948948
*FUNCTION_MAX_ARGS_SIZE,
949949
"FunctionArgumentsTooLarge",
950950
|| "Large size of the action arguments".to_string(),
951951
None,
952952
Some(" bytes"),
953953
None,
954-
)?;
954+
)? {
955+
self.trace_system(warning)?;
956+
}
955957
self.add_warnings_to_log_lines(execution_time)?;
956958

957959
if let Some(result) = result {
958-
add_warning_if_approaching_limit(
959-
self,
960+
if let Some(warning) = approaching_limit_warning(
960961
result.size(),
961962
*FUNCTION_MAX_RESULT_SIZE,
962963
"TooLargeFunctionResult",
963964
|| "Large size of the action return value".to_string(),
964965
None,
965966
Some(" bytes"),
966967
None,
967-
)?
968+
)? {
969+
self.trace_system(warning)?;
970+
}
968971
};
969972
Ok(())
970973
}
@@ -980,16 +983,17 @@ impl<RT: Runtime> ActionEnvironment<RT> {
980983
return Ok(());
981984
};
982985
if let Some(body) = response.body.as_ref() {
983-
add_warning_if_approaching_limit(
984-
self,
986+
if let Some(warning) = approaching_limit_warning(
985987
body.len(),
986988
HTTP_ACTION_BODY_LIMIT,
987989
"HttpResponseTooLarge",
988990
|| "Large response returned from an HTTP action".to_string(),
989991
None,
990992
Some(" bytes"),
991993
None,
992-
)?;
994+
)? {
995+
self.trace_system(warning)?;
996+
}
993997
};
994998
Ok(())
995999
}
@@ -1003,21 +1007,30 @@ impl<RT: Runtime> ActionEnvironment<RT> {
10031007
let total_dangling_tasks = dangling_task_counts.values().sum();
10041008
let task_names = dangling_task_counts.keys().join(", ");
10051009
log_unawaited_pending_op(total_dangling_tasks, "action");
1006-
self.trace_system(LogLevel::Warn, vec![format!(
1007-
"{total_dangling_tasks} unawaited operation{}: [{task_names}]. Async operations should be awaited or they might not run. \
1008-
See https://docs.convex.dev/functions/actions#dangling-promises for more information.",
1009-
if total_dangling_tasks == 1 { "" } else { "s" },
1010-
)], SystemLogMetadata { code: "UnawaitedOperations".to_string() })?;
1010+
let message = format!(
1011+
"{total_dangling_tasks} unawaited operation{}: [{task_names}]. Async operations should be awaited or they might not run. \
1012+
See https://docs.convex.dev/functions/actions#dangling-promises for more information.",
1013+
if total_dangling_tasks == 1 { "" } else { "s" },
1014+
);
1015+
let warning = SystemWarning {
1016+
level: LogLevel::Warn,
1017+
messages: vec![message],
1018+
system_log_metadata: SystemLogMetadata {
1019+
code: "UnawaitedOperations".to_string(),
1020+
},
1021+
};
1022+
self.trace_system(warning)?;
10111023
}
1012-
1013-
add_warning_if_approaching_duration_limit(
1014-
self,
1024+
if let Some(warning) = approaching_duration_limit_warning(
10151025
execution_time.elapsed,
10161026
execution_time.limit,
10171027
"UserTimeout",
10181028
"Function execution took a long time",
10191029
None,
1020-
)
1030+
)? {
1031+
self.trace_system(warning)?;
1032+
}
1033+
Ok(())
10211034
}
10221035

10231036
fn dangling_task_counts(&self) -> BTreeMap<String, usize> {
@@ -1051,6 +1064,17 @@ impl<RT: Runtime> ActionEnvironment<RT> {
10511064
.expect("TaskExecutor went away?");
10521065
Ok(())
10531066
}
1067+
1068+
fn trace_system(&mut self, warning: SystemWarning) -> anyhow::Result<()> {
1069+
self.log_line_sender
1070+
.unbounded_send(LogLine::new_system_log_line(
1071+
warning.level,
1072+
warning.messages,
1073+
self.rt.unix_timestamp(),
1074+
warning.system_log_metadata,
1075+
))?;
1076+
Ok(())
1077+
}
10541078
}
10551079

10561080
impl<RT: Runtime> IsolateEnvironment<RT> for ActionEnvironment<RT> {
@@ -1084,22 +1108,6 @@ impl<RT: Runtime> IsolateEnvironment<RT> for ActionEnvironment<RT> {
10841108
Ok(())
10851109
}
10861110

1087-
fn trace_system(
1088-
&mut self,
1089-
level: LogLevel,
1090-
messages: Vec<String>,
1091-
system_log_metadata: SystemLogMetadata,
1092-
) -> anyhow::Result<()> {
1093-
self.log_line_sender
1094-
.unbounded_send(LogLine::new_system_log_line(
1095-
level,
1096-
messages,
1097-
self.rt.unix_timestamp(),
1098-
system_log_metadata,
1099-
))?;
1100-
Ok(())
1101-
}
1102-
11031111
fn rng(&mut self) -> anyhow::Result<&mut ChaCha12Rng> {
11041112
self.phase.rng()
11051113
}

crates/isolate/src/environment/analyze.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ use common::{
1515
DATABASE_UDF_SYSTEM_TIMEOUT,
1616
DATABASE_UDF_USER_TIMEOUT,
1717
},
18-
log_lines::{
19-
LogLevel,
20-
SystemLogMetadata,
21-
},
18+
log_lines::LogLevel,
2219
runtime::{
2320
Runtime,
2421
UnixTimestamp,
@@ -132,19 +129,6 @@ impl<RT: Runtime> IsolateEnvironment<RT> for AnalyzeEnvironment {
132129
Ok(())
133130
}
134131

135-
fn trace_system(
136-
&mut self,
137-
_level: LogLevel,
138-
messages: Vec<String>,
139-
_system_log_metadata: SystemLogMetadata,
140-
) -> anyhow::Result<()> {
141-
tracing::warn!(
142-
"Unexpected Console access at import time: {}",
143-
messages.join(" ")
144-
);
145-
Ok(())
146-
}
147-
148132
fn rng(&mut self) -> anyhow::Result<&mut ChaCha12Rng> {
149133
Ok(&mut self.rng)
150134
}

crates/isolate/src/environment/auth_config.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use common::{
1010
DATABASE_UDF_SYSTEM_TIMEOUT,
1111
DATABASE_UDF_USER_TIMEOUT,
1212
},
13-
log_lines::{
14-
LogLevel,
15-
SystemLogMetadata,
16-
},
13+
log_lines::LogLevel,
1714
runtime::{
1815
Runtime,
1916
UnixTimestamp,
@@ -86,19 +83,6 @@ impl<RT: Runtime> IsolateEnvironment<RT> for AuthConfigEnvironment {
8683
Ok(())
8784
}
8885

89-
fn trace_system(
90-
&mut self,
91-
_level: LogLevel,
92-
messages: Vec<String>,
93-
_system_log_metadata: SystemLogMetadata,
94-
) -> anyhow::Result<()> {
95-
tracing::warn!(
96-
"Unexpected Console access when evaluating auth config file: {}",
97-
messages.join(" ")
98-
);
99-
Ok(())
100-
}
101-
10286
fn rng(&mut self) -> anyhow::Result<&mut ChaCha12Rng> {
10387
anyhow::bail!(ErrorMetadata::bad_request(
10488
"NoRandomDuringAuthConfig",

crates/isolate/src/environment/mod.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ pub mod auth_config;
1111
pub mod helpers;
1212
pub mod schema;
1313
pub mod udf;
14-
mod warnings;
14+
pub mod warnings;
1515

1616
use common::{
1717
errors::JsError,
18-
log_lines::{
19-
LogLevel,
20-
SystemLogMetadata,
21-
},
18+
log_lines::LogLevel,
2219
runtime::{
2320
Runtime,
2421
UnixTimestamp,
@@ -79,12 +76,6 @@ pub trait IsolateEnvironment<RT: Runtime>: 'static {
7976
) -> anyhow::Result<()>;
8077

8178
fn trace(&mut self, level: LogLevel, messages: Vec<String>) -> anyhow::Result<()>;
82-
fn trace_system(
83-
&mut self,
84-
level: LogLevel,
85-
messages: Vec<String>,
86-
system_log_metadata: SystemLogMetadata,
87-
) -> anyhow::Result<()>;
8879
fn rng(&mut self) -> anyhow::Result<&mut ChaCha12Rng>;
8980
fn unix_timestamp(&self) -> anyhow::Result<UnixTimestamp>;
9081

crates/isolate/src/environment/schema.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use common::{
66
DATABASE_UDF_SYSTEM_TIMEOUT,
77
DATABASE_UDF_USER_TIMEOUT,
88
},
9-
log_lines::{
10-
LogLevel,
11-
SystemLogMetadata,
12-
},
9+
log_lines::LogLevel,
1310
runtime::{
1411
Runtime,
1512
UnixTimestamp,
@@ -82,19 +79,6 @@ impl<RT: Runtime> IsolateEnvironment<RT> for SchemaEnvironment {
8279
Ok(())
8380
}
8481

85-
fn trace_system(
86-
&mut self,
87-
_level: LogLevel,
88-
messages: Vec<String>,
89-
_system_log_metadata: SystemLogMetadata,
90-
) -> anyhow::Result<()> {
91-
tracing::warn!(
92-
"Unexpected Console access at schema evaluation time: {}",
93-
messages.join(" ")
94-
);
95-
Ok(())
96-
}
97-
9882
fn rng(&mut self) -> anyhow::Result<&mut ChaCha12Rng> {
9983
Ok(&mut self.rng)
10084
}

0 commit comments

Comments
 (0)