@@ -5,12 +5,23 @@ const router = createRouter();
55const g_db = require ( "@arangodb" ) . db ;
66const g_lib = require ( "./support" ) ;
77const joi = require ( "joi" ) ;
8+ const logger = require ( "./lib/logger" ) ;
89
910module . exports = router ;
1011
12+ const basePath = "metrics" ;
1113router
1214 . post ( "/msg_count/update" , function ( req , res ) {
15+ const client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
1316 try {
17+ logger . logRequestStarted ( {
18+ client : client ?. _id ,
19+ correlationId : req . headers [ "x-correlation-id" ] ,
20+ httpVerb : "GET" ,
21+ routePath : basePath + "/msg_count/update" ,
22+ status : "Started" ,
23+ description : "Update message metrics" ,
24+ } ) ;
1425 var i ,
1526 u ,
1627 ts = req . body . timestamp ,
@@ -33,7 +44,26 @@ router
3344 } ;
3445 g_db . metrics . save ( obj ) ;
3546 }
47+ logger . logRequestSuccess ( {
48+ client : client ?. _id ,
49+ correlationId : req . headers [ "x-correlation-id" ] ,
50+ httpVerb : "GET" ,
51+ routePath : basePath + "/msg_count/update" ,
52+ status : "Success" ,
53+ description : "Update message metrics" ,
54+ extra : obj ,
55+ } ) ;
3656 } catch ( e ) {
57+ logger . logRequestFailure ( {
58+ client : client ?. _id ,
59+ correlationId : req . headers [ "x-correlation-id" ] ,
60+ httpVerb : "GET" ,
61+ routePath : basePath + "/msg_count/update" ,
62+ status : "Failure" ,
63+ description : "Update message metrics" ,
64+ extra : obj ,
65+ error : e ,
66+ } ) ;
3767 g_lib . handleException ( e , res ) ;
3868 }
3969 } )
@@ -43,7 +73,16 @@ router
4373
4474router
4575 . get ( "/msg_count" , function ( req , res ) {
76+ const client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
4677 try {
78+ logger . logRequestStarted ( {
79+ client : client ?. _id ,
80+ correlationId : req . headers [ "x-correlation-id" ] ,
81+ httpVerb : "GET" ,
82+ routePath : basePath + "/msg_count" ,
83+ status : "Started" ,
84+ description : "Update message metrics" ,
85+ } ) ;
4786 var par = {
4887 now : Date . now ( ) / 1000 ,
4988 since : 60 * ( req . queryParams . since ? req . queryParams . since : 60 ) ,
@@ -71,7 +110,26 @@ router
71110 }
72111
73112 res . send ( result ) ;
113+ logger . logRequestSuccess ( {
114+ client : client ?. _id ,
115+ correlationId : req . headers [ "x-correlation-id" ] ,
116+ httpVerb : "GET" ,
117+ routePath : basePath + "/msg_count" ,
118+ status : "Success" ,
119+ description : "Update message metrics" ,
120+ extra : result ,
121+ } ) ;
74122 } catch ( e ) {
123+ logger . logRequestFailure ( {
124+ client : client ?. _id ,
125+ correlationId : req . headers [ "x-correlation-id" ] ,
126+ httpVerb : "GET" ,
127+ routePath : basePath + "/msg_count" ,
128+ status : "Failure" ,
129+ description : "Update message metrics" ,
130+ extra : result ,
131+ error : e ,
132+ } ) ;
75133 g_lib . handleException ( e , res ) ;
76134 }
77135 } )
@@ -87,7 +145,19 @@ router
87145
88146router
89147 . get ( "/users/active" , function ( req , res ) {
148+ const client = req . queryParams . client
149+ ? g_lib . getUserFromClientID ( req . queryParams . client )
150+ : null ;
90151 try {
152+ logger . logRequestStarted ( {
153+ client : client ?. _id ,
154+ correlationId : req . headers [ "x-correlation-id" ] ,
155+ httpVerb : "GET" ,
156+ routePath : basePath + "/users/active" ,
157+ status : "Started" ,
158+ description : "Get recently active users from metrics" ,
159+ } ) ;
160+
91161 var cnt = { } ,
92162 u ,
93163 r ,
@@ -111,7 +181,27 @@ router
111181 }
112182
113183 res . json ( cnt ) ;
184+ logger . logRequestSuccess ( {
185+ client : client ?. _id ,
186+ correlationId : req . headers [ "x-correlation-id" ] ,
187+ httpVerb : "GET" ,
188+ routePath : basePath + "/users/active" ,
189+ status : "Success" ,
190+ description : "Get recently active users from metrics" ,
191+ extra : cnt ,
192+ } ) ;
114193 } catch ( e ) {
194+ logger . logRequestFailure ( {
195+ client : client ?. _id ,
196+ correlationId : req . headers [ "x-correlation-id" ] ,
197+ httpVerb : "GET" ,
198+ routePath : basePath + "/users/active" ,
199+ status : "Failure" ,
200+ description : "Get recently active users from metrics" ,
201+ extra : cnt ,
202+ error : e ,
203+ } ) ;
204+
115205 g_lib . handleException ( e , res ) ;
116206 }
117207 } )
@@ -125,7 +215,17 @@ router
125215
126216router
127217 . post ( "/purge" , function ( req , res ) {
218+ const client = g_lib . getUserFromClientID ( req . queryParams . client ) ;
128219 try {
220+ logger . logRequestStarted ( {
221+ client : client ?. _id ,
222+ correlationId : req . headers [ "x-correlation-id" ] ,
223+ httpVerb : "GET" ,
224+ routePath : basePath + "/purge" ,
225+ status : "Started" ,
226+ description : "Purge older metrics" ,
227+ } ) ;
228+
129229 g_db . metrics . save ( {
130230 timestamp : Math . floor ( Date . now ( ) / 1000 ) ,
131231 type : "purge" ,
@@ -135,7 +235,26 @@ router
135235 g_db . _query ( "for i in metrics filter i.timestamp < @ts remove i in metrics" , {
136236 ts : req . queryParams . timestamp ,
137237 } ) ;
238+ logger . logRequestSuccess ( {
239+ client : client ?. _id ,
240+ correlationId : req . headers [ "x-correlation-id" ] ,
241+ httpVerb : "GET" ,
242+ routePath : basePath + "/purge" ,
243+ status : "Success" ,
244+ description : "Purge older metrics" ,
245+ extra : "undefined" ,
246+ } ) ;
138247 } catch ( e ) {
248+ logger . logRequestFailure ( {
249+ client : client ?. _id ,
250+ correlationId : req . headers [ "x-correlation-id" ] ,
251+ httpVerb : "GET" ,
252+ routePath : basePath + "/purge" ,
253+ status : "Failure" ,
254+ description : "Purge older metrics" ,
255+ extra : "undefined" ,
256+ error : e ,
257+ } ) ;
139258 g_lib . handleException ( e , res ) ;
140259 }
141260 } )
0 commit comments