Skip to content

Commit

Permalink
chore: add get res_name && resource_type function, add home dir in lo…
Browse files Browse the repository at this point in the history
…g dir
  • Loading branch information
fanhan authored and Forsworns committed Nov 14, 2023
1 parent b72cd36 commit 1c3d3c8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions sentinel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ k8s-openapi = { version = "0.16.0", default-features = false, features = [
"v1_25",
], optional = true }
schemars = { version = "0.8.8", optional = true }
dirs = "5.0.1"

[target.'cfg(not(target_arch="wasm32"))'.dependencies]
# cannot add "wasm-bindgen" feature to uuid,
Expand Down
8 changes: 8 additions & 0 deletions sentinel-core/src/core/config/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,11 @@ pub fn metric_stat_sample_count() -> u32 {
.try_with(|c| c.borrow().config.stat.sample_count)
.unwrap()
}

#[inline]
pub fn get_default_log_dir() -> String {
match dirs::home_dir() {
Some(path) => path.join(LOG_METRICS_DIR).to_string_lossy().to_string(),
None => LOG_METRICS_DIR.to_string(),
}
}
3 changes: 2 additions & 1 deletion sentinel-core/src/core/config/entity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::constant::*;
use crate::config::get_default_log_dir;
use crate::{
base::{check_validity_for_reuse_statistic, constant::*, ResourceType},
Error, Result,
Expand Down Expand Up @@ -38,7 +39,7 @@ impl Default for LogMetricConfig {
fn default() -> Self {
LogMetricConfig {
use_pid: true,
dir: LOG_METRICS_DIR.into(),
dir: get_default_log_dir(),
single_file_max_size: SINGLE_FILE_MAX_SIZE,
max_file_count: MAX_FILE_AMOUNT,
flush_interval_sec: FLUSH_INTERVAL_SEC,
Expand Down
8 changes: 8 additions & 0 deletions sentinel-core/src/core/stat/resource_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ impl ResourceNode {
pub fn max_concurrency(&self) -> u32 {
self.metric.max_concurrency()
}

pub fn get_res_name(&self) -> &str {
self.res_name.as_ref()
}

pub fn get_resource_type(&self) -> ResourceType {
self.resource_type
}
}

impl MetricItemRetriever for ResourceNode {
Expand Down

0 comments on commit 1c3d3c8

Please sign in to comment.