@@ -5,6 +5,7 @@ use std::task::Context;
5
5
use std:: task:: Poll ;
6
6
use std:: time:: Instant ;
7
7
8
+ use graph:: data:: query:: QueryResults ;
8
9
use graph:: prelude:: * ;
9
10
use graph:: { components:: server:: query:: GraphQLServerError , data:: query:: QueryTarget } ;
10
11
use http:: header;
@@ -19,7 +20,6 @@ use crate::request::parse_graphql_request;
19
20
20
21
pub struct GraphQLServiceMetrics {
21
22
query_execution_time : Box < HistogramVec > ,
22
- failed_query_execution_time : Box < HistogramVec > ,
23
23
}
24
24
25
25
impl fmt:: Debug for GraphQLServiceMetrics {
@@ -34,36 +34,29 @@ impl GraphQLServiceMetrics {
34
34
. new_histogram_vec (
35
35
"query_execution_time" ,
36
36
"Execution time for successful GraphQL queries" ,
37
- vec ! [ String :: from( "deployment" ) ] ,
37
+ vec ! [ String :: from( "deployment" ) , String :: from ( "status" ) ] ,
38
38
vec ! [ 0.1 , 0.5 , 1.0 , 10.0 , 100.0 ] ,
39
39
)
40
40
. expect ( "failed to create `query_execution_time` histogram" ) ;
41
41
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
-
51
42
Self {
52
43
query_execution_time,
53
- failed_query_execution_time,
54
44
}
55
45
}
56
46
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
+ } ;
58
57
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 ( ) ) ;
67
60
}
68
61
}
69
62
@@ -197,10 +190,7 @@ where
197
190
Err ( e) => return Err ( e) ,
198
191
} ;
199
192
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) ;
204
194
205
195
Ok ( result. as_http_response ( ) )
206
196
}
0 commit comments