Repository navigation
fix(bigquery-jdbc): migrate direct Cloud Logging export to GAPIC LoggingClient - #15346
keshavdandeva wants to merge 4 commits into
Conversation
… BigQueryConnection
There was a problem hiding this comment.
Code Review
This pull request replaces the standard Google Cloud Logging client with a custom GcpLogWriter backed by the GAPIC LoggingClient to coordinate concurrent log writes with connection teardown and enforce a bounded flush on close. Feedback on the changes highlights a potential NullPointerException in GcpLogWriter.java if connectionId is null, as protobuf maps do not accept null values; a guard should be added to only include the label when it is non-null.
| LogEntry.Builder entryBuilder = | ||
| LogEntry.newBuilder() | ||
| .setLogName(LogName.ofProjectLogName(projectId, logId).toString()) | ||
| .setResource(resource) | ||
| .setSeverity(severity) | ||
| .setTimestamp( | ||
| Timestamp.newBuilder() | ||
| .setSeconds(timestamp.getEpochSecond()) | ||
| .setNanos(timestamp.getNano()) | ||
| .build()) | ||
| .setTextPayload(message) | ||
| .putLabels(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY, connectionId); |
There was a problem hiding this comment.
If connectionId is null (which can happen if a log is published from a thread without an active connection context), calling putLabels with a null value will throw a NullPointerException because protobuf map values cannot be null.
We should guard the putLabels call to only add the connection ID label if it is non-null.
LogEntry.Builder entryBuilder =
LogEntry.newBuilder()
.setLogName(LogName.ofProjectLogName(projectId, logId).toString())
.setResource(resource)
.setSeverity(severity)
.setTimestamp(
Timestamp.newBuilder()
.setSeconds(timestamp.getEpochSecond())
.setNanos(timestamp.getNano())
.build())
.setTextPayload(message);
if (connectionId != null) {
entryBuilder.putLabels(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY, connectionId);
}
Summary
Replaces the legacy
com.google.cloud.logging.Logging/LoggingOptionsclient inside the driver with a package-privateGcpLogWriterbacked by the generated GAPICcom.google.cloud.logging.v2.LoggingClientso direct Cloud Logging export honorsuniverseDomain,ProxyHost/ProxyPort/ProxyUid/ProxyPwd,SSLTrustStore*, andEndpointOverrides(OAUTH2).Key Decisions
LoggingClientover legacyLoggingOptions:LoggingOptionsdoes not accept a gRPCTransportChannelProviderwithout a customLoggingRpcadapter. Using the generated GAPICLoggingClient(already ingoogle-cloud-logging) acceptsBigQueryJdbcProxyUtility'sTransportChannelProvider,universeDomain,HeaderProvider, and write-scoped credentials natively with zeropom.xmlchanges.LimitExceededBehavior.Block), aThreadLocalre-entrancy guard, and aReentrantReadWriteLockbetweenwrite()andclose().close()waits up to 6s for in-flight writes and escalates tologgingClient.shutdownNow()on timeout or interrupt so stalled endpoints do not hang connection close.MonitoredResourcedetection: CallsMonitoredResourceUtil.getResource(projectId, null)behind a per-project cache inGcpLogWriterto preserve GKE/GCE/Cloud Run resource association while avoiding repeated 5s metadata-server probes on every connection (working aroundMonitoredResourceUtil's cache miss onnullresource type).WARNINGand logs a single dropped-write count onclose()to avoid log storms while preserving visibility into export errors.Behavior Changes
enableGcpLogExporter=true: Direct Cloud Logging now uses the connection's gRPCTransportChannelProvider(includingProxyUid/ProxyPwdandSSLTrustStore*),universeDomain, and credential HTTP transport/overrides.traceis now formatted asprojects/<projectId>/traces/<traceId>(instead of the raw trace ID string), and the legacyLoggingImplDEBUGsourceLocationauto-population is no longer attached.LoggingImpl's per-failurestderrprints with oneWARNINGon first failure plus a dropped-write summary onclose().gcpTelemetryProjectId/ProjectId,ServiceAccountCredentials.getProjectId(),ServiceOptions.getDefaultProjectId(), throwingBigQueryJdbcRuntimeExceptionif none is available.BigQueryJdbcOpenTelemetry.createLoggingClient(...)with package-privateGcpLogWriter.create(...).