Skip to content

Commit 1af8925

Browse files
chore: improve embedded version handling (googleapis#715)
* chore: improve embedded version handling Use new feature in releasetool (googleapis/releasetool#317) to manage the client version instead of maven tricks introduced in googleapis#451 * migrate to new version scheme * rename back to Version * config release-please for version bumps * make sure file doesnt get clobbered * add a couple of tests * fmt
1 parent b61c5ce commit 1af8925

File tree

7 files changed

+110
-18
lines changed

7 files changed

+110
-18
lines changed

.github/release-please.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
releaseType: java-yoshi
2-
bumpMinorPreMajor: true
2+
bumpMinorPreMajor: true
3+
extraFiles:
4+
- google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/ClientVersion.java

google-cloud-bigtable/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -427,16 +427,6 @@
427427
</profiles>
428428

429429
<build>
430-
<resources>
431-
<resource>
432-
<directory>src/main/templates</directory>
433-
<includes>
434-
<include>**/*.java</include>
435-
</includes>
436-
<filtering>true</filtering>
437-
<targetPath>${project.build.directory}/generated-sources/java</targetPath>
438-
</resource>
439-
</resources>
440430
<plugins>
441431
<plugin>
442432
<groupId>org.codehaus.mojo</groupId>

google-cloud-bigtable/src/main/templates/com/google/cloud/bigtable/Version.java renamed to google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/Version.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 Google LLC
2+
* Copyright 2021 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919

2020
@InternalApi("For internal use only")
2121
public final class Version {
22-
// The released version, populated by maven.
23-
public static String VERSION = "${java-bigtable.version}";
22+
// {x-version-update-start:google-cloud-bigtable:current}
23+
public static String VERSION = "1.22.1-SNAPSHOT";
24+
// {x-version-update-end}
2425
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.api.gax.batching.FlowController;
2323
import com.google.api.gax.core.BackgroundResource;
2424
import com.google.api.gax.core.FixedCredentialsProvider;
25-
import com.google.api.gax.core.GaxProperties;
2625
import com.google.api.gax.grpc.GaxGrpcProperties;
2726
import com.google.api.gax.grpc.GrpcCallSettings;
2827
import com.google.api.gax.grpc.GrpcRawCallableFactory;
@@ -55,6 +54,7 @@
5554
import com.google.bigtable.v2.ReadRowsResponse;
5655
import com.google.bigtable.v2.SampleRowKeysRequest;
5756
import com.google.bigtable.v2.SampleRowKeysResponse;
57+
import com.google.cloud.bigtable.Version;
5858
import com.google.cloud.bigtable.data.v2.internal.RequestContext;
5959
import com.google.cloud.bigtable.data.v2.models.BulkMutation;
6060
import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
@@ -199,9 +199,7 @@ public static EnhancedBigtableStubSettings finalizeSettings(
199199
// Also annotate traces with library versions
200200
.put("gax", GaxGrpcProperties.getGaxGrpcVersion())
201201
.put("grpc", GaxGrpcProperties.getGrpcVersion())
202-
.put(
203-
"gapic",
204-
GaxProperties.getLibraryVersion(EnhancedBigtableStubSettings.class))
202+
.put("gapic", Version.VERSION)
205203
.build()),
206204
// Add OpenCensus Metrics
207205
MetricsTracerFactory.create(tagger, stats, attributes),
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.bigtable;
17+
18+
import static com.google.common.truth.Truth.assertThat;
19+
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
import org.junit.runners.JUnit4;
23+
24+
/** Smoke test to ensure that release tooling doesn't accidentally corrupt the version */
25+
@RunWith(JUnit4.class)
26+
public class VersionTest {
27+
@Test
28+
public void testVersion() {
29+
assertThat(Version.VERSION).matches("\\d+\\.\\d+\\.\\d(?:-SNAPSHOT)?");
30+
31+
assertThat(Version.VERSION).isGreaterThan("1.22.0");
32+
}
33+
}

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import com.google.api.gax.batching.FlowControlSettings;
2323
import com.google.api.gax.batching.FlowController.LimitExceededBehavior;
2424
import com.google.api.gax.core.NoCredentialsProvider;
25+
import com.google.api.gax.grpc.GaxGrpcProperties;
2526
import com.google.api.gax.rpc.ServerStreamingCallable;
2627
import com.google.bigtable.v2.BigtableGrpc;
2728
import com.google.bigtable.v2.ReadRowsRequest;
2829
import com.google.bigtable.v2.ReadRowsResponse;
2930
import com.google.bigtable.v2.RowSet;
31+
import com.google.cloud.bigtable.Version;
3032
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
3133
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
3234
import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
@@ -43,8 +45,17 @@
4345
import io.grpc.ServerCall.Listener;
4446
import io.grpc.ServerCallHandler;
4547
import io.grpc.ServerInterceptor;
48+
import io.grpc.internal.GrpcUtil;
4649
import io.grpc.stub.StreamObserver;
50+
import io.opencensus.common.Scope;
51+
import io.opencensus.trace.AttributeValue;
52+
import io.opencensus.trace.Tracing;
53+
import io.opencensus.trace.export.SpanData;
54+
import io.opencensus.trace.export.SpanExporter.Handler;
55+
import io.opencensus.trace.samplers.Samplers;
4756
import java.io.IOException;
57+
import java.util.Collection;
58+
import java.util.concurrent.ArrayBlockingQueue;
4859
import java.util.concurrent.BlockingQueue;
4960
import java.util.concurrent.TimeUnit;
5061
import org.junit.After;
@@ -157,6 +168,61 @@ public void testUserAgent() throws InterruptedException {
157168
.containsMatch("bigtable-java/\\d+\\.\\d+\\.\\d+(?:-SNAPSHOT)?");
158169
}
159170

171+
@Test
172+
public void testSpanAttributes() throws InterruptedException {
173+
final BlockingQueue<SpanData> spans = new ArrayBlockingQueue<>(100);
174+
175+
// inject a temporary trace exporter
176+
String handlerName = "stub-test-exporter";
177+
178+
Tracing.getExportComponent()
179+
.getSpanExporter()
180+
.registerHandler(
181+
handlerName,
182+
new Handler() {
183+
@Override
184+
public void export(Collection<SpanData> collection) {
185+
spans.addAll(collection);
186+
}
187+
});
188+
189+
SpanData foundSpanData = null;
190+
// Issue the rpc and grab the span
191+
try {
192+
try (Scope ignored =
193+
Tracing.getTracer()
194+
.spanBuilder("fake-parent-span")
195+
.setSampler(Samplers.alwaysSample())
196+
.startScopedSpan()) {
197+
enhancedBigtableStub.readRowCallable().call(Query.create("table-id").rowKey("row-key"));
198+
}
199+
200+
for (int i = 0; i < 100; i++) {
201+
SpanData spanData = spans.poll(10, TimeUnit.SECONDS);
202+
if ("Bigtable.ReadRow".equals(spanData.getName())) {
203+
foundSpanData = spanData;
204+
break;
205+
}
206+
}
207+
} finally {
208+
// cleanup
209+
Tracing.getExportComponent().getSpanExporter().unregisterHandler(handlerName);
210+
}
211+
212+
// Examine the caught span
213+
assertThat(foundSpanData).isNotNull();
214+
assertThat(foundSpanData.getAttributes().getAttributeMap())
215+
.containsEntry("gapic", AttributeValue.stringAttributeValue(Version.VERSION));
216+
assertThat(foundSpanData.getAttributes().getAttributeMap())
217+
.containsEntry(
218+
"grpc",
219+
AttributeValue.stringAttributeValue(
220+
GrpcUtil.getGrpcBuildVersion().getImplementationVersion()));
221+
assertThat(foundSpanData.getAttributes().getAttributeMap())
222+
.containsEntry(
223+
"gax", AttributeValue.stringAttributeValue(GaxGrpcProperties.getGaxGrpcVersion()));
224+
}
225+
160226
@Test
161227
public void testBulkMutationFlowControllerConfigured() throws Exception {
162228
BigtableDataSettings.Builder settings =

synth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def main():
4343
'CONTRIBUTING.md',
4444
# exclude autogen
4545
'codecov.yaml'
46+
# needed for extraFiles
47+
'.github/release-please.yml',
4648
])
4749

4850
def generate_data_api(gapic):

0 commit comments

Comments
 (0)