@@ -5,6 +5,7 @@ use std::task::Context;
55use std:: task:: Poll ;
66use std:: time:: Instant ;
77
8+ use graph:: data:: query:: QueryResults ;
89use graph:: prelude:: * ;
910use graph:: { components:: server:: query:: GraphQLServerError , data:: query:: QueryTarget } ;
1011use http:: header;
@@ -19,7 +20,6 @@ use crate::request::parse_graphql_request;
1920
2021pub struct GraphQLServiceMetrics {
2122 query_execution_time : Box < HistogramVec > ,
22- failed_query_execution_time : Box < HistogramVec > ,
2323}
2424
2525impl fmt:: Debug for GraphQLServiceMetrics {
@@ -34,36 +34,29 @@ impl GraphQLServiceMetrics {
3434 . new_histogram_vec (
3535 "query_execution_time" ,
3636 "Execution time for successful GraphQL queries" ,
37- vec ! [ String :: from( "deployment" ) ] ,
37+ vec ! [ String :: from( "deployment" ) , String :: from ( "status" ) ] ,
3838 vec ! [ 0.1 , 0.5 , 1.0 , 10.0 , 100.0 ] ,
3939 )
4040 . expect ( "failed to create `query_execution_time` histogram" ) ;
4141
42- let failed_query_execution_time = registry
43- . new_histogram_vec (
44- "query_failed_execution_time" ,
45- "Execution time for failed GraphQL queries" ,
46- vec ! [ String :: from( "deployment" ) ] ,
47- vec ! [ 0.1 , 0.5 , 1.0 , 10.0 , 100.0 ] ,
48- )
49- . expect ( "failed to create `query_failed_execution_time` histogram" ) ;
50-
5142 Self {
5243 query_execution_time,
53- failed_query_execution_time,
5444 }
5545 }
5646
57- pub fn observe_query_execution_time ( & self , duration : f64 , deployment_id : String ) {
47+ pub fn observe_query ( & self , duration : Duration , results : & QueryResults ) {
48+ let id = results
49+ . deployment_hash ( )
50+ . map ( |h| h. as_str ( ) )
51+ . unwrap_or ( "unknown" ) ;
52+ let status = if results. has_errors ( ) {
53+ "failed"
54+ } else {
55+ "success"
56+ } ;
5857 self . query_execution_time
59- . with_label_values ( vec ! [ deployment_id. as_ref( ) ] . as_slice ( ) )
60- . observe ( duration) ;
61- }
62-
63- pub fn observe_failed_query_execution_time ( & self , duration : f64 , deployment_id : String ) {
64- self . failed_query_execution_time
65- . with_label_values ( vec ! [ deployment_id. as_ref( ) ] . as_slice ( ) )
66- . observe ( duration) ;
58+ . with_label_values ( & [ id, status] )
59+ . observe ( duration. as_secs_f64 ( ) ) ;
6760 }
6861}
6962
@@ -197,10 +190,7 @@ where
197190 Err ( e) => return Err ( e) ,
198191 } ;
199192
200- if let Some ( id) = result. first ( ) . and_then ( |res| res. deployment . clone ( ) ) {
201- service_metrics
202- . observe_query_execution_time ( start. elapsed ( ) . as_secs_f64 ( ) , id. to_string ( ) ) ;
203- }
193+ service_metrics. observe_query ( start. elapsed ( ) , & result) ;
204194
205195 Ok ( result. as_http_response ( ) )
206196 }
0 commit comments