Skip to main content

qlog_dancer/reports/
mod.rs

1// Copyright (C) 2025, Cloudflare, Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8//     * Redistributions of source code must retain the above copyright notice,
9//       this list of conditions and the following disclaimer.
10//
11//     * Redistributions in binary form must reproduce the above copyright
12//       notice, this list of conditions and the following disclaimer in the
13//       documentation and/or other materials provided with the distribution.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27//! Reporting (tables etc.)
28
29use events::sqlog_event_list;
30use tabled::settings::Style;
31
32use crate::config::AppConfig;
33use crate::LogFileParseResult;
34
35pub fn report(log_file: &LogFileParseResult, config: &AppConfig) {
36    if config.report_text {
37        for data in &log_file.data {
38            if let Some(table) = text::request_timing_table(data, config) {
39                println!(
40                    "Request timing table for session ID: {:?}, app proto: {:?}, host: {:?}",
41                    data.datastore.session_id.unwrap_or(-1),
42                    data.datastore.application_proto,
43                    data.datastore
44                        .host
45                        .clone()
46                        .unwrap_or("ERROR UNKNOWN".to_string())
47                );
48                println!("{}", table);
49                println!();
50            }
51
52            text::print_stats(&data.datastore, &config.stats_config);
53            println!();
54
55            match &data.raw {
56                crate::RawLogEvents::QlogJson { events: _ } => todo!(),
57                crate::RawLogEvents::QlogJsonSeq { events } => {
58                    let mut table = sqlog_event_list(events).build();
59                    table.with(Style::sharp());
60                    println!("Qlog events");
61                    println!("{}", table);
62                },
63                crate::RawLogEvents::Netlog => todo!(),
64            }
65        }
66
67        // TODO: make this more configurable
68        text::print_packet_loss(&log_file.data);
69        text::print_flow_control(&log_file.data);
70    }
71
72    if config.report_html {
73        html::overview(log_file, config);
74        html::closures(log_file, config);
75        html::requests(log_file, config);
76        html::event_list(log_file, config);
77    }
78}
79
80mod events;
81pub mod html;
82mod text;