1use crate::config::PipelineConfigProgramInfo;
2use crate::program_schema::ProgramSchema;
3use feldera_ir::{MirNode, MirNodeId};
4use serde::{Deserialize, Serialize};
5use std::{
6 collections::{BTreeMap, HashMap},
7 fmt::Display,
8};
9use utoipa::ToSchema;
10
11#[derive(Debug, Default, Clone, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
13pub struct ProgramDiff {
14 added_tables: Vec<String>,
15 removed_tables: Vec<String>,
16 modified_tables: Vec<String>,
17
18 added_views: Vec<String>,
19 removed_views: Vec<String>,
20 modified_views: Vec<String>,
21}
22
23impl Display for ProgramDiff {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 fn quoted_list(list: &[String]) -> String {
26 list.iter()
27 .map(|s| format!("'{}'", s))
28 .collect::<Vec<_>>()
29 .join(", ")
30 }
31
32 if !self.added_tables.is_empty() {
33 writeln!(f, "Added tables: {}", quoted_list(&self.added_tables))?;
34 }
35 if !self.removed_tables.is_empty() {
36 writeln!(f, "Removed tables: {}", quoted_list(&self.removed_tables))?;
37 }
38 if !self.modified_tables.is_empty() {
39 writeln!(f, "Modified tables: {}", quoted_list(&self.modified_tables))?;
40 }
41 if !self.added_views.is_empty() {
42 writeln!(f, "Added views: {}", quoted_list(&self.added_views))?;
43 }
44 if !self.removed_views.is_empty() {
45 writeln!(f, "Removed views: {}", quoted_list(&self.removed_views))?;
46 }
47 if !self.modified_views.is_empty() {
48 writeln!(f, "Modified views: {}", quoted_list(&self.modified_views))?;
49 }
50 Ok(())
51 }
52}
53
54impl ProgramDiff {
55 pub fn new() -> Self {
56 Self {
57 added_tables: Vec::new(),
58 removed_tables: Vec::new(),
59 modified_tables: Vec::new(),
60 added_views: Vec::new(),
61 removed_views: Vec::new(),
62 modified_views: Vec::new(),
63 }
64 }
65
66 pub fn with_added_tables(mut self, mut tables: Vec<String>) -> Self {
67 tables.sort();
68 self.added_tables = tables;
69 self
70 }
71
72 pub fn with_removed_tables(mut self, mut tables: Vec<String>) -> Self {
73 tables.sort();
74 self.removed_tables = tables;
75 self
76 }
77
78 pub fn with_modified_tables(mut self, mut tables: Vec<String>) -> Self {
79 tables.sort();
80 self.modified_tables = tables;
81 self
82 }
83
84 pub fn with_added_views(mut self, mut views: Vec<String>) -> Self {
85 views.sort();
86 self.added_views = views;
87 self
88 }
89
90 pub fn with_removed_views(mut self, mut views: Vec<String>) -> Self {
91 views.sort();
92 self.removed_views = views;
93 self
94 }
95
96 pub fn with_modified_views(mut self, mut views: Vec<String>) -> Self {
97 views.sort();
98 self.modified_views = views;
99 self
100 }
101
102 pub fn added_tables(&self) -> &Vec<String> {
103 &self.added_tables
104 }
105
106 pub fn removed_tables(&self) -> &Vec<String> {
107 &self.removed_tables
108 }
109
110 pub fn modified_tables(&self) -> &Vec<String> {
111 &self.modified_tables
112 }
113
114 pub fn added_views(&self) -> &Vec<String> {
115 &self.added_views
116 }
117
118 pub fn removed_views(&self) -> &Vec<String> {
119 &self.removed_views
120 }
121
122 pub fn modified_views(&self) -> &Vec<String> {
123 &self.modified_views
124 }
125
126 pub fn is_empty(&self) -> bool {
127 self.added_tables.is_empty()
128 && self.removed_tables.is_empty()
129 && self.modified_tables.is_empty()
130 && self.added_views.is_empty()
131 && self.removed_views.is_empty()
132 && self.modified_views.is_empty()
133 }
134
135 pub fn is_affected_relation(&self, relation_name: &str) -> bool {
136 let relation_name = relation_name.to_string();
137 self.added_tables.contains(&relation_name)
138 || self.removed_tables.contains(&relation_name)
139 || self.modified_tables.contains(&relation_name)
140 || self.added_views.contains(&relation_name)
141 || self.removed_views.contains(&relation_name)
142 || self.modified_views.contains(&relation_name)
143 }
144}
145
146#[derive(Debug, Serialize, Deserialize, ToSchema, Clone, PartialEq, Eq)]
148pub struct PipelineDiff {
149 program_diff: Option<ProgramDiff>,
151 program_diff_error: Option<String>,
152
153 added_input_connectors: Vec<String>,
154 modified_input_connectors: Vec<String>,
155 removed_input_connectors: Vec<String>,
156
157 added_output_connectors: Vec<String>,
158 modified_output_connectors: Vec<String>,
159 removed_output_connectors: Vec<String>,
160 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
163 view_integrals_moved: bool,
164}
165
166impl Display for PipelineDiff {
167 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
168 if let Some(err) = &self.program_diff_error {
169 writeln!(f, "Could not compute program diff: {err}")?;
170 }
171
172 if self.view_integrals_moved {
173 writeln!(
174 f,
175 "The checkpoint keeps the state of materialized views in another layout than the pipeline uses (see `dev_tweaks.view_integrals`), so the pipeline rebuilds it."
176 )?;
177 }
178
179 if let Some(diff) = &self.program_diff
180 && !diff.is_empty()
181 {
182 writeln!(f, "Program changes:")?;
183 for change in diff.to_string().lines() {
184 writeln!(f, " {change}")?;
185 }
186 }
187
188 if !self.added_input_connectors.is_empty() {
189 writeln!(
190 f,
191 "Added input connectors: {}",
192 self.added_input_connectors.join(", ")
193 )?;
194 }
195
196 if !self.removed_input_connectors.is_empty() {
197 writeln!(
198 f,
199 "Removed input connectors: {}",
200 self.removed_input_connectors.join(", ")
201 )?;
202 }
203
204 if !self.modified_input_connectors.is_empty() {
205 writeln!(
206 f,
207 "Modified input connectors: {}",
208 self.modified_input_connectors.join(", ")
209 )?;
210 }
211
212 if !self.added_output_connectors.is_empty() {
213 writeln!(
214 f,
215 "Added output connectors: {}",
216 self.added_output_connectors.join(", ")
217 )?;
218 }
219
220 if !self.removed_output_connectors.is_empty() {
221 writeln!(
222 f,
223 "Removed output connectors: {}",
224 self.removed_output_connectors.join(", ")
225 )?;
226 }
227
228 if !self.modified_output_connectors.is_empty() {
229 writeln!(
230 f,
231 "Modified output connectors: {}",
232 self.modified_output_connectors.join(", ")
233 )?;
234 }
235
236 Ok(())
237 }
238}
239
240impl PipelineDiff {
241 pub fn new(program_diff_or_err: Result<ProgramDiff, String>) -> Self {
242 match program_diff_or_err {
243 Ok(program_diff) => Self::new_with_program_diff(program_diff),
244 Err(program_diff_error) => Self::new_with_program_diff_error(program_diff_error),
245 }
246 }
247
248 pub fn new_with_program_diff(program_diff: ProgramDiff) -> Self {
249 Self {
250 program_diff: Some(program_diff),
251 program_diff_error: None,
252 added_input_connectors: Vec::new(),
253 modified_input_connectors: Vec::new(),
254 removed_input_connectors: Vec::new(),
255 added_output_connectors: Vec::new(),
256 modified_output_connectors: Vec::new(),
257 removed_output_connectors: Vec::new(),
258 view_integrals_moved: false,
259 }
260 }
261
262 pub fn new_with_program_diff_error(program_diff_error: String) -> Self {
263 Self {
264 program_diff: None,
265 program_diff_error: Some(program_diff_error),
266 added_input_connectors: Vec::new(),
267 modified_input_connectors: Vec::new(),
268 removed_input_connectors: Vec::new(),
269 added_output_connectors: Vec::new(),
270 modified_output_connectors: Vec::new(),
271 removed_output_connectors: Vec::new(),
272 view_integrals_moved: false,
273 }
274 }
275
276 pub fn with_added_input_connectors(mut self, mut connectors: Vec<String>) -> Self {
277 connectors.sort();
278 self.added_input_connectors = connectors;
279 self
280 }
281
282 pub fn with_modified_input_connectors(mut self, mut connectors: Vec<String>) -> Self {
283 connectors.sort();
284 self.modified_input_connectors = connectors;
285 self
286 }
287
288 pub fn with_removed_input_connectors(mut self, mut connectors: Vec<String>) -> Self {
289 connectors.sort();
290 self.removed_input_connectors = connectors;
291 self
292 }
293
294 pub fn with_added_output_connectors(mut self, mut connectors: Vec<String>) -> Self {
295 connectors.sort();
296 self.added_output_connectors = connectors;
297 self
298 }
299
300 pub fn with_modified_output_connectors(mut self, mut connectors: Vec<String>) -> Self {
301 connectors.sort();
302 self.modified_output_connectors = connectors;
303 self
304 }
305
306 pub fn with_removed_output_connectors(mut self, mut connectors: Vec<String>) -> Self {
307 connectors.sort();
308 self.removed_output_connectors = connectors;
309 self
310 }
311
312 pub fn with_view_integrals_moved(mut self) -> Self {
316 self.view_integrals_moved = true;
317 self
318 }
319
320 pub fn view_integrals_moved(&self) -> bool {
323 self.view_integrals_moved
324 }
325
326 pub fn is_empty(&self) -> bool {
327 self.program_diff
328 .as_ref()
329 .map(|diff| diff.is_empty())
330 .unwrap_or(false)
331 && self.added_input_connectors.is_empty()
332 && self.removed_input_connectors.is_empty()
333 && self.modified_input_connectors.is_empty()
334 && self.added_output_connectors.is_empty()
335 && self.removed_output_connectors.is_empty()
336 && self.modified_output_connectors.is_empty()
337 && !self.view_integrals_moved
338 }
339
340 pub fn clear_program_diff(&mut self) {
341 self.program_diff = Some(ProgramDiff::default());
342 }
343
344 pub fn is_affected_connector(&self, connector_name: &str) -> bool {
345 let connector_name = connector_name.to_string();
346 self.added_input_connectors.contains(&connector_name)
347 || self.removed_input_connectors.contains(&connector_name)
348 || self.modified_input_connectors.contains(&connector_name)
349 || self.added_output_connectors.contains(&connector_name)
350 || self.removed_output_connectors.contains(&connector_name)
351 || self.modified_output_connectors.contains(&connector_name)
352 }
353
354 pub fn is_affected_relation(&self, relation_name: &str) -> bool {
355 self.program_diff
356 .as_ref()
357 .map(|diff| diff.is_affected_relation(relation_name))
358 .unwrap_or(false)
359 }
360
361 pub fn program_diff(&self) -> Option<&ProgramDiff> {
362 self.program_diff.as_ref()
363 }
364
365 pub fn program_diff_error(&self) -> Option<&String> {
366 self.program_diff_error.as_ref()
367 }
368
369 pub fn added_input_connectors(&self) -> &Vec<String> {
370 &self.added_input_connectors
371 }
372
373 pub fn modified_input_connectors(&self) -> &Vec<String> {
374 &self.modified_input_connectors
375 }
376
377 pub fn removed_input_connectors(&self) -> &Vec<String> {
378 &self.removed_input_connectors
379 }
380
381 pub fn added_output_connectors(&self) -> &Vec<String> {
382 &self.added_output_connectors
383 }
384
385 pub fn modified_output_connectors(&self) -> &Vec<String> {
386 &self.modified_output_connectors
387 }
388
389 pub fn removed_output_connectors(&self) -> &Vec<String> {
390 &self.removed_output_connectors
391 }
392}
393
394pub fn program_diff(
395 old_mir: &HashMap<MirNodeId, MirNode>,
396 new_mir: &HashMap<MirNodeId, MirNode>,
397) -> ProgramDiff {
398 let old_tables: HashMap<String, String> = old_mir
399 .values()
400 .filter(|node| node.persistent_id.is_some())
401 .filter_map(|node| {
402 node.table
403 .as_ref()
404 .map(|name| (name.clone(), node.persistent_id.clone().unwrap()))
405 })
406 .collect();
407
408 let old_views: HashMap<String, String> = old_mir
409 .values()
410 .filter(|node| node.persistent_id.is_some())
411 .filter_map(|node| {
412 node.view
413 .as_ref()
414 .map(|name| (name.clone(), node.persistent_id.clone().unwrap()))
415 })
416 .collect();
417
418 let new_tables: HashMap<String, String> = new_mir
419 .values()
420 .filter(|node| node.persistent_id.is_some())
421 .filter_map(|node| {
422 node.table
423 .as_ref()
424 .map(|name| (name.clone(), node.persistent_id.clone().unwrap()))
425 })
426 .collect();
427
428 let new_views: HashMap<String, String> = new_mir
429 .values()
430 .filter(|node| node.persistent_id.is_some())
431 .filter_map(|node| {
432 node.view
433 .as_ref()
434 .map(|name| (name.clone(), node.persistent_id.clone().unwrap()))
435 })
436 .collect();
437
438 let added_tables = new_tables
439 .keys()
440 .filter(|k| !old_tables.contains_key(*k))
441 .cloned()
442 .collect();
443 let removed_tables = old_tables
444 .keys()
445 .filter(|k| !new_tables.contains_key(*k))
446 .cloned()
447 .collect();
448 let modified_tables = new_tables
449 .iter()
450 .filter_map(|(name, id)| {
451 if let Some(old_id) = old_tables.get(name) {
452 if old_id != id {
453 Some(name.clone())
454 } else {
455 None
456 }
457 } else {
458 None
459 }
460 })
461 .collect();
462
463 let added_views = new_views
464 .keys()
465 .filter(|k| !old_views.contains_key(*k))
466 .cloned()
467 .collect();
468 let removed_views = old_views
469 .keys()
470 .filter(|k| !new_views.contains_key(*k))
471 .cloned()
472 .collect();
473 let modified_views = new_views
474 .iter()
475 .filter_map(|(name, id)| {
476 if let Some(old_id) = old_views.get(name) {
477 if old_id != id {
478 Some(name.clone())
479 } else {
480 None
481 }
482 } else {
483 None
484 }
485 })
486 .collect();
487
488 ProgramDiff::new()
489 .with_added_tables(added_tables)
490 .with_removed_tables(removed_tables)
491 .with_modified_tables(modified_tables)
492 .with_added_views(added_views)
493 .with_removed_views(removed_views)
494 .with_modified_views(modified_views)
495}
496
497struct BootstrapBlockers {
499 new_relations_with_lateness: Vec<String>,
501
502 old_relations_with_lateness: Vec<String>,
504}
505
506impl BootstrapBlockers {
507 fn is_empty(&self) -> bool {
508 self.new_relations_with_lateness.is_empty() && self.old_relations_with_lateness.is_empty()
509 }
510}
511
512impl Display for BootstrapBlockers {
513 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
514 if !self.new_relations_with_lateness.is_empty() {
515 writeln!(
516 f,
517 "- The new version of the program has relations with lateness: {}",
518 self.new_relations_with_lateness.join(", ")
519 )?;
520 }
521 if !self.old_relations_with_lateness.is_empty() {
522 writeln!(
523 f,
524 "- The checkpointed version of the program has relations with lateness: {}",
525 self.old_relations_with_lateness.join(", ")
526 )?;
527 }
528 Ok(())
529 }
530}
531
532#[derive(Debug, Clone, thiserror::Error)]
534pub enum PipelineDiffError {
535 #[error("{error}")]
538 BootstrapNotAllowed { error: String },
539}
540
541fn compute_program_diff(
542 old_config: &PipelineConfigProgramInfo,
543 new_config: &PipelineConfigProgramInfo,
544) -> Result<(ProgramDiff, BootstrapBlockers), String> {
545 let Some(old_dataflow) = &old_config.program_ir else {
546 return Err("Unable to compute the diff between the checkpointed and new pipeline configurations: the checkpointed configuration does not contain program information. It was likely created by an old version of Feldera.".to_owned());
547 };
548
549 let Some(new_dataflow) = &new_config.program_ir else {
550 return Err("Unable to compute the diff between the checkpointed and new pipeline configurations: the new configuration does not contain program information. It was likely created by an old version of Feldera.".to_owned());
551 };
552
553 let new_program_schema: ProgramSchema =
556 serde_json::from_value(new_dataflow.program_schema.clone())
557 .map_err(|e| format!("Error parsing new program schema: {}", e))?;
558 let old_program_schema: ProgramSchema =
559 serde_json::from_value(old_dataflow.program_schema.clone())
560 .map_err(|e| format!("Error parsing old program schema: {}", e))?;
561
562 let new_relations_with_lateness = new_program_schema
563 .relations_with_lateness()
564 .into_iter()
565 .map(|s| s.name())
566 .collect::<Vec<_>>();
567 let old_relations_with_lateness = old_program_schema
568 .relations_with_lateness()
569 .into_iter()
570 .map(|s| s.name())
571 .collect::<Vec<_>>();
572
573 let blockers = BootstrapBlockers {
574 new_relations_with_lateness,
575 old_relations_with_lateness,
576 };
577
578 Ok((program_diff(&old_dataflow.mir, &new_dataflow.mir), blockers))
579}
580
581pub fn compute_pipeline_diff(
589 old_config: &PipelineConfigProgramInfo,
590 new_config: &PipelineConfigProgramInfo,
591) -> Result<PipelineDiff, PipelineDiffError> {
592 let diff = compute_program_diff(old_config, new_config);
593
594 if let Ok((diff, blockers)) = &diff
595 && !blockers.is_empty()
596 && !diff.is_empty()
597 {
598 return Err(PipelineDiffError::BootstrapNotAllowed {
599 error: blockers.to_string(),
600 });
601 };
602
603 let mut old_configured_inputs = old_config
604 .inputs
605 .iter()
606 .filter(|(_, cfg)| !cfg.connector_config.transport.is_transient())
607 .map(|(name, cfg)| (name.clone(), cfg.clone()))
608 .collect::<BTreeMap<_, _>>();
609
610 old_configured_inputs.remove("now");
611
612 let old_configured_outputs = old_config
613 .outputs
614 .iter()
615 .filter(|(_, cfg)| !cfg.connector_config.transport.is_transient())
616 .map(|(name, cfg)| (name.clone(), cfg.clone()))
617 .collect::<BTreeMap<_, _>>();
618
619 let added_input_connectors = new_config
620 .inputs
621 .keys()
622 .filter(|k| !old_configured_inputs.contains_key(*k))
623 .map(|k| k.to_string())
624 .collect::<Vec<_>>();
625
626 let removed_input_connectors = old_configured_inputs
627 .iter()
628 .filter(|(k, config)| {
629 !new_config.inputs.contains_key(*k)
630 && !diff
631 .as_ref()
632 .map(|(mir_diff, _)| {
633 mir_diff
634 .removed_tables()
635 .iter()
636 .any(|t| t == &config.stream)
637 })
638 .unwrap_or(true)
639 })
640 .map(|(k, _)| k.to_string())
641 .collect::<Vec<_>>();
642
643 let modified_input_connectors = new_config
644 .inputs
645 .iter()
646 .filter(|(k, v)| {
647 old_configured_inputs.contains_key(*k)
648 && !old_configured_inputs
649 .get(*k)
650 .unwrap()
651 .connector_config
652 .equal_for_input_checkpoint_replay(&v.connector_config)
653 })
654 .map(|(k, _)| k.to_string())
655 .collect::<Vec<_>>();
656
657 let added_output_connectors = new_config
658 .outputs
659 .keys()
660 .filter(|k| !old_configured_outputs.contains_key(*k))
661 .map(|k| k.to_string())
662 .collect::<Vec<_>>();
663
664 let removed_output_connectors = old_configured_outputs
665 .iter()
666 .filter(|(k, config)| {
667 !new_config.outputs.contains_key(*k)
668 && !diff
669 .as_ref()
670 .map(|(mir_diff, _)| {
671 mir_diff.removed_views().iter().any(|v| v == &config.stream)
672 })
673 .unwrap_or(true)
674 })
675 .map(|(k, _)| k.to_string())
676 .collect::<Vec<_>>();
677
678 let modified_output_connectors = new_config
679 .outputs
680 .iter()
681 .filter(|(k, v)| {
682 old_configured_outputs.contains_key(*k)
683 && !old_configured_outputs
684 .get(*k)
685 .unwrap()
686 .connector_config
687 .equal_modulo_paused(&v.connector_config)
688 })
689 .map(|(k, _)| k.to_string())
690 .collect::<Vec<_>>();
691
692 Ok(PipelineDiff::new(diff.map(|(diff, _)| diff))
693 .with_added_input_connectors(added_input_connectors)
694 .with_modified_input_connectors(modified_input_connectors)
695 .with_removed_input_connectors(removed_input_connectors)
696 .with_added_output_connectors(added_output_connectors)
697 .with_modified_output_connectors(modified_output_connectors)
698 .with_removed_output_connectors(removed_output_connectors))
699}
700
701#[cfg(test)]
702mod tests {
703 use super::compute_pipeline_diff;
704 use crate::config::PipelineConfigProgramInfo;
705 use serde_json::{Map, Value, json};
706
707 #[test]
713 fn legacy_output_defaults_do_not_modify_connector() {
714 fn outputs(output: Value) -> PipelineConfigProgramInfo {
715 serde_json::from_value(json!({"inputs": {}, "outputs": {"v1.out": output}})).unwrap()
716 }
717 let fresh = json!({
718 "stream": "v1",
719 "transport": {"name": "kafka_output", "config": {"topic": "t"}},
720 "enable_output_buffer": false,
721 });
722 let buffer_default = json!({
723 "stream": "v1",
724 "transport": {"name": "kafka_output", "config": {"topic": "t"}},
725 "enable_output_buffer": false,
726 "max_output_buffer_time_millis": u64::MAX,
727 });
728 let kafka_default = json!({
729 "stream": "v1",
730 "transport": {
731 "name": "kafka_output",
732 "config": {"topic": "t", "initialization_timeout_secs": 60},
733 },
734 "enable_output_buffer": false,
735 });
736 let both_defaults = json!({
737 "stream": "v1",
738 "transport": {
739 "name": "kafka_output",
740 "config": {"topic": "t", "initialization_timeout_secs": 60},
741 },
742 "enable_output_buffer": false,
743 "max_output_buffer_time_millis": u64::MAX,
744 });
745 for stored in [buffer_default, kafka_default, both_defaults] {
746 let diff =
747 compute_pipeline_diff(&outputs(stored.clone()), &outputs(fresh.clone())).unwrap();
748 assert!(
749 diff.modified_output_connectors().is_empty(),
750 "{stored} reads as modified"
751 );
752 }
753
754 let changed = json!({
756 "stream": "v1",
757 "transport": {
758 "name": "kafka_output",
759 "config": {"topic": "t", "initialization_timeout": "90s"},
760 },
761 "enable_output_buffer": false,
762 });
763 let diff = compute_pipeline_diff(&outputs(fresh), &outputs(changed)).unwrap();
764 assert_eq!(
765 diff.modified_output_connectors(),
766 &vec!["v1.out".to_string()]
767 );
768 }
769
770 #[test]
776 fn legacy_input_defaults_do_not_modify_connector() {
777 let cases = [
778 (
779 "kafka_input",
780 json!({"name": "kafka_input", "config": {"topic": "t"}}),
781 json!({"name": "kafka_input", "config": {
782 "topic": "t", "group_join_timeout_secs": 10}}),
783 ),
784 (
785 "nats_input",
786 json!({"name": "nats_input", "config": {
787 "connection_config": {"server_url": "nats://x"},
788 "stream_name": "s",
789 "consumer_config": {"deliver_policy": "All"}}}),
790 json!({"name": "nats_input", "config": {
791 "connection_config": {"server_url": "nats://x",
792 "connection_timeout_secs": 10, "request_timeout_secs": 10},
793 "stream_name": "s",
794 "consumer_config": {"deliver_policy": "All"},
795 "inactivity_timeout_secs": 60, "retry_interval_secs": 5}}),
796 ),
797 (
798 "url_input",
799 json!({"name": "url_input", "config": {"path": "http://x"}}),
800 json!({"name": "url_input", "config": {"path": "http://x", "pause_timeout": 60}}),
801 ),
802 ];
803 for (name, fresh, stored) in cases {
804 let fresh = pipeline_config(json!({"stream": "t1", "transport": fresh}));
805 let stored = pipeline_config(json!({"stream": "t1", "transport": stored}));
806 let diff = compute_pipeline_diff(&stored, &fresh).unwrap();
807 assert!(
808 diff.modified_input_connectors().is_empty(),
809 "{name} with its legacy defaults spelled out reads as modified"
810 );
811 }
812
813 let fresh = pipeline_config(json!({"stream": "t1",
815 "transport": {"name": "kafka_input", "config": {"topic": "t"}}}));
816 let changed = pipeline_config(json!({"stream": "t1",
817 "transport": {"name": "kafka_input", "config": {
818 "topic": "t", "group_join_timeout": "30s"}}}));
819 let diff = compute_pipeline_diff(&fresh, &changed).unwrap();
820 assert_eq!(
821 diff.modified_input_connectors(),
822 &vec!["t1.connector".to_string()]
823 );
824 }
825
826 fn input_endpoint(mut fields: Map<String, Value>) -> Value {
827 let mut endpoint = Map::from_iter([
828 ("stream".to_string(), json!("t1")),
829 ("transport".to_string(), json!({"name": "empty_input"})),
830 ]);
831 endpoint.append(&mut fields);
832 Value::Object(endpoint)
833 }
834
835 fn pipeline_config(input: Value) -> PipelineConfigProgramInfo {
836 serde_json::from_value(json!({
837 "inputs": {
838 "t1.connector": input
839 }
840 }))
841 .unwrap()
842 }
843
844 #[test]
845 fn input_flow_control_changes_do_not_modify_connector() {
846 let old_config = pipeline_config(input_endpoint(Map::new()));
847 let new_config = pipeline_config(input_endpoint(Map::from_iter([
848 ("max_queued_records".to_string(), json!(5000)),
849 ("max_queued_bytes".to_string(), json!(6000)),
850 ("max_batch_size".to_string(), json!(7000)),
851 ("max_worker_batch_size".to_string(), json!(8000)),
852 ("paused".to_string(), json!(true)),
853 ])));
854
855 let diff = compute_pipeline_diff(&old_config, &new_config).unwrap();
856
857 assert!(diff.modified_input_connectors().is_empty());
858 }
859
860 #[test]
861 fn input_transport_changes_still_modify_connector() {
862 let old_config = pipeline_config(input_endpoint(Map::new()));
863 let new_config = pipeline_config(input_endpoint(Map::from_iter([(
864 "transport".to_string(),
865 json!({
866 "name": "datagen",
867 "config": {
868 "plan": [{"limit": 1}]
869 }
870 }),
871 )])));
872
873 let diff = compute_pipeline_diff(&old_config, &new_config).unwrap();
874
875 assert_eq!(
876 diff.modified_input_connectors(),
877 &vec!["t1.connector".to_string()]
878 );
879 }
880}