From 9603e2d1367f777fc006ed008be02863509750d3 Mon Sep 17 00:00:00 2001 From: andrewinci Date: Tue, 11 Oct 2022 06:00:30 +0100 Subject: [PATCH] feat: use avro by default and fallback on string on failure --- src-tauri/src/api/consumer.rs | 14 +++++++++++++- src/pages/topics/consumer-modal.tsx | 8 -------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/api/consumer.rs b/src-tauri/src/api/consumer.rs index 753c23c3..9dc1bf00 100644 --- a/src-tauri/src/api/consumer.rs +++ b/src-tauri/src/api/consumer.rs @@ -1,3 +1,5 @@ +use log::warn; + use super::{ error::Result, AppState }; use crate::lib::{ ConsumerOffsetConfiguration, ConsumerState, ParserMode, ParsedKafkaRecord }; @@ -38,7 +40,17 @@ pub async fn get_record( let cluster = state.get_cluster_by_id(&cluster_id).await; let consumer = cluster.get_consumer(&topic).await; match consumer.get_record(index).await { - Some(r) => Ok(Some(cluster.parser.parse_record(r, ParserMode::Avro).await?)), + Some(r) => { + let avro_record = cluster.parser.parse_record(r.clone(), ParserMode::Avro).await; + let parsed = match avro_record { + Ok(res) => res, + Err(_) => { + warn!("Unable to parse record with avro. Topic: {} Index : {}", topic, index); + cluster.parser.parse_record(r, ParserMode::String).await? + } + }; + Ok(Some(parsed)) + } None => Ok(None), } } \ No newline at end of file diff --git a/src/pages/topics/consumer-modal.tsx b/src/pages/topics/consumer-modal.tsx index d278c813..27c7ae9a 100644 --- a/src/pages/topics/consumer-modal.tsx +++ b/src/pages/topics/consumer-modal.tsx @@ -26,7 +26,6 @@ const ModalBody = ({ cluster, topicName }: ConsumerModalProps) => { const form = useForm({ initialValues: { from: "End", - useAvro: cluster.schemaRegistry ? true : false, dateInterval: [nowUTC, nowUTC], onlyBeginning: false, timeInterval: [zeroUTC, zeroUTC], @@ -76,12 +75,6 @@ const ModalBody = ({ cluster, topicName }: ConsumerModalProps) => { - - Start consuming from End @@ -121,7 +114,6 @@ export const dateTimeToUnixTimeMs = (dateUTC: Date, timeUTC: Date): number => { type ConsumerForm = { from: "Beginning" | "End" | "Custom"; - useAvro: boolean; dateInterval: [Date, Date]; timeInterval: [Date, Date]; onlyBeginning: boolean;