(database *store.DatabaseMessage, queryType store.QueryHistoryType, statement string, userEmail string, duration time.Duration, queryErr error)
| 1370 | } |
| 1371 | |
| 1372 | func (s *SQLService) createQueryHistory(database *store.DatabaseMessage, queryType store.QueryHistoryType, statement string, userEmail string, duration time.Duration, queryErr error) { |
| 1373 | qh := &store.QueryHistoryMessage{ |
| 1374 | Creator: userEmail, |
| 1375 | Project: database.ProjectID, |
| 1376 | Database: common.FormatDatabase(database.InstanceID, database.DatabaseName), |
| 1377 | Statement: statement, |
| 1378 | Type: queryType, |
| 1379 | Payload: &storepb.QueryHistoryPayload{ |
| 1380 | Error: nil, |
| 1381 | Duration: durationpb.New(duration), |
| 1382 | }, |
| 1383 | } |
| 1384 | if queryErr != nil { |
| 1385 | qh.Payload.Error = new(queryErr.Error()) |
| 1386 | } |
| 1387 | |
| 1388 | // Use a fresh context with timeout for creating query history |
| 1389 | // to avoid being affected by request cancellation |
| 1390 | historyCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 1391 | defer cancel() |
| 1392 | if _, err := s.store.CreateQueryHistory(historyCtx, qh); err != nil { |
| 1393 | queryErr := "" |
| 1394 | if v := qh.Payload.Error; v != nil { |
| 1395 | queryErr = *v |
| 1396 | } |
| 1397 | slog.Error( |
| 1398 | "failed to create query history", |
| 1399 | log.BBError(err), |
| 1400 | slog.String("instance", database.InstanceID), |
| 1401 | slog.String("database", database.DatabaseName), |
| 1402 | slog.String("project", database.ProjectID), |
| 1403 | slog.String("query_error", queryErr), |
| 1404 | ) |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | // SearchQueryHistories lists query histories. |
| 1409 | func (s *SQLService) SearchQueryHistories(ctx context.Context, req *connect.Request[v1pb.SearchQueryHistoriesRequest]) (*connect.Response[v1pb.SearchQueryHistoriesResponse], error) { |
no test coverage detected