@@ -2,13 +2,17 @@ use super::prelude::*;
2
2
3
3
/// Returns count of Physical Disks per status
4
4
///
5
- #[ cfg_attr( feature = "swagger" ,
5
+ #[ cfg_attr( all ( feature = "swagger" , debug_assertions ) ,
6
6
utoipa:: path(
7
7
get,
8
8
context_path = ApiV1 :: to_path( ) ,
9
9
path = "/disks/count" ,
10
10
responses(
11
- ( status = 200 , body = DiskCount , content_type = "application/json" , description = "Returns a list with count of physical disks per status" ) ,
11
+ (
12
+ status = 200 , body = DiskCount ,
13
+ content_type = "application/json" ,
14
+ description = "Returns a list with count of physical disks per status"
15
+ ) ,
12
16
( status = 401 , description = "Unauthorized" )
13
17
) ,
14
18
security( ( "api_key" = [ ] ) )
@@ -65,14 +69,10 @@ pub async fn get_disks_count(Extension(client): Extension<HttpBobClient>) -> Jso
65
69
} ;
66
70
let active_disks = disks. iter ( ) . filter ( |disk| disk. is_active ) ;
67
71
for disk in active_disks {
68
- if let Some ( & occupied_space) = space. occupied_disk_space_by_disk . get ( & disk. name ) {
69
- #[ allow( clippy:: cast_precision_loss) ]
70
- match disk_status_from_space ( & space, occupied_space) {
71
- DiskStatus :: Good => count[ DiskStatusName :: Good ] += 1 ,
72
- _ => count[ DiskStatusName :: Bad ] += 1 ,
73
- }
74
- } else {
75
- count[ DiskStatusName :: Offline ] += 1 ;
72
+ match DiskStatus :: from_space_info ( & space, & disk. name ) {
73
+ DiskStatus :: Good => count[ DiskStatusName :: Good ] += 1 ,
74
+ DiskStatus :: Offline => count[ DiskStatusName :: Offline ] += 1 ,
75
+ DiskStatus :: Bad ( _) => count[ DiskStatusName :: Bad ] += 1 ,
76
76
}
77
77
}
78
78
}
@@ -83,16 +83,21 @@ pub async fn get_disks_count(Extension(client): Extension<HttpBobClient>) -> Jso
83
83
84
84
/// Get Nodes count per Status
85
85
///
86
- #[ cfg_attr( feature = "swagger" , utoipa:: path(
86
+ #[ cfg_attr( all( feature = "swagger" , debug_assertions) ,
87
+ utoipa:: path(
87
88
get,
88
89
context_path = ApiV1 :: to_path( ) ,
89
90
path = "/nodes/count" ,
90
91
responses(
91
- ( status = 200 , body = NodeCount , content_type = "application/json" , description = "Node count list per status" ) ,
92
+ (
93
+ status = 200 , body = NodeCount ,
94
+ content_type = "application/json" ,
95
+ description = "Node count list per status"
96
+ ) ,
92
97
( status = 401 , description = "Unauthorized" )
93
98
) ,
94
99
security( ( "api_key" = [ ] ) )
95
- ) ) ]
100
+ ) ) ]
96
101
pub async fn get_nodes_count ( Extension ( client) : Extension < HttpBobClient > ) -> Json < NodeCount > {
97
102
tracing:: info!( "get /nodes/count : {:?}" , client) ;
98
103
@@ -109,9 +114,8 @@ pub async fn get_nodes_count(Extension(client): Extension<HttpBobClient>) -> Jso
109
114
let mut counter = 0 ;
110
115
while let Some ( res) = metrics. next ( ) . await {
111
116
if let Ok ( Ok ( GetMetricsResponse :: Metrics ( metrics) ) ) = res {
112
- tracing:: info!( "#{counter}: metrics received successfully" ) ;
113
- let metrics = Into :: < TypedMetrics > :: into ( metrics) ;
114
- if is_bad_node ( & metrics) {
117
+ tracing:: trace!( "#{counter}: metrics received successfully" ) ;
118
+ if Into :: < TypedMetrics > :: into ( metrics) . is_bad_node ( ) {
115
119
count[ NodeStatusName :: Bad ] += 1 ;
116
120
} else {
117
121
count[ NodeStatusName :: Good ] += 1 ;
@@ -129,16 +133,21 @@ pub async fn get_nodes_count(Extension(client): Extension<HttpBobClient>) -> Jso
129
133
130
134
/// Returns Total RPS on cluster
131
135
///
132
- #[ cfg_attr( feature = "swagger" , utoipa:: path(
136
+ #[ cfg_attr( all( feature = "swagger" , debug_assertions) ,
137
+ utoipa:: path(
133
138
get,
134
139
context_path = ApiV1 :: to_path( ) ,
135
140
path = "/nodes/rps" ,
136
141
responses(
137
- ( status = 200 , body = RPS , content_type = "application/json" , description = "RPS list per operation on all nodes" ) ,
142
+ (
143
+ status = 200 , body = RPS ,
144
+ content_type = "application/json" ,
145
+ description = "RPS list per operation on all nodes"
146
+ ) ,
138
147
( status = 401 , description = "Unauthorized" )
139
148
) ,
140
149
security( ( "api_key" = [ ] ) )
141
- ) ) ]
150
+ ) ) ]
142
151
pub async fn get_rps ( Extension ( client) : Extension < HttpBobClient > ) -> Json < RPS > {
143
152
tracing:: info!( "get /nodes/rps : {:?}" , client) ;
144
153
@@ -155,7 +164,6 @@ pub async fn get_rps(Extension(client): Extension<HttpBobClient>) -> Json<RPS> {
155
164
while let Some ( res) = metrics. next ( ) . await {
156
165
if let Ok ( Ok ( metrics) ) = res {
157
166
tracing:: info!( "#{counter}: metrics received successfully" ) ;
158
-
159
167
let GetMetricsResponse :: Metrics ( metrics) = metrics;
160
168
let metrics = Into :: < TypedMetrics > :: into ( metrics) ;
161
169
rps[ Operation :: Get ] += metrics[ RawMetricEntry :: ClusterGrinderGetCountRate ] . value ;
@@ -174,7 +182,8 @@ pub async fn get_rps(Extension(client): Extension<HttpBobClient>) -> Json<RPS> {
174
182
175
183
/// Return inforamtion about space on cluster
176
184
///
177
- #[ cfg_attr( feature = "swagger" , utoipa:: path(
185
+ #[ cfg_attr( all( feature = "swagger" , debug_assertions) ,
186
+ utoipa:: path(
178
187
get,
179
188
context_path = ApiV1 :: to_path( ) ,
180
189
path = "/nodes/space" ,
@@ -183,7 +192,7 @@ pub async fn get_rps(Extension(client): Extension<HttpBobClient>) -> Json<RPS> {
183
192
( status = 401 , description = "Unauthorized" )
184
193
) ,
185
194
security( ( "api_key" = [ ] ) )
186
- ) ) ]
195
+ ) ) ]
187
196
pub async fn get_space ( Extension ( client) : Extension < HttpBobClient > ) -> Json < SpaceInfo > {
188
197
tracing:: info!( "get /space : {:?}" , client) ;
189
198
let mut spaces: FuturesUnordered < _ > = client
@@ -214,29 +223,3 @@ pub async fn get_space(Extension(client): Extension<HttpBobClient>) -> Json<Spac
214
223
215
224
Json ( total_space)
216
225
}
217
-
218
- #[ allow( clippy:: cast_precision_loss) ]
219
- fn is_bad_node ( node_metrics : & TypedMetrics ) -> bool {
220
- node_metrics[ RawMetricEntry :: BackendAlienCount ] . value != 0
221
- || node_metrics[ RawMetricEntry :: BackendCorruptedBlobCount ] . value != 0
222
- || node_metrics[ RawMetricEntry :: HardwareBobCpuLoad ] . value >= DEFAULT_MAX_CPU
223
- || ( 1.
224
- - ( node_metrics[ RawMetricEntry :: HardwareTotalSpace ] . value
225
- - node_metrics[ RawMetricEntry :: HardwareFreeSpace ] . value ) as f64
226
- / node_metrics[ RawMetricEntry :: HardwareTotalSpace ] . value as f64 )
227
- < DEFAULT_MIN_FREE_SPACE
228
- || node_metrics[ RawMetricEntry :: HardwareBobVirtualRam ]
229
- > node_metrics[ RawMetricEntry :: HardwareTotalRam ]
230
- }
231
-
232
- #[ allow( clippy:: cast_precision_loss) ]
233
- fn disk_status_from_space ( space : & dto:: SpaceInfo , occupied_space : u64 ) -> DiskStatus {
234
- if ( ( space. total_disk_space_bytes - occupied_space) as f64
235
- / space. total_disk_space_bytes as f64 )
236
- < DEFAULT_MIN_FREE_SPACE
237
- {
238
- DiskStatus :: Bad ( vec ! [ DiskProblem :: FreeSpaceRunningOut ] )
239
- } else {
240
- DiskStatus :: Good
241
- }
242
- }
0 commit comments