Skip to content

Commit

Permalink
cleaning up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kvey committed Oct 31, 2024
1 parent 5f4c907 commit 4ec0b3b
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 171 deletions.
4 changes: 2 additions & 2 deletions toolchain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions toolchain/chidori-core/src/cells/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use crate::library::std::ai::llm::ChatModelBatch;
#[archive_attr(derive(Debug))]
pub enum SupportedLanguage {
PyO3,
Starlark,
Deno,
}

Expand All @@ -49,7 +48,8 @@ pub enum SupportedLanguage {
))]
#[archive_attr(derive(Debug))]
pub struct BackingFileReference {
path: String
pub(crate) path: String,
pub(crate) text_range: Option<TextRange>
}

#[derive(
Expand Down Expand Up @@ -432,6 +432,7 @@ Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
Default,
Clone,
)]
Expand All @@ -446,6 +447,26 @@ pub struct TextRange {
pub end: usize,
}


impl Ord for TextRange {
fn cmp(&self, other: &Self) -> Ordering {
// First compare by start position
match self.start.cmp(&other.start) {
Ordering::Equal => {
// If starts are equal, compare by end position
self.end.cmp(&other.end)
}
ordering => ordering,
}
}
}

impl PartialOrd for TextRange {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[derive(
Archive,
serde::Serialize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use uuid::Uuid;
use crate::cells::CellTypes;
use crate::execution::primitives::operation::OperationFnOutput;
use tokio::sync::mpsc::{Sender, channel};

use tracing::debug;
// TODO: update all of these identifies to include a "space" they're within

type EdgeIdentity = (OperationId, OperationId, DependencyReference);
Expand Down Expand Up @@ -140,7 +140,7 @@ pub struct ExecutionEvent {
impl ExecutionGraph {
#[tracing::instrument]
pub fn new() -> Self {
println!("Initializing ExecutionGraph");
debug!("Initializing ExecutionGraph");
let (sender, mut execution_graph_event_receiver) = tokio::sync::mpsc::channel::<ExecutionGraphSendPayload>(1028);

let mut state_id_to_state = DashMap::new();
Expand Down Expand Up @@ -176,7 +176,7 @@ impl ExecutionGraph {
// Kick off a background thread that listens for events from async operations
// These events inject additional state into the execution graph on new branches
// Those branches will continue to evaluate independently.
println!("Initializing background thread for handling async updates to our execution graph");
debug!("Initializing background thread for handling async updates to our execution graph");
let handle = tokio::spawn(async move {
// Signal that the task has started, we can continue initialization
initialization_notify_clone.notify_one();
Expand All @@ -185,7 +185,7 @@ impl ExecutionGraph {
biased; // Prioritize message handling over cancellation

Some((resulting_execution_state, oneshot)) = execution_graph_event_receiver.recv() => {
println!("==== Execution Graph received dispatch event {:?}", resulting_execution_state.id());
debug!("==== Execution Graph received dispatch event {:?}", resulting_execution_state.id());

let s = resulting_execution_state.clone();
match &resulting_execution_state {
Expand All @@ -195,15 +195,15 @@ impl ExecutionGraph {
id: resulting_state_id.clone(),
evaluation: s.clone()
}).await {
println!("Failed to send execution event: {}", e);
debug!("Failed to send execution event: {}", e);
}
}
ExecutionStateEvaluation::EvalFailure(id) => {
if let Err(e) = execution_event_tx_clone.send(ExecutionEvent{
id: id.clone(),
evaluation: s.clone()
}).await {
println!("Failed to send execution event: {}", e);
debug!("Failed to send execution event: {}", e);
}
}
ExecutionStateEvaluation::Complete(state) => {
Expand All @@ -212,7 +212,7 @@ impl ExecutionGraph {
id: resulting_state_id.clone(),
evaluation: s.clone()
}).await {
println!("Failed to send execution event: {}", e);
debug!("Failed to send execution event: {}", e);
}
}
ExecutionStateEvaluation::Executing(state) => {
Expand All @@ -221,7 +221,7 @@ impl ExecutionGraph {
id: resulting_state_id.clone(),
evaluation: s.clone()
}).await {
println!("Failed to send execution event: {}", e);
debug!("Failed to send execution event: {}", e);
}
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ impl ExecutionGraph {
}
}
_ = cancellation_notify_clone.notified() => {
println!("Task is notified to stop");
debug!("Task is notified to stop");
return;
}
}
Expand Down
3 changes: 0 additions & 3 deletions toolchain/chidori-core/src/execution/primitives/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,6 @@ impl OperationNode {
SupportedLanguage::PyO3 => {
crate::cells::code_cell::code_cell_exec_python(code_cell.clone())
}
SupportedLanguage::Starlark => {
unreachable!("We do not yet support starlark")
}
SupportedLanguage::Deno => {
crate::cells::code_cell::code_cell_exec_deno(code_cell.clone())
}
Expand Down
3 changes: 1 addition & 2 deletions toolchain/chidori-core/src/library/std/ai/llm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,9 @@ pub async fn ai_llm_code_generation_chat_model(
let mut cells = vec![];
crate::sdk::md::extract_code_blocks(&text)
.iter()
.filter_map(|block| interpret_markdown_code_block(block).unwrap())
.filter_map(|block| interpret_markdown_code_block(block, None).unwrap())
.for_each(|block| { cells.push(block); });
cells.sort();
dbg!(&cells);

for cell in cells {
let (s, _) = new_execution_state.update_operation(cell, Uuid::now_v7())?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::{HashMap, HashSet};
use tokio_cron_scheduler::{Job, JobScheduler, JobSchedulerError};
use tracing::debug;
use uuid::Uuid;
use crate::cells::{CellTypes, CodeCell, ScheduleCell};
use crate::execution::execution::ExecutionState;
Expand Down Expand Up @@ -88,7 +89,7 @@ pub async fn run_cron(
// Add code to be run during/after shutdown
sched.set_shutdown_handler(Box::new(|| {
Box::pin(async move {
println!("Shut down done");
debug!("Shut down done");
})
}));

Expand Down
11 changes: 6 additions & 5 deletions toolchain/chidori-core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod sdk;
mod utils;

pub use tokio;
use tracing::info;
pub use uuid;
use chidori_core::sdk::chidori::Chidori;
use chidori_core::sdk::entry::PlaybackState;
Expand Down Expand Up @@ -75,22 +76,22 @@ async fn run_command(run_directory: &PathBuf) -> anyhow::Result<()> {
let result = instance.run(PlaybackState::Running).await;
match result {
Ok(_) => {
println!("Instance completed execution and closed successfully.");
info!("Instance completed execution and closed successfully.");
break;
}
Err(e) => {
println!("Error occurred: {}, retrying...", e);
info!("Error occurred: {}, retrying...", e);
}
}
}
});

// Here you can add any additional setup or processing needed for the run command
println!("Chidori instance is running in the background.");
info!("Chidori instance is running in the background.");

// Keep the main thread alive
tokio::signal::ctrl_c().await.expect("Failed to listen for ctrl+c");
println!("Received shutdown signal. Terminating...");
info!("Received shutdown signal. Terminating...");
Ok(())
}

Expand All @@ -100,7 +101,7 @@ async fn main() -> anyhow::Result<()>{

match &cli.command {
Some(Commands::Run { load }) => {
println!("Running Chidori with target src directory: {:?}", load);
info!("Running Chidori with target src directory: {:?}", load);
run_command(load).await
}
// Some(Commands::Test { test_dir, verbose }) => {
Expand Down
41 changes: 20 additions & 21 deletions toolchain/chidori-core/src/sdk/chidori.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::sync::mpsc::Sender;
use tracing::dispatcher::DefaultGuard;
use std::collections::HashMap;
use std::path::Path;
use futures_util::future::Shared;
use tracing::info;
use crate::cells::{CellTypes, get_cell_name};
use crate::execution::execution::execution_graph::ExecutionGraph;
use crate::sdk::entry::{CellHolder, EventsFromRuntime, PlaybackState, SharedState, UserInteractionMessage};
Expand Down Expand Up @@ -40,41 +42,38 @@ impl std::fmt::Debug for Chidori {
}
}

fn initialize_shared_state_object() -> Arc<Mutex<SharedState>> {
Arc::new(Mutex::new(SharedState {
execution_id_to_evaluation: Default::default(),
execution_state_head_id: Uuid::nil(),
editor_cells: Default::default(),
at_execution_state_cells: vec![],
latest_state: None,
}))
}

impl Chidori {
pub fn new() -> Self {
Chidori {
instanced_env_tx: None,
runtime_event_sender: None,
trace_event_sender: None,
loaded_path: None,
shared_state: Arc::new(Mutex::new(SharedState {
execution_id_to_evaluation: Default::default(),
execution_state_head_id: Uuid::nil(),
editor_cells: Default::default(),
at_execution_state_cells: vec![],
latest_state: None,
})),
shared_state: initialize_shared_state_object(),
tracing_guard: None,
}
}

pub fn new_with_events(sender: Sender<TraceEvents>, runtime_event_sender: Sender<EventsFromRuntime>) -> Self {
tracing::subscriber::set_global_default(init_internal_telemetry(sender.clone())).expect("Failed to set global default");
let guard: DefaultGuard = tracing::subscriber::set_default(init_internal_telemetry(sender.clone()));
let init_telemetry = init_internal_telemetry(sender.clone());
// tracing::subscriber::set_global_default(init_telemetry.clone()).expect("Failed to set global default");
let guard: DefaultGuard = tracing::subscriber::set_default(init_telemetry);
Chidori {
instanced_env_tx: None,
runtime_event_sender: Some(runtime_event_sender),
trace_event_sender: Some(sender),
loaded_path: None,
shared_state: Arc::new(Mutex::new(SharedState {
execution_id_to_evaluation: Default::default(),
execution_state_head_id: Uuid::nil(),
editor_cells: Default::default(),

at_execution_state_cells: vec![],

latest_state: None,
})),
shared_state: initialize_shared_state_object(),
tracing_guard: Some(guard)
}
}
Expand Down Expand Up @@ -143,7 +142,7 @@ impl Chidori {
let mut cells = vec![];
crate::sdk::md::extract_code_blocks(s)
.iter()
.filter_map(|block| interpret_markdown_code_block(block).unwrap())
.filter_map(|block| interpret_markdown_code_block(block, None).unwrap())
.for_each(|block| { cells.push(block); });
cells.sort();
self.loaded_path = Some("raw_text".to_string());
Expand All @@ -155,14 +154,14 @@ impl Chidori {
let mut cells = vec![];
for file in files {
for block in file.result {
if let Some(block) = interpret_markdown_code_block(&block).unwrap() {
if let Some(block) = interpret_markdown_code_block(&block, Some(path.to_string_lossy().to_string())).unwrap() {
cells.push(block);
}
}
}
self.loaded_path = Some(path.to_str().unwrap().to_string());
cells.sort();
println!("Loading {} cells from {:?}", cells.len(), path);
info!("Loading {} cells from {:?}", cells.len(), path);
self.load_cells(cells)
}

Expand Down
Loading

0 comments on commit 4ec0b3b

Please sign in to comment.