Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-5369. Added API for transaction log for commits #3183

Merged
merged 27 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
02baaf3
CB-5369. Added API for transaction log for commits
DenisSinelnikov Jan 9, 2025
d352e50
Merge branch 'devel' into CB-5369-transaction-log-for-commits
DenisSinelnikov Jan 9, 2025
8d47710
CB-5369. Refactor after review
DenisSinelnikov Jan 9, 2025
1f04b43
Merge remote-tracking branch 'origin/CB-5369-transaction-log-for-comm…
DenisSinelnikov Jan 9, 2025
89e0ff4
CB-5369 add transaction logs table
devnaumov Jan 9, 2025
d0c621b
Merge branches 'CB-5369-transaction-log-for-commits' and 'CB-5369-tra…
devnaumov Jan 9, 2025
854f830
CB-5369. Added id for data
DenisSinelnikov Jan 10, 2025
0848dbf
Merge remote-tracking branch 'origin/CB-5369-transaction-log-for-comm…
DenisSinelnikov Jan 10, 2025
5f44a3b
CB-5369 fix typo
devnaumov Jan 10, 2025
b9fd5fb
CB-5369. Added event for get count
DenisSinelnikov Jan 10, 2025
a171da8
Merge remote-tracking branch 'origin/CB-5369-transaction-log-for-comm…
DenisSinelnikov Jan 10, 2025
024c671
CB-5369. Refactor event
DenisSinelnikov Jan 12, 2025
6659111
CB-5369. Refactor event
DenisSinelnikov Jan 12, 2025
bc54897
CB-5369. Refactor after review
DenisSinelnikov Jan 12, 2025
5622605
CB-5369. Refactor after review
DenisSinelnikov Jan 12, 2025
4e7b62f
CB-5369. Added connectionId to event
DenisSinelnikov Jan 12, 2025
3314f75
CB-5369 support count event
devnaumov Jan 12, 2025
c1f5834
CB-5369. Rename eventId
DenisSinelnikov Jan 13, 2025
96954ff
Merge remote-tracking branch 'origin/CB-5369-transaction-log-for-comm…
DenisSinelnikov Jan 13, 2025
0647177
CB-5369 adjust count styles
devnaumov Jan 13, 2025
6bea6b0
CB-5369 format time
devnaumov Jan 13, 2025
41c60fa
CB-5369 add missing deps
devnaumov Jan 13, 2025
abad3a0
CB-5369 remove extra important flags
devnaumov Jan 13, 2025
3c5332a
CB-5369 review fixes
devnaumov Jan 13, 2025
8f6e63e
CB-5369 remove extra import
devnaumov Jan 13, 2025
e0e5f82
Merge branch 'devel' into CB-5369-transaction-log-for-commits
dariamarutkina Jan 14, 2025
691ae67
Merge branch 'devel' into CB-5369-transaction-log-for-commits
dariamarutkina Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions server/bundles/io.cloudbeaver.server/schema/service.core.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,21 @@ type LogEntry {
stackTrace: String
}


type TransactionLogInfos {
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved
count: Int
transactionLogInfos: [TransactionLogInfoItem!]!
}

type TransactionLogInfoItem {
time: DateTime!
type: String!
queryString: String!
durationMs: Int!
rows: Int!
result: String!
}

####################################################
# Input types
####################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ extend type Mutation {
dataFormat: ResultDataFormat
): AsyncTaskInfo!

getTransactionLogInfo(
projectId: ID!,
connectionId: ID!,
contextId: ID!
): TransactionLogInfos

# Close results (free resources)
sqlResultClose(projectId: ID, connectionId: ID!, contextId: ID!, resultId: ID!): Boolean!

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cloudbeaver.model;

import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;

import java.util.List;

