Skip to content

feat(db): add postgres audit helpers#231

Open
pjb157 wants to merge 1 commit into
mainfrom
imparando/69eaab5e-a36f-4c43-aaa7-8adb2adb8310
Open

feat(db): add postgres audit helpers#231
pjb157 wants to merge 1 commit into
mainfrom
imparando/69eaab5e-a36f-4c43-aaa7-8adb2adb8310

Conversation

@pjb157
Copy link
Copy Markdown
Contributor

@pjb157 pjb157 commented Apr 21, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 21, 2026 14:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a small, Postgres-feature-gated “audit” module to the crate to help standardize Postgres connection application naming and to log whether pgAudit-related settings appear to be enabled.

Changes:

  • Introduces src/audit.rs with helpers to set application_name and to log pgAudit / connection logging configuration detected via SQL.
  • Exposes the new module and re-exports its public helpers from src/lib.rs behind the postgres feature.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/lib.rs Feature-gated module + re-exports for new Postgres audit helpers.
src/audit.rs New helpers for setting Postgres application_name and auditing/logging pgAudit-related settings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/audit.rs
Comment on lines +10 to +42
let database_name: String = match sqlx::query_scalar("SELECT current_database()")
.fetch_one(pool)
.await
{
Ok(name) => name,
Err(error) => {
tracing::warn!(error = %error, "Failed to inspect PostgreSQL audit settings");
return;
}
};

let extension_installed: bool = match sqlx::query_scalar(
"SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pgaudit')",
)
.fetch_one(pool)
.await
{
Ok(installed) => installed,
Err(error) => {
tracing::warn!(
database = %database_name,
error = %error,
"Failed to check whether pgAudit is installed"
);
return;
}
};

let shared_preload_libraries: Option<String> =
match sqlx::query_scalar("SELECT current_setting('shared_preload_libraries', true)")
.fetch_one(pool)
.await
{
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

log_postgres_audit_status performs multiple round trips to the database sequentially (current_database, pg_extension check, and four current_setting reads). This increases startup latency and load; consider combining these into a single SELECT (or at least running independent reads concurrently) and then evaluating the results locally.

Copilot uses AI. Check for mistakes.
Comment thread src/audit.rs
use sqlx::{PgPool, postgres::PgConnectOptions};

pub const POSTGRES_APPLICATION_NAME: &str = "fusillade";

Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

with_application_name only has an effect via its return value; if a caller accidentally ignores the returned PgConnectOptions, the application name won't be set and the compiler won't warn. Consider adding #[must_use] to this helper (or changing the signature to take &mut PgConnectOptions and mutate in place) so misuse is caught early.

Suggested change
#[must_use]

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants