Skip to content

ext/pgsql: pg_trace allow to refine its trace mode via 2 new constants. #11041

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

Closed
wants to merge 2 commits into from

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented Apr 9, 2023

  • PGSQL_TRACE_SUPPRESS_TIMESTAMPS.
  • PGSQL_TRACE_REGRESS_MODE to have a more verbose and observable output to check possible regressions.

PQsetTraceFlags(pgsql, trace_mode);
}
#else
php_error_docref(NULL, E_WARNING, "Trace mode unsupported");
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this should return false or not if the mode is unssuported :/

if (trace_mode > 0) {
#ifdef PQTRACE_REGRESS_MODE
if (trace_mode > (PQTRACE_SUPPRESS_TIMESTAMPS|PQTRACE_REGRESS_MODE)) {
zend_argument_value_error(2, "must be PGSQL_TRACE_SUPPRESS_TIMESTAMPS and/or PGSQL_TRACE_REGRESS_MODE");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
zend_argument_value_error(2, "must be PGSQL_TRACE_SUPPRESS_TIMESTAMPS and/or PGSQL_TRACE_REGRESS_MODE");
zend_argument_value_error(4, "must be PGSQL_TRACE_SUPPRESS_TIMESTAMPS and/or PGSQL_TRACE_REGRESS_MODE");

Maybe add a test which hits this code path? As it would have indicated you were targeting the wrong arg num

@devnexen devnexen force-pushed the pg_trace_upd branch 2 times, most recently from 0705d93 to c957f22 Compare April 9, 2023 16:40
@devnexen devnexen requested a review from kocsismate April 9, 2023 18:29
PQsetTraceFlags(pgsql, trace_mode);
}
#else
zend_argument_value_error(4, "cannot set as trace is unsupported");
Copy link
Member

Choose a reason for hiding this comment

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

@iluuu1994 could I have your opinion on this, is it fine to use a value error, or do you think it should be switched back to an E_WARNING as possibly it can't be known in advance if Postgress supports that mode?

Copy link
Member

Choose a reason for hiding this comment

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

I agree that exceptions should be thrown when errors are unexpected and generally not handled immediately. It's not clear to me whether that's the case here, when you're passing those flags you probably expect the extension to have built with support for it. So an exception doesn't seem wrong at the least.

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact PQsetTraceFlags serving only as formatting the output of the said trace, i did not necessarily want a total failure "just" because of this and let the trace beginning. You may argue then throwing an exception might not be appropriate then.

@devnexen devnexen requested a review from iluuu1994 April 15, 2023 16:15
@@ -2147,6 +2148,17 @@ PHP_FUNCTION(pg_trace)
}
php_stream_auto_cleanup(stream);
PQtrace(pgsql, fp);
if (trace_mode > 0) {
#ifdef PQTRACE_REGRESS_MODE
if (trace_mode > (PQTRACE_SUPPRESS_TIMESTAMPS|PQTRACE_REGRESS_MODE)) {
Copy link
Member

Choose a reason for hiding this comment

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

This test is a bit odd, why not !(trace_mode & (PQTRACE_SUPPRESS_TIMESTAMPS|PQTRACE_REGRESS_MODE))? This would hide unhandled, smaller flags if they didn't start at 0.

Copy link
Member

@iluuu1994 iluuu1994 Apr 20, 2023

Choose a reason for hiding this comment

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

Does this also need a php_stream_close(stream); as above? Edit: This comment was meant to go below, to the zend_argument_value_error.

PQsetTraceFlags(pgsql, trace_mode);
}
#else
zend_argument_value_error(4, "cannot set as trace is unsupported");
Copy link
Member

Choose a reason for hiding this comment

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

I agree that exceptions should be thrown when errors are unexpected and generally not handled immediately. It's not clear to me whether that's the case here, when you're passing those flags you probably expect the extension to have built with support for it. So an exception doesn't seem wrong at the least.

if (trace_mode > 0) {
#ifdef PQTRACE_REGRESS_MODE
if (trace_mode > (PQTRACE_SUPPRESS_TIMESTAMPS|PQTRACE_REGRESS_MODE)) {
zend_argument_value_error(4, "must be PGSQL_TRACE_SUPPRESS_TIMESTAMPS and/or PGSQL_TRACE_REGRESS_MODE");
Copy link
Member

Choose a reason for hiding this comment

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

RETURN_THROWS(); is missing here and below. Doesn't matter for now but could be missed if more things are added to the function.

devnexen added 2 commits May 1, 2023 13:17
- PGSQL_TRACE_SUPPRESS_TIMESTAMPS.
- PGSQL_TRACE_REGRESS_MODE to have a more verbose and observable
output to check possible regressions.
@devnexen devnexen closed this in 7ec8ae1 May 5, 2023
llaville added a commit to llaville/php-compatinfo-db that referenced this pull request Oct 10, 2023
llaville added a commit to llaville/php-compatinfo-db that referenced this pull request Nov 18, 2023
llaville added a commit to llaville/php-compatinfo-db that referenced this pull request Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants