Skip to content

Commit 46d95ca

Browse files
authored
test(logging): Add verbose logging and reroute to test files via maven failsafe plugin (#2295)
test(logging): Add verbose logging and reroute to test files via maven failsafe plugin
1 parent 4888836 commit 46d95ca

File tree

8 files changed

+30
-56
lines changed

8 files changed

+30
-56
lines changed

.kokoro/nightly/integration.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env_vars: {
88

99
env_vars: {
1010
key: "INTEGRATION_TEST_ARGS"
11-
value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
11+
value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it,enable-verbose-grpc-logs -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
1212
}
1313

1414
env_vars: {

.kokoro/presubmit/graalvm-native-17.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env_vars: {
1313

1414
env_vars: {
1515
key: "INTEGRATION_TEST_ARGS"
16-
value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
16+
value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it,enable-verbose-grpc-logs -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
1717
}
1818

1919
# TODO: remove this after we've migrated all tests and scripts

.kokoro/presubmit/graalvm-native.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ env_vars: {
1919

2020
env_vars: {
2121
key: "INTEGRATION_TEST_ARGS"
22-
value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
22+
value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it,enable-verbose-grpc-logs -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
2323
}
2424

2525
env_vars: {

.kokoro/presubmit/integration.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env_vars: {
88

99
env_vars: {
1010
key: "INTEGRATION_TEST_ARGS"
11-
value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
11+
value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it,enable-verbose-grpc-logs -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
1212
}
1313

1414
env_vars: {

google-cloud-bigtable/pom.xml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
<skipTests>false</skipTests>
2626
<skipUnitTests>${skipTests}</skipUnitTests>
2727
<skipITs>${skipTests}</skipITs>
28-
28+
<!-- Configure test logging output. By default tests print info logs to stdout/err.
29+
However for kokoro runs to enable better debugging of connection failures,
30+
the `enable-verbose-grpc-logs` profile is enabled.
31+
It will enable verbose logs and redirect output to a test specific file in the integration tests report directory.
32+
These propeties should only be set by the `enable-verbose-grpc-logs` profile -->
33+
<java-log-config>src/test/resources/logging.properties</java-log-config>
2934
<!-- Use client defined default endpoints -->
3035
<!-- Can be overriden on the commandline via `-Dbigtable.cfe-data-endpoint=bigtableadmin.googleapis.com:443` -->
3136
<bigtable.cfe-data-endpoint/>
@@ -335,13 +340,10 @@
335340

336341
<profiles>
337342
<profile>
338-
<!-- Enable per-test verbose grpc logs
339-
However, parallel test execution must be disabled to allow TestEnvRule to add/remove the
340-
appender -->
341343
<id>enable-verbose-grpc-logs</id>
342344
<properties>
343345
<bigtable.enable-grpc-logs>true</bigtable.enable-grpc-logs>
344-
<!-- NOTE: bigtable.grpc-log-dir is configured separately for each execution -->
346+
<java-log-config>src/test/resources/logging-verbose.properties</java-log-config>
345347
</properties>
346348
<build>
347349
<plugins>
@@ -351,6 +353,7 @@
351353
<configuration>
352354
<forkCount>1</forkCount>
353355
<parallel>none</parallel>
356+
<redirectTestOutputToFile>true</redirectTestOutputToFile>
354357
</configuration>
355358
</plugin>
356359
</plugins>
@@ -495,7 +498,6 @@
495498
</goals>
496499
<configuration>
497500
<skip>false</skip>
498-
499501
<systemPropertyVariables>
500502
<bigtable.env>cloud</bigtable.env>
501503
<bigtable.data-endpoint>${bigtable.directpath-data-endpoint}</bigtable.data-endpoint>
@@ -730,6 +732,9 @@
730732

731733
<!-- print full stacktraces by default -->
732734
<trimStackTrace>false</trimStackTrace>
735+
<systemPropertyVariables>
736+
<java.util.logging.config.file>${java-log-config}</java.util.logging.config.file>
737+
</systemPropertyVariables>
733738
</configuration>
734739
</plugin>
735740

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/TestEnvRule.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,15 @@
2525
import com.google.cloud.bigtable.admin.v2.models.Cluster;
2626
import com.google.cloud.bigtable.admin.v2.models.Instance;
2727
import com.google.cloud.bigtable.admin.v2.models.UpdateAuthorizedViewRequest;
28-
import com.google.common.base.Joiner;
29-
import com.google.common.base.Preconditions;
30-
import com.google.common.base.Strings;
3128
import com.google.common.collect.ImmutableSet;
3229
import java.io.IOException;
33-
import java.nio.file.Files;
34-
import java.nio.file.Path;
35-
import java.nio.file.Paths;
3630
import java.util.ArrayList;
3731
import java.util.List;
3832
import java.util.Set;
3933
import java.util.concurrent.ExecutionException;
40-
import java.util.logging.FileHandler;
4134
import java.util.logging.Handler;
4235
import java.util.logging.Level;
4336
import java.util.logging.Logger;
44-
import java.util.logging.SimpleFormatter;
4537
import org.junit.rules.TestRule;
4638
import org.junit.runner.Description;
4739
import org.junit.runners.model.Statement;
@@ -107,8 +99,6 @@ protected void before(Description description) throws Throwable {
10799
.that(System.getenv())
108100
.doesNotContainKey(BIGTABLE_EMULATOR_HOST_ENV_VAR);
109101

110-
configureLogging(description);
111-
112102
switch (env) {
113103
case "emulator":
114104
testEnv = EmulatorEnv.createBundled();
@@ -125,33 +115,6 @@ protected void before(Description description) throws Throwable {
125115
testEnv.start();
126116
}
127117

128-
private void configureLogging(Description description) throws IOException {
129-
if (!BIGTABLE_ENABLE_VERBOSE_GRPC_LOGS) {
130-
return;
131-
}
132-
Preconditions.checkState(
133-
!Strings.isNullOrEmpty(BIGTABLE_GRPC_LOG_DIR),
134-
"The property "
135-
+ BIGTABLE_GRPC_LOG_DIR
136-
+ " must be set when verbose grpc logs are enabled");
137-
138-
Files.createDirectories(Paths.get(BIGTABLE_GRPC_LOG_DIR));
139-
140-
String basename =
141-
Joiner.on("-").useForNull("").join(description.getClassName(), description.getMethodName());
142-
Path logPath = Paths.get(BIGTABLE_GRPC_LOG_DIR, basename + ".log");
143-
144-
grpcLogHandler = new FileHandler(logPath.toString());
145-
grpcLogHandler.setFormatter(new SimpleFormatter());
146-
grpcLogHandler.setLevel(Level.ALL);
147-
148-
for (String grpcLoggerName : GRPC_LOGGER_NAMES) {
149-
Logger logger = Logger.getLogger(grpcLoggerName);
150-
logger.setLevel(Level.ALL);
151-
logger.addHandler(grpcLogHandler);
152-
}
153-
}
154-
155118
private void after() {
156119
try {
157120
cleanUpStale();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Verbose logging configuration used by enable-verbose-grpc-logs profile.
2+
handlers= java.util.logging.ConsoleHandler
3+
.level= FINEST
4+
5+
# hide "Connecting to the Bigtable emulator at localhost:XXXX" lines
6+
com.google.cloud.bigtable.data.v2.BigtableDataSettings.level=WARNING
7+
java.util.logging.ConsoleHandler.level = FINEST
8+
9+
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
10+
# time [level] loggerName: message
11+
java.util.logging.SimpleFormatter.format=%1$tT [%4$-7s] %2$s: %5$s%n
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
handlers= java.util.logging.ConsoleHandler
22
.level= INFO
33

4+
# hide "Connecting to the Bigtable emulator at localhost:XXXX" lines
5+
com.google.cloud.bigtable.data.v2.BigtableDataSettings.level=WARNING
46
java.util.logging.ConsoleHandler.level = INFO
5-
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
6-
7-
# Example to customize the SimpleFormatter output format
8-
# to print one-line log message like this:
9-
# <level>: <log message> [<date/time>]
10-
#
117

12-
#java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n
8+
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
139
# time [level] loggerName: message
1410
java.util.logging.SimpleFormatter.format=%1$tT [%4$-7s] %2$s: %5$s%n
1511

16-
# hide "Connecting to the Bigtable emulator at localhost:XXXX" lines
17-
com.google.cloud.bigtable.data.v2.BigtableDataSettings.level=WARNING
12+

0 commit comments

Comments
 (0)