|
20 | 20 | use std::num::NonZeroUsize;
|
21 | 21 |
|
22 | 22 | use quickwit_common::rand::append_random_suffix;
|
23 |
| -use quickwit_config::{IndexConfig, SourceConfig, SourceInputFormat, SourceParams}; |
| 23 | +use quickwit_config::{ |
| 24 | + IndexConfig, SourceConfig, SourceInputFormat, SourceParams, TransformConfig, |
| 25 | +}; |
24 | 26 | use quickwit_proto::metastore::{
|
25 | 27 | AddSourceRequest, CreateIndexRequest, DeleteSourceRequest, EntityKind, IndexMetadataRequest,
|
26 | 28 | MetastoreError, PublishSplitsRequest, ResetSourceCheckpointRequest, SourceType,
|
27 |
| - StageSplitsRequest, ToggleSourceRequest, |
| 29 | + StageSplitsRequest, ToggleSourceRequest, UpdateSourceRequest, |
28 | 30 | };
|
29 | 31 | use quickwit_proto::types::IndexUid;
|
30 | 32 |
|
31 | 33 | use super::DefaultForTest;
|
32 | 34 | use crate::checkpoint::SourceCheckpoint;
|
| 35 | +use crate::metastore::UpdateSourceRequestExt; |
33 | 36 | use crate::tests::cleanup_index;
|
34 | 37 | use crate::{
|
35 | 38 | AddSourceRequestExt, CreateIndexRequestExt, IndexMetadataResponseExt, MetastoreServiceExt,
|
@@ -136,6 +139,112 @@ pub async fn test_metastore_add_source<MetastoreToTest: MetastoreServiceExt + De
|
136 | 139 | cleanup_index(&mut metastore, index_uid).await;
|
137 | 140 | }
|
138 | 141 |
|
| 142 | +pub async fn test_metastore_update_source<MetastoreToTest: MetastoreServiceExt + DefaultForTest>() { |
| 143 | + let mut metastore = MetastoreToTest::default_for_test().await; |
| 144 | + |
| 145 | + let index_id = append_random_suffix("test-add-source"); |
| 146 | + let index_uri = format!("ram:///indexes/{index_id}"); |
| 147 | + let index_config = IndexConfig::for_test(&index_id, &index_uri); |
| 148 | + |
| 149 | + let create_index_request = CreateIndexRequest::try_from_index_config(&index_config).unwrap(); |
| 150 | + let index_uid: IndexUid = metastore |
| 151 | + .create_index(create_index_request) |
| 152 | + .await |
| 153 | + .unwrap() |
| 154 | + .index_uid() |
| 155 | + .clone(); |
| 156 | + |
| 157 | + let source_id = format!("{index_id}--source"); |
| 158 | + |
| 159 | + let mut source = SourceConfig { |
| 160 | + source_id: source_id.to_string(), |
| 161 | + num_pipelines: NonZeroUsize::new(1).unwrap(), |
| 162 | + enabled: true, |
| 163 | + source_params: SourceParams::void(), |
| 164 | + transform_config: None, |
| 165 | + input_format: SourceInputFormat::Json, |
| 166 | + }; |
| 167 | + |
| 168 | + assert_eq!( |
| 169 | + metastore |
| 170 | + .index_metadata(IndexMetadataRequest::for_index_id(index_id.to_string())) |
| 171 | + .await |
| 172 | + .unwrap() |
| 173 | + .deserialize_index_metadata() |
| 174 | + .unwrap() |
| 175 | + .checkpoint |
| 176 | + .source_checkpoint(&source_id), |
| 177 | + None |
| 178 | + ); |
| 179 | + |
| 180 | + let add_source_request = |
| 181 | + AddSourceRequest::try_from_source_config(index_uid.clone(), &source).unwrap(); |
| 182 | + metastore.add_source(add_source_request).await.unwrap(); |
| 183 | + |
| 184 | + source.transform_config = Some(TransformConfig::new("del(.username)".to_string(), None)); |
| 185 | + |
| 186 | + // Update the source twice with the same value to validate indempotency |
| 187 | + for _ in 0..2 { |
| 188 | + let update_source_request = |
| 189 | + UpdateSourceRequest::try_from_source_config(index_uid.clone(), &source).unwrap(); |
| 190 | + metastore |
| 191 | + .update_source(update_source_request) |
| 192 | + .await |
| 193 | + .unwrap(); |
| 194 | + |
| 195 | + let index_metadata = metastore |
| 196 | + .index_metadata(IndexMetadataRequest::for_index_id(index_id.to_string())) |
| 197 | + .await |
| 198 | + .unwrap() |
| 199 | + .deserialize_index_metadata() |
| 200 | + .unwrap(); |
| 201 | + |
| 202 | + let sources = &index_metadata.sources; |
| 203 | + assert_eq!(sources.len(), 1); |
| 204 | + assert!(sources.contains_key(&source_id)); |
| 205 | + assert_eq!(sources.get(&source_id).unwrap().source_id, source_id); |
| 206 | + assert_eq!( |
| 207 | + sources.get(&source_id).unwrap().source_type(), |
| 208 | + SourceType::Void |
| 209 | + ); |
| 210 | + assert_eq!( |
| 211 | + sources.get(&source_id).unwrap().transform_config, |
| 212 | + Some(TransformConfig::new("del(.username)".to_string(), None)) |
| 213 | + ); |
| 214 | + assert_eq!( |
| 215 | + index_metadata.checkpoint.source_checkpoint(&source_id), |
| 216 | + Some(&SourceCheckpoint::default()) |
| 217 | + ); |
| 218 | + } |
| 219 | + |
| 220 | + source.source_id = "unknown-src-id".to_string(); |
| 221 | + assert!(matches!( |
| 222 | + metastore |
| 223 | + .update_source( |
| 224 | + UpdateSourceRequest::try_from_source_config(index_uid.clone(), &source).unwrap() |
| 225 | + ) |
| 226 | + .await |
| 227 | + .unwrap_err(), |
| 228 | + MetastoreError::NotFound(EntityKind::Source { .. }) |
| 229 | + )); |
| 230 | + source.source_id = source_id; |
| 231 | + assert!(matches!( |
| 232 | + metastore |
| 233 | + .add_source( |
| 234 | + AddSourceRequest::try_from_source_config( |
| 235 | + IndexUid::new_with_random_ulid("index-not-found"), |
| 236 | + &source |
| 237 | + ) |
| 238 | + .unwrap() |
| 239 | + ) |
| 240 | + .await |
| 241 | + .unwrap_err(), |
| 242 | + MetastoreError::NotFound(EntityKind::Index { .. }) |
| 243 | + )); |
| 244 | + |
| 245 | + cleanup_index(&mut metastore, index_uid).await; |
| 246 | +} |
| 247 | + |
139 | 248 | pub async fn test_metastore_toggle_source<MetastoreToTest: MetastoreServiceExt + DefaultForTest>() {
|
140 | 249 | let mut metastore = MetastoreToTest::default_for_test().await;
|
141 | 250 |
|
|
0 commit comments