Skip to content

Commit

Permalink
1. 增加监控页面权限控制,只有管理员与开发者可以查看系统监控;
Browse files Browse the repository at this point in the history
2. 更新前端版本号为v0.3.14以支持监控页面;
3. http监控指标忽略配置监控长链接,避免干扰处理时长统计; #117
  • Loading branch information
heqingpan committed Jul 14, 2024
1 parent 65e9b72 commit 9b9a156
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mime_guess = { version = "2" }
rusqlite = { version = "0.25", features = ["bundled"] }
rsql_builder = "0.1.5"
inner-mem-cache = "0.1.7"
rnacos-web-dist-wrap = "=0.3.13"
rnacos-web-dist-wrap = "=0.3.14"
nacos_rust_client = "0.2"
zip = "0.6"
tempfile = "3"
Expand Down
2 changes: 1 addition & 1 deletion src/console/model/metrics_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl From<TimelineQueryRequest> for TimelineQueryParam {
keys = value
.string_key
.unwrap_or_default()
.split(",")
.split(',')
.filter(|e| !e.is_empty())
.map(|e| e.to_string())
.collect();
Expand Down
4 changes: 2 additions & 2 deletions src/metrics/timeline/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl TimelineGroup {
if let Some(timeline_summary) = summery_data.get_mut(str_key) {
timeline_summary
} else {
let timeline_summary = Self::build_timeline_summary(&v, index_len);
let timeline_summary = Self::build_timeline_summary(v, index_len);
summery_data.insert(str_key.to_owned(), timeline_summary);
summery_data.get_mut(str_key).unwrap()
};
Expand Down Expand Up @@ -156,7 +156,7 @@ impl MetricsTimelineManager {
}

pub fn add_least_record(&mut self, snapshot: MetricsSnapshot) {
self.minute_timeline_group.add_record(snapshot);
self.least_timeline_group.add_record(snapshot);
}

pub fn query(&self, param: TimelineQueryParam) -> TimelineQueryResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/timeline/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl TimelineValue {
let summary_key =
MetricsKey::get_summary_from_histogram(key).unwrap_or(key.to_owned());
let mut summary = SummaryValue::new(&DEFAULT_SUMMARY_BOUNDS);
summary.recalculate_from_histogram(&item);
summary.recalculate_from_histogram(item);
self.section_summary
.insert(summary_key, SummaryWrapValue::new(summary, diff_ms));
}
Expand Down
8 changes: 7 additions & 1 deletion src/openapi/middle/auth_middle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ lazy_static::lazy_static! {
"/nacos/v1/auth/login", "/nacos/v1/auth/users/login","/nacos/metrics"
];
pub static ref API_PATH: Regex = Regex::new(r"(?i)/nacos/.*").unwrap();
pub static ref IGNORE_METRICS_PATH: Vec<&'static str> = vec![
"/nacos/v1/cs/configs/listener"
];
//pub static ref PARM_AUTH_TOKEN: Regex = Regex::new(r"accessToken=(\w*)").unwrap();
}

Expand Down Expand Up @@ -86,6 +89,7 @@ where
} else {
true
};
let ignore_metrics = IGNORE_METRICS_PATH.contains(&path);
let app_share_data = self.app_share_data.clone();
let service = self.service.clone();
Box::pin(async move {
Expand Down Expand Up @@ -131,7 +135,9 @@ where
.duration_since(start)
.unwrap_or_default()
.as_secs_f64();
record_req_metrics(&app_share_data.metrics_manager, duration, success);
if !ignore_metrics {
record_req_metrics(&app_share_data.metrics_manager, duration, success);
}
ServiceResponse::map_into_left_body(item)
})
} else {
Expand Down
12 changes: 12 additions & 0 deletions src/user/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ lazy_static::lazy_static! {
R::Path("/rnacos/api/console/v2/instance/remove",HTTP_METHOD_ALL),
]);

static ref M_METRICS_VISITOR: ModuleResource = ModuleResource::new(vec![
//WebResource
R::WebResource("/manage/appmonitor"),
//path
R::Path("/rnacos/manage/appmonitor",HTTP_METHOD_GET),
R::Path("/rnacos/api/console/v2/metrics/timeline",HTTP_METHOD_ALL),
R::Path("/rnacos/api/console/cluster/cluster_node_list",HTTP_METHOD_GET),
R::Path("/rnacos/api/console/v2/cluster/cluster_node_list",HTTP_METHOD_GET),
]);

static ref R_VISITOR: Arc<GroupResource> = Arc::new(GroupResource::new(vec![
&M_BASE,
//&M_CLUSTER_VISITOR,
Expand All @@ -316,6 +326,7 @@ lazy_static::lazy_static! {
&M_NAMESPACE_MANAGE,
&M_CONFIG_MANAGE,
&M_NAMING_MANAGE,
&M_METRICS_VISITOR,
]));

static ref R_MANAGER: Arc<GroupResource> = Arc::new(GroupResource::new(vec![
Expand All @@ -325,6 +336,7 @@ lazy_static::lazy_static! {
&M_CONFIG_MANAGE,
&M_NAMING_MANAGE,
&M_USER_MANAGE,
&M_METRICS_VISITOR,
]));

}
Expand Down

0 comments on commit 9b9a156

Please sign in to comment.