You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2023/06/07 13:57:35 UTC

[avro] branch branch-1.11 updated: AVRO-3771: [Rust] Logging flood during validate method (#2272)

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new 2d4c3cda8 AVRO-3771: [Rust] Logging flood during validate method (#2272)
2d4c3cda8 is described below

commit 2d4c3cda8ac06dd2cc1f926dc0bfe60a1ad7c838
Author: theo <43...@users.noreply.github.com>
AuthorDate: Wed Jun 7 16:57:03 2023 +0300

    AVRO-3771: [Rust] Logging flood during validate method (#2272)
    
    * fix: lower log level for validation errors
    
    * AVRO-3771: [Rust] Log the validation failure as error if validating against a single schema
    
    If validating against several schemata then it is expected that it
    should fail for all but one most of the time, so log it as debug
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    ---------
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    Co-authored-by: Fedor Telnov <f....@picodata.io>
    Co-authored-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    (cherry picked from commit 7bf4f5e392b383df456cf3f711885756a77aefbe)
---
 lang/rust/avro/src/types.rs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lang/rust/avro/src/types.rs b/lang/rust/avro/src/types.rs
index d5b00b719..9cdda8a51 100644
--- a/lang/rust/avro/src/types.rs
+++ b/lang/rust/avro/src/types.rs
@@ -345,15 +345,21 @@ impl Value {
     pub fn validate_schemata(&self, schemata: Vec<&Schema>) -> bool {
         let rs = ResolvedSchema::try_from(schemata.clone())
             .expect("Schemata didn't successfully resolve");
+        let schemata_len = schemata.len();
         schemata.iter().any(|schema| {
             let enclosing_namespace = schema.namespace();
 
             match self.validate_internal(schema, rs.get_names(), &enclosing_namespace) {
-                Some(error_msg) => {
-                    error!(
+                Some(reason) => {
+                    let log_message = format!(
                         "Invalid value: {:?} for schema: {:?}. Reason: {}",
-                        self, schema, error_msg
+                        self, schema, reason
                     );
+                    if schemata_len == 1 {
+                        error!("{}", log_message);
+                    } else {
+                        debug!("{}", log_message);
+                    };
                     false
                 }
                 None => true,