You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "hanwxx (via GitHub)" <gi...@apache.org> on 2024/08/19 06:44:08 UTC
[PR] [#3973] improvement(core):support audit log [gravitino]
hanwxx opened a new pull request, #4575:
URL: https://github.com/apache/gravitino/pull/4575
<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
Examples:
- "[#123] feat(operator): support xxx"
- "[#233] fix: check null before access result in xxx"
- "[MINOR] refactor: fix typo in variable name"
- "[MINOR] docs: fix typo in README"
- "[#255] test: fix flaky test NameOfTheTest"
Reference: https://www.conventionalcommits.org/en/v1.0.0/
2. If the PR is unfinished, please mark this PR as draft.
-->
### What changes were proposed in this pull request?
Design a gravitino audit framework.
### Why are the changes needed?
improvement:[#3973]
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
1. Add UT
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1804629015
##########
core/src/main/java/org/apache/gravitino/audit/SimpleAuditLog.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.text.SimpleDateFormat;
+import lombok.Builder;
+
+/** The default implementation of the audit log. */
+@Builder
+public class SimpleAuditLog implements AuditLog {
+
+ private String user;
+
+ private Operation operation;
+
+ private String identifier;
+
+ private long timestamp;
+
+ private Status status;
+
+ @Override
+ public String user() {
+ return user;
+ }
+
+ @Override
+ public Operation operation() {
+ return operation;
+ }
+
+ @Override
+ public String identifier() {
+ return identifier;
+ }
+
+ @Override
+ public long timestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public Status status() {
+ return status;
+ }
+
+ @Override
+ public String toString() {
+ return String.format(
+ "[%s] %s %s %s %s",
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp),
Review Comment:
@jerryshao WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1805755120
##########
core/src/main/java/org/apache/gravitino/audit/SimpleAuditLog.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.text.SimpleDateFormat;
+import lombok.Builder;
+
+/** The default implementation of the audit log. */
+@Builder
+public class SimpleAuditLog implements AuditLog {
+
+ private String user;
+
+ private Operation operation;
+
+ private String identifier;
+
+ private long timestamp;
+
+ private Status status;
+
+ @Override
+ public String user() {
+ return user;
+ }
+
+ @Override
+ public Operation operation() {
+ return operation;
+ }
+
+ @Override
+ public String identifier() {
+ return identifier;
+ }
+
+ @Override
+ public long timestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public Status status() {
+ return status;
+ }
+
+ @Override
+ public String toString() {
+ return String.format(
+ "[%s] %s %s %s %s",
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp),
Review Comment:
How about using '\t' to split items, using space to split time? @hanwxx
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2413271699
@FANNG1 can you please do another round of review?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2359811020
@hanwxx , is there anything blocking the move forward?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1808306901
##########
docs/gravitino-server-config.md:
##########
@@ -144,29 +144,29 @@ The audit log framework defines how audit logs are formatted and written to vari
Gravitino provides a default implement to log basic audit information to a file, you could extend the audit system by implementation corresponding interfaces.
-| Property name | Description | Default value | Required | Since Version |
-|---------------------------------------|----------------------------------------|---------------------------------------------|----------|---------------|
-| `gravitino.audit.enabled` | The audit log enable flag. | false | NO | 0.7.0 |
-| `gravitino.audit.writer.className` | The class name of audit log writer. | org.apache.gravitino.audit.FileAuditWriter | NO | 0.7.0 |
-| `gravitino.audit.formatter.className` | The class name of audit log formatter. | org.apache.gravitino.audit.SimpleFormatter | NO | 0.7.0 |
+| Property name | Description | Default value | Required | Since Version |
+|---------------------------------------|----------------------------------------|---------------------------------------------|----------|----------------------------|
+| `gravitino.audit.enabled` | The audit log enable flag. | false | NO | 0.7.0-incubating |
+| `gravitino.audit.writer.className` | The class name of audit log writer. | org.apache.gravitino.audit.FileAuditWriter | NO | 0.7.0-incubating |
+| `gravitino.audit.formatter.className` | The class name of audit log formatter. | org.apache.gravitino.audit.SimpleFormatter | NO | 0.7.0-incubating |
+
+#### Audit log formatter
+
+The Formatter defines an interface that formats metadata audit logs into a unified format. `SimpleFormatter` is a default implement to format audit information, you don't need to do extra configurations.
#### Audit log writer
The `AuditLogWriter` defines an interface that enables the writing of metadata audit logs to different storage mediums such as files, databases, etc.
Writer configuration begins with `gravitino.audit.writer.${name}`, where ${name} is replaced with the actual writer name defined in method `name()`. `FileAuditWriter` is a default implement to log audit information, whose name is `file`.
-| Property name | Description | Default value | Required | Since Version |
-|-----------------------------------------------------|-----------------------------------------------------------------------------------------|---------------------|----------|---------------|
-| `gravitino.audit.writer.file.fileName` | The audit log file name, the path is ${sys:gravitino.log.path}/${fileName} | gravitino_audit.log | NO | 0.7.0 |
-| `gravitino.audit.writer.file.immediateFlush` | whether the writer will flush at the end of each write operation. | false | NO | 0.7.0 |
-| `gravitino.audit.writer.file.append` | whether the log will be written to the end or the beginning of the file. | true | NO | 0.7.0 |
-| `gravitino.audit.writer.file.buffered` | whether the writer use an internal `ByteBuffer` to store audit log before writing them. | true | NO | 0.7.0 |
-| `gravitino.audit.writer.file.bufferSize` | The size of the `ByteBuffer`. | 8192 | NO | 0.7.0 |
-| `gravitino.audit.writer.file.lineSeparator` | The audit log line separator. | \n | NO | 0.7.0 |
-
-#### Audit log formatter
-The Formatter defines an interface that formats metadata audit logs into a unified format. `SimpleFormatter` is a default implement to format audit information, it not needs any configuration.
+| Property name | Description | Default value | Required | Since Version |
+|-----------------------------------------------------|-----------------------------------------------------------------------------------------|---------------------|----------|----------------------------|
+| `gravitino.audit.writer.file.fileName` | The audit log file name, the path is ${sys:gravitino.log.path}/${fileName}. | gravitino_audit.log | NO | 0.7.0-incubating |
+| `gravitino.audit.writer.file.immediateFlush` | Whether the writer will flush at the end of each write operation. | false | NO | 0.7.0-incubating |
+| `gravitino.audit.writer.file.append` | Whether the log will be written to the end or the beginning of the file. | true | NO | 0.7.0-incubating |
+| `gravitino.audit.writer.file.buffered` | Whether the writer use an internal `ByteBuffer` to store audit log before writing them. | true | NO | 0.7.0-incubating |
Review Comment:
please remove the properties not used any more
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2426427250
LGTM
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2367187644
@jerryshao do you have time to review this PR?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1801040725
##########
core/src/main/java/org/apache/gravitino/audit/SimpleAuditLog.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.text.SimpleDateFormat;
+import lombok.Builder;
+
+/** The default implementation of the audit log. */
+@Builder
+public class SimpleAuditLog implements AuditLog {
+
+ private String user;
+
+ private Operation operation;
+
+ private String identifier;
+
+ private long timestamp;
+
+ private Status status;
+
+ @Override
+ public String user() {
+ return user;
+ }
+
+ @Override
+ public Operation operation() {
+ return operation;
+ }
+
+ @Override
+ public String identifier() {
+ return identifier;
+ }
+
+ @Override
+ public long timestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public Status status() {
+ return status;
+ }
+
+ @Override
+ public String toString() {
+ return String.format(
+ "[%s] %s %s %s %s",
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp),
Review Comment:
We use spaces as separators for different items, seems we should avoid using it in time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "hanwxx (via GitHub)" <gi...@apache.org>.
hanwxx commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2421623655
> LGTM except the comment, @hanwxx could you add a document for audit log in `gravitino-server-config.md`?
Thanks, has add in document, please see again.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1724907611
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogManager.java:
##########
@@ -0,0 +1,90 @@
+package org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.listener.EventListenerManager;
+import org.apache.gravitino.listener.api.EventListenerPlugin;
+import org.apache.gravitino.listener.api.event.Event;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditLogManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuditLogManager.class);
+
+ @VisibleForTesting private AuditLogWriter auditLogWriter;
+
+ public void init(Map<String, String> properties, EventListenerManager eventBusManager) {
+ LOG.info("Audit log properties {}", properties);
+ AuditLogConfig auditLogConfig = new AuditLogConfig(properties);
+ if (!auditLogConfig.isAuditEnabled()) {
+ LOG.warn("Audit log is not enabled");
+ return;
+ }
+
+ LOG.info("Audit log config {}", auditLogConfig);
+ String writerClassName = auditLogConfig.getWriterClassName();
+ String formatterClassName = auditLogConfig.getAuditLogFormatterClassName();
+ Formatter formatter = loadFormatter(formatterClassName);
+ LOG.info("Audit log writer class name {}", writerClassName);
+ if (StringUtils.isEmpty(writerClassName)) {
+ throw new GravitinoRuntimeException("Audit log writer class is not configured");
+ }
+
+ auditLogWriter =
+ loadAuditLogWriter(
+ writerClassName, auditLogConfig.getWriterProperties(properties), formatter);
+
+ eventBusManager.addEventListener(
Review Comment:
The event listener mode is `SYNC` by default which means will block the main process if writer blocks, How about using `ASYNC_ISOLATED` by default?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1724890644
##########
core/src/main/java/org/apache/gravitino/audit/AbstractAuditLogWriter.java:
##########
@@ -0,0 +1,27 @@
+package org.apache.gravitino.audit;
Review Comment:
please add apache header
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "hanwxx (via GitHub)" <gi...@apache.org>.
hanwxx commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2412850572
@jerryshao Hi, adjusted based on review comments, please see again.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1772941030
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogManager.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.listener.EventListenerManager;
+import org.apache.gravitino.listener.api.EventListenerPlugin;
+import org.apache.gravitino.listener.api.event.Event;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditLogManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuditLogManager.class);
+
+ public static final String AUDIT_LOG_PREFIX = "gravitino.audit.";
+
+ @VisibleForTesting private AuditLogWriter auditLogWriter;
+
+ public void init(Map<String, String> properties, EventListenerManager eventBusManager) {
+ AuditLogConfig auditLogConfig = new AuditLogConfig(properties);
+ if (!auditLogConfig.isAuditEnabled()) {
+ LOG.warn("Audit log is not enabled");
+ return;
+ }
+
+ String writerClassName = auditLogConfig.getWriterClassName();
+ String formatterClassName = auditLogConfig.getAuditLogFormatterClassName();
+ Formatter formatter = loadFormatter(formatterClassName);
+ LOG.info("Audit log writer class name {}", writerClassName);
Review Comment:
add formatter to log too?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1772960525
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogWriter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.listener.api.event.Event;
+
+/** Interface for writing the audit log. */
+public interface AuditLogWriter {
Review Comment:
The current implementation needs audit writer to extend `AbstractAuditLogWriter`, How about define a default write method in `AuditLogWriter` interface to use formatter to format the event, then we could use one single interface to define the behavior of the AuditLogWriter, like
```
Formatter<R> getFormatter();
void doWrite(R auditLog);
default void write(Event event) {
doWrite(getFormatter().format(event))
}
```
@jerryshao WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1776573289
##########
core/src/main/java/org/apache/gravitino/audit/AbstractAuditLogWriter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.gravitino.listener.api.event.Event;
+
+public abstract class AbstractAuditLogWriter implements AuditLogWriter {
+
+ private Formatter formatter;
+
+ public AbstractAuditLogWriter(Formatter formatter) {
+ this.formatter = formatter;
+ }
+
+ public void write(Event event) {
+ Object formatted = formatter.format(event);
Review Comment:
It loses the type info here, why can we make this class a generic class?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1807748444
##########
docs/gravitino-server-config.md:
##########
@@ -138,6 +138,23 @@ The plugin provides several operational modes for how to process event, supporti
For more details, please refer to the definition of the plugin.
+### Audit log configuration
+
+The audit log framework defines how metadata changes are logged to various storages. The formatter defines an interface that transforms different `Event` types into a unified `AuditLog`.
+The writer defines an interface for writing to different storage types.
Review Comment:
The writer defines an interface for writing to different storage types. -> The writer defines an interface to writing `AuditLog` to different storages. ?
##########
docs/gravitino-server-config.md:
##########
@@ -138,6 +138,23 @@ The plugin provides several operational modes for how to process event, supporti
For more details, please refer to the definition of the plugin.
+### Audit log configuration
+
+The audit log framework defines how metadata changes are logged to various storages. The formatter defines an interface that transforms different `Event` types into a unified `AuditLog`.
Review Comment:
The audit log framework defines how metadata changes are logged to various storages -> The audit log framework defines how audit logs are formatted and written to various storages?
##########
docs/gravitino-server-config.md:
##########
@@ -138,6 +138,23 @@ The plugin provides several operational modes for how to process event, supporti
For more details, please refer to the definition of the plugin.
+### Audit log configuration
+
+The audit log framework defines how metadata changes are logged to various storages. The formatter defines an interface that transforms different `Event` types into a unified `AuditLog`.
+The writer defines an interface for writing to different storage types.
Review Comment:
please add `Gravitino provides a default implement to log basic audit information to a file, you could extend the audit system by implementation corresponding interfaces.`
##########
docs/gravitino-server-config.md:
##########
@@ -138,6 +138,23 @@ The plugin provides several operational modes for how to process event, supporti
For more details, please refer to the definition of the plugin.
+### Audit log configuration
+
+The audit log framework defines how metadata changes are logged to various storages. The formatter defines an interface that transforms different `Event` types into a unified `AuditLog`.
+The writer defines an interface for writing to different storage types.
+
+| Property name | Description | Default value | Required | Since Version |
+|---------------------------------------|---------------------------------------|---------------------------------------------|----------|---------------|
+| `gravitino.audit.enabled` | The audit log enable flag | false | NO | 0.7.0 |
+| `gravitino.audit.writer.className` | The class name of audit log writer | org.apache.gravitino.audit.FileAuditWriter | NO | 0.7.0 |
+| `gravitino.audit.formatter.className` | The class name of audit log formatter | org.apache.gravitino.audit.SimpleFormatter | NO | 0.7.0 |
+
+#### Audit log writer
+
+The `AuditLogWriter` defines an interface that enables the writing of metadata audit logs to different storage mediums such as files, databases, etc.
+
+Writer configuration begins with `gravitino.audit.writer.${name}`, where ${name} is replaced with the actual writer name which define in method `name()`.
Review Comment:
please provide the configuration for `FileAuditWriter` and `SimpleFormatter`
##########
docs/gravitino-server-config.md:
##########
@@ -138,6 +138,23 @@ The plugin provides several operational modes for how to process event, supporti
For more details, please refer to the definition of the plugin.
+### Audit log configuration
+
+The audit log framework defines how metadata changes are logged to various storages. The formatter defines an interface that transforms different `Event` types into a unified `AuditLog`.
+The writer defines an interface for writing to different storage types.
Review Comment:
Could you combine the two line into one line?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1807750081
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "fileName";
+
+ public static final String APPEND = "append";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ public static final String BUFFERED = "buffered";
+
+ public static final String BUFFER_SIZE = "bufferSize";
+
+ public static final String LINE_SEPARATOR = "lineSeparator";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ String lineSeparator;
+
+ boolean append;
+
+ boolean buffered;
+
+ int bufferSize;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ fileName = properties.getOrDefault(LOG_FILE_NAME_CONFIG, "gravitino_audit.log");
+ immediateFlush =
+ Boolean.parseBoolean(properties.getOrDefault(FILE_IMMEDIATE_FLUSH_CONFIG, "false"));
+ lineSeparator = properties.getOrDefault(LINE_SEPARATOR, "\n");
+ append = Boolean.parseBoolean(properties.getOrDefault(APPEND, "false"));
Review Comment:
I prefer to set `true` for the default value for the append.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1751415076
##########
core/src/main/java/org/apache/gravitino/audit/AbstractAuditLogWriter.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.gravitino.listener.api.event.Event;
+
+public abstract class AbstractAuditLogWriter implements AuditLogWriter {
+
+ private Formatter formatter;
+
+ public AbstractAuditLogWriter(Formatter formatter) {
+ this.formatter = formatter;
+ }
+
+ public void write(Event event) {
+ Object formatted = this.formatter.format(event);
+ doWrite(formatted);
+ }
+
+ public abstract void doWrite(Object event);
Review Comment:
why public ?
##########
core/src/main/java/org/apache/gravitino/audit/AbstractAuditLogWriter.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.gravitino.listener.api.event.Event;
+
+public abstract class AbstractAuditLogWriter implements AuditLogWriter {
+
+ private Formatter formatter;
+
+ public AbstractAuditLogWriter(Formatter formatter) {
+ this.formatter = formatter;
+ }
+
+ public void write(Event event) {
+ Object formatted = this.formatter.format(event);
Review Comment:
please remove `this.`
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogConfig.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+import org.apache.gravitino.utils.MapUtils;
+
+public class AuditLogConfig extends Config {
+ public static final String AUDIT_LOG_PREFIX = "gravitino.audit.";
+
+ public static final String AUDIT_LOG_ENABLED = "enable";
+ static final String AUDIT_LOG_WRITER_PREFIX = "writer.";
+ static final String AUDIT_FORMATTER_PREFIX = "formatter.";
+ static final String AUDIT_LOG_WRITER_CLASS_NAME = AUDIT_LOG_WRITER_PREFIX + "class";
+ static final String AUDIT_LOG_FORMATTER_CLASS_NAME = AUDIT_FORMATTER_PREFIX + "class";
+
+ static final ConfigEntry<String> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder(AUDIT_LOG_ENABLED)
+ .doc("Gravitino audit log enable flag")
+ .version(ConfigConstants.VERSION_0_5_0)
Review Comment:
VERSION_0_7_0 ?
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogConfig.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+import org.apache.gravitino.utils.MapUtils;
+
+public class AuditLogConfig extends Config {
+ public static final String AUDIT_LOG_PREFIX = "gravitino.audit.";
+
+ public static final String AUDIT_LOG_ENABLED = "enable";
+ static final String AUDIT_LOG_WRITER_PREFIX = "writer.";
+ static final String AUDIT_FORMATTER_PREFIX = "formatter.";
+ static final String AUDIT_LOG_WRITER_CLASS_NAME = AUDIT_LOG_WRITER_PREFIX + "class";
+ static final String AUDIT_LOG_FORMATTER_CLASS_NAME = AUDIT_FORMATTER_PREFIX + "class";
+
+ static final ConfigEntry<String> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder(AUDIT_LOG_ENABLED)
+ .doc("Gravitino audit log enable flag")
+ .version(ConfigConstants.VERSION_0_5_0)
+ .stringConf()
+ .createWithDefault("false");
+
+ static final ConfigEntry<String> WRITER_CLASS_NAME =
+ new ConfigBuilder(AUDIT_LOG_WRITER_CLASS_NAME)
Review Comment:
should we check whether the content is empty ? like
```
public static final ConfigEntry<String> CATALOG_WAREHOUSE =
new ConfigBuilder(IcebergConstants.WAREHOUSE)
.doc("Warehouse directory of catalog")
.version(ConfigConstants.VERSION_0_2_0)
.stringConf()
.checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)
.create();
```
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogConfig.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+import org.apache.gravitino.utils.MapUtils;
+
+public class AuditLogConfig extends Config {
+ public static final String AUDIT_LOG_PREFIX = "gravitino.audit.";
+
+ public static final String AUDIT_LOG_ENABLED = "enable";
+ static final String AUDIT_LOG_WRITER_PREFIX = "writer.";
+ static final String AUDIT_FORMATTER_PREFIX = "formatter.";
+ static final String AUDIT_LOG_WRITER_CLASS_NAME = AUDIT_LOG_WRITER_PREFIX + "class";
+ static final String AUDIT_LOG_FORMATTER_CLASS_NAME = AUDIT_FORMATTER_PREFIX + "class";
+
+ static final ConfigEntry<String> AUDIT_LOG_ENABLED_CONF =
Review Comment:
String -> bool
##########
core/src/main/java/org/apache/gravitino/audit/AbstractAuditLogWriter.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.gravitino.listener.api.event.Event;
+
+public abstract class AbstractAuditLogWriter implements AuditLogWriter {
+
+ private Formatter formatter;
+
+ public AbstractAuditLogWriter(Formatter formatter) {
+ this.formatter = formatter;
+ }
+
+ public void write(Event event) {
+ Object formatted = this.formatter.format(event);
+ doWrite(formatted);
+ }
+
+ public abstract void doWrite(Object event);
+
+ public abstract void close();
Review Comment:
use make close method as abstract method here?
##########
core/src/test/java/org/apache/gravitino/audit/TestAuditManager.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.listener.EventBus;
+import org.apache.gravitino.listener.EventListenerManager;
+import org.apache.gravitino.listener.api.event.Event;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class TestAuditManager {
+
+ @Test
+ public void testAuditLog() {
+ DummyEvent dummyEvent = mockDummyEvent();
+ EventListenerManager eventListenerManager = mockEventListenerManager();
+ AuditLogManager auditLogManager = mockAuditLogManager(eventListenerManager);
+ EventBus eventBus = eventListenerManager.createEventBus();
+ eventBus.dispatchEvent(dummyEvent);
+ Assertions.assertInstanceOf(DummyAuditWriter.class, auditLogManager.getAuditLogWriter());
+ Assertions.assertInstanceOf(
+ DummyAuditFormatter.class,
+ ((DummyAuditWriter) auditLogManager.getAuditLogWriter()).getFormatter());
+ DummyAuditWriter dummyAuditWriter = (DummyAuditWriter) auditLogManager.getAuditLogWriter();
+ Assertions.assertEquals(1, dummyAuditWriter.getAuditLogs().size());
+ Assertions.assertInstanceOf(Map.class, dummyAuditWriter.getAuditLogs().get(0));
Review Comment:
could you check the audit log content?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1805815377
##########
core/src/main/java/org/apache/gravitino/Configs.java:
##########
@@ -342,4 +342,27 @@ private Configs() {}
.stringConf()
.toSequence()
.createWithDefault(Collections.emptyList());
+
+ public static final String AUDIT_LOG_WRITER_CONFIG_PREFIX = "gravitino.audit.writer.";
+
+ public static final ConfigEntry<Boolean> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder("gravitino.audit.enable")
+ .doc("Gravitino audit log enable flag")
+ .version(ConfigConstants.VERSION_0_7_0)
+ .booleanConf()
+ .createWithDefault(false);
+
+ public static final ConfigEntry<String> AUDIT_LOG_WRITER_CLASS_NAME =
+ new ConfigBuilder("gravitino.audit.writer.class")
+ .doc("Gravitino audit log writer class name")
+ .version(ConfigConstants.VERSION_0_7_0)
+ .stringConf()
+ .createWithDefault("org.apache.gravitino.audit.FileAuditWriter");
Review Comment:
could you use `FileAuditWriter.getClass().getName()`?
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "fileName";
+
+ public static final String APPEND = "append";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ public static final String BUFFERED = "buffered";
+
+ public static final String BUFFER_SIZE = "bufferSize";
+
+ public static final String LINE_SEPARATOR = "lineSeparator";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ String lineSeparator;
+
+ boolean append;
+
+ boolean buffered;
+
+ int bufferSize;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ fileName = properties.getOrDefault(LOG_FILE_NAME_CONFIG, "gravitino_audit.log");
+ immediateFlush =
+ Boolean.parseBoolean(properties.getOrDefault(FILE_IMMEDIATE_FLUSH_CONFIG, "false"));
+ lineSeparator = properties.getOrDefault(LINE_SEPARATOR, "\n");
+ append = Boolean.parseBoolean(properties.getOrDefault(APPEND, "false"));
+ buffered = Boolean.parseBoolean(properties.getOrDefault(BUFFERED, "true"));
Review Comment:
what's the effect for adding the buffer? the system has a buffer already.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1807748898
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "fileName";
+
+ public static final String APPEND = "append";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ public static final String BUFFERED = "buffered";
+
+ public static final String BUFFER_SIZE = "bufferSize";
+
+ public static final String LINE_SEPARATOR = "lineSeparator";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ String lineSeparator;
+
+ boolean append;
+
+ boolean buffered;
+
+ int bufferSize;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ fileName = properties.getOrDefault(LOG_FILE_NAME_CONFIG, "gravitino_audit.log");
+ immediateFlush =
+ Boolean.parseBoolean(properties.getOrDefault(FILE_IMMEDIATE_FLUSH_CONFIG, "false"));
+ lineSeparator = properties.getOrDefault(LINE_SEPARATOR, "\n");
+ append = Boolean.parseBoolean(properties.getOrDefault(APPEND, "false"));
+ buffered = Boolean.parseBoolean(properties.getOrDefault(BUFFERED, "true"));
Review Comment:
@hanwxx if no strong option to add the buffer, I prefer to remove it, WHYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "hanwxx (via GitHub)" <gi...@apache.org>.
hanwxx commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2363087162
> @hanwxx , is there anything blocking the move forward?@hanwxx , is there anything blocking the move forward?@hanwxx ,有什么东西阻碍了前进吗?
Submitted new code, please review it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1772960525
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogWriter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.listener.api.event.Event;
+
+/** Interface for writing the audit log. */
+public interface AuditLogWriter {
Review Comment:
How about define a default method for write to use formatter to format the event like
```
Formatter<R> getFormatter();
void doWrite(R auditLog);
default void write(Event event) {
doWrite(getFormatter().format(event))
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1772960525
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogWriter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.listener.api.event.Event;
+
+/** Interface for writing the audit log. */
+public interface AuditLogWriter {
Review Comment:
The current implementation needs audit writer to extend `AbstractAuditLogWriter`, How about define a default write method in `AuditLogWriter` interface to use formatter to format the event, then we could use one single interface to define the behavior the AuditLogWriter, like
```
Formatter<R> getFormatter();
void doWrite(R auditLog);
default void write(Event event) {
doWrite(getFormatter().format(event))
}
```
@jerryshao WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1773054315
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogConfig.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+import org.apache.gravitino.utils.MapUtils;
+
+public class AuditLogConfig extends Config {
+ public static final String AUDIT_LOG_ENABLED = "enable";
+ static final String AUDIT_LOG_WRITER_PREFIX = "writer.";
+ static final String AUDIT_FORMATTER_PREFIX = "formatter.";
+ static final String AUDIT_LOG_WRITER_CLASS_NAME = AUDIT_LOG_WRITER_PREFIX + "class";
+ static final String AUDIT_LOG_FORMATTER_CLASS_NAME = AUDIT_FORMATTER_PREFIX + "class";
+
+ static final ConfigEntry<Boolean> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder(AUDIT_LOG_ENABLED)
+ .doc("Gravitino audit log enable flag")
Review Comment:
I would suggest to move all the configuration definitions to class `Configs`, it is not necessary to have a separate place to maintain the configurations.
Also, please use the full name to manage the configurations for simplicity, and you can define the `AuditLogManager#initialize(Config config, xxx)` like this. You don't help to remove the prefix and make things complicated.
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogConfig.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+import org.apache.gravitino.utils.MapUtils;
+
+public class AuditLogConfig extends Config {
+ public static final String AUDIT_LOG_ENABLED = "enable";
+ static final String AUDIT_LOG_WRITER_PREFIX = "writer.";
+ static final String AUDIT_FORMATTER_PREFIX = "formatter.";
+ static final String AUDIT_LOG_WRITER_CLASS_NAME = AUDIT_LOG_WRITER_PREFIX + "class";
+ static final String AUDIT_LOG_FORMATTER_CLASS_NAME = AUDIT_FORMATTER_PREFIX + "class";
+
+ static final ConfigEntry<Boolean> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder(AUDIT_LOG_ENABLED)
+ .doc("Gravitino audit log enable flag")
Review Comment:
I would suggest to move all the configuration definitions to class `Configs`, it is not necessary to have a separate place to maintain the configurations.
Also, please use the full name to manage the configurations for simplicity, and you can define the `AuditLogManager#initialize(Config config, xxx)` like this. You don't have to remove the prefix and make things complicated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1772936186
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogConfig.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+import org.apache.gravitino.utils.MapUtils;
+
+public class AuditLogConfig extends Config {
+ public static final String AUDIT_LOG_ENABLED = "enable";
+ static final String AUDIT_LOG_WRITER_PREFIX = "writer.";
+ static final String AUDIT_FORMATTER_PREFIX = "formatter.";
+ static final String AUDIT_LOG_WRITER_CLASS_NAME = AUDIT_LOG_WRITER_PREFIX + "class";
+ static final String AUDIT_LOG_FORMATTER_CLASS_NAME = AUDIT_FORMATTER_PREFIX + "class";
+
+ static final ConfigEntry<Boolean> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder(AUDIT_LOG_ENABLED)
+ .doc("Gravitino audit log enable flag")
Review Comment:
Whether to enable Gravitino audit log ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1772950327
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogManager.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.listener.EventListenerManager;
+import org.apache.gravitino.listener.api.EventListenerPlugin;
+import org.apache.gravitino.listener.api.event.Event;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditLogManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuditLogManager.class);
+
+ public static final String AUDIT_LOG_PREFIX = "gravitino.audit.";
+
+ @VisibleForTesting private AuditLogWriter auditLogWriter;
+
+ public void init(Map<String, String> properties, EventListenerManager eventBusManager) {
+ AuditLogConfig auditLogConfig = new AuditLogConfig(properties);
+ if (!auditLogConfig.isAuditEnabled()) {
+ LOG.warn("Audit log is not enabled");
+ return;
+ }
+
+ String writerClassName = auditLogConfig.getWriterClassName();
+ String formatterClassName = auditLogConfig.getAuditLogFormatterClassName();
+ Formatter formatter = loadFormatter(formatterClassName);
+ LOG.info("Audit log writer class name {}", writerClassName);
+ if (StringUtils.isEmpty(writerClassName)) {
+ throw new GravitinoRuntimeException("Audit log writer class is not configured");
+ }
+
+ auditLogWriter =
+ loadAuditLogWriter(
+ writerClassName, auditLogConfig.getWriterProperties(properties), formatter);
+
+ eventBusManager.addEventListener(
+ "audit-log",
+ new EventListenerPlugin() {
+
+ @Override
+ public void init(Map<String, String> properties) throws RuntimeException {}
+
+ @Override
+ public void start() throws RuntimeException {}
+
+ @Override
+ public void stop() throws RuntimeException {
+ auditLogWriter.close();
+ }
+
+ @Override
+ public void onPostEvent(Event event) throws RuntimeException {
+ try {
+ auditLogWriter.write(event);
+ } catch (Exception e) {
+ LOG.warn("Failed to write audit log {}.", event, e);
+ }
+ }
+
+ @Override
+ public Mode mode() {
+ return Mode.ASYNC_ISOLATED;
+ }
+ });
+ }
+
+ private AuditLogWriter loadAuditLogWriter(
+ String className, Map<String, String> config, Formatter formatter) {
+ try {
+ AuditLogWriter auditLogWriter =
+ (AuditLogWriter)
+ Class.forName(className).getConstructor(Formatter.class).newInstance(formatter);
Review Comment:
Here add a constrict about the constructor of `AuditLogWriter` implicitly, but not defined in interface, how about pass `format` in auditLogWriter.init(formatter, config) ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1772950327
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogManager.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.listener.EventListenerManager;
+import org.apache.gravitino.listener.api.EventListenerPlugin;
+import org.apache.gravitino.listener.api.event.Event;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditLogManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuditLogManager.class);
+
+ public static final String AUDIT_LOG_PREFIX = "gravitino.audit.";
+
+ @VisibleForTesting private AuditLogWriter auditLogWriter;
+
+ public void init(Map<String, String> properties, EventListenerManager eventBusManager) {
+ AuditLogConfig auditLogConfig = new AuditLogConfig(properties);
+ if (!auditLogConfig.isAuditEnabled()) {
+ LOG.warn("Audit log is not enabled");
+ return;
+ }
+
+ String writerClassName = auditLogConfig.getWriterClassName();
+ String formatterClassName = auditLogConfig.getAuditLogFormatterClassName();
+ Formatter formatter = loadFormatter(formatterClassName);
+ LOG.info("Audit log writer class name {}", writerClassName);
+ if (StringUtils.isEmpty(writerClassName)) {
+ throw new GravitinoRuntimeException("Audit log writer class is not configured");
+ }
+
+ auditLogWriter =
+ loadAuditLogWriter(
+ writerClassName, auditLogConfig.getWriterProperties(properties), formatter);
+
+ eventBusManager.addEventListener(
+ "audit-log",
+ new EventListenerPlugin() {
+
+ @Override
+ public void init(Map<String, String> properties) throws RuntimeException {}
+
+ @Override
+ public void start() throws RuntimeException {}
+
+ @Override
+ public void stop() throws RuntimeException {
+ auditLogWriter.close();
+ }
+
+ @Override
+ public void onPostEvent(Event event) throws RuntimeException {
+ try {
+ auditLogWriter.write(event);
+ } catch (Exception e) {
+ LOG.warn("Failed to write audit log {}.", event, e);
+ }
+ }
+
+ @Override
+ public Mode mode() {
+ return Mode.ASYNC_ISOLATED;
+ }
+ });
+ }
+
+ private AuditLogWriter loadAuditLogWriter(
+ String className, Map<String, String> config, Formatter formatter) {
+ try {
+ AuditLogWriter auditLogWriter =
+ (AuditLogWriter)
+ Class.forName(className).getConstructor(Formatter.class).newInstance(formatter);
Review Comment:
Here add a constrict about the constructor of `AuditLogWriter`, but not defined in interface, how about pass `format` in auditLogWriter.init(formatter, config) ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1807749837
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "fileName";
+
+ public static final String APPEND = "append";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ public static final String BUFFERED = "buffered";
+
+ public static final String BUFFER_SIZE = "bufferSize";
+
+ public static final String LINE_SEPARATOR = "lineSeparator";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ String lineSeparator;
+
+ boolean append;
+
+ boolean buffered;
+
+ int bufferSize;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ fileName = properties.getOrDefault(LOG_FILE_NAME_CONFIG, "gravitino_audit.log");
+ immediateFlush =
Review Comment:
please add `this` when the class variables are first initializated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1724895664
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogConfig.java:
##########
@@ -0,0 +1,60 @@
+package org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+import org.apache.gravitino.utils.MapUtils;
+
+public class AuditLogConfig extends Config {
+ public static final String AUDIT_LOG_PREFIX = "gravitino.audit.";
+
+ public static final String AUDIT_LOG_ENABLED = "enable";
+ static final String AUDIT_LOG_WRITER_PREFIX = "writer.";
+ static final String AUDIT_FORMATTER_PREFIX = "formatter.";
+ static final String AUDIT_LOG_WRITER_CLASS_NAME = AUDIT_LOG_WRITER_PREFIX + "class";
+ static final String AUDIT_LOG_FORMATTER_CLASS_NAME = AUDIT_FORMATTER_PREFIX + "class";
+
+ static final ConfigEntry<String> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder(AUDIT_LOG_ENABLED)
+ .doc("Gravitino event audit log writer class")
Review Comment:
please correct the doc
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2426784466
A great feature for Gravitino, @hanwxx thanks for your work!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2412653833
> > I kind of agree with @hanwxx , AuditLog and event are two things, we don't have to use interface to put them together. Using a converter to bridge them together without hard combination seems better to me.
>
> It will hard to transform `IcebergRESTServiceEvent` to `AuditLog` when supporting Iceberg REST server audit log. `IcebergRESTServiceEvent` will be defined in `IcebergRESTServer` module because it may contains some Iceberg specific object like `TableMetaData`. I agree that we'd better not mix event and audit, but maybe we need a trade-off.
let's keep the current implementation to move forward the PR, @hanwxx do you have time to continue work on the PR to meet the release of 0.7 ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1800978054
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogWriter.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.io.Closeable;
+import java.util.Map;
+import org.apache.gravitino.listener.api.event.Event;
+
+/**
+ * Interface for writing the audit log, which can write to different storage, such as file,
+ * database,mq.
+ */
+public interface AuditLogWriter extends Closeable {
+
+ /** @return formatter. */
+ Formatter getFormatter();
+
+ /**
+ * Initialize the writer with the given configuration.
+ *
+ * @param properties
+ */
+ void init(Formatter formatter, Map<String, String> properties);
+
+ /**
+ * Write the audit event to storage.
+ *
+ * @param auditLog
+ */
+ void doWrite(AuditLog auditLog);
+
+ /**
+ * Write the audit event to storage.
+ *
+ * @param event
+ */
+ default void write(Event event) {
+ doWrite(getFormatter().format(event));
+ }
+
+ /** Close the writer. */
+ void close();
Review Comment:
why re exporting `close` method in `AuditLogWriter` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1807750251
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "fileName";
+
+ public static final String APPEND = "append";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ public static final String BUFFERED = "buffered";
+
+ public static final String BUFFER_SIZE = "bufferSize";
+
+ public static final String LINE_SEPARATOR = "lineSeparator";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ String lineSeparator;
+
+ boolean append;
+
+ boolean buffered;
+
+ int bufferSize;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ fileName = properties.getOrDefault(LOG_FILE_NAME_CONFIG, "gravitino_audit.log");
+ immediateFlush =
+ Boolean.parseBoolean(properties.getOrDefault(FILE_IMMEDIATE_FLUSH_CONFIG, "false"));
+ lineSeparator = properties.getOrDefault(LINE_SEPARATOR, "\n");
+ append = Boolean.parseBoolean(properties.getOrDefault(APPEND, "false"));
+ buffered = Boolean.parseBoolean(properties.getOrDefault(BUFFERED, "true"));
+ bufferSize = Integer.parseInt(properties.getOrDefault(BUFFER_SIZE, "8192"));
+ try {
+ OutputStream outputStream = new FileOutputStream(fileName, append);
Review Comment:
Better to place the audit log file in `log` directory?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2421289283
LGTM except the comment, @hanwxx could you add a document for audit log in `gravitino-server-config.md`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2367200003
I will review it today.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "hanwxx (via GitHub)" <gi...@apache.org>.
hanwxx commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2325805995
Get, i will split sub-tasks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2301857646
@hanwxx , this PR seems mainly about audit frame, could you split separate sub-tasks from #3973 ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1808181506
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "fileName";
+
+ public static final String APPEND = "append";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
Review Comment:
use `AUDIT_LOG_FILE_IMMEDIATE_FLUSH`? config seems redundant
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "fileName";
Review Comment:
please use `AUDIT_LOG_FILE_NAME`
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "fileName";
+
+ public static final String APPEND = "append";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ public static final String BUFFERED = "buffered";
+
+ public static final String BUFFER_SIZE = "bufferSize";
+
+ public static final String LINE_SEPARATOR = "lineSeparator";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ String lineSeparator;
+
+ boolean append;
+
+ boolean buffered;
+
+ int bufferSize;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ this.fileName =
+ System.getProperty("gravitino.log.path")
+ + "/"
+ + properties.getOrDefault(LOG_FILE_NAME_CONFIG, "gravitino_audit.log");
+ this.immediateFlush =
+ Boolean.parseBoolean(properties.getOrDefault(FILE_IMMEDIATE_FLUSH_CONFIG, "false"));
+ this.lineSeparator = properties.getOrDefault(LINE_SEPARATOR, "\n");
+ this.append = Boolean.parseBoolean(properties.getOrDefault(APPEND, "true"));
+ this.buffered = Boolean.parseBoolean(properties.getOrDefault(BUFFERED, "true"));
Review Comment:
seems confusing to export buffer and immediateFlush configuration to user
##########
docs/gravitino-server-config.md:
##########
@@ -138,6 +138,36 @@ The plugin provides several operational modes for how to process event, supporti
For more details, please refer to the definition of the plugin.
+### Audit log configuration
+
+The audit log framework defines how audit logs are formatted and written to various storages. The formatter defines an interface that transforms different `Event` types into a unified `AuditLog`. The writer defines an interface to writing AuditLog to different storages.
+
+Gravitino provides a default implement to log basic audit information to a file, you could extend the audit system by implementation corresponding interfaces.
+
+| Property name | Description | Default value | Required | Since Version |
+|---------------------------------------|----------------------------------------|---------------------------------------------|----------|---------------|
+| `gravitino.audit.enabled` | The audit log enable flag. | false | NO | 0.7.0 |
+| `gravitino.audit.writer.className` | The class name of audit log writer. | org.apache.gravitino.audit.FileAuditWriter | NO | 0.7.0 |
+| `gravitino.audit.formatter.className` | The class name of audit log formatter. | org.apache.gravitino.audit.SimpleFormatter | NO | 0.7.0 |
+
+#### Audit log writer
+
+The `AuditLogWriter` defines an interface that enables the writing of metadata audit logs to different storage mediums such as files, databases, etc.
+
+Writer configuration begins with `gravitino.audit.writer.${name}`, where ${name} is replaced with the actual writer name defined in method `name()`. `FileAuditWriter` is a default implement to log audit information, whose name is `file`.
+
+| Property name | Description | Default value | Required | Since Version |
+|-----------------------------------------------------|-----------------------------------------------------------------------------------------|---------------------|----------|---------------|
+| `gravitino.audit.writer.file.fileName` | The audit log file name, the path is ${sys:gravitino.log.path}/${fileName} | gravitino_audit.log | NO | 0.7.0 |
+| `gravitino.audit.writer.file.immediateFlush` | whether the writer will flush at the end of each write operation. | false | NO | 0.7.0 |
+| `gravitino.audit.writer.file.append` | whether the log will be written to the end or the beginning of the file. | true | NO | 0.7.0 |
+| `gravitino.audit.writer.file.buffered` | whether the writer use an internal `ByteBuffer` to store audit log before writing them. | true | NO | 0.7.0 |
+| `gravitino.audit.writer.file.bufferSize` | The size of the `ByteBuffer`. | 8192 | NO | 0.7.0 |
+| `gravitino.audit.writer.file.lineSeparator` | The audit log line separator. | \n | NO | 0.7.0 |
+
+#### Audit log formatter
Review Comment:
please add an empty line after the title
##########
docs/gravitino-server-config.md:
##########
@@ -138,6 +138,36 @@ The plugin provides several operational modes for how to process event, supporti
For more details, please refer to the definition of the plugin.
+### Audit log configuration
+
+The audit log framework defines how audit logs are formatted and written to various storages. The formatter defines an interface that transforms different `Event` types into a unified `AuditLog`. The writer defines an interface to writing AuditLog to different storages.
+
+Gravitino provides a default implement to log basic audit information to a file, you could extend the audit system by implementation corresponding interfaces.
+
+| Property name | Description | Default value | Required | Since Version |
+|---------------------------------------|----------------------------------------|---------------------------------------------|----------|---------------|
+| `gravitino.audit.enabled` | The audit log enable flag. | false | NO | 0.7.0 |
+| `gravitino.audit.writer.className` | The class name of audit log writer. | org.apache.gravitino.audit.FileAuditWriter | NO | 0.7.0 |
+| `gravitino.audit.formatter.className` | The class name of audit log formatter. | org.apache.gravitino.audit.SimpleFormatter | NO | 0.7.0 |
+
+#### Audit log writer
+
+The `AuditLogWriter` defines an interface that enables the writing of metadata audit logs to different storage mediums such as files, databases, etc.
+
+Writer configuration begins with `gravitino.audit.writer.${name}`, where ${name} is replaced with the actual writer name defined in method `name()`. `FileAuditWriter` is a default implement to log audit information, whose name is `file`.
+
+| Property name | Description | Default value | Required | Since Version |
+|-----------------------------------------------------|-----------------------------------------------------------------------------------------|---------------------|----------|---------------|
+| `gravitino.audit.writer.file.fileName` | The audit log file name, the path is ${sys:gravitino.log.path}/${fileName} | gravitino_audit.log | NO | 0.7.0 |
+| `gravitino.audit.writer.file.immediateFlush` | whether the writer will flush at the end of each write operation. | false | NO | 0.7.0 |
+| `gravitino.audit.writer.file.append` | whether the log will be written to the end or the beginning of the file. | true | NO | 0.7.0 |
+| `gravitino.audit.writer.file.buffered` | whether the writer use an internal `ByteBuffer` to store audit log before writing them. | true | NO | 0.7.0 |
+| `gravitino.audit.writer.file.bufferSize` | The size of the `ByteBuffer`. | 8192 | NO | 0.7.0 |
+| `gravitino.audit.writer.file.lineSeparator` | The audit log line separator. | \n | NO | 0.7.0 |
+
+#### Audit log formatter
Review Comment:
could you more `formatter` section before `writer`?
##########
docs/gravitino-server-config.md:
##########
@@ -138,6 +138,36 @@ The plugin provides several operational modes for how to process event, supporti
For more details, please refer to the definition of the plugin.
+### Audit log configuration
+
+The audit log framework defines how audit logs are formatted and written to various storages. The formatter defines an interface that transforms different `Event` types into a unified `AuditLog`. The writer defines an interface to writing AuditLog to different storages.
+
+Gravitino provides a default implement to log basic audit information to a file, you could extend the audit system by implementation corresponding interfaces.
+
+| Property name | Description | Default value | Required | Since Version |
+|---------------------------------------|----------------------------------------|---------------------------------------------|----------|---------------|
+| `gravitino.audit.enabled` | The audit log enable flag. | false | NO | 0.7.0 |
Review Comment:
please use `0.7.0-incubating`
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogManager.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.listener.EventListenerManager;
+import org.apache.gravitino.listener.api.EventListenerPlugin;
+import org.apache.gravitino.listener.api.event.Event;
+import org.apache.gravitino.utils.MapUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * AuditLogManager is responsible for initializing the audit log writer and formatter,
+ * which are used to write metadata audit logs.
+ * */
+public class AuditLogManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuditLogManager.class);
+
+ @VisibleForTesting private AuditLogWriter auditLogWriter;
+
+ public void init(Config config, EventListenerManager eventBusManager) {
+ if (!config.get(Configs.AUDIT_LOG_ENABLED_CONF)) {
+ LOG.info("Audit log is not enabled");
+ return;
+ }
+
+ // If formatter class name is not config, use default formatter class name
+ String formatterClassName = config.get(Configs.AUDIT_LOG_FORMATTER_CLASS_NAME);
+ Formatter formatter = loadFormatter(formatterClassName);
+ LOG.info("Audit log formatter class name:{}", formatterClassName);
+
+ String writerClassName = config.get(Configs.AUDIT_LOG_WRITER_CLASS_NAME);
+ // If writer class name is not config, use default writer class name
Review Comment:
please remove this comment
##########
docs/gravitino-server-config.md:
##########
@@ -138,6 +138,36 @@ The plugin provides several operational modes for how to process event, supporti
For more details, please refer to the definition of the plugin.
+### Audit log configuration
+
+The audit log framework defines how audit logs are formatted and written to various storages. The formatter defines an interface that transforms different `Event` types into a unified `AuditLog`. The writer defines an interface to writing AuditLog to different storages.
+
+Gravitino provides a default implement to log basic audit information to a file, you could extend the audit system by implementation corresponding interfaces.
+
+| Property name | Description | Default value | Required | Since Version |
+|---------------------------------------|----------------------------------------|---------------------------------------------|----------|---------------|
+| `gravitino.audit.enabled` | The audit log enable flag. | false | NO | 0.7.0 |
+| `gravitino.audit.writer.className` | The class name of audit log writer. | org.apache.gravitino.audit.FileAuditWriter | NO | 0.7.0 |
+| `gravitino.audit.formatter.className` | The class name of audit log formatter. | org.apache.gravitino.audit.SimpleFormatter | NO | 0.7.0 |
+
+#### Audit log writer
+
+The `AuditLogWriter` defines an interface that enables the writing of metadata audit logs to different storage mediums such as files, databases, etc.
+
+Writer configuration begins with `gravitino.audit.writer.${name}`, where ${name} is replaced with the actual writer name defined in method `name()`. `FileAuditWriter` is a default implement to log audit information, whose name is `file`.
+
+| Property name | Description | Default value | Required | Since Version |
+|-----------------------------------------------------|-----------------------------------------------------------------------------------------|---------------------|----------|---------------|
+| `gravitino.audit.writer.file.fileName` | The audit log file name, the path is ${sys:gravitino.log.path}/${fileName} | gravitino_audit.log | NO | 0.7.0 |
+| `gravitino.audit.writer.file.immediateFlush` | whether the writer will flush at the end of each write operation. | false | NO | 0.7.0 |
Review Comment:
whether -> Whether
##########
docs/gravitino-server-config.md:
##########
@@ -138,6 +138,36 @@ The plugin provides several operational modes for how to process event, supporti
For more details, please refer to the definition of the plugin.
+### Audit log configuration
+
+The audit log framework defines how audit logs are formatted and written to various storages. The formatter defines an interface that transforms different `Event` types into a unified `AuditLog`. The writer defines an interface to writing AuditLog to different storages.
+
+Gravitino provides a default implement to log basic audit information to a file, you could extend the audit system by implementation corresponding interfaces.
+
+| Property name | Description | Default value | Required | Since Version |
+|---------------------------------------|----------------------------------------|---------------------------------------------|----------|---------------|
+| `gravitino.audit.enabled` | The audit log enable flag. | false | NO | 0.7.0 |
+| `gravitino.audit.writer.className` | The class name of audit log writer. | org.apache.gravitino.audit.FileAuditWriter | NO | 0.7.0 |
+| `gravitino.audit.formatter.className` | The class name of audit log formatter. | org.apache.gravitino.audit.SimpleFormatter | NO | 0.7.0 |
+
+#### Audit log writer
+
+The `AuditLogWriter` defines an interface that enables the writing of metadata audit logs to different storage mediums such as files, databases, etc.
+
+Writer configuration begins with `gravitino.audit.writer.${name}`, where ${name} is replaced with the actual writer name defined in method `name()`. `FileAuditWriter` is a default implement to log audit information, whose name is `file`.
+
+| Property name | Description | Default value | Required | Since Version |
+|-----------------------------------------------------|-----------------------------------------------------------------------------------------|---------------------|----------|---------------|
+| `gravitino.audit.writer.file.fileName` | The audit log file name, the path is ${sys:gravitino.log.path}/${fileName} | gravitino_audit.log | NO | 0.7.0 |
+| `gravitino.audit.writer.file.immediateFlush` | whether the writer will flush at the end of each write operation. | false | NO | 0.7.0 |
+| `gravitino.audit.writer.file.append` | whether the log will be written to the end or the beginning of the file. | true | NO | 0.7.0 |
+| `gravitino.audit.writer.file.buffered` | whether the writer use an internal `ByteBuffer` to store audit log before writing them. | true | NO | 0.7.0 |
+| `gravitino.audit.writer.file.bufferSize` | The size of the `ByteBuffer`. | 8192 | NO | 0.7.0 |
+| `gravitino.audit.writer.file.lineSeparator` | The audit log line separator. | \n | NO | 0.7.0 |
+
+#### Audit log formatter
+The Formatter defines an interface that formats metadata audit logs into a unified format. `SimpleFormatter` is a default implement to format audit information, it not needs any configuration.
Review Comment:
it not needs any configuration. -> you don't need to do extra configurations.
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "fileName";
+
+ public static final String APPEND = "append";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ public static final String BUFFERED = "buffered";
+
+ public static final String BUFFER_SIZE = "bufferSize";
+
+ public static final String LINE_SEPARATOR = "lineSeparator";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ String lineSeparator;
+
+ boolean append;
+
+ boolean buffered;
+
+ int bufferSize;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ this.fileName =
+ System.getProperty("gravitino.log.path")
+ + "/"
+ + properties.getOrDefault(LOG_FILE_NAME_CONFIG, "gravitino_audit.log");
+ this.immediateFlush =
+ Boolean.parseBoolean(properties.getOrDefault(FILE_IMMEDIATE_FLUSH_CONFIG, "false"));
+ this.lineSeparator = properties.getOrDefault(LINE_SEPARATOR, "\n");
Review Comment:
I prefer to remove lineSeparator, because user doesn't need to config it in most cases. and maybe we should use a more platform independent way to represent line seperator since it will be `\r\n` in windows.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1800341207
##########
core/src/main/java/org/apache/gravitino/Configs.java:
##########
@@ -342,4 +342,31 @@ private Configs() {}
.stringConf()
.toSequence()
.createWithDefault(Collections.emptyList());
+
+ public static final String AUDIT_LOG_WRITER_CONFIG_PREFIX = "gravitino.audit.writer";
+
+ public static final String AUDIT_LOG_DEFAULT_FILE_WRITER_FILE_NAME =
+ "default_gravitino_audit_log";
+ public static final ConfigEntry<Boolean> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder("gravitino.audit.enable")
+ .doc("Gravitino audit log enable flag")
+ .version(ConfigConstants.VERSION_0_7_0)
+ .booleanConf()
+ .createWithDefault(false);
+
+ public static final ConfigEntry<String> WRITER_CLASS_NAME =
+ new ConfigBuilder("gravitino.audit.writer.")
+ .doc("Gravitino audit log writer class name")
+ .version(ConfigConstants.VERSION_0_7_0)
+ .stringConf()
+ .checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)
+ .createWithDefault("");
+
+ public static final ConfigEntry<String> FORMATTER_CLASS_NAME =
+ new ConfigBuilder("gravitino.audit.writer.class")
Review Comment:
not fixed?
##########
core/src/main/java/org/apache/gravitino/Configs.java:
##########
@@ -342,4 +342,29 @@ private Configs() {}
.stringConf()
.toSequence()
.createWithDefault(Collections.emptyList());
+
+ public static final String AUDIT_LOG_WRITER_CONFIG_PREFIX = "gravitino.audit.writer.";
+
+ public static final ConfigEntry<Boolean> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder("gravitino.audit.enable")
+ .doc("Gravitino audit log enable flag")
+ .version(ConfigConstants.VERSION_0_7_0)
+ .booleanConf()
+ .createWithDefault(false);
+
+ public static final ConfigEntry<String> AUDIT_LOG_WRITER_CLASS_NAME =
+ new ConfigBuilder("gravitino.audit.writer.")
+ .doc("Gravitino audit log writer class name")
+ .version(ConfigConstants.VERSION_0_7_0)
+ .stringConf()
+ .checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)
Review Comment:
There is no need add the empty check if the config has the default value
##########
core/src/main/java/org/apache/gravitino/Configs.java:
##########
@@ -342,4 +342,31 @@ private Configs() {}
.stringConf()
.toSequence()
.createWithDefault(Collections.emptyList());
+
+ public static final String AUDIT_LOG_WRITER_CONFIG_PREFIX = "gravitino.audit.writer";
+
+ public static final String AUDIT_LOG_DEFAULT_FILE_WRITER_FILE_NAME =
+ "default_gravitino_audit_log";
+ public static final ConfigEntry<Boolean> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder("gravitino.audit.enable")
+ .doc("Gravitino audit log enable flag")
+ .version(ConfigConstants.VERSION_0_7_0)
+ .booleanConf()
+ .createWithDefault(false);
+
+ public static final ConfigEntry<String> WRITER_CLASS_NAME =
+ new ConfigBuilder("gravitino.audit.writer.")
Review Comment:
not fixed
##########
core/src/main/java/org/apache/gravitino/audit/StringFormatter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Objects;
+import org.apache.gravitino.audit.AuditLog.Status;
+import org.apache.gravitino.listener.api.event.Event;
+import org.apache.gravitino.listener.api.event.FailureEvent;
+
+/** The default implementation of the audit log. */
+public class StringFormatter implements Formatter {
Review Comment:
seems not related to String, rename to `SimpleAuditLogFormatter`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "hanwxx (via GitHub)" <gi...@apache.org>.
hanwxx commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2412737315
> > > I kind of agree with @hanwxx , AuditLog and event are two things, we don't have to use interface to put them together. Using a converter to bridge them together without hard combination seems better to me.
> >
> >
> > It will hard to transform `IcebergRESTServiceEvent` to `AuditLog` when supporting Iceberg REST server audit log. `IcebergRESTServiceEvent` will be defined in `IcebergRESTServer` module because it may contains some Iceberg specific object like `TableMetaData`. I agree that we'd better not mix event and audit, but maybe we need a trade-off.
>
> let's keep the current implementation to move forward the PR, @hanwxx do you have time to continue work on the PR to meet the release of 0.7 ?
In addition to design a log audit framework, next i will focus on
> > > I kind of agree with @hanwxx , AuditLog and event are two things, we don't have to use interface to put them together. Using a converter to bridge them together without hard combination seems better to me.
> >
> >
> > It will hard to transform `IcebergRESTServiceEvent` to `AuditLog` when supporting Iceberg REST server audit log. `IcebergRESTServiceEvent` will be defined in `IcebergRESTServer` module because it may contains some Iceberg specific object like `TableMetaData`. I agree that we'd better not mix event and audit, but maybe we need a trade-off.
>
> let's keep the current implementation to move forward the PR, @hanwxx do you have time to continue work on the PR to meet the release of 0.7 ?
After finished audit log framework design, next i will optimize class Audit Log, which will contain more detail for different operation, this subtask may not finished in the release of 0.7.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2408453321
> I kind of agree with @hanwxx , AuditLog and event are two things, we don't have to use interface to put them together. Using a converter to bridge them together without hard combination seems better to me.
It will hard to transform `IcebergRESTServiceEvent` to `AuditLog` when supporting Iceberg REST server audit log. `IcebergRESTServiceEvent` will be defined in `IcebergRESTServer` module because it may contains some Iceberg specific object like `TableMetaData`. I agree that we'd better not mix event and audit, but maybe we need a trade-off.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1805755120
##########
core/src/main/java/org/apache/gravitino/audit/SimpleAuditLog.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.text.SimpleDateFormat;
+import lombok.Builder;
+
+/** The default implementation of the audit log. */
+@Builder
+public class SimpleAuditLog implements AuditLog {
+
+ private String user;
+
+ private Operation operation;
+
+ private String identifier;
+
+ private long timestamp;
+
+ private Status status;
+
+ @Override
+ public String user() {
+ return user;
+ }
+
+ @Override
+ public Operation operation() {
+ return operation;
+ }
+
+ @Override
+ public String identifier() {
+ return identifier;
+ }
+
+ @Override
+ public long timestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public Status status() {
+ return status;
+ }
+
+ @Override
+ public String toString() {
+ return String.format(
+ "[%s] %s %s %s %s",
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp),
Review Comment:
How about using '\t' to split items, using space to split time?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 merged PR #4575:
URL: https://github.com/apache/gravitino/pull/4575
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1772941793
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogManager.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.listener.EventListenerManager;
+import org.apache.gravitino.listener.api.EventListenerPlugin;
+import org.apache.gravitino.listener.api.event.Event;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditLogManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuditLogManager.class);
+
+ public static final String AUDIT_LOG_PREFIX = "gravitino.audit.";
+
+ @VisibleForTesting private AuditLogWriter auditLogWriter;
+
+ public void init(Map<String, String> properties, EventListenerManager eventBusManager) {
+ AuditLogConfig auditLogConfig = new AuditLogConfig(properties);
+ if (!auditLogConfig.isAuditEnabled()) {
+ LOG.warn("Audit log is not enabled");
+ return;
+ }
+
+ String writerClassName = auditLogConfig.getWriterClassName();
+ String formatterClassName = auditLogConfig.getAuditLogFormatterClassName();
+ Formatter formatter = loadFormatter(formatterClassName);
+ LOG.info("Audit log writer class name {}", writerClassName);
+ if (StringUtils.isEmpty(writerClassName)) {
Review Comment:
No need to check it again, it has been checked in ` auditLogConfig.getWriterClassName`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1772967649
##########
core/src/test/java/org/apache/gravitino/audit/DummyAuditFormatter.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.collect.Maps;
+import java.util.Map;
+import org.apache.gravitino.listener.api.event.Event;
+
+public class DummyAuditFormatter implements Formatter {
+ @Override
+ public Object format(Event event) {
Review Comment:
Does it support returning a more concrete object like `Map` here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1724910883
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogManager.java:
##########
@@ -0,0 +1,90 @@
+package org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.listener.EventListenerManager;
+import org.apache.gravitino.listener.api.EventListenerPlugin;
+import org.apache.gravitino.listener.api.event.Event;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditLogManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuditLogManager.class);
+
+ @VisibleForTesting private AuditLogWriter auditLogWriter;
+
+ public void init(Map<String, String> properties, EventListenerManager eventBusManager) {
+ LOG.info("Audit log properties {}", properties);
+ AuditLogConfig auditLogConfig = new AuditLogConfig(properties);
+ if (!auditLogConfig.isAuditEnabled()) {
+ LOG.warn("Audit log is not enabled");
+ return;
+ }
+
+ LOG.info("Audit log config {}", auditLogConfig);
+ String writerClassName = auditLogConfig.getWriterClassName();
+ String formatterClassName = auditLogConfig.getAuditLogFormatterClassName();
+ Formatter formatter = loadFormatter(formatterClassName);
+ LOG.info("Audit log writer class name {}", writerClassName);
+ if (StringUtils.isEmpty(writerClassName)) {
+ throw new GravitinoRuntimeException("Audit log writer class is not configured");
+ }
+
+ auditLogWriter =
+ loadAuditLogWriter(
+ writerClassName, auditLogConfig.getWriterProperties(properties), formatter);
+
+ eventBusManager.addEventListener(
+ "audit-log",
+ new EventListenerPlugin() {
+
+ @Override
+ public void init(Map<String, String> properties) throws RuntimeException {}
+
+ @Override
+ public void start() throws RuntimeException {}
+
+ @Override
+ public void stop() throws RuntimeException {
+ auditLogWriter.close();
+ }
+
+ @Override
+ public void onPostEvent(Event event) throws RuntimeException {
+ try {
+ auditLogWriter.write(event);
+ } catch (Exception e) {
+ throw new GravitinoRuntimeException(e, "Failed to write audit log");
Review Comment:
it's critical to throw an exception here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1776572132
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogWriter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.listener.api.event.Event;
+
+/** Interface for writing the audit log. */
+public interface AuditLogWriter {
Review Comment:
I'm fine with your idea, I think it is not a block issue. What I feel in the code is that it loses the type information for formatter in the code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1797544622
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogWriter.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.listener.api.event.Event;
+
+/**
+ * Interface for writing the audit log, which can write to different storage, such as file,
+ * database,mq.
+ */
+public interface AuditLogWriter {
Review Comment:
You can define this as `public interface AuditLogWriter extends Closeable` to avoid adding `close` interface.
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogWriter.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.listener.api.event.Event;
+
+/**
+ * Interface for writing the audit log, which can write to different storage, such as file,
+ * database,mq.
+ */
+public interface AuditLogWriter {
+
+ /** @return formatter. */
+ Formatter getFormatter();
+
+ /**
+ * Initialize the writer with the given configuration.
+ *
+ * @param properties
+ */
+ void init(Formatter formatter, Map<String, String> properties);
Review Comment:
We can have properties for different writer, so my suggestion is that we can do one more interface to represent writer name like:
```
String name();
```
For example file writer can be "file". Then this specific writer related configurations can be "gravitino.audit.writer.file.xxx", what do you think?
##########
core/src/main/java/org/apache/gravitino/audit/DefaultAuditLog.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import lombok.Builder;
+import lombok.SneakyThrows;
+import org.apache.gravitino.json.JsonUtils;
+
+/** The default implementation of the audit log. */
+@Builder
+public class DefaultAuditLog implements AuditLog {
+
+ private String user;
+
+ private Operation operation;
+
+ private String identifier;
+
+ private long timestamp;
+
+ private boolean successful;
+
+ @Override
+ public String user() {
+ return user;
+ }
+
+ @Override
+ public Operation operation() {
+ return operation;
+ }
+
+ @Override
+ public String identifier() {
+ return identifier;
+ }
+
+ @Override
+ public long timestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public boolean successful() {
+ return successful;
+ }
Review Comment:
I think it is better to define an enum to represent `SUCCESS` or `FAILURE`, also output the string not the boolean value, what do you think?
Besides, instead of using JSON format for output, is it better to follow like web log format like Nginx and others, which is a standard format, what do you think?
##########
core/src/main/java/org/apache/gravitino/audit/AuditLog.java:
##########
@@ -0,0 +1,294 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import org.apache.gravitino.listener.api.event.AlterCatalogEvent;
+import org.apache.gravitino.listener.api.event.AlterCatalogFailureEvent;
+import org.apache.gravitino.listener.api.event.AlterFilesetEvent;
+import org.apache.gravitino.listener.api.event.AlterFilesetFailureEvent;
+import org.apache.gravitino.listener.api.event.AlterMetalakeEvent;
+import org.apache.gravitino.listener.api.event.AlterMetalakeFailureEvent;
+import org.apache.gravitino.listener.api.event.AlterSchemaEvent;
+import org.apache.gravitino.listener.api.event.AlterSchemaFailureEvent;
+import org.apache.gravitino.listener.api.event.AlterTableEvent;
+import org.apache.gravitino.listener.api.event.AlterTableFailureEvent;
+import org.apache.gravitino.listener.api.event.AlterTopicEvent;
+import org.apache.gravitino.listener.api.event.AlterTopicFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateCatalogEvent;
+import org.apache.gravitino.listener.api.event.CreateCatalogFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateFilesetEvent;
+import org.apache.gravitino.listener.api.event.CreateFilesetFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateMetalakeEvent;
+import org.apache.gravitino.listener.api.event.CreateMetalakeFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateSchemaEvent;
+import org.apache.gravitino.listener.api.event.CreateSchemaFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateTableEvent;
+import org.apache.gravitino.listener.api.event.CreateTableFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateTopicEvent;
+import org.apache.gravitino.listener.api.event.CreateTopicFailureEvent;
+import org.apache.gravitino.listener.api.event.DropCatalogEvent;
+import org.apache.gravitino.listener.api.event.DropCatalogFailureEvent;
+import org.apache.gravitino.listener.api.event.DropFilesetEvent;
+import org.apache.gravitino.listener.api.event.DropFilesetFailureEvent;
+import org.apache.gravitino.listener.api.event.DropMetalakeEvent;
+import org.apache.gravitino.listener.api.event.DropMetalakeFailureEvent;
+import org.apache.gravitino.listener.api.event.DropSchemaEvent;
+import org.apache.gravitino.listener.api.event.DropSchemaFailureEvent;
+import org.apache.gravitino.listener.api.event.DropTableEvent;
+import org.apache.gravitino.listener.api.event.DropTableFailureEvent;
+import org.apache.gravitino.listener.api.event.DropTopicEvent;
+import org.apache.gravitino.listener.api.event.DropTopicFailureEvent;
+import org.apache.gravitino.listener.api.event.Event;
+import org.apache.gravitino.listener.api.event.GetFileLocationEvent;
+import org.apache.gravitino.listener.api.event.GetFileLocationFailureEvent;
+import org.apache.gravitino.listener.api.event.GetPartitionEvent;
+import org.apache.gravitino.listener.api.event.GetPartitionFailureEvent;
+import org.apache.gravitino.listener.api.event.ListCatalogEvent;
+import org.apache.gravitino.listener.api.event.ListCatalogFailureEvent;
+import org.apache.gravitino.listener.api.event.ListFilesetEvent;
+import org.apache.gravitino.listener.api.event.ListFilesetFailureEvent;
+import org.apache.gravitino.listener.api.event.ListMetalakeEvent;
+import org.apache.gravitino.listener.api.event.ListMetalakeFailureEvent;
+import org.apache.gravitino.listener.api.event.ListPartitionEvent;
+import org.apache.gravitino.listener.api.event.ListPartitionFailureEvent;
+import org.apache.gravitino.listener.api.event.ListSchemaEvent;
+import org.apache.gravitino.listener.api.event.ListSchemaFailureEvent;
+import org.apache.gravitino.listener.api.event.ListTableEvent;
+import org.apache.gravitino.listener.api.event.ListTableFailureEvent;
+import org.apache.gravitino.listener.api.event.ListTopicEvent;
+import org.apache.gravitino.listener.api.event.ListTopicFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadCatalogEvent;
+import org.apache.gravitino.listener.api.event.LoadCatalogFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadFilesetEvent;
+import org.apache.gravitino.listener.api.event.LoadFilesetFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadMetalakeEvent;
+import org.apache.gravitino.listener.api.event.LoadMetalakeFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadSchemaEvent;
+import org.apache.gravitino.listener.api.event.LoadSchemaFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadTableEvent;
+import org.apache.gravitino.listener.api.event.LoadTableFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadTopicEvent;
+import org.apache.gravitino.listener.api.event.LoadTopicFailureEvent;
+import org.apache.gravitino.listener.api.event.PartitionExistsEvent;
+import org.apache.gravitino.listener.api.event.PartitionExistsFailureEvent;
+import org.apache.gravitino.listener.api.event.PurgePartitionEvent;
+import org.apache.gravitino.listener.api.event.PurgePartitionFailureEvent;
+import org.apache.gravitino.listener.api.event.PurgeTableEvent;
+import org.apache.gravitino.listener.api.event.PurgeTableFailureEvent;
+
+/** The interface define unified audit log schema. */
+public interface AuditLog {
Review Comment:
The name `AuditInfo` is duplicated with the one we already define in Gravitino, I'm fine to use `AuditLog` to differentiate.
##########
core/src/main/java/org/apache/gravitino/Configs.java:
##########
@@ -342,4 +342,39 @@ private Configs() {}
.stringConf()
.toSequence()
.createWithDefault(Collections.emptyList());
+
+ public static final String AUDIT_LOG_WRITER_CONFIG_PREFIX = "gravitino.audit.writer.";
+
+ public static final String AUDIT_LOG_FILE_WRITER_DEFAULT_FILE_NAME =
+ "default_gravitino_audit_log";
+
+ public static final ConfigEntry<Boolean> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder("gravitino.audit.enable")
+ .doc("Gravitino audit log enable flag")
+ .version(ConfigConstants.VERSION_0_7_0)
+ .booleanConf()
+ .createWithDefault(false);
+
+ public static final ConfigEntry<String> AUDIT_LOG_WRITER_CLASS_NAME =
+ new ConfigBuilder("gravitino.audit.writer.")
+ .doc("Gravitino audit log writer class name")
+ .version(ConfigConstants.VERSION_0_7_0)
+ .stringConf()
+ .checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)
+ .createWithDefault("org.apache.gravitino.audit.DefaultFileAuditWriter");
+
+ public static final ConfigEntry<String> AUDIT_LOG_FORMATTER_CLASS_NAME =
+ new ConfigBuilder("gravitino.audit.writer.class")
+ .doc("Gravitino event log formatter class name")
+ .version(ConfigConstants.VERSION_0_7_0)
+ .stringConf()
+ .checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)
+ .createWithDefault("org.apache.gravitino.audit.DefaultFormatter");
+
+ public static final ConfigEntry<Boolean> AUDIT_LOG_FILE_WRITER_IMMEDIATE_FLUSH =
+ new ConfigBuilder("gravitino.audit.writer.immediateFlush")
Review Comment:
Seems like this configuration is only for default file audit log writer, right?
##########
core/src/main/java/org/apache/gravitino/audit/DefaultFileAuditWriter.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class DefaultFileAuditWriter implements AuditLogWriter {
Review Comment:
It is not good to use the name like `DefaultXXX`, you can directly use the name like `FileAuditWriter`, `StringFormatter`, etc.
##########
core/src/main/java/org/apache/gravitino/audit/AuditLog.java:
##########
@@ -0,0 +1,294 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import org.apache.gravitino.listener.api.event.AlterCatalogEvent;
+import org.apache.gravitino.listener.api.event.AlterCatalogFailureEvent;
+import org.apache.gravitino.listener.api.event.AlterFilesetEvent;
+import org.apache.gravitino.listener.api.event.AlterFilesetFailureEvent;
+import org.apache.gravitino.listener.api.event.AlterMetalakeEvent;
+import org.apache.gravitino.listener.api.event.AlterMetalakeFailureEvent;
+import org.apache.gravitino.listener.api.event.AlterSchemaEvent;
+import org.apache.gravitino.listener.api.event.AlterSchemaFailureEvent;
+import org.apache.gravitino.listener.api.event.AlterTableEvent;
+import org.apache.gravitino.listener.api.event.AlterTableFailureEvent;
+import org.apache.gravitino.listener.api.event.AlterTopicEvent;
+import org.apache.gravitino.listener.api.event.AlterTopicFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateCatalogEvent;
+import org.apache.gravitino.listener.api.event.CreateCatalogFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateFilesetEvent;
+import org.apache.gravitino.listener.api.event.CreateFilesetFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateMetalakeEvent;
+import org.apache.gravitino.listener.api.event.CreateMetalakeFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateSchemaEvent;
+import org.apache.gravitino.listener.api.event.CreateSchemaFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateTableEvent;
+import org.apache.gravitino.listener.api.event.CreateTableFailureEvent;
+import org.apache.gravitino.listener.api.event.CreateTopicEvent;
+import org.apache.gravitino.listener.api.event.CreateTopicFailureEvent;
+import org.apache.gravitino.listener.api.event.DropCatalogEvent;
+import org.apache.gravitino.listener.api.event.DropCatalogFailureEvent;
+import org.apache.gravitino.listener.api.event.DropFilesetEvent;
+import org.apache.gravitino.listener.api.event.DropFilesetFailureEvent;
+import org.apache.gravitino.listener.api.event.DropMetalakeEvent;
+import org.apache.gravitino.listener.api.event.DropMetalakeFailureEvent;
+import org.apache.gravitino.listener.api.event.DropSchemaEvent;
+import org.apache.gravitino.listener.api.event.DropSchemaFailureEvent;
+import org.apache.gravitino.listener.api.event.DropTableEvent;
+import org.apache.gravitino.listener.api.event.DropTableFailureEvent;
+import org.apache.gravitino.listener.api.event.DropTopicEvent;
+import org.apache.gravitino.listener.api.event.DropTopicFailureEvent;
+import org.apache.gravitino.listener.api.event.Event;
+import org.apache.gravitino.listener.api.event.GetFileLocationEvent;
+import org.apache.gravitino.listener.api.event.GetFileLocationFailureEvent;
+import org.apache.gravitino.listener.api.event.GetPartitionEvent;
+import org.apache.gravitino.listener.api.event.GetPartitionFailureEvent;
+import org.apache.gravitino.listener.api.event.ListCatalogEvent;
+import org.apache.gravitino.listener.api.event.ListCatalogFailureEvent;
+import org.apache.gravitino.listener.api.event.ListFilesetEvent;
+import org.apache.gravitino.listener.api.event.ListFilesetFailureEvent;
+import org.apache.gravitino.listener.api.event.ListMetalakeEvent;
+import org.apache.gravitino.listener.api.event.ListMetalakeFailureEvent;
+import org.apache.gravitino.listener.api.event.ListPartitionEvent;
+import org.apache.gravitino.listener.api.event.ListPartitionFailureEvent;
+import org.apache.gravitino.listener.api.event.ListSchemaEvent;
+import org.apache.gravitino.listener.api.event.ListSchemaFailureEvent;
+import org.apache.gravitino.listener.api.event.ListTableEvent;
+import org.apache.gravitino.listener.api.event.ListTableFailureEvent;
+import org.apache.gravitino.listener.api.event.ListTopicEvent;
+import org.apache.gravitino.listener.api.event.ListTopicFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadCatalogEvent;
+import org.apache.gravitino.listener.api.event.LoadCatalogFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadFilesetEvent;
+import org.apache.gravitino.listener.api.event.LoadFilesetFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadMetalakeEvent;
+import org.apache.gravitino.listener.api.event.LoadMetalakeFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadSchemaEvent;
+import org.apache.gravitino.listener.api.event.LoadSchemaFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadTableEvent;
+import org.apache.gravitino.listener.api.event.LoadTableFailureEvent;
+import org.apache.gravitino.listener.api.event.LoadTopicEvent;
+import org.apache.gravitino.listener.api.event.LoadTopicFailureEvent;
+import org.apache.gravitino.listener.api.event.PartitionExistsEvent;
+import org.apache.gravitino.listener.api.event.PartitionExistsFailureEvent;
+import org.apache.gravitino.listener.api.event.PurgePartitionEvent;
+import org.apache.gravitino.listener.api.event.PurgePartitionFailureEvent;
+import org.apache.gravitino.listener.api.event.PurgeTableEvent;
+import org.apache.gravitino.listener.api.event.PurgeTableFailureEvent;
+
+/** The interface define unified audit log schema. */
+public interface AuditLog {
+ /**
+ * The user who do the operation.
+ *
+ * @return user name.
+ */
+ String user();
+
+ /**
+ * The operation name.
+ *
+ * @return operation name.
+ */
+ Operation operation();
+
+ /**
+ * The identifier of the resource.
+ *
+ * @return resource identifier name.
+ */
+ String identifier();
Review Comment:
What is the meaning and definition of `identifier` here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#issuecomment-2408353688
> > @hanwxx , appreciate for your work on audit log, we introduced `AuditLog` in the latest PR, and how about let `event` implement `AuditLog`, and the default formater could return event directly? the Pros is better extensibility if adding new event, no need to change default event formatter. WDYT? cc @jerryshao
> > Thank you very much for reviewing the code, it is very helpful to me.
> > In the comment, i have different idea, evnt is not suitable as the default auditlog.
>
> 1. AuditLog and event responsibilities are different, even though now audit log depend on event listener. Event focus on provide a post hook.Audit logs focus on persistent storage of logs.
> 2. Provided a unified audit log schema is very important, it should be flat,he inheritance relationship of Event is complex.
>
> In our practice, we often need to convert different events into a unified Audit object and finally persist it into a table for easy retrieval. In my design, the conversion action is necessary. The class Formatter is responsible for it.
I kind of agree with @hanwxx , AuditLog and event are two things, we don't have to use interface to put them together. Using a converter to bridge them together without hard combination seems better to me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1773054315
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogConfig.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+import org.apache.gravitino.utils.MapUtils;
+
+public class AuditLogConfig extends Config {
+ public static final String AUDIT_LOG_ENABLED = "enable";
+ static final String AUDIT_LOG_WRITER_PREFIX = "writer.";
+ static final String AUDIT_FORMATTER_PREFIX = "formatter.";
+ static final String AUDIT_LOG_WRITER_CLASS_NAME = AUDIT_LOG_WRITER_PREFIX + "class";
+ static final String AUDIT_LOG_FORMATTER_CLASS_NAME = AUDIT_FORMATTER_PREFIX + "class";
+
+ static final ConfigEntry<Boolean> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder(AUDIT_LOG_ENABLED)
+ .doc("Gravitino audit log enable flag")
Review Comment:
I would suggest to move all the configuration definitions to class `Configs`, it is not necessary to have a separate place to maintain the configurations.
Also, please use the full name to manage the configurations for simplicity, and you can define the `AuditLogManager#init(Config config, xxx)` like this. You don't have to remove the prefix and make things complicated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1772960525
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogWriter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.gravitino.listener.api.event.Event;
+
+/** Interface for writing the audit log. */
+public interface AuditLogWriter {
Review Comment:
The current implementation needs audit writer to extend `AbstractAuditLogWriter`, How about define a default write method in `AuditLogWriter` interface to use formatter to format the event like
```
Formatter<R> getFormatter();
void doWrite(R auditLog);
default void write(Event event) {
doWrite(getFormatter().format(event))
}
```
@jerryshao WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1800987291
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "name";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ fileName = properties.getOrDefault(LOG_FILE_NAME_CONFIG, "default_gravitino_audit_log");
+ immediateFlush =
+ Boolean.parseBoolean(properties.getOrDefault(FILE_IMMEDIATE_FLUSH_CONFIG, "false"));
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(fileName), "FileAuditWriter: fileName is not set in configuration.");
+ try {
+ OutputStream outputStream = new FileOutputStream(fileName, true);
+ outWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
+ } catch (FileNotFoundException e) {
+ throw new GravitinoRuntimeException(
+ String.format("Audit log file: %s is not exists", fileName));
Review Comment:
`is not exists` seems not correct, there may be other reason like permission.
##########
core/src/main/java/org/apache/gravitino/audit/Formatter.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import org.apache.gravitino.listener.api.event.Event;
+
+/** The interface defined the conversions of metadata change event to unified log format. */
+public interface Formatter {
+
+ /**
+ * Format the event, returning the unified audit log format.
+ *
+ * @param event The event to format.
+ * @return The formatted event.
Review Comment:
`@return The formatted event` not correct
##########
core/src/main/java/org/apache/gravitino/audit/SimpleAuditLog.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.text.SimpleDateFormat;
+import lombok.Builder;
+
+/** The default implementation of the audit log. */
+@Builder
+public class SimpleAuditLog implements AuditLog {
+
+ private String user;
+
+ private Operation operation;
+
+ private String identifier;
+
+ private long timestamp;
+
+ private Status status;
+
+ @Override
+ public String user() {
+ return user;
+ }
+
+ @Override
+ public Operation operation() {
+ return operation;
+ }
+
+ @Override
Review Comment:
please add @Nullable anotation.
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "name";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
Review Comment:
How about replacing `immediateFlush` with `flushInterval`? The perfermance is too bad if `immediateFlush` with true, and the flush time is unexpected if `immediateFlush` is false.
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "name";
Review Comment:
name -> fileName?
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "name";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ fileName = properties.getOrDefault(LOG_FILE_NAME_CONFIG, "default_gravitino_audit_log");
+ immediateFlush =
+ Boolean.parseBoolean(properties.getOrDefault(FILE_IMMEDIATE_FLUSH_CONFIG, "false"));
+ Preconditions.checkArgument(
Review Comment:
seems no need to check the filename since there is a default value
##########
core/src/main/java/org/apache/gravitino/audit/SimpleFormatter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Objects;
+import org.apache.gravitino.audit.AuditLog.Status;
+import org.apache.gravitino.listener.api.event.Event;
+import org.apache.gravitino.listener.api.event.FailureEvent;
+
+/** The default implementation of the audit log. */
+public class SimpleFormatter implements Formatter {
+
+ @Override
+ public SimpleAuditLog format(Event event) {
+ Status status = event instanceof FailureEvent ? Status.FAILURE : Status.SUCCESS;
+ return SimpleAuditLog.builder()
+ .user(event.user())
+ .operation(AuditLog.Operation.fromEvent(event))
+ .identifier(
+ event.identifier() != null
Review Comment:
replace with the below code?
```java
Optional.ofNullable(event.identifier()).map(identifier -> identifier.toString()).orElse(null)
```
##########
core/src/main/java/org/apache/gravitino/audit/SimpleFormatter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Objects;
+import org.apache.gravitino.audit.AuditLog.Status;
+import org.apache.gravitino.listener.api.event.Event;
+import org.apache.gravitino.listener.api.event.FailureEvent;
+
+/** The default implementation of the audit log. */
+public class SimpleFormatter implements Formatter {
+
+ @Override
+ public SimpleAuditLog format(Event event) {
+ Status status = event instanceof FailureEvent ? Status.FAILURE : Status.SUCCESS;
+ return SimpleAuditLog.builder()
+ .user(event.user())
+ .operation(AuditLog.Operation.fromEvent(event))
+ .identifier(
+ event.identifier() != null
Review Comment:
or
```
event.identifier() != null ? event.identifier().toString() : null
```
##########
core/src/main/java/org/apache/gravitino/audit/SimpleFormatter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Objects;
+import org.apache.gravitino.audit.AuditLog.Status;
+import org.apache.gravitino.listener.api.event.Event;
+import org.apache.gravitino.listener.api.event.FailureEvent;
+
+/** The default implementation of the audit log. */
Review Comment:
The default formatter implementation of the audit log
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "name";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ fileName = properties.getOrDefault(LOG_FILE_NAME_CONFIG, "default_gravitino_audit_log");
Review Comment:
default_gravitino_audit_log -> gravitino_audit.log ?
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "name";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ fileName = properties.getOrDefault(LOG_FILE_NAME_CONFIG, "default_gravitino_audit_log");
+ immediateFlush =
+ Boolean.parseBoolean(properties.getOrDefault(FILE_IMMEDIATE_FLUSH_CONFIG, "false"));
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(fileName), "FileAuditWriter: fileName is not set in configuration.");
+ try {
+ OutputStream outputStream = new FileOutputStream(fileName, true);
+ outWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
+ } catch (FileNotFoundException e) {
+ throw new GravitinoRuntimeException(
+ String.format("Audit log file: %s is not exists", fileName));
+ }
+ }
+
+ @Override
+ public void doWrite(AuditLog auditLog) {
+ String log = auditLog.toString();
+ try {
+ outWriter.write(log);
+ if (immediateFlush) {
+ outWriter.flush();
+ }
+ } catch (Exception e) {
+ Log.warn("Failed to write audit log: {}", log, e);
+ }
+ }
+
+ @Override
+ public void close() {
+ if (outWriter != null) {
+ try {
+ outWriter.close();
+ } catch (Exception e) {
+ Log.warn("Failed to close writer", e);
+ }
+ }
+ }
+
+ @Override
+ public String name() {
+ return "file";
Review Comment:
`file` is too general, use `fileAuditWriter`?
##########
core/src/main/java/org/apache/gravitino/audit/FileAuditWriter.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DefaultFileAuditWriter is the default implementation of AuditLogWriter, which writes audit logs
+ * to a file.
+ */
+public class FileAuditWriter implements AuditLogWriter {
+ private static final Logger Log = LoggerFactory.getLogger(FileAuditWriter.class);
+
+ public static final String LOG_FILE_NAME_CONFIG = "name";
+
+ public static final String FILE_IMMEDIATE_FLUSH_CONFIG = "immediateFlush";
+
+ private Formatter formatter;
+ private Writer outWriter;
+ @VisibleForTesting String fileName;
+
+ boolean immediateFlush;
+
+ @Override
+ public Formatter getFormatter() {
+ return formatter;
+ }
+
+ @Override
+ public void init(Formatter formatter, Map<String, String> properties) {
+ this.formatter = formatter;
+ fileName = properties.getOrDefault(LOG_FILE_NAME_CONFIG, "default_gravitino_audit_log");
+ immediateFlush =
+ Boolean.parseBoolean(properties.getOrDefault(FILE_IMMEDIATE_FLUSH_CONFIG, "false"));
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(fileName), "FileAuditWriter: fileName is not set in configuration.");
+ try {
+ OutputStream outputStream = new FileOutputStream(fileName, true);
+ outWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
+ } catch (FileNotFoundException e) {
+ throw new GravitinoRuntimeException(
+ String.format("Audit log file: %s is not exists", fileName));
+ }
+ }
+
+ @Override
+ public void doWrite(AuditLog auditLog) {
+ String log = auditLog.toString();
+ try {
+ outWriter.write(log);
Review Comment:
seems we should append `\n` ? please keep compatibility with different systems like windows
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1751416440
##########
core/src/main/java/org/apache/gravitino/audit/AbstractAuditLogWriter.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.gravitino.listener.api.event.Event;
+
+public abstract class AbstractAuditLogWriter implements AuditLogWriter {
+
+ private Formatter formatter;
+
+ public AbstractAuditLogWriter(Formatter formatter) {
+ this.formatter = formatter;
+ }
+
+ public void write(Event event) {
+ Object formatted = this.formatter.format(event);
+ doWrite(formatted);
+ }
+
+ public abstract void doWrite(Object event);
+
+ public abstract void close();
Review Comment:
why make `close` as abstract method here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#3973] improvement(core):support audit log [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4575:
URL: https://github.com/apache/gravitino/pull/4575#discussion_r1773019387
##########
core/src/main/java/org/apache/gravitino/audit/AuditLogConfig.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.audit;
+
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+import org.apache.gravitino.utils.MapUtils;
+
+public class AuditLogConfig extends Config {
+ public static final String AUDIT_LOG_ENABLED = "enable";
+ static final String AUDIT_LOG_WRITER_PREFIX = "writer.";
+ static final String AUDIT_FORMATTER_PREFIX = "formatter.";
+ static final String AUDIT_LOG_WRITER_CLASS_NAME = AUDIT_LOG_WRITER_PREFIX + "class";
+ static final String AUDIT_LOG_FORMATTER_CLASS_NAME = AUDIT_FORMATTER_PREFIX + "class";
+
+ static final ConfigEntry<Boolean> AUDIT_LOG_ENABLED_CONF =
+ new ConfigBuilder(AUDIT_LOG_ENABLED)
+ .doc("Gravitino audit log enable flag")
Review Comment:
What is the configuration name here? I just saw "enabled", is it correct? If it is a configuration, it should be like "gravitino.audit.enabled", something like this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org