public record WebTransactionLogInfo(@NotNull List<WebTransactionLogItemInfo> transactionLogInfos, @Nullable

Integer count) {

Check warning on line 26 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebTransactionLogInfo.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 'Integer' has incorrect indentation level 0, expected level should be 4. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebTransactionLogInfo.java:26:1: warning: 'Integer' has incorrect indentation level 0, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cloudbeaver.model;

import org.jkiss.code.NotNull;

public record WebTransactionLogItemInfo(
@NotNull String time,
@NotNull String type,
@NotNull String queryString,
long durationMs,
long rows,
String result
) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -27,6 +27,7 @@
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.exec.DBCLogicalOperator;
import org.jkiss.dbeaver.model.exec.trace.DBCTraceProperty;
import io.cloudbeaver.model.WebTransactionLogInfo;

Check warning on line 30 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/DBWServiceSQL.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Wrong lexicographical order for 'io.cloudbeaver.model.WebTransactionLogInfo' import. Should be before 'org.jkiss.dbeaver.model.exec.trace.DBCTraceProperty'. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/DBWServiceSQL.java:30:1: warning: Wrong lexicographical order for 'io.cloudbeaver.model.WebTransactionLogInfo' import. Should be before 'org.jkiss.dbeaver.model.exec.trace.DBCTraceProperty'. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved
import org.jkiss.dbeaver.model.sql.registry.SQLGeneratorDescriptor;

import java.util.List;
Expand Down Expand Up @@ -202,4 +203,10 @@
WebAsyncTaskInfo asyncSqlCommitTransaction(
@NotNull WebSession webSession,
@NotNull WebSQLContextInfo sqlContext);

@WebAction

Check warning on line 207 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/DBWServiceSQL.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/DBWServiceSQL.java:207:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
WebTransactionLogInfo getTransactionLogInfo(
@NotNull WebSession webSession,
@NotNull WebSQLContextInfo sqlContext
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,13 +26,21 @@
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.exec.trace.DBCTrace;
import org.jkiss.dbeaver.model.messages.ModelMessages;
import org.jkiss.dbeaver.model.meta.Property;
import io.cloudbeaver.model.WebTransactionLogInfo;

Check warning on line 36 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Wrong lexicographical order for 'io.cloudbeaver.model.WebTransactionLogInfo' import. Should be before 'org.jkiss.dbeaver.model.meta.Property'. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java:36:1: warning: Wrong lexicographical order for 'io.cloudbeaver.model.WebTransactionLogInfo' import. Should be before 'org.jkiss.dbeaver.model.meta.Property'. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import io.cloudbeaver.model.WebTransactionLogItemInfo;

Check warning on line 37 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Wrong lexicographical order for 'io.cloudbeaver.model.WebTransactionLogItemInfo' import. Should be before 'org.jkiss.dbeaver.model.meta.Property'. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java:37:1: warning: Wrong lexicographical order for 'io.cloudbeaver.model.WebTransactionLogItemInfo' import. Should be before 'org.jkiss.dbeaver.model.meta.Property'. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import org.jkiss.dbeaver.model.qm.QMTransactionState;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.qm.meta.QMMConnectionInfo;
import org.jkiss.dbeaver.model.qm.meta.QMMStatementExecuteInfo;
import org.jkiss.dbeaver.model.qm.meta.QMMTransactionInfo;
import org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
import org.jkiss.dbeaver.model.struct.rdb.DBSCatalog;
Expand All @@ -41,7 +49,12 @@
import org.jkiss.utils.CommonUtils;

import java.lang.reflect.InvocationTargetException;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -59,6 +72,9 @@

private final AtomicInteger resultId = new AtomicInteger();

public static final DateTimeFormatter ISO_DATE_FORMAT = DateTimeFormatter.ofPattern(DBConstants.DEFAULT_ISO_TIMESTAMP_FORMAT)
.withZone(ZoneId.of("UTC"));

public WebSQLContextInfo(
WebSQLProcessor processor, String id, String catalogName, String schemaName, String projectId
) throws DBCException {
Expand Down Expand Up @@ -216,7 +232,65 @@

}

public WebTransactionLogInfo getTransactionLogInfo() {

Check warning on line 235 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java:235:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
DBCExecutionContext context = processor.getExecutionContext();
return getTransactionLogInfo(context);
}

@NotNull
private WebTransactionLogInfo getTransactionLogInfo(DBCExecutionContext executionContext) {
int updateCount = 0;
List<WebTransactionLogItemInfo> logItemInfos = new ArrayList<>();
QMMConnectionInfo sessionInfo = QMUtils.getCurrentConnection(executionContext);
if (sessionInfo.isTransactional()) {
QMMTransactionInfo txnInfo = sessionInfo.getTransaction();
if (txnInfo != null) {
QMMTransactionSavepointInfo sp = txnInfo.getCurrentSavepoint();
QMMStatementExecuteInfo execInfo = sp.getLastExecute();
for (QMMStatementExecuteInfo exec = execInfo; exec != null && exec.getSavepoint() == sp; exec = exec.getPrevious()) {
if (exec.getUpdateRowCount() > 0 ) {

Check warning on line 251 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 ')' is preceded with whitespace. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java:251:54: warning: ')' is preceded with whitespace. (com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck)
DBCExecutionPurpose purpose = exec.getStatement().getPurpose();
if (!exec.hasError() && purpose != DBCExecutionPurpose.META && purpose != DBCExecutionPurpose.UTIL) {
updateCount++;
}
generateLogInfo(logItemInfos, exec, purpose);
}
}
}
} else {
QMMStatementExecuteInfo execInfo = sessionInfo.getExecutionStack();
for (QMMStatementExecuteInfo exec = execInfo; exec != null; exec = exec.getPrevious()) {
if (exec.getUpdateRowCount() > 0) {
DBCExecutionPurpose purpose = exec.getStatement().getPurpose();
generateLogInfo(logItemInfos, exec, purpose);
}
}
}
return new WebTransactionLogInfo(logItemInfos, updateCount == 0 ? null : updateCount);
}

private void generateLogInfo(List<WebTransactionLogItemInfo> logItemInfos, QMMStatementExecuteInfo exec, DBCExecutionPurpose purpose) {
String type = "SQL / " + purpose.getTitle();
String dateTime = ISO_DATE_FORMAT.format(Instant.ofEpochMilli(exec.getCloseTime()));
String result = ModelMessages.controls_querylog_success;
if (exec.hasError()) {
if (exec.getErrorCode() == 0) {
result = exec.getErrorMessage();
} else if (exec.getErrorMessage() == null) {
result = ModelMessages.controls_querylog_error + exec.getErrorCode() + "]"; //$NON-NLS-1$
} else {
result = "[" + exec.getErrorCode() + "] " + exec.getErrorMessage(); //$NON-NLS-1$ //$NON-NLS-2$
}
}

logItemInfos.add(
new WebTransactionLogItemInfo(dateTime, type, exec.getQueryString(),
exec.getDuration(), exec.getUpdateRowCount(), result)
);
}


public WebAsyncTaskInfo commitTransaction() {

Check warning on line 293 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java:293:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
DBCExecutionContext context = processor.getExecutionContext();
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
WebAsyncTaskProcessor<String> runnable = new WebAsyncTaskProcessor<>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -226,6 +226,11 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
getWebSession(env),
getSQLContext(env)
))
.dataFetcher("getTransactionLogInfo", env ->
getService(env).getTransactionLogInfo(
getWebSession(env),
getSQLContext(env)
))
.dataFetcher("asyncSqlRollbackTransaction", env ->
getService(env).asyncSqlRollbackTransaction(
getWebSession(env),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +42,7 @@
import org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import io.cloudbeaver.model.WebTransactionLogInfo;

Check warning on line 45 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Wrong lexicographical order for 'io.cloudbeaver.model.WebTransactionLogInfo' import. Should be before 'org.jkiss.dbeaver.model.navigator.DBNNode'. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java:45:1: warning: Wrong lexicographical order for 'io.cloudbeaver.model.WebTransactionLogInfo' import. Should be before 'org.jkiss.dbeaver.model.navigator.DBNNode'. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.*;
import org.jkiss.dbeaver.model.sql.completion.SQLCompletionAnalyzer;
Expand Down Expand Up @@ -318,6 +319,7 @@
}
}
);
// do event
return result[0];
} catch (DBException e) {
throw new DBWebException("Error updating resultset data", e);
Expand Down Expand Up @@ -615,4 +617,8 @@
return contextInfo.commitTransaction();
}

