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

sql: fix exec+audit logs for BEGIN, COMMIT, SET stmts #107912

Merged
merged 3 commits into from
Aug 8, 2023

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented Jul 31, 2023

Epic: None
Release note (bug fix): Fixed a bug where BEGIN, COMMIT, SET, ROLLBACK, and SAVEPOINT statements would not be written to the execution or audit logs.

@rafiss rafiss added the backport-23.1.x Flags PRs that need to be backported to 23.1 label Jul 31, 2023
@rafiss rafiss requested a review from a team July 31, 2023 20:41
@blathers-crl
Copy link

blathers-crl bot commented Jul 31, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@j82w j82w left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)


-- commits line 4 at r1:
Does the audit log capture queries that fail from syntax issues?


pkg/sql/conn_executor_exec.go line 755 at r1 (raw file):

	// If adminAuditLogging is enabled, we want to check for HasAdminRole
	// before maybeLogStatement.
	// We must check prior to execution in the case the txn is aborted due to

Is there any way to keep all this logic in the same place or have a flag on the request?


pkg/sql/conn_executor_exec.go line 757 at r1 (raw file):

	// We must check prior to execution in the case the txn is aborted due to
	// an error. HasAdminRole can only be checked in a valid txn.
	if adminAuditLog := adminAuditLogEnabled.Get(

Should the ex.extraTxnState.hasAdminRoleCache.IsSet be checked and skip this logic if it's already set?

Copy link
Collaborator Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @j82w)


-- commits line 4 at r1:

Previously, j82w (Jake) wrote…

Does the audit log capture queries that fail from syntax issues?

i don't believe it does, but if we want it to, i think that should be handled as a separate issue, since it sounds more like a feature request


pkg/sql/conn_executor_exec.go line 755 at r1 (raw file):

Previously, j82w (Jake) wrote…

Is there any way to keep all this logic in the same place or have a flag on the request?

just to clarify, which logic do you refer to? and same place as what other logic?


pkg/sql/conn_executor_exec.go line 757 at r1 (raw file):

Previously, j82w (Jake) wrote…

Should the ex.extraTxnState.hasAdminRoleCache.IsSet be checked and skip this logic if it's already set?

the code is already doing that (3 lines below this one)

Copy link
Collaborator Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @j82w)


-- commits line 4 at r1:

Previously, rafiss (Rafi Shamim) wrote…

i don't believe it does, but if we want it to, i think that should be handled as a separate issue, since it sounds more like a feature request

we do log all syntax errors in the exec log though:

log.SqlExec.Infof(ctx, "could not parse simple query: %s", query)

https://github.com/cockroachdb/cockroach/blob/dc28e1932b9b01907203374005d450cfda2a562a/pkg/sql/pgwire/conn.go#L485C6-L485C6

Copy link
Contributor

@j82w j82w left a comment

Choose a reason for hiding this comment

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

Please add a test. Other than that it LGTM.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

@rafiss rafiss requested a review from a team as a code owner August 4, 2023 19:13
@rafiss rafiss requested a review from cucaroach August 4, 2023 19:13
@rafiss rafiss force-pushed the fix-stmt-logs branch 2 times, most recently from de1dad2 to ae2a391 Compare August 8, 2023 04:43
rafiss added 3 commits August 8, 2023 12:56
Release note (bug fix): Fixed a bug where BEGIN, COMMIT, SET, ROLLBACK,
and SAVEPOINT statements would not be written to the execution or audit
logs.
There was no need for this to live in the sessioninit cache. It just
caused an extra dependency.

Release note: None
We don't need this field, since it's only used in one conditional, and
that check can be replaced by a direct check of the txn associated with
the planner.

Release note: None
@rafiss
Copy link
Collaborator Author

rafiss commented Aug 8, 2023

tftr!

bors r=j82w

@craig
Copy link
Contributor

craig bot commented Aug 8, 2023

Timed out.

@rafiss
Copy link
Collaborator Author

rafiss commented Aug 8, 2023

bors r+

@craig craig bot merged commit 0d110cd into cockroachdb:master Aug 8, 2023
@craig
Copy link
Contributor

craig bot commented Aug 8, 2023

Build succeeded:

@blathers-crl
Copy link

blathers-crl bot commented Aug 8, 2023

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 4a3e787 to blathers/backport-release-23.1-107912: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants