@@ -26,8 +26,8 @@ const postgresController = {
26
26
//----------Function to collect all schema and data from database-----------------------------------------------------------------
27
27
postgresQuery : async ( req : Request , res : Response , next : NextFunction ) => {
28
28
const PostgresDataSource = await dbConnect ( req ) ;
29
- console . log ( 'postgresQuery REQ: ' , req ) ;
30
- console . log ( 'MADE IT TO postgresQuery MIDDLEWARE' ) ;
29
+ // console.log('postgresQuery REQ: ', req);
30
+ // console.log('MADE IT TO postgresQuery MIDDLEWARE');
31
31
32
32
/*
33
33
* Used for storing Primary Key table and column names that are
@@ -170,21 +170,20 @@ const postgresController = {
170
170
//----------Function to gather query metrics from database-----------------------------------------------------------------
171
171
postgresGetMetrics : async ( req : Request , res : Response , next : NextFunction ) => {
172
172
const PostgresGetMetrics = await dbConnect ( req ) ;
173
- console . log ( 'REACHED postgresGetMetrics MIDDLEWARE' ) ;
174
- console . log ( 'REQ QUERY: ' , req . query ) ;
173
+ // console.log('REACHED postgresGetMetrics MIDDLEWARE');
174
+ // console.log('REQ QUERY: ', req.query);
175
175
try {
176
176
// destructuing the below 2 fields to store to the queries table in mysql db
177
177
const { queryString, queryName, hostname, database_name } = req . query ;
178
- console . log ( '❓ QUERY FROM FE IS: ' , queryString ) ;
179
- console . log ( 'hostname:' , hostname ) ;
180
- console . log ( 'database_name' , database_name ) ;
178
+ // console.log('❓ QUERY FROM FE IS: ', queryString);
179
+ // console.log('hostname:', hostname);
180
+ // console.log('database_name', database_name);
181
181
182
182
// Query string (EXPLAIN) to access performance data
183
183
const testQuery = `EXPLAIN (FORMAT JSON, ANALYZE, VERBOSE, BUFFERS) ${ queryString } ;` ;
184
184
const result = await PostgresGetMetrics . query ( testQuery ) ;
185
185
186
- console . log ( '⭐️QUERY PLAN RESULT: ' , result [ 0 ] [ 'QUERY PLAN' ] ) ;
187
- // 🌟🌟🌟
186
+ // console.log('⭐️QUERY PLAN RESULT: ', result[0]['QUERY PLAN']);
188
187
/*
189
188
Key Metrics Explanation:
190
189
- Execution Time: total time it takes to execute the query (in ms)
@@ -198,15 +197,13 @@ const postgresController = {
198
197
199
198
//pull exec time alone for the mysql update when storing queries
200
199
const exec_time = result [ 0 ] [ 'QUERY PLAN' ] [ 0 ] [ 'Execution Time' ] ;
201
- console . log ( 'exec_time:' , exec_time ) ;
202
200
203
201
// Pull Execution time only
204
202
const resObj = result [ 0 ] [ 'QUERY PLAN' ] [ 0 ] ;
205
203
const resObjPlan = resObj [ 'Plan' ] ;
206
204
const executionTime = `Execution Time: ${ resObj [ 'Execution Time' ] } ms` ;
207
205
const namedQuery = `Query Name: ${ queryName } ` ;
208
206
const queryStr = `Query: ${ queryString } ` ;
209
- // console.log('⏰ EXECUTION TIME METRIC', executionTime);
210
207
211
208
const otherMetrics : Array < object > = [
212
209
{
@@ -221,7 +218,6 @@ const postgresController = {
221
218
sharedRead : resObjPlan [ 'Shared Read Blocks' ] ,
222
219
} ,
223
220
] ;
224
- // console.log('OTHER METRICCSSSS: ', otherMetrics);
225
221
226
222
// Create date metric to add to response
227
223
const now = new Date ( ) ;
@@ -255,8 +251,8 @@ const postgresController = {
255
251
}
256
252
257
253
try {
258
- console . log ( 'REACHED postgresSaveMetrics MIDDLEWARE' ) ;
259
- console . log ( 'REQ BODY: ' , req . body . params ) ;
254
+ // console.log('REACHED postgresSaveMetrics MIDDLEWARE');
255
+ // console.log('REQ BODY: ', req.body.params);
260
256
261
257
const userEmail = user . email ;
262
258
const { query_date, exec_time } = req . body . params . extractedQueryRes ;
@@ -277,7 +273,7 @@ const postgresController = {
277
273
// converting date to DATE format (YYYY-MM-DD) for MySQL to insert into queries table
278
274
const date = new Date ( query_date ) ;
279
275
const formatDateForMySql = date . toISOString ( ) . split ( 'T' ) [ 0 ] ;
280
- console . log ( 'formatted date: ' , formatDateForMySql ) ;
276
+ // console.log('formatted date: ', formatDateForMySql);
281
277
282
278
const insertQueryStr = `INSERT INTO queries (email, query, db_link, exec_time, db_name, query_date, name, planning_time, total_cost, actual_total_time, node_type, relation_name, plan_rows, actual_rows, shared_hit_blocks, shared_read_blocks) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)` ;
283
279
0 commit comments