Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions auditlog_clickhouse/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
===================================
Audit Log ClickHouse store and read
===================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:11aaa38bad24a890554c0d34d74d31e13b933facbba3fea31f4cbf22ae8fd842
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/18.0/auditlog_clickhouse
:alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-auditlog_clickhouse
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module implements buffered asynchronous transfers of audit logs
from PostgreSQL to ClickHouse. Storing audit data in a columnar database
that is write-only prevents database bloat, makes audit records
effectively immutable, and allows for scaling to very large volumes of
logs without slowing down normal transactions. Audit logs are written
asynchronously to reduce the load on business operations. Audit logs
stored in ClickHouse are displayed in standard Odoo audit log views
(logs, log lines, forms with detailed log information) without any
changes to existing view definitions.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

The auditlog module stores audit data in PostgreSQL. In production
systems with extensive audit rules, these tables grow without limits,
causing three issues:

- Database bloat;
- Immutability gap: Members of group_auditlog_manager (implied by
base.group_system) have full CRUD access to audit tables, allowing
audit records to be altered or deleted via UI, ORM, or SQL;
- Performance overhead: Audit logging runs synchronously in the same
transaction and performs multiple ORM create() calls, adding latency
to audited operations.

Configuration
=============

This module requires:

- A reachable ClickHouse server.
- Python dependency ``clickhouse-driver`` available in the Odoo
environment.
- A ClickHouse database created in advance (the module does **not**
create databases/users/grants).
- A ClickHouse user with at least:

- ``INSERT`` and ``CREATE TABLE`` privileges on the target database.

- The ``pg_clickhouse`` extension installed on the PostgreSQL server.

Steps:

- Make sure ``clickhouse-driver`` is available in your system.
- Install the module.
- Configure the connection parameters in Odoo:

- **Settings > Technical > Auditlog > Clickhouse configuration**
- Fill in the following parameters:

+---------------------------------------+
| Field |
+=======================================+
| Hostname or IP |
+---------------------------------------+
| TCP port |
+---------------------------------------+
| ClickHouse database name |
+---------------------------------------+
| ClickHouse user |
+---------------------------------------+
| ClickHouse Password |
+---------------------------------------+
| queue_job_batch_size (default = 1000) |
+---------------------------------------+
| channel_id (default root) |
+---------------------------------------+

- Click **Test connection**.
- Optionally, click **Create Auditlog Tables** to create the tables in
the target database.
- Click **Setup FDW read** to configure the Foreign Data Wrapper so that
standard Odoo audit log views read data directly from ClickHouse.

Usage
=====

Once auditlog_clickhouse is installed and configured:

- Users perform tracked operations (create, write, unlink, read, export)
on models with active auditlog.rule subscriptions. This behavior is
unchanged from the base auditlog module.
- Log data is serialized and stored in the local auditlog.log.buffer
table instantly. The standard auditlog tables are not populated.
- Every 5 minutes (default), the Cron job runs, pushes data to
ClickHouse, and cleans the local buffer.
- Data is permanently stored in ClickHouse and cannot be modified or
deleted via Odoo.

All standard Odoo audit log views work as expected - logs, log lines,
and forms with detailed log data display data from ClickHouse. Search,
filtering, and grouping (by user, model, date, session, query) work
through FDW with the query being forwarded to ClickHouse. The “View
logs” quick access button in audited model forms works as expected.
Audit logs are read-only. Attempting to modify or delete a log entry
from the user interface raises an error.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20auditlog_clickhouse%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Cetmix

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/18.0/auditlog_clickhouse>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions auditlog_clickhouse/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions auditlog_clickhouse/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Audit Log ClickHouse store and read",
"version": "18.0.1.0.0",
"summary": "Asynchronous audit log storage in ClickHouse",
"category": "Tools",
"license": "AGPL-3",
"author": "Odoo Community Association (OCA), Cetmix",
"website": "https://github.com/OCA/server-tools",
"depends": [
"auditlog",
"queue_job",
],
"external_dependencies": {
"python": ["clickhouse-driver"],
},
"data": [
"security/ir.model.access.csv",
"data/auditlog_clickhouse_queue.xml",
"views/auditlog_clickhouse_config_views.xml",
],
}
27 changes: 27 additions & 0 deletions auditlog_clickhouse/data/auditlog_clickhouse_queue.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<odoo noupdate="1">
<record id="ir_cron_auditlog_clickhouse_enqueue_flush" model="ir.cron">
<field name="name">Auditlog ClickHouse: enqueue buffer flush</field>
<field name="model_id" ref="model_auditlog_log_buffer" />
<field name="state">code</field>
<field name="code">model._cron_flush_to_clickhouse()</field>
<field name="interval_number">5</field>
<field name="interval_type">minutes</field>
<field name="active">True</field>
<field name="user_id" ref="base.user_root" />
</record>

<record
id="action_configure_auditlog_clickhouse_cron"
model="ir.actions.act_window"
>
<field name="name">Edit buffer flush schedule</field>
<field name="res_model">ir.cron</field>
<field
name="res_id"
ref="auditlog_clickhouse.ir_cron_auditlog_clickhouse_enqueue_flush"
/>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>
Loading