Skip to content

Commit 6c377b1

Browse files
committed
move logs to native
1 parent 63923e4 commit 6c377b1

File tree

2 files changed

+93
-25
lines changed

2 files changed

+93
-25
lines changed

packages/cubejs-api-gateway/src/gateway.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -391,32 +391,32 @@ class ApiGateway {
391391
try {
392392
await this.assertApiScope('data', req.context?.securityContext);
393393

394-
this.log({
395-
type: 'Load Request',
396-
query: {
397-
sql: query,
398-
},
399-
apiType: 'sql',
400-
streaming: true
401-
}, req.context);
394+
// this.log({
395+
// type: 'Load Request',
396+
// query: {
397+
// sql: query,
398+
// },
399+
// apiType: 'sql',
400+
// streaming: true
401+
// }, req.context);
402402

403403
await this.sqlServer.execSql(req.body.query, res, req.context?.securityContext);
404404

405-
this.log(
406-
{
407-
type: 'Load Request Success',
408-
query: {
409-
sql: query,
410-
},
411-
duration: this.duration(requestStarted),
412-
apiType: 'sql',
413-
isDataQuery: true,
414-
isPlayground: Boolean(
415-
req.context?.signedWithPlaygroundAuthSecret
416-
),
417-
},
418-
req.context,
419-
);
405+
// this.log(
406+
// {
407+
// type: 'Load Request Success',
408+
// query: {
409+
// sql: query,
410+
// },
411+
// duration: this.duration(requestStarted),
412+
// apiType: 'sql',
413+
// isDataQuery: true,
414+
// isPlayground: Boolean(
415+
// req.context?.signedWithPlaygroundAuthSecret
416+
// ),
417+
// },
418+
// req.context,
419+
// );
420420
} catch (e: any) {
421421
this.handleError({
422422
e,

packages/cubejs-backend-native/src/node_export.rs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use std::net::SocketAddr;
3030
use std::rc::Rc;
3131
use std::str::FromStr;
3232
use std::sync::Arc;
33+
use std::time::SystemTime;
3334

3435
use cubesql::{telemetry::ReportingLogger, CubeError};
3536

@@ -185,6 +186,8 @@ async fn handle_sql_query(
185186
stream_methods: WritableStreamMethods,
186187
sql_query: &String,
187188
) -> Result<(), CubeError> {
189+
let start_time = SystemTime::now();
190+
188191
let config = services
189192
.injector()
190193
.get_service_typed::<dyn ConfigObj>()
@@ -222,7 +225,26 @@ async fn handle_sql_query(
222225
.state
223226
.set_auth_context(Some(native_auth_ctx.clone()));
224227

225-
let connection_id = session.state.connection_id;
228+
if let Some(auth_context) = session.state.auth_context() {
229+
session
230+
.session_manager
231+
.server
232+
.transport
233+
.log_load_state(
234+
None,
235+
auth_context,
236+
session.state.get_load_request_meta("sql"),
237+
"Load Request".to_string(),
238+
serde_json::json!({
239+
"query": {
240+
"sql": sql_query,
241+
}
242+
}),
243+
)
244+
.await?;
245+
}
246+
247+
let session_clone = Arc::clone(&session);
226248

227249
let execute = || async move {
228250
// todo: can we use compiler_cache?
@@ -310,8 +332,54 @@ async fn handle_sql_query(
310332
};
311333

312334
let result = execute().await;
335+
let duration = start_time.elapsed().unwrap().as_millis() as u64;
336+
337+
match &result {
338+
Ok(_) => {
339+
session_clone
340+
.session_manager
341+
.server
342+
.transport
343+
.log_load_state(
344+
None,
345+
session_clone.state.auth_context().unwrap(),
346+
session_clone.state.get_load_request_meta("sql"),
347+
"Load Request Success".to_string(),
348+
serde_json::json!({
349+
"query": {
350+
"sql": sql_query,
351+
},
352+
"apiType": "sql",
353+
"duration": duration,
354+
"isDataQuery": true
355+
}),
356+
)
357+
.await?;
358+
}
359+
Err(err) => {
360+
session_clone
361+
.session_manager
362+
.server
363+
.transport
364+
.log_load_state(
365+
None,
366+
session_clone.state.auth_context().unwrap(),
367+
session_clone.state.get_load_request_meta("sql"),
368+
"Cube SQL Error".to_string(),
369+
serde_json::json!({
370+
"query": {
371+
"sql": sql_query
372+
},
373+
"apiType": "sql",
374+
"duration": duration,
375+
"error": err.message,
376+
}),
377+
)
378+
.await?;
379+
}
380+
}
313381

314-
session_manager.drop_session(connection_id).await;
382+
session_manager.drop_session(session_clone.state.connection_id).await;
315383

316384
result
317385
}

0 commit comments

Comments
 (0)