@@ -112,8 +112,18 @@ mod handlers {
112112 Ok ( reply:: server_error ( err) )
113113 }
114114 } ,
115- Ok ( SignatureRegistrationStatus :: Registered ) => Ok ( reply:: empty ( StatusCode :: CREATED ) ) ,
116- Ok ( SignatureRegistrationStatus :: Buffered ) => Ok ( reply:: empty ( StatusCode :: ACCEPTED ) ) ,
115+ Ok ( registration_status) => {
116+ metrics_service
117+ . get_signature_registration_total_successful_since_startup ( )
118+ . increment ( & [ METRICS_HTTP_ORIGIN ] ) ;
119+
120+ match registration_status {
121+ SignatureRegistrationStatus :: Registered => {
122+ Ok ( reply:: empty ( StatusCode :: CREATED ) )
123+ }
124+ SignatureRegistrationStatus :: Buffered => Ok ( reply:: empty ( StatusCode :: ACCEPTED ) ) ,
125+ }
126+ }
117127 }
118128 }
119129}
@@ -127,6 +137,7 @@ mod tests {
127137 use warp:: test:: request;
128138
129139 use mithril_api_spec:: APISpec ;
140+ use mithril_common:: test:: mock_extensions:: MockBuilder ;
130141 use mithril_common:: {
131142 entities:: SignedEntityType , messages:: RegisterSignatureMessageHttp , test:: double:: Dummy ,
132143 } ;
@@ -150,15 +161,28 @@ mod tests {
150161 }
151162
152163 #[ tokio:: test]
153- async fn test_register_signatures_increments_signature_registration_total_received_since_startup_metric ( )
164+ async fn test_register_signatures_increments_signature_registration_total_received_and_successful_since_startup_metric_if_successful ( )
154165 {
155166 let method = Method :: POST . as_str ( ) ;
156167 let path = "/register-signatures" ;
157- let dependency_manager = Arc :: new ( initialize_dependencies ! ( ) . await ) ;
158- let initial_counter_value = dependency_manager
168+ let dependency_manager = {
169+ let mut deps = initialize_dependencies ! ( ) . await ;
170+ deps. certifier_service = MockBuilder :: < MockCertifierService > :: configure ( |mock| {
171+ mock. expect_register_single_signature ( )
172+ . returning ( |_, _| Ok ( SignatureRegistrationStatus :: Registered ) ) ;
173+ } ) ;
174+ deps. single_signer_authenticator =
175+ Arc :: new ( SingleSignatureAuthenticator :: new_that_authenticate_everything ( ) ) ;
176+ Arc :: new ( deps)
177+ } ;
178+ let initial_received_counter_value = dependency_manager
159179 . metrics_service
160180 . get_signature_registration_total_received_since_startup ( )
161181 . get ( & [ "HTTP" ] ) ;
182+ let initial_successful_counter_value = dependency_manager
183+ . metrics_service
184+ . get_signature_registration_total_successful_since_startup ( )
185+ . get ( & [ "HTTP" ] ) ;
162186
163187 request ( )
164188 . method ( method)
@@ -170,12 +194,65 @@ mod tests {
170194 . await ;
171195
172196 assert_eq ! (
173- initial_counter_value + 1 ,
197+ initial_received_counter_value + 1 ,
174198 dependency_manager
175199 . metrics_service
176200 . get_signature_registration_total_received_since_startup( )
177201 . get( & [ "HTTP" ] )
178202 ) ;
203+ assert_eq ! (
204+ initial_successful_counter_value + 1 ,
205+ dependency_manager
206+ . metrics_service
207+ . get_signature_registration_total_successful_since_startup( )
208+ . get( & [ "HTTP" ] )
209+ ) ;
210+ }
211+
212+ #[ tokio:: test]
213+ async fn test_register_signatures_only_increments_signature_registration_total_received_since_startup_metric_if_failure ( )
214+ {
215+ let method = Method :: POST . as_str ( ) ;
216+ let path = "/register-signatures" ;
217+ let dependency_manager = {
218+ let mut deps = initialize_dependencies ! ( ) . await ;
219+ deps. single_signer_authenticator =
220+ Arc :: new ( SingleSignatureAuthenticator :: new_that_reject_everything ( ) ) ;
221+ Arc :: new ( deps)
222+ } ;
223+
224+ let initial_received_counter_value = dependency_manager
225+ . metrics_service
226+ . get_signature_registration_total_received_since_startup ( )
227+ . get ( & [ "HTTP" ] ) ;
228+ let initial_successful_counter_value = dependency_manager
229+ . metrics_service
230+ . get_signature_registration_total_successful_since_startup ( )
231+ . get ( & [ "HTTP" ] ) ;
232+
233+ request ( )
234+ . method ( method)
235+ . path ( path)
236+ . json ( & RegisterSignatureMessageHttp :: dummy ( ) )
237+ . reply ( & setup_router ( RouterState :: new_with_dummy_config (
238+ dependency_manager. clone ( ) ,
239+ ) ) )
240+ . await ;
241+
242+ assert_eq ! (
243+ initial_received_counter_value + 1 ,
244+ dependency_manager
245+ . metrics_service
246+ . get_signature_registration_total_received_since_startup( )
247+ . get( & [ "HTTP" ] )
248+ ) ;
249+ assert_eq ! (
250+ initial_successful_counter_value,
251+ dependency_manager
252+ . metrics_service
253+ . get_signature_registration_total_successful_since_startup( )
254+ . get( & [ "HTTP" ] )
255+ ) ;
179256 }
180257
181258 #[ tokio:: test]
0 commit comments