Skip to content

Commit 7e321dd

Browse files
dianpopaalxiord
authored andcommitted
metrics: add support for flushing metrics to...
a secondary named pipe. Also do not flush metrics if the logging system was not initialized. Signed-off-by: Diana Popa <[email protected]>
1 parent 4da6448 commit 7e321dd

File tree

8 files changed

+200
-148
lines changed

8 files changed

+200
-148
lines changed

api_server/src/http_service.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,8 @@ mod tests {
10821082
let path = "/foo";
10831083
let path_tokens: Vec<&str> = path[1..].split_terminator('/').collect();
10841084
let json = "{
1085-
\"path\": \"tmp\",
1085+
\"log_fifo\": \"tmp1\",
1086+
\"metrics_fifo\": \"tmp2\",
10861087
\"level\": \"Info\",
10871088
\"show_level\": true,
10881089
\"show_log_origin\": true

api_server/src/request/sync/logger.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ pub enum APILoggerLevel {
1818
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1919
#[serde(deny_unknown_fields)]
2020
pub struct APILoggerDescription {
21-
pub path: String,
21+
pub log_fifo: String,
22+
pub metrics_fifo: String,
2223
#[serde(skip_serializing_if = "Option::is_none")]
2324
pub level: Option<APILoggerLevel>,
2425
#[serde(skip_serializing_if = "Option::is_none")]
@@ -109,7 +110,8 @@ mod tests {
109110
#[test]
110111
fn test_into_parsed_request() {
111112
let desc = APILoggerDescription {
112-
path: String::from(""),
113+
log_fifo: String::from("log"),
114+
metrics_fifo: String::from("metrics"),
113115
level: None,
114116
show_level: None,
115117
show_log_origin: None,

logger/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ serde = ">=1.0.27"
1212
serde_derive = ">=1.0.27"
1313
serde_json = ">=1.0.9"
1414
time = "0.1.34"
15+
16+
[dev-dependencies]
17+
tempfile = ">=3.0.2"

logger/src/error.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ pub enum LoggerError {
1010
NeverInitialized(String),
1111
/// The logger does not allow reinitialization.
1212
AlreadyInitialized,
13-
/// Creating log file fails.
14-
CreateLogFile(std::io::Error),
15-
/// Writing to log file fails.
16-
FileLogWrite(std::io::Error),
13+
/// Opening named pipe fails.
14+
OpenFIFO(std::io::Error),
15+
/// Writing to named pipe fails.
16+
LogWrite(std::io::Error),
1717
/// Flushing to disk fails.
18-
FileLogFlush(std::io::Error),
18+
LogFlush(std::io::Error),
1919
/// Error obtaining lock on mutex.
2020
MutexLockFailure(String),
2121
/// Error in the logging of the metrics.
@@ -31,14 +31,14 @@ impl fmt::Display for LoggerError {
3131
LoggerError::AlreadyInitialized => {
3232
format!("{}", "Reinitialization of logger not allowed.")
3333
}
34-
LoggerError::CreateLogFile(ref e) => {
35-
format!("Failed to create log file. Error: {}", e.description())
34+
LoggerError::OpenFIFO(ref e) => {
35+
format!("Failed to open pipe. Error: {}", e.description())
3636
}
37-
LoggerError::FileLogWrite(ref e) => {
38-
format!("Failed to write to log file. Error: {}", e.description())
37+
LoggerError::LogWrite(ref e) => {
38+
format!("Failed to write logs. Error: {}", e.description())
3939
}
40-
LoggerError::FileLogFlush(ref e) => {
41-
format!("Failed to flush log file. Error: {}", e.description())
40+
LoggerError::LogFlush(ref e) => {
41+
format!("Failed to flush logs. Error: {}", e.description())
4242
}
4343
LoggerError::MutexLockFailure(ref e) => format!("{}", e),
4444
LoggerError::LogMetricFailure(ref e) => format!("{}", e),
@@ -78,29 +78,29 @@ mod tests {
7878
assert!(
7979
format!(
8080
"{:?}",
81-
LoggerError::FileLogWrite(std::io::Error::new(ErrorKind::Interrupted, "write"))
82-
).contains("FileLogWrite")
81+
LoggerError::LogWrite(std::io::Error::new(ErrorKind::Interrupted, "write"))
82+
).contains("LogWrite")
8383
);
8484
assert_eq!(
8585
format!(
8686
"{}",
87-
LoggerError::FileLogWrite(std::io::Error::new(ErrorKind::Interrupted, "write"))
87+
LoggerError::LogWrite(std::io::Error::new(ErrorKind::Interrupted, "write"))
8888
),
89-
"Failed to write to log file. Error: write"
89+
"Failed to write logs. Error: write"
9090
);
9191

9292
assert!(
9393
format!(
9494
"{:?}",
95-
LoggerError::FileLogFlush(std::io::Error::new(ErrorKind::Interrupted, "flush"))
96-
).contains("FileLogFlush")
95+
LoggerError::LogFlush(std::io::Error::new(ErrorKind::Interrupted, "flush"))
96+
).contains("LogFlush")
9797
);
9898
assert_eq!(
9999
format!(
100100
"{}",
101-
LoggerError::FileLogFlush(std::io::Error::new(ErrorKind::Interrupted, "flush"))
101+
LoggerError::LogFlush(std::io::Error::new(ErrorKind::Interrupted, "flush"))
102102
),
103-
"Failed to flush log file. Error: flush"
103+
"Failed to flush logs. Error: flush"
104104
);
105105

106106
assert!(
@@ -126,9 +126,9 @@ mod tests {
126126
assert_eq!(
127127
format!(
128128
"{}",
129-
LoggerError::LogMetricFailure("Failure in the logging of the metrics.".to_string())
129+
LoggerError::LogMetricFailure("Failed to log metrics.".to_string())
130130
),
131-
"Failure in the logging of the metrics."
131+
"Failed to log metrics."
132132
);
133133

134134
assert!(format!("{:?}", LoggerError::LogMetricRateLimit).contains("LogMetricRateLimit"));

0 commit comments

Comments
 (0)