|
17 | 17 | *
|
18 | 18 | */
|
19 | 19 |
|
20 |
| -use std::collections::HashMap; |
21 |
| - |
22 |
| -use serde_json::{Value, json}; |
23 |
| - |
24 | 20 | use crate::{
|
25 |
| - catalog::snapshot::CURRENT_SNAPSHOT_VERSION, handlers::http::cluster::INTERNAL_STREAM_NAME, |
| 21 | + catalog::snapshot::CURRENT_SNAPSHOT_VERSION, |
| 22 | + handlers::{TelemetryType, http::cluster::INTERNAL_STREAM_NAME}, |
26 | 23 | storage,
|
27 | 24 | };
|
| 25 | +use serde_json::{Value, json}; |
28 | 26 |
|
29 | 27 | pub fn v1_v4(mut stream_metadata: Value) -> Value {
|
30 | 28 | let stream_metadata_map = stream_metadata.as_object_mut().unwrap();
|
@@ -232,38 +230,45 @@ fn default_log_source_entry() -> Value {
|
232 | 230 | })
|
233 | 231 | }
|
234 | 232 |
|
235 |
| -pub fn rename_log_source_v6(mut stream_metadata: Value) -> Value { |
236 |
| - let format_mapping = create_format_mapping(); |
| 233 | +pub fn v6_v7(mut stream_metadata: Value) -> Value { |
| 234 | + let stream_metadata_map = stream_metadata.as_object_mut().unwrap(); |
| 235 | + stream_metadata_map.insert( |
| 236 | + "objectstore-format".to_owned(), |
| 237 | + Value::String(storage::CURRENT_OBJECT_STORE_VERSION.into()), |
| 238 | + ); |
| 239 | + stream_metadata_map.insert( |
| 240 | + "version".to_owned(), |
| 241 | + Value::String(storage::CURRENT_SCHEMA_VERSION.into()), |
| 242 | + ); |
| 243 | + |
| 244 | + // fetch log_source, if log_source=otel-traces, telemetry_type=traces |
| 245 | + // if log_source=otel-metrics, telemetry_type=metrics |
| 246 | + // else telemetry_type=logs |
| 247 | + let log_source = stream_metadata_map |
| 248 | + .get("log_source") |
| 249 | + .and_then(|v| v.as_array()) |
| 250 | + .and_then(|arr| arr.first()) |
| 251 | + .and_then(|v| v.get("log_source_format")) |
| 252 | + .and_then(|v| v.as_str()) |
| 253 | + .unwrap_or("json"); |
| 254 | + let telemetry_type = match log_source { |
| 255 | + "otel-logs" => TelemetryType::Logs, |
| 256 | + "otel-traces" => TelemetryType::Traces, |
| 257 | + "otel-metrics" => TelemetryType::Metrics, |
| 258 | + _ => TelemetryType::Logs, // Default to Logs if not recognized |
| 259 | + }; |
237 | 260 |
|
238 |
| - if let Some(log_sources) = stream_metadata |
239 |
| - .get_mut("log_source") |
240 |
| - .and_then(|v| v.as_array_mut()) |
241 |
| - { |
242 |
| - for source in log_sources.iter_mut() { |
243 |
| - if let Some(format_value) = source.get_mut("log_source_format") { |
244 |
| - if let Some(format_str) = format_value.as_str() { |
245 |
| - if let Some(new_format) = format_mapping.get(format_str) { |
246 |
| - *format_value = json!(new_format); |
247 |
| - } |
248 |
| - } |
249 |
| - } |
250 |
| - } |
| 261 | + // add telemetry_type if not present |
| 262 | + if !stream_metadata_map.contains_key("telemetry_type") { |
| 263 | + stream_metadata_map.insert( |
| 264 | + "telemetry_type".to_owned(), |
| 265 | + Value::String(telemetry_type.to_string()), |
| 266 | + ); |
251 | 267 | }
|
252 | 268 |
|
253 | 269 | stream_metadata
|
254 | 270 | }
|
255 | 271 |
|
256 |
| -fn create_format_mapping() -> HashMap<&'static str, &'static str> { |
257 |
| - HashMap::from([ |
258 |
| - ("Kinesis", "kinesis"), |
259 |
| - ("OtelLogs", "otel-logs"), |
260 |
| - ("OtelTraces", "otel-traces"), |
261 |
| - ("OtelMetrics", "otel-metrics"), |
262 |
| - ("Pmeta", "pmeta"), |
263 |
| - ("Json", "json"), |
264 |
| - ]) |
265 |
| -} |
266 |
| - |
267 | 272 | fn v1_v2_snapshot_migration(mut snapshot: Value) -> Value {
|
268 | 273 | let manifest_list = snapshot.get("manifest_list").unwrap();
|
269 | 274 | let mut new_manifest_list = Vec::new();
|
@@ -331,12 +336,4 @@ mod tests {
|
331 | 336 | let updated_stream_metadata = super::v5_v6(stream_metadata.clone());
|
332 | 337 | assert_eq!(updated_stream_metadata, expected);
|
333 | 338 | }
|
334 |
| - |
335 |
| - #[test] |
336 |
| - fn test_rename_log_source_v6() { |
337 |
| - let stream_metadata = serde_json::json!({"version":"v6","schema_version":"v1","objectstore-format":"v6","created-at":"2025-03-25T02:37:00.664625075+00:00","first-event-at":"2025-03-24T22:37:00.665-04:00","owner":{"id":"admin","group":"admin"},"permissions":[{"id":"admin","group":"admin","access":["all"]}],"stats":{"lifetime_stats":{"events":94,"ingestion":146530,"storage":29248},"current_stats":{"events":94,"ingestion":146530,"storage":29248},"deleted_stats":{"events":0,"ingestion":0,"storage":0}},"snapshot":{"version":"v2","manifest_list":[{"manifest_path":"home/nikhilsinha/Parseable/parseable/data/test11/date=2025-03-25/manifest.json","time_lower_bound":"2025-03-25T00:00:00Z","time_upper_bound":"2025-03-25T23:59:59.999999999Z","events_ingested":94,"ingestion_size":146530,"storage_size":29248}]},"hot_tier_enabled":false,"stream_type":"UserDefined","log_source":[{"log_source_format":"OtelLogs","fields":["span_id","trace_id","time_unix_nano","severity_text","severity_number","body"]},{"log_source_format":"OtelTraces","fields":["span_status_code","flags","span_parent_span_id","span_trace_id","span_status_message","event_name","span_span_id","span_name","span_kind_description","event_time_unix_nano","span_end_time_unix_nano","span_status_description","span_start_time_unix_nano","span_kind","name"]},{"log_source_format":"OtelMetrics","fields":["metric_unit","start_time_unix_nano","time_unix_nano","metric_name","metric_description"]}]}); |
338 |
| - let expected = serde_json::json!({"version":"v6","schema_version":"v1","objectstore-format":"v6","created-at":"2025-03-25T02:37:00.664625075+00:00","first-event-at":"2025-03-24T22:37:00.665-04:00","owner":{"id":"admin","group":"admin"},"permissions":[{"id":"admin","group":"admin","access":["all"]}],"stats":{"lifetime_stats":{"events":94,"ingestion":146530,"storage":29248},"current_stats":{"events":94,"ingestion":146530,"storage":29248},"deleted_stats":{"events":0,"ingestion":0,"storage":0}},"snapshot":{"version":"v2","manifest_list":[{"manifest_path":"home/nikhilsinha/Parseable/parseable/data/test11/date=2025-03-25/manifest.json","time_lower_bound":"2025-03-25T00:00:00Z","time_upper_bound":"2025-03-25T23:59:59.999999999Z","events_ingested":94,"ingestion_size":146530,"storage_size":29248}]},"hot_tier_enabled":false,"stream_type":"UserDefined","log_source":[{"log_source_format":"otel-logs","fields":["span_id","trace_id","time_unix_nano","severity_text","severity_number","body"]},{"log_source_format":"otel-traces","fields":["span_status_code","flags","span_parent_span_id","span_trace_id","span_status_message","event_name","span_span_id","span_name","span_kind_description","event_time_unix_nano","span_end_time_unix_nano","span_status_description","span_start_time_unix_nano","span_kind","name"]},{"log_source_format":"otel-metrics","fields":["metric_unit","start_time_unix_nano","time_unix_nano","metric_name","metric_description"]}]}); |
339 |
| - let updated_stream_metadata = super::rename_log_source_v6(stream_metadata.clone()); |
340 |
| - assert_eq!(updated_stream_metadata, expected); |
341 |
| - } |
342 | 339 | }
|
0 commit comments