diff --git a/.github/release-please.yml b/.github/release-please.yml index dce2c84509..7442886ff0 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1,2 +1,4 @@ releaseType: java-yoshi -bumpMinorPreMajor: true \ No newline at end of file +bumpMinorPreMajor: true +extraFiles: + - google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/ClientVersion.java diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml index a131e37901..6765dffe72 100644 --- a/google-cloud-bigtable/pom.xml +++ b/google-cloud-bigtable/pom.xml @@ -391,16 +391,6 @@ - - - src/main/templates - - **/*.java - - true - ${project.build.directory}/generated-sources/java - - org.codehaus.mojo diff --git a/google-cloud-bigtable/src/main/templates/com/google/cloud/bigtable/Version.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/Version.java similarity index 80% rename from google-cloud-bigtable/src/main/templates/com/google/cloud/bigtable/Version.java rename to google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/Version.java index 7f87f249dc..9a18460b1d 100644 --- a/google-cloud-bigtable/src/main/templates/com/google/cloud/bigtable/Version.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/Version.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Google LLC + * Copyright 2021 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ @InternalApi("For internal use only") public final class Version { - // The released version, populated by maven. - public static String VERSION = "${java-bigtable.version}"; + // {x-version-update-start:google-cloud-bigtable:current} + public static String VERSION = "1.22.1-SNAPSHOT"; + // {x-version-update-end} } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java index 8f2505c58f..902b86ffcd 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java @@ -21,7 +21,6 @@ import com.google.api.gax.batching.BatcherImpl; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.FixedCredentialsProvider; -import com.google.api.gax.core.GaxProperties; import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcRawCallableFactory; @@ -54,6 +53,7 @@ import com.google.bigtable.v2.ReadRowsResponse; import com.google.bigtable.v2.SampleRowKeysRequest; import com.google.bigtable.v2.SampleRowKeysResponse; +import com.google.cloud.bigtable.Version; import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.cloud.bigtable.data.v2.models.BulkMutation; import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; @@ -194,9 +194,7 @@ public static EnhancedBigtableStubSettings finalizeSettings( // Also annotate traces with library versions .put("gax", GaxGrpcProperties.getGaxGrpcVersion()) .put("grpc", GaxGrpcProperties.getGrpcVersion()) - .put( - "gapic", - GaxProperties.getLibraryVersion(EnhancedBigtableStubSettings.class)) + .put("gapic", Version.VERSION) .build()), // Add OpenCensus Metrics MetricsTracerFactory.create(tagger, stats, attributes), diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/VersionTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/VersionTest.java new file mode 100644 index 0000000000..e07f7a4a5a --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/VersionTest.java @@ -0,0 +1,33 @@ +/* + * Copyright 2021 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable; + +import static com.google.common.truth.Truth.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Smoke test to ensure that release tooling doesn't accidentally corrupt the version */ +@RunWith(JUnit4.class) +public class VersionTest { + @Test + public void testVersion() { + assertThat(Version.VERSION).matches("\\d+\\.\\d+\\.\\d(?:-SNAPSHOT)?"); + + assertThat(Version.VERSION).isGreaterThan("1.22.0"); + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java index 194123b1bd..36bb271ff0 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java @@ -18,11 +18,13 @@ import static com.google.common.truth.Truth.assertThat; import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.bigtable.v2.BigtableGrpc; import com.google.bigtable.v2.ReadRowsRequest; import com.google.bigtable.v2.ReadRowsResponse; import com.google.bigtable.v2.RowSet; +import com.google.cloud.bigtable.Version; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.cloud.bigtable.data.v2.BigtableDataSettings; import com.google.cloud.bigtable.data.v2.FakeServiceHelper; @@ -39,8 +41,17 @@ import io.grpc.ServerCall.Listener; import io.grpc.ServerCallHandler; import io.grpc.ServerInterceptor; +import io.grpc.internal.GrpcUtil; import io.grpc.stub.StreamObserver; +import io.opencensus.common.Scope; +import io.opencensus.trace.AttributeValue; +import io.opencensus.trace.Tracing; +import io.opencensus.trace.export.SpanData; +import io.opencensus.trace.export.SpanExporter.Handler; +import io.opencensus.trace.samplers.Samplers; import java.io.IOException; +import java.util.Collection; +import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; import org.junit.After; @@ -152,6 +163,61 @@ public void testUserAgent() throws InterruptedException { .containsMatch("bigtable-java/\\d+\\.\\d+\\.\\d+(?:-SNAPSHOT)?"); } + @Test + public void testSpanAttributes() throws InterruptedException { + final BlockingQueue spans = new ArrayBlockingQueue<>(100); + + // inject a temporary trace exporter + String handlerName = "stub-test-exporter"; + + Tracing.getExportComponent() + .getSpanExporter() + .registerHandler( + handlerName, + new Handler() { + @Override + public void export(Collection collection) { + spans.addAll(collection); + } + }); + + SpanData foundSpanData = null; + // Issue the rpc and grab the span + try { + try (Scope ignored = + Tracing.getTracer() + .spanBuilder("fake-parent-span") + .setSampler(Samplers.alwaysSample()) + .startScopedSpan()) { + enhancedBigtableStub.readRowCallable().call(Query.create("table-id").rowKey("row-key")); + } + + for (int i = 0; i < 100; i++) { + SpanData spanData = spans.poll(10, TimeUnit.SECONDS); + if ("Bigtable.ReadRow".equals(spanData.getName())) { + foundSpanData = spanData; + break; + } + } + } finally { + // cleanup + Tracing.getExportComponent().getSpanExporter().unregisterHandler(handlerName); + } + + // Examine the caught span + assertThat(foundSpanData).isNotNull(); + assertThat(foundSpanData.getAttributes().getAttributeMap()) + .containsEntry("gapic", AttributeValue.stringAttributeValue(Version.VERSION)); + assertThat(foundSpanData.getAttributes().getAttributeMap()) + .containsEntry( + "grpc", + AttributeValue.stringAttributeValue( + GrpcUtil.getGrpcBuildVersion().getImplementationVersion())); + assertThat(foundSpanData.getAttributes().getAttributeMap()) + .containsEntry( + "gax", AttributeValue.stringAttributeValue(GaxGrpcProperties.getGaxGrpcVersion())); + } + private static class MetadataInterceptor implements ServerInterceptor { final BlockingQueue headers = Queues.newLinkedBlockingDeque(); diff --git a/synth.py b/synth.py index e26edaac07..4e48e756b0 100644 --- a/synth.py +++ b/synth.py @@ -41,6 +41,10 @@ def main(): # todo remove once template is updated '.github/ISSUE_TEMPLATE/bug_report.md', 'CONTRIBUTING.md', + # exclude autogen + 'codecov.yaml' + # needed for extraFiles + '.github/release-please.yml', ]) def generate_data_api(gapic):