Skip to content

Commit 21bb502

Browse files
authored
Adds testing to bytestream backwards compatibility (TraceMachina#1979)
1 parent 0c02306 commit 21bb502

2 files changed

Lines changed: 72 additions & 6 deletions

File tree

nativelink-config/src/backcompat.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,45 @@ mod tests {
190190
let value: FullConfig = serde_json::from_value(json).unwrap();
191191
assert_eq!(value.cas, None);
192192
}
193+
194+
#[derive(Debug, Deserialize, Serialize, PartialEq)]
195+
struct FullBytestreamConfig {
196+
#[serde(default, deserialize_with = "opt_bytestream")]
197+
pub bytestream: Option<Vec<WithInstanceName<ByteStreamConfig>>>,
198+
}
199+
200+
#[test]
201+
#[traced_test]
202+
fn test_bytestream_old_config() {
203+
let old_format = json!({
204+
"bytestream": {
205+
"cas_stores": {
206+
"": "WORKER_FAST_SLOW_STORE"
207+
}}
208+
});
209+
210+
let new_format = json!({
211+
"bytestream": [
212+
{
213+
"cas_store": "WORKER_FAST_SLOW_STORE",
214+
},
215+
],
216+
});
217+
218+
let old_format: FullBytestreamConfig = serde_json::from_value(old_format).unwrap();
219+
let new_format: FullBytestreamConfig = serde_json::from_value(new_format).unwrap();
220+
221+
assert_eq!(old_format, new_format);
222+
223+
logs_assert(|lines: &[&str]| {
224+
if lines.len() != 1 {
225+
return Err(format!("Expected 1 log line, got: {lines:?}"));
226+
}
227+
let line = lines[0];
228+
// TODO(palfrey): we should be checking the whole thing, but tracing-test is broken with multi-line items
229+
// See https://github.com/dbrgn/tracing-test/issues/48
230+
assert!(line.ends_with("WARNING: Using deprecated map format for services. Please migrate to the new array format:"));
231+
Ok(())
232+
});
233+
}
193234
}

nativelink-config/src/cas_server.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ pub struct PushConfig {
176176
pub read_only: bool,
177177
}
178178

179-
#[derive(Deserialize, Serialize, Debug, Default)]
179+
// From https://github.com/serde-rs/serde/issues/818#issuecomment-287438544
180+
fn default<T: Default + PartialEq>(t: &T) -> bool {
181+
*t == Default::default()
182+
}
183+
184+
#[derive(Deserialize, Serialize, Debug, Default, PartialEq, Eq)]
180185
#[serde(deny_unknown_fields)]
181186
pub struct ByteStreamConfig {
182187
/// Name of the store in the "stores" configuration.
@@ -188,7 +193,11 @@ pub struct ByteStreamConfig {
188193
///
189194
///
190195
/// Default: 64KiB
191-
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
196+
#[serde(
197+
default,
198+
deserialize_with = "convert_data_size_with_shellexpand",
199+
skip_serializing_if = "default"
200+
)]
192201
pub max_bytes_per_stream: usize,
193202

194203
/// In the event a client disconnects while uploading a blob, we will hold
@@ -197,7 +206,11 @@ pub struct ByteStreamConfig {
197206
/// the same blob.
198207
///
199208
/// Default: 10 (seconds)
200-
#[serde(default, deserialize_with = "convert_duration_with_shellexpand")]
209+
#[serde(
210+
default,
211+
deserialize_with = "convert_duration_with_shellexpand",
212+
skip_serializing_if = "default"
213+
)]
201214
pub persist_stream_on_disconnect_timeout: usize,
202215
}
203216

@@ -208,11 +221,23 @@ pub struct ByteStreamConfig {
208221
#[serde(deny_unknown_fields)]
209222
pub struct OldByteStreamConfig {
210223
pub cas_stores: HashMap<InstanceName, StoreRefName>,
211-
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
224+
#[serde(
225+
default,
226+
deserialize_with = "convert_data_size_with_shellexpand",
227+
skip_serializing_if = "default"
228+
)]
212229
pub max_bytes_per_stream: usize,
213-
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
230+
#[serde(
231+
default,
232+
deserialize_with = "convert_data_size_with_shellexpand",
233+
skip_serializing_if = "default"
234+
)]
214235
pub max_decoding_message_size: usize,
215-
#[serde(default, deserialize_with = "convert_duration_with_shellexpand")]
236+
#[serde(
237+
default,
238+
deserialize_with = "convert_duration_with_shellexpand",
239+
skip_serializing_if = "default"
240+
)]
216241
pub persist_stream_on_disconnect_timeout: usize,
217242
}
218243

0 commit comments

Comments
 (0)