Skip to content

Commit

Permalink
feat: log version and settings on startup (#3601)
Browse files Browse the repository at this point in the history
Add some informative log messages about the client on startup. A similar feature existed in 1x, but got lost in the upgrade 2.0. Will print the artifact name, version and settings for each new connection
  • Loading branch information
igorbernstein2 authored May 3, 2022
1 parent 9a693e8 commit 109023a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ protected String getRequiredValue(String key, String displayName) {
!isNullOrEmpty(value), String.format("%s must be supplied via %s", displayName, key));
return value;
}

public abstract String toDebugString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings;
import com.google.cloud.bigtable.hbase.wrappers.veneer.metrics.MetricsApiTracerAdapterFactory;
import com.google.common.base.Joiner;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -257,6 +258,15 @@ public BigtableInstanceAdminSettings getInstanceAdminSettings() {
return instanceAdminSettings;
}

@Override
public String toDebugString() {
return MoreObjects.toStringHelper(this)
.add("dataSettings", dataSettings)
.add("tableAdminSettings", tableAdminSettings)
.add("instanceAdminSettings", instanceAdminSettings)
.toString();
}

// ************** Private Helpers **************
private BigtableDataSettings buildBigtableDataSettings(ClientOperationTimeouts clientTimeouts)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.api.core.InternalApi;
import com.google.cloud.bigtable.hbase.BigtableBufferedMutator;
import com.google.cloud.bigtable.hbase.BigtableHBaseVersion;
import com.google.cloud.bigtable.hbase.BigtableRegionLocator;
import com.google.cloud.bigtable.hbase.adapters.Adapters;
import com.google.cloud.bigtable.hbase.adapters.HBaseRequestAdapter;
Expand All @@ -30,10 +31,12 @@
import java.io.Closeable;
import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
Expand Down Expand Up @@ -114,11 +117,43 @@ protected AbstractBigtableConnection(
throw ioe;
}

logStartup(LOG, conf, settings);

this.batchPool = pool;
this.closed = false;
this.bigtableApi = BigtableApi.create(settings);
}

private static final AtomicBoolean firstConnection = new AtomicBoolean();

private void logStartup(Logger logger, Configuration userConfig, BigtableHBaseSettings settings) {
if (firstConnection.compareAndSet(false, true)) {
String jarPath;
try {
jarPath = getClass().getProtectionDomain().getCodeSource().getLocation().toString();
} catch (RuntimeException e) {
jarPath = "<unknown>";
}

logger.info(
"Using bigtable-hbase client from jar %s. Version: %s",
jarPath, BigtableHBaseVersion.getVersion());
}
// Dump user configuration
if (logger.getLog().isDebugEnabled()) {
MoreObjects.ToStringHelper configHelper = MoreObjects.toStringHelper("BigtableConfiguration");

for (Map.Entry<String, String> entry : userConfig) {
if (!entry.getKey().startsWith("google.bigtable")) {
continue;
}
configHelper.add(entry.getKey(), entry.getValue());
}
logger.debug("User Configuration: " + configHelper);
logger.debug("Effective settings: " + settings.toDebugString());
}
}

/** {@inheritDoc} */
@Override
public Configuration getConfiguration() {
Expand Down

0 comments on commit 109023a

Please sign in to comment.