Skip to content
Open
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
172 changes: 172 additions & 0 deletions auditlog_clickhouse_write/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
=============================
Store Audit Log in Clickhouse
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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_write
: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_write
: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 audit of 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.

**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.

..

ClickHouse installation (Docker guide):
``https://clickhouse.com/docs/install/docker``

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.

Usage
=====

Once auditlog_clickhouse_write 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.

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_write%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

Contributors
------------

- `Cetmix <https://cetmix.com/>`__

- Ivan Sokolov
- George Smirnov
- Dmitry Meita

Other credits
-------------

The development of this module has been financially supported by:

- Geschäftsstelle Sozialinfo

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_write>`_ 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_write/__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_write/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Store Audit Log in Clickhouse",
"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_write/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_write_enqueue_flush" model="ir.cron">
<field name="name">Auditlog ClickHouse Write: 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_write_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_write.ir_cron_auditlog_clickhouse_write_enqueue_flush"
/>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>
Loading
Loading