Skip to content

Add table for Gateway audit logs#816

Open
kjsbot wants to merge 15 commits intotrinodb:mainfrom
kjsbot:feature/audit-table
Open

Add table for Gateway audit logs#816
kjsbot wants to merge 15 commits intotrinodb:mainfrom
kjsbot:feature/audit-table

Conversation

@kjsbot
Copy link
Contributor

@kjsbot kjsbot commented Jan 2, 2026

Description

Adds support for a audit logs table for all 3 databases.

Additional context and related issues

Following up on the discussion for issue #803, this PR adds new tables for auditing logs, it also creates supporting classes for updating the tables. Comments will be collected via the UI and from the body of curl requests (separate PR). Open to any further discussion or questions!

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
(x) Release notes are required, with the following suggested text:

* Add new table for audit logs.

@cla-bot cla-bot bot added the cla-signed label Jan 2, 2026

import static java.util.Objects.requireNonNull;

public class AuditLogger
Copy link
Contributor

@kbhatianr kbhatianr Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make AuditLogger an interface, and then add different types of AuditLoggers. e.g, a DatabaseAuditLogger for writing it to to the DB, and/or a LogAuditLogger that simply emits it out to log.info()

@kjsbot kjsbot changed the title [DRAFT WIP]Add table for Gateway audit logs Add table for Gateway audit logs Jan 6, 2026
@kjsbot kjsbot marked this pull request as ready for review January 6, 2026 21:47
user_name VARCHAR(256) NOT NULL,
ip_address VARCHAR(45),
backend_name VARCHAR(256) NOT NULL,
operation VARCHAR(256) NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

256 seems to be too long. isn't this one of AuditActions?
64 seems to be sufficient

ip_address VARCHAR(45),
backend_name VARCHAR(256) NOT NULL,
operation VARCHAR(256) NOT NULL,
context VARCHAR(256) NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what you intent by context, but it seems to be quite small. Why not text?

Copy link
Contributor Author

@kjsbot kjsbot Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context refers to where the admin made the change - ex: curl-ing, webapp, etc

context VARCHAR(256) NOT NULL,
success BOOLEAN NOT NULL,
user_comment VARCHAR(1024),
change_time TIMESTAMP NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Audit log should have default timestamp, no?

);

CREATE TABLE IF NOT EXISTS gateway_audit_logs (
audit_id BIGSERIAL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
audit_id BIGSERIAL,
audit_id BIGSERIAL PRIMARY KEY,

not so sure, but can you do this instead of line 91?

ip_address VARCHAR(45),
backend_name VARCHAR(256) NOT NULL,
operation VARCHAR(256) NOT NULL,
context VARCHAR(256) NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSONB?

Copy link
Contributor Author

@kjsbot kjsbot Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, I think having different columns can make management simpler as well as being better for querying

backend_name VARCHAR(256) NOT NULL,
operation VARCHAR(256) NOT NULL,
context VARCHAR(256) NOT NULL,
success SMALLINT NOT NULL CHECK (success IN (0, 1)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not BOOLEAN?

operation VARCHAR(256) NOT NULL,
context VARCHAR(256) NOT NULL,
success SMALLINT NOT NULL CHECK (success IN (0, 1)),
user_comment VARCHAR(1024),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about text?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally comments will be kept sort and brief which is why the 1024 limit is kept, anything going over should be truncated

ip_address VARCHAR2(45),
backend_name VARCHAR(256) NOT NULL,
operation VARCHAR(256) NOT NULL,
context VARCHAR(256) NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe CLOB?

context VARCHAR(256) NOT NULL,
success SMALLINT NOT NULL CHECK (success IN (0, 1)),
user_comment VARCHAR(1024),
change_time TIMESTAMP NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about TIMESTAMPTZ NOT NULL DEFAULT now()?

context VARCHAR(256) NOT NULL,
success NUMBER(1) NOT NULL CHECK (success IN (0,1)),
user_comment VARCHAR(1024),
change_time TIMESTAMP NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

TIMESTAMP WITH TIME ZONE CURRENT_TIMESTAMP NOT NULL

);

CREATE TABLE gateway_audit_logs (
audit_id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
audit_id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
audit_id NUMBER(19) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
Image

@Chaho12
Copy link
Member

Chaho12 commented Feb 4, 2026

Can you rebase and resolve conflicts?

@kjsbot kjsbot force-pushed the feature/audit-table branch from 71f5cfd to d7c9058 Compare February 4, 2026 19:43
String c = requireNonNullElse(comment, "");
return c.replaceAll("\\s+", " ").trim();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t like the design where CompositeAuditLogger implements AuditLogger.

There are a few problems with this design:

  • It mixes normal binding and multibindings on the same interface (AuditLogger), which makes the configuration hard to understand:
        binder().bind(AuditLogger.class).to(CompositeAuditLogger.class).in(Scopes.SINGLETON);

        Multibinder<AuditLogger> auditLoggers = newSetBinder(binder(), AuditLogger.class);
        auditLoggers.addBinding().to(DatabaseAuditLogger.class).in(Scopes.SINGLETON);
        auditLoggers.addBinding().to(LogAuditLogger.class).in(Scopes.SINGLETON);
  • It mixes implementation details with the interface (e.g., static String sanitizeComment).
  • The roles of CompositeAuditLogger and the other loggers are different, so they should not be combined under the same interface.

I would recommend using the following approach instead:

@oneonestar oneonestar linked an issue Feb 13, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Add New Table for Audit Logs

4 participants

Comments