-
Notifications
You must be signed in to change notification settings - Fork 3
Recording runtime logs in DB #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
castelao
wants to merge
44
commits into
main
Choose a base branch
from
logs_in_db
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 34 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
a93be03
feat: Expected log levels
castelao b33d807
cfg: Adding dependency on chrono
castelao 653b695
feat: LogRecord.parse()
castelao f91e5f1
test: LogRecord::parse
castelao ba5a6a2
feat: LogRecord::init_db
castelao b1fb6c6
feat: LogRecord::init_db
castelao 10e029f
Importing requirements
castelao fb0c726
renaming tests
castelao c494e9e
Transparent Regex errors
castelao 818aa1f
cfg: Adding Regex as dependency
castelao 5d2d4f5
refact: Trim logs before processing
castelao 18d5ae3
feat: LogRecord::open()
castelao 1a8b397
feat: LogRecord::sample()
castelao 4700231
test: Adding a sample with a county
castelao 926f20f
feat: Include logs when opening
castelao 16f5327
test: Extending open_scraped_ordinaces to include logs
castelao bb9e044
feat: RuntimeLogs as a collection of LogRecord
castelao d2e53e4
test, refact: Import super::*
castelao bfde5e5
cfg: Importing duckdb and trace
castelao f480e38
feat: LogRecord::record()
castelao 49e6dfb
feat: Logs record in DB must have bookkeeper id
castelao 6d13d20
style:
castelao a30d076
feat: Including DebugToFile
castelao 52b5187
refact: Compile regex only once
castelao 55333a5
fix: Removing extra spaces from sample
castelao da4de66
doc: RuntimeLogs::parse()
castelao f79cdb2
refact: Filtering and logging RuntimeLogs::parse
castelao 6d8bf27
log: Bump recording on database message to info level
castelao 16850c9
refact: Minimum information with expect instead of unwrap
castelao 152eb1f
feat: Recording logs in the DB
castelao 9722898
style: Left behind some imports from development
castelao 6404901
refact: Breaking log module in parts
castelao 2e9a7a2
clean:
castelao 279067e
doc:
castelao 834e2b1
typo:
castelao 46dbf2e
clean:
castelao a88a1ef
fix: Missing miliseconds
castelao 652e153
doc:
castelao 2350093
typo:
castelao 4b10335
clean:
castelao 8811311
refact: Return one of our custom errros
castelao 28c79b8
fix: Bad format for microseconds
castelao 6d1563b
log: Promoting initializing usage to debug level
castelao 3a697a7
log: Providing more information on parsing dates
castelao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| //! Runtime logs | ||
| //! | ||
| //! Parse and record the logs emitted by the runtime to support | ||
| //! pos-processing and analysis. | ||
|
|
||
| /// Log levels emitted by the (Python) runtime. | ||
| #[derive(Debug, PartialEq, serde::Deserialize)] | ||
| pub(super) enum LogLevel { | ||
| #[serde(rename = "DEBUG_TO_FILE")] | ||
| DebugToFile, | ||
| #[serde(rename = "TRACE")] | ||
| Trace, | ||
| #[serde(rename = "DEBUG")] | ||
| Debug, | ||
| #[serde(rename = "INFO")] | ||
| Info, | ||
| #[serde(rename = "WARNING")] | ||
| Warning, | ||
| #[serde(rename = "ERROR")] | ||
| Error, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod test_loglevel { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn deserialize_trace() { | ||
| let json = r#""TRACE""#; | ||
| let level: LogLevel = serde_json::from_str(json).unwrap(); | ||
| assert!(matches!(level, LogLevel::Trace)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_debug() { | ||
| let json = r#""DEBUG""#; | ||
| let level: LogLevel = serde_json::from_str(json).unwrap(); | ||
| assert!(matches!(level, LogLevel::Debug)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_info() { | ||
| let json = r#""INFO""#; | ||
| let level: LogLevel = serde_json::from_str(json).unwrap(); | ||
| assert!(matches!(level, LogLevel::Info)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_warning() { | ||
| let json = r#""WARNING""#; | ||
| let level: LogLevel = serde_json::from_str(json).unwrap(); | ||
| assert!(matches!(level, LogLevel::Warning)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_error() { | ||
| let json = r#""ERROR""#; | ||
| let level: LogLevel = serde_json::from_str(json).unwrap(); | ||
| assert!(matches!(level, LogLevel::Error)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_invalid_variant() { | ||
| let json = r#""INVALID""#; | ||
| let result: std::result::Result<LogLevel, _> = serde_json::from_str(json); | ||
| assert!(result.is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_lowercase_fails() { | ||
| let json = r#""trace""#; | ||
| let result: std::result::Result<LogLevel, _> = serde_json::from_str(json); | ||
| assert!(result.is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_mixed_case_fails() { | ||
| let json = r#""Trace""#; | ||
| let result: std::result::Result<LogLevel, _> = serde_json::from_str(json); | ||
| assert!(result.is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_in_struct() { | ||
| #[derive(serde::Deserialize)] | ||
| struct LogEntry { | ||
| level: LogLevel, | ||
| message: String, | ||
| } | ||
|
|
||
| let json = r#"{"level": "ERROR", "message": "Something went wrong"}"#; | ||
| let entry: LogEntry = serde_json::from_str(json).unwrap(); | ||
| assert!(matches!(entry.level, LogLevel::Error)); | ||
| assert_eq!(entry.message, "Something went wrong"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_array_of_levels() { | ||
| let json = r#"["TRACE", "INFO", "ERROR"]"#; | ||
| let levels: Vec<LogLevel> = serde_json::from_str(json).unwrap(); | ||
| assert_eq!(levels.len(), 3); | ||
| assert!(matches!(levels[0], LogLevel::Trace)); | ||
| assert!(matches!(levels[1], LogLevel::Info)); | ||
| assert!(matches!(levels[2], LogLevel::Error)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_with_whitespace() { | ||
| let json = r#" "INFO" "#; | ||
| let level: LogLevel = serde_json::from_str(json).unwrap(); | ||
| assert!(matches!(level, LogLevel::Info)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn error_message_contains_valid_options() { | ||
| let json = r#""FATAL""#; | ||
| let result: std::result::Result<LogLevel, _> = serde_json::from_str(json); | ||
|
|
||
| match result { | ||
| Err(e) => { | ||
| let error_msg = e.to_string(); | ||
| // The error message should mention valid variants | ||
| assert!(error_msg.contains("unknown variant")); | ||
| } | ||
| Ok(_) => panic!("Expected deserialization to fail"), | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.