Repository navigation
perf(bigquery-jdbc): short-circuit disabled connection logs at Gate 1 #15114
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -75,12 +75,7 @@ public static BigQueryJdbcResultSetLogger getLogger(Class<?> clazz, String conne | |||||
| if (connectionId == null || connectionId.isEmpty()) { | ||||||
| return getLogger(clazz, (ConnectionLogContext) null); | ||||||
| } | ||||||
| ConnectionLogContext active = BigQueryJdbcRootLogger.findActiveContext(connectionId); | ||||||
| ConnectionLogContext context = | ||||||
| active != null | ||||||
| ? active | ||||||
| : new ConnectionLogContext(connectionId, ConnectionLogContext.ALL_VALUE); | ||||||
| return getLogger(clazz, context); | ||||||
| return getLogger(clazz, BigQueryJdbcRootLogger.resolveContext(connectionId)); | ||||||
| } | ||||||
|
|
||||||
| static BigQueryJdbcResultSetLogger getLogger( | ||||||
|
|
@@ -105,7 +100,12 @@ BigQueryJdbcCustomLogger delegate() { | |||||
| } | ||||||
|
|
||||||
| public boolean isLoggable(Level level) { | ||||||
| return delegate.isLoggable(level); | ||||||
| if (level == null) { | ||||||
| return false; | ||||||
| } | ||||||
| ConnectionLogContext ctx = | ||||||
| connectionContext != null ? connectionContext : BigQueryJdbcMdc.getContext(); | ||||||
| return delegate.isLoggableForContext(level, ctx); | ||||||
| } | ||||||
|
|
||||||
| public BigQueryJdbcResultSetLogger getArrowStructLogger() { | ||||||
|
|
@@ -143,6 +143,9 @@ public BigQueryJdbcResultSetLogger getJsonArrayLogger() { | |||||
| * BigQueryJdbcCustomLogger.BigQueryJdbcLogRecord} to infer them lazily. | ||||||
| */ | ||||||
| public void log(LogRecord record) { | ||||||
| if (record == null || !isLoggable(record.getLevel())) { | ||||||
| return; | ||||||
| } | ||||||
| if (connectionContext != null) { | ||||||
| Object[] existingParams = record.getParameters(); | ||||||
| if (existingParams == null || existingParams.length == 0) { | ||||||
|
|
@@ -153,12 +156,20 @@ public void log(LogRecord record) { | |||||
| System.arraycopy(existingParams, 0, newParams, 1, existingParams.length); | ||||||
| record.setParameters(newParams); | ||||||
| } | ||||||
| ConnectionLogContext threadContext = BigQueryJdbcMdc.getContext(); | ||||||
| if (threadContext != null && threadContext != connectionContext) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When We should simplify the condition to
Suggested change
|
||||||
| try (BigQueryJdbcMdc.MdcCloseable ignored = | ||||||
| BigQueryJdbcMdc.registerContext(connectionContext)) { | ||||||
| delegate.log(record); | ||||||
| } | ||||||
| return; | ||||||
| } | ||||||
| } | ||||||
| delegate.log(record); | ||||||
| } | ||||||
|
|
||||||
| private void logTrace(Level level, String methodName, String msg) { | ||||||
| if (!delegate.isLoggable(level)) { | ||||||
| if (!isLoggable(level)) { | ||||||
| return; | ||||||
| } | ||||||
| LogRecord record = new LogRecord(level, msg); | ||||||
|
|
@@ -168,15 +179,18 @@ private void logTrace(Level level, String methodName, String msg) { | |||||
| } | ||||||
|
|
||||||
| private void logTrace(Level level, String methodName, Supplier<String> msgSupplier) { | ||||||
| if (!delegate.isLoggable(level)) { | ||||||
| if (!isLoggable(level)) { | ||||||
| return; | ||||||
| } | ||||||
| logTrace(level, methodName, msgSupplier.get()); | ||||||
| LogRecord record = new LogRecord(level, msgSupplier.get()); | ||||||
| record.setSourceClassName(targetClassName); | ||||||
| record.setSourceMethodName(methodName); | ||||||
| log(record); | ||||||
| } | ||||||
|
|
||||||
| /** Cold path: builds a record whose caller is inferred lazily by the formatter. */ | ||||||
| private void logWithCaller(Level level, Throwable thrown, String msg) { | ||||||
| if (!delegate.isLoggable(level)) { | ||||||
| if (!isLoggable(level)) { | ||||||
| return; | ||||||
| } | ||||||
| LogRecord record = new BigQueryJdbcCustomLogger.BigQueryJdbcLogRecord(level, msg); | ||||||
|
|
@@ -244,7 +258,7 @@ public void fine(Supplier<String> msgSupplier) { | |||||
| } | ||||||
|
|
||||||
| public void warning(String format, Object... args) { | ||||||
| if (!delegate.isLoggable(Level.WARNING)) { | ||||||
| if (!isLoggable(Level.WARNING)) { | ||||||
| return; | ||||||
| } | ||||||
| String message = (args == null || args.length == 0) ? format : String.format(format, args); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the call to use the renamed getter method
getExplicitGlobalLevelValue()to maintain consistency and improve readability.