-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add support for specifying different files for flushing metrics #362
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass 1, will do another one in a few hours.
api_server/src/http_service.rs
Outdated
); | ||
|
||
// Test case when JSON is broken. | ||
let json = "{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not testing that the JSON is broken. The JSON is correct. The problem here is that the state is a required field and since you misspelled it on purpose, Serde doesn't find it. You should update the comment or actually pass an invalid json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the comment. Take a look.
api_server/src/http_service.rs
Outdated
@@ -1081,7 +1081,8 @@ mod tests { | |||
let path = "/foo"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you have an extra u in the commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are referring to another commit; This one 'metrics: add suuport for flushing metrics to...', right?
api_server/src/http_service.rs
Outdated
|
||
// PUT | ||
let logger_deser = serde_json::from_slice::<request::APILoggerDescription>(&body); | ||
match logger_deser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This match
tests serde
functionalities instead of your code, please replace it with an unwrap
and match
only on the result of parse_logger_req
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
logger/src/lib.rs
Outdated
/// This is used by the internal logger to either flush human-readable logs or metrics. | ||
fn log_to_fifo(mut msg: String, fifo_writer: &mut PipeLogWriter) -> Result<()> { | ||
msg = format!("{}\n", msg); | ||
if let Err(e) = fifo_writer.write(&msg) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this be replaced with the ?
operator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it can and it has been replaced.
logger/src/lib.rs
Outdated
|
||
File::create(&Path::new(&log_file_str())).expect("Failed to create temporary log file."); | ||
File::create(&Path::new(&metrics_file_str())) | ||
.expect("Failed to create temporary log file."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please choose another error message to differentiate between the temporary log and metrics files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did change it. Take a look where I initialize the two NamedTempFile.
logger/src/lib.rs
Outdated
File::create(&Path::new(&metrics_file_str())) | ||
.expect("Failed to create temporary log file."); | ||
|
||
assert!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If any assert
fails, the temporary files will not be cleaned up. Please store the results and assert
on them after removing the files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if there is no limitation and you just need a file, you can actually use the tempfile crate. Take a look at my PR #367 to see if tempfiles would be a good fit here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am now using NamedTempFile. Thanks @andreeaflorescu for the suggestion.
logger/src/writers.rs
Outdated
let res = FileLogWriter::new(&file); | ||
let bad_file: String = "./inexistent/tmp.log".to_string(); | ||
assert!(PipeLogWriter::new(&bad_file).is_err()); | ||
format!("{:?}", PipeLogWriter::new(&bad_file)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks less like a test and more like a trick to increase coverage, I'd remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed all the formats
.
let filename = "tmp.log"; | ||
File::create(&Path::new(&log_filename)).expect("Failed to create temporary log file."); | ||
|
||
File::create(&Path::new(&metrics_filename)).expect("Failed to create temporary log file."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please modify the error message to make it specific to the metrics file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
...as part of the decision to use two named pipes as logging destinations: one for human readable logs and one for metrics. Signed-off-by: Diana Popa <[email protected]>
Signed-off-by: Diana Popa <[email protected]>
a secondary named pipe. Also do not flush metrics if the logging system was not initialized. Signed-off-by: Diana Popa <[email protected]>
and metrics being flushed to two different named pipes. Signed-off-by: Diana Popa <[email protected]>
Changes
http_service.rs
firecracker.yaml
specification to also mention themetrics_fifo
fieldTesting
Build Time
Prerequisite
## add the necessary musl target to the active toolchain and install musl-gcc rustup target add x86_64-unknown-linux-musl
Build tests
Coverage report for related files
73.1%
.Integration Testing
sudo rm -f /tmp/firecracker.socket && \ target/x86_64-unknown-linux-musl/debug/firecracker
$log_fifo
is being consumed$metric_fifo
is being consumed."logger":{"missed_metrics_count":0,"missed_log_count":0
.