@Override
public WebTransactionLogInfo getTransactionLogInfo(@NotNull WebSession webSession, @NotNull WebSQLContextInfo sqlContext) {
return sqlContext.getTransactionLogInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ export class ConnectionExecutionContext implements IConnectionExecutionContext {
return mapAsyncTaskInfo(result);
}

async getLogs() {
const result = await this.withContext(async context => {
const { logs } = await this.graphQLService.sdk.getTransactionsLogs({
projectId: context.projectId,
connectionId: context.connectionId,
contextId: context.id,
});

return logs;
});

return result?.transactionLogInfos;
}

private withContext<R>(callback: (context: IConnectionExecutionContextInfo) => Promise<R>): Promise<R> {
if (!this.context) {
throw new Error('Execution Context not found');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mutation getTransactionLogs($projectId: ID!, $connectionId: ID!, $contextId: ID!) {
logs: getTransactionLogInfo(projectId: $projectId, connectionId: $connectionId, contextId: $contextId) {
transactionLogInfos {
time
type
queryString
durationMs
rows
result
}
}
}
13 changes: 11 additions & 2 deletions webapp/packages/plugin-datasource-transaction-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,24 @@
"@cloudbeaver/core-events": "^0",
"@cloudbeaver/core-executor": "^0",
"@cloudbeaver/core-localization": "^0",
"@cloudbeaver/core-sdk": "^0",
"@cloudbeaver/core-settings": "^0",
"@cloudbeaver/core-ui": "^0",
"@cloudbeaver/core-utils": "^0",
"@cloudbeaver/core-view": "^0",
"@cloudbeaver/plugin-codemirror6": "^0",
"@cloudbeaver/plugin-data-grid": "^0",
"@cloudbeaver/plugin-datasource-context-switch": "^0",
"@cloudbeaver/plugin-top-app-bar": "^0"
"@cloudbeaver/plugin-sql-editor-new": "^0",
"@cloudbeaver/plugin-top-app-bar": "^0",
"mobx": "^6",
"mobx-react-lite": "^4",
"react": "^18"
},
"peerDependencies": {},
"devDependencies": {
"typescript": "^5"
"@types/react": "^18",
"typescript": "^5",
"typescript-plugin-css-modules": "^5"
}
}
Loading
Loading