Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgsql/logger: open json object from logger fn - v3 #11008

Closed
wants to merge 2 commits into from
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
3 changes: 3 additions & 0 deletions rust/src/pgsql/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std;
pub const PGSQL_LOG_PASSWORDS: u32 = BIT_U32!(0);

fn log_pgsql(tx: &PgsqlTransaction, flags: u32, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.open_object("pgsql")?;
js.set_uint("tx_id", tx.tx_id)?;
if let Some(request) = &tx.request {
js.set_object("request", &log_request(request, flags)?)?;
Expand All @@ -35,12 +36,14 @@ fn log_pgsql(tx: &PgsqlTransaction, flags: u32, js: &mut JsonBuilder) -> Result<
// TODO Log anomaly event instead?
js.set_bool("request", false)?;
js.set_bool("response", false)?;
js.close()?;
return Ok(());
}

if !tx.responses.is_empty() {
js.set_object("response", &log_response_object(tx)?)?;
}
js.close()?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions rust/src/pgsql/pgsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl PgsqlState {
let mut index = 0;
for i in 0..len {
let tx = &self.transactions[i];
if tx.tx_id == tx_id + 1 {
if tx.tx_id == tx_id {
found = true;
index = i;
break;
Expand All @@ -188,7 +188,7 @@ impl PgsqlState {
}

pub fn get_tx(&mut self, tx_id: u64) -> Option<&PgsqlTransaction> {
self.transactions.iter().find(|tx| tx.tx_id == tx_id + 1)
self.transactions.iter().find(|tx| tx.tx_id == tx_id)
}

fn new_tx(&mut self) -> PgsqlTransaction {
Expand Down
2 changes: 0 additions & 2 deletions src/output-json-pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ static int JsonPgsqlLogger(ThreadVars *tv, void *thread_data, const Packet *p, F
return TM_ECODE_FAILED;
}

jb_open_object(jb, "pgsql");
if (!rs_pgsql_logger(txptr, thread->pgsqllog_ctx->flags, jb)) {
goto error;
}
jb_close(jb);

OutputJsonBuilderBuffer(jb, thread->ctx);
jb_free(jb);
Expand Down
Loading