xds: Move node id logging out of xds.client

This removes a grpc-ism environment variable. Note that the logger is
still registered under XdsClientImpl. That could maybe change, but it is
a bit unclear what it should become and it seemed better for this to
have no behavior changes.
This commit is contained in:
Eric Anderson 2024-03-05 16:11:45 -08:00
parent 42b2cbdec3
commit 9ee5e9f008
2 changed files with 8 additions and 9 deletions

View File

@ -34,6 +34,8 @@ import io.grpc.xds.internal.security.TlsContextManagerImpl;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
@ -44,6 +46,9 @@ import javax.annotation.concurrent.ThreadSafe;
*/
@ThreadSafe
final class SharedXdsClientPoolProvider implements XdsClientPoolFactory {
private static final boolean LOG_XDS_NODE_ID = Boolean.parseBoolean(
System.getenv("GRPC_LOG_XDS_NODE_ID"));
private static final Logger log = Logger.getLogger(XdsClientImpl.class.getName());
private final Bootstrapper bootstrapper;
private final Object lock = new Object();
@ -123,6 +128,9 @@ final class SharedXdsClientPoolProvider implements XdsClientPoolFactory {
public XdsClient getObject() {
synchronized (lock) {
if (refCount == 0) {
if (LOG_XDS_NODE_ID) {
log.log(Level.INFO, "xDS node ID: {0}", bootstrapInfo.node().getId());
}
scheduler = SharedResourceHolder.get(GrpcUtil.TIMER_SERVICE);
xdsClient = new XdsClientImpl(
DEFAULT_XDS_TRANSPORT_FACTORY,

View File

@ -54,8 +54,6 @@ import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
/**
@ -64,10 +62,6 @@ import javax.annotation.Nullable;
@Internal
public final class XdsClientImpl extends XdsClient implements XdsResponseHandler, ResourceStore {
private static final boolean LOG_XDS_NODE_ID = Boolean.parseBoolean(
System.getenv("GRPC_LOG_XDS_NODE_ID"));
private static final Logger classLogger = Logger.getLogger(XdsClientImpl.class.getName());
// Longest time to wait, since the subscription to some resource, for concluding its absence.
@VisibleForTesting
public static final int INITIAL_RESOURCE_FETCH_TIMEOUT_SEC = 15;
@ -127,9 +121,6 @@ public final class XdsClientImpl extends XdsClient implements XdsResponseHandler
logId = InternalLogId.allocate("xds-client", null);
logger = XdsLogger.withLogId(logId);
logger.log(XdsLogLevel.INFO, "Created");
if (LOG_XDS_NODE_ID) {
classLogger.log(Level.INFO, "xDS node ID: {0}", bootstrapInfo.node().getId());
}
}
@